code cleanup
[case] / src / utils.cpp
index bf082e0..8a50e16 100644 (file)
 
 #include "utils.h"
 
+#include <QFSFileEngine>
+
+
+QString shortenPath(const QString &path) {
+    QString homePath = QFSFileEngine::homePath();
+
+    if (path.indexOf(homePath, 0) == 0) {
+        QString result = path;
+
+        result.replace(0, homePath.size(), "~");
+        return result;
+    }
+
+    return path;
+}
+
+
+QString unwindPath(const QString &path) {
+    QString result = path;
+    // if ~ is the first character and / or nothing follows it, replace with home dir
+    if (path == "~" || path.indexOf("~/", 0) == 0) {
+        QString homePath = QFSFileEngine::homePath();
+        result.replace(0, 1, homePath);
+    // in case someone wants to enter a dir called ~ in the current dir, he can escape it with \~
+    } else if (path == "\\~" || path.indexOf("\\~/", 0) == 0) {
+        result.replace(0, 2, "~");
+    }
+
+    return result;
+}
+
 
 void themeImage(const QPalette &p, QImage &image, const bool inverse) {
     image = image.convertToFormat(QImage::Format_Indexed8);