summaryrefslogtreecommitdiff
path: root/src/utils/paths.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-07 02:18:27 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-07 02:18:27 +0300
commit0f85899c0aad7d6dbc15490189e97a68b4653d1c (patch)
tree08e31a7fbbd5661a7a1791cd7858f7581236e0d3 /src/utils/paths.cpp
parent4c057739d0538d01481643848a6cb558e0ef4e51 (diff)
downloadmv-0f85899c0aad7d6dbc15490189e97a68b4653d1c.tar.gz
mv-0f85899c0aad7d6dbc15490189e97a68b4653d1c.tar.bz2
mv-0f85899c0aad7d6dbc15490189e97a68b4653d1c.tar.xz
mv-0f85899c0aad7d6dbc15490189e97a68b4653d1c.zip
Get real desktop dir in linux for screenshots.
Diffstat (limited to 'src/utils/paths.cpp')
-rw-r--r--src/utils/paths.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index 228276efd..c9ade0e68 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -18,10 +18,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef _MSC_VER
+# include "msvc/config.h"
+#elif defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
+
#include "utils/paths.h"
#include "utils/stringutils.h"
+#include "resources/resourcemanager.h"
+
#include <string.h>
#include <cstdarg>
#include <cstdio>
@@ -128,3 +136,42 @@ std::string getSelfName()
}
#endif
+
+std::string getDesktopDir()
+{
+#ifdef WIN32
+ std::string dir = getSpecialFolderLocation(CSIDL_MYPICTURES);
+ if (dir.empty())
+ dir = getSpecialFolderLocation(CSIDL_DESKTOP);
+ return dir;
+#elif USE_X11
+ char *xdg = getenv("XDG_CONFIG_HOME");
+ std::string file;
+ if (!xdg)
+ file = std::string(PHYSFS_getUserDir()) + "/.config/user-dirs.dirs";
+ else
+ file = std::string(xdg) + "/user-dirs.dirs";
+
+ StringVect arr = ResourceManager::loadTextFileLocal(file);
+ for(StringVectCIter it = arr.begin(), it_end = arr.end();
+ it != it_end; ++ it)
+ {
+ std::string str = *it;
+ if (findCutFirst(str, "XDG_DESKTOP_DIR=\""))
+ {
+ str = str.substr(0, str.size() - 1);
+ // use hack to replace $HOME var.
+ // if in string other vars, fallback to default path
+ replaceAll(str, "$HOME/", PHYSFS_getUserDir());
+ str = getRealPath(str);
+ if (str.empty())
+ str = std::string(PHYSFS_getUserDir()) + "Desktop";
+ return str;
+ }
+ }
+
+ return std::string(PHYSFS_getUserDir()) + "Desktop";
+#else
+ return std::string(PHYSFS_getUserDir()) + "Desktop";
+#endif
+}