Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Follow XDG Base Directory spec on Linux #1624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion src/core/Helpers/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <QtCore/QFileInfo>
#include <QtCore/QCoreApplication>
#include <QDateTime>
#if defined(Q_OS_MACX) || defined(WIN32)
#else
#include <QStandardPaths>
#endif

#ifdef H2CORE_HAVE_OSC
#include <core/NsmClient.h>
Expand Down Expand Up @@ -100,14 +104,16 @@ const QString Filesystem::playlists_filter_name = "Hydrogen Playlists (*.h2playl

QString Filesystem::__sys_data_path;
QString Filesystem::__usr_data_path;
QString Filesystem::__usr_cache_path;
QString Filesystem::__usr_cfg_path;

#ifdef Q_OS_MACX
QString Filesystem::__usr_log_path =QDir::homePath().append( "/Library/Application Support/Hydrogen/" LOG_FILE );
#elif WIN32
QString Filesystem::__usr_log_path = QDir::homePath().append( "/.hydrogen/" LOG_FILE );
#else
QString Filesystem::__usr_log_path = QDir::homePath().append( "/" H2_USR_PATH "/" LOG_FILE);
QString Filesystem::__usr_log_path = QDir::homePath().append( "/" H2_USR_PATH "/" );
bool __usr_log_path_initialized = false;
#endif


Expand Down Expand Up @@ -412,9 +418,36 @@ bool Filesystem::check_sys_paths()
}


#if defined(Q_OS_MACX) || defined(WIN32)
#else
void Filesystem::update_usr_paths()
{
// If the old path exists (e.g. ~/.hydrogen), old path is used; else uses
// QStandardPaths to get XDG Paths on Linux.
if ( !QFileInfo::exists( QFileInfo(__usr_cfg_path).absolutePath() ) )
{
__usr_cfg_path = QStandardPaths::writableLocation(
QStandardPaths::AppConfigLocation).append("/" USR_CONFIG);
__usr_data_path = QStandardPaths::writableLocation(
QStandardPaths::AppLocalDataLocation).append("/");
__usr_cache_path = QStandardPaths::writableLocation(
QStandardPaths::CacheLocation).append("/");
} else {
__usr_cache_path = __usr_data_path + CACHE;
}
}
#endif


bool Filesystem::check_usr_paths()
{
bool ret = true;

#if defined(Q_OS_MACX) || defined(WIN32)
#else
update_usr_paths();
if ( !path_usable( QFileInfo(__usr_cfg_path).absolutePath() ) ) ret = false;
#endif
if( !path_usable( tmp_dir() ) ) ret = false;
if( !path_usable( __usr_data_path ) ) ret = false;
if( !path_usable( cache_dir() ) ) ret = false;
Expand Down Expand Up @@ -518,6 +551,20 @@ QString Filesystem::playlist_xsd_path( )
}
QString Filesystem::log_file_path()
{
#if defined(Q_OS_MACX) || defined(WIN32)
#else
if ( !__usr_log_path_initialized )
{
if ( !QFileInfo::exists( __usr_log_path ) )
{
__usr_log_path = QStandardPaths::writableLocation(
QStandardPaths::AppLocalDataLocation).append( "/" LOG_FILE );
} else {
__usr_log_path.append( LOG_FILE );
}
__usr_log_path_initialized = true;
}
#endif
return __usr_log_path;
}

Expand Down Expand Up @@ -592,11 +639,19 @@ QString Filesystem::playlist_path( const QString& pl_name )
}
QString Filesystem::cache_dir()
{
#if defined(Q_OS_MACX) || defined(WIN32)
return __usr_data_path + CACHE;
#else
return __usr_cache_path;
#endif
}
QString Filesystem::repositories_cache_dir()
{
#if defined(Q_OS_MACX) || defined(WIN32)
return __usr_data_path + CACHE + REPOSITORIES;
#else
return __usr_cache_path + REPOSITORIES;
#endif
}
QString Filesystem::demos_dir()
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/Helpers/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ namespace H2Core
*/
static bool check_permissions( const QString& path, const int perms, bool silent );

/**
* Update the data, config and cache paths with QStandardPaths if old
* folder doesn't exist (e.g. ~/.hydrogen/).
*/
static void update_usr_paths();

/**
* Path to the system files set in Filesystem::bootstrap().
*
Expand All @@ -471,6 +477,7 @@ namespace H2Core
*/
static QString __sys_data_path; ///< the path to the system files
static QString __usr_data_path; ///< the path to the user files
static QString __usr_cache_path; ///< the path to the cache files
static QString __usr_cfg_path; ///< the path to the user config file
static QString __usr_log_path; ///< the path to the log file
static QStringList __ladspa_paths; ///< paths to laspa plugins
Expand Down