From e0a636050df98da817ff1e22d78155c60437579a Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Thu, 30 Jul 2009 18:04:17 -0400 Subject: [PATCH] [#1791] If XDG env variables are not null but empty, use default ones --- sflphone-common/src/history/historymanager.cpp | 16 +++++++++++++--- sflphone-common/src/managerimpl.cpp | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/sflphone-common/src/history/historymanager.cpp b/sflphone-common/src/history/historymanager.cpp index 8e9be9380e..39cba3ae7e 100644 --- a/sflphone-common/src/history/historymanager.cpp +++ b/sflphone-common/src/history/historymanager.cpp @@ -146,13 +146,23 @@ void HistoryManager::add_new_history_entry (HistoryItem *new_item) int HistoryManager::create_history_path (std::string path) { - std::string filename, userdata; + std::string filename, userdata, xdg_env, xdg_data; + + xdg_data = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".local/share"; if (path == "") { // TODO Should use $XDG_DATA_HOME (which default to .local/share) instead of HOMEDIR - (XDG_DATA_HOME != NULL) ? userdata = std::string (XDG_DATA_HOME) : userdata = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".local/share"; - filename = userdata + DIR_SEPARATOR_STR + PROGDIR; + if (XDG_DATA_HOME != NULL) + { + xdg_env = std::string (XDG_DATA_HOME); + (xdg_env.length() > 0) ? userdata = xdg_env + : userdata = xdg_data; + } + else + userdata = xdg_data; + + filename = userdata + DIR_SEPARATOR_STR + PROGDIR; if (mkdir (filename.data(), 0755) != 0) { // If directory creation failed diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index e38a7b0ab1..ad14f21a19 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -1291,10 +1291,21 @@ int ManagerImpl::createSettingsPath (void) { - //_path = std::string (HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR; - (XDG_CONFIG_HOME != NULL) ? _path = std::string (XDG_CONFIG_HOME) - : _path = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".config" + DIR_SEPARATOR_STR + PROGDIR; + std::string xdg_config, xdg_env; + + _debug ("XDG_CONFIG_HOME: %s\n", XDG_CONFIG_HOME); + xdg_config = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".config" + DIR_SEPARATOR_STR + PROGDIR; + + //_path = std::string (HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR; + if (XDG_CONFIG_HOME != NULL) + { + xdg_env = std::string (XDG_CONFIG_HOME); + (xdg_env.length() > 0) ? _path = xdg_env + : _path = xdg_config; + } + else + _path = xdg_config; if (mkdir (_path.data(), 0700) != 0) { // If directory creation failed -- GitLab