diff --git a/daemon/src/client/configurationmanager.cpp b/daemon/src/client/configurationmanager.cpp index 034e43cdc189977d5af65a8583d5906104a11987..381ad9be593baa5be6dc649d5859d46c2dc34487 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 971633ae579122f18769c728d04942c079b33cea..28cbadce4523ebd73cba36b8b0e6aa229b6cfe51 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 474e64c704392cc75a9cf41059b866ad4ba7353b..c981f5f980c69d8e4e22908267b90a9859e1aa0d 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 d944abd06c64cd84ee1167938e68dba45928fd64..b95f24dd7641ce1e51b97c95e0d16e0d5b3c6c1a 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