From 8c6f14a8bbe9d5a74878ee5226cddd864b842983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Thu, 4 Sep 2014 17:33:32 -0400 Subject: [PATCH] fileutils: compute DATA_HOME accoding to the spec http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html Change-Id: Ic136ac98a8b4be554d1fb6e530ebbe1c2af0186a --- daemon/src/client/configurationmanager.cpp | 2 +- daemon/src/fileutils.cpp | 16 +++++++++++++++- daemon/src/fileutils.h | 3 ++- daemon/src/history/history.cpp | 7 +------ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/daemon/src/client/configurationmanager.cpp b/daemon/src/client/configurationmanager.cpp index 034e43cdc1..381ad9be59 100644 --- a/daemon/src/client/configurationmanager.cpp +++ b/daemon/src/client/configurationmanager.cpp @@ -302,7 +302,7 @@ void ConfigurationManager::setAgcState(const bool& enabled) std::map<std::string, std::string> ConfigurationManager::getRingtoneList() { std::map<std::string, std::string> ringToneList; - std::string r_path(fileutils::get_data_dir()); + std::string r_path(fileutils::get_ringtone_dir()); struct dirent **namelist; int n = scandir(r_path.c_str(), &namelist, 0, alphasort); if (n == -1) { diff --git a/daemon/src/fileutils.cpp b/daemon/src/fileutils.cpp index 971633ae57..28cbadce45 100644 --- a/daemon/src/fileutils.cpp +++ b/daemon/src/fileutils.cpp @@ -94,7 +94,7 @@ const char *get_program_dir() // FIXME: This should use our real DATADIR std::string -get_data_dir() +get_ringtone_dir() { return std::string(get_program_dir()) + "/../../share/sflphone/ringtones/"; } @@ -264,4 +264,18 @@ get_home_dir() return ""; #endif } + +std::string +get_data_dir() +{ +#ifdef __ANDROID__ + return get_program_dir(); +#endif + const std::string data_home(XDG_DATA_HOME); + if (not data_home.empty()) + return data_home + DIR_SEPARATOR_STR + PACKAGE; + // "If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used." + return get_home_dir()+DIR_SEPARATOR_STR".local"DIR_SEPARATOR_STR"share"DIR_SEPARATOR_STR + PACKAGE; +} + } diff --git a/daemon/src/fileutils.h b/daemon/src/fileutils.h index 474e64c704..c981f5f980 100644 --- a/daemon/src/fileutils.h +++ b/daemon/src/fileutils.h @@ -47,12 +47,13 @@ #define DIR_SEPARATOR_CH '/' // Directory separator string namespace fileutils { + std::string get_data_dir(); std::string get_home_dir(); std::string get_cache_dir(); bool check_dir(const char *path); void set_program_dir(char *program_path); const char *get_program_dir(); - std::string get_data_dir(); + std::string get_ringtone_dir(); std::string expand_path(const std::string &path); bool isDirectoryWritable(const std::string &directory); struct FileHandle { diff --git a/daemon/src/history/history.cpp b/daemon/src/history/history.cpp index d944abd06c..b95f24dd76 100644 --- a/daemon/src/history/history.cpp +++ b/daemon/src/history/history.cpp @@ -98,12 +98,7 @@ void History::ensurePath() #ifdef __ANDROID__ path_ = fileutils::get_home_dir() + DIR_SEPARATOR_STR + "history"; #else - const string xdg_data = fileutils::get_home_dir() + DIR_SEPARATOR_STR + - ".local/share/sflphone"; - // If the environment variable is set (not null and not empty), we'll use it to save the history - // Else we 'll the standard one, ie: XDG_DATA_HOME = $HOME/.local/share/sflphone - string xdg_env(XDG_DATA_HOME); - const string userdata = not xdg_env.empty() ? xdg_env : xdg_data; + const string userdata = fileutils::get_data_dir(); if (mkdir(userdata.data(), 0755) != 0) { // If directory creation failed -- GitLab