X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Futils.cpp;h=8a50e160341f8abe393580f1b490b8c5fe50cd44;hb=2edb4f2f10329116492492b442c2957653381c28;hp=bf082e0cc4bfe8ea00f7d3c5d3b730996deadf2c;hpb=55d99074d0b0b5eca3530d0c0f683faee48f10f9;p=case diff --git a/src/utils.cpp b/src/utils.cpp index bf082e0..8a50e16 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -17,6 +17,37 @@ #include "utils.h" +#include + + +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);