Skip to content
Snippets Groups Projects
Commit 8c6f14a8 authored by Adrien Béraud's avatar Adrien Béraud Committed by Tristan Matthews
Browse files

fileutils: compute DATA_HOME accoding to the spec

http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

Change-Id: Ic136ac98a8b4be554d1fb6e530ebbe1c2af0186a
parent 28de301d
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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;
}
}
......@@ -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 {
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment