diff --git a/sflphone-common/src/history/historymanager.cpp b/sflphone-common/src/history/historymanager.cpp
index 8e9be9380ea8c89843beaf80c731ab5f298021ea..39cba3ae7e9ae5fb896412726d7a387df0d55789 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 e38a7b0ab1e5b744282ce0b90baa10c8e2cf2afe..ad14f21a1906b98eee3257a5278af29028e5a1d8 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