From: Lukas Hrazky Date: Fri, 30 Jul 2010 20:39:01 +0000 (+0200) Subject: fixed entering path from the addressbar X-Git-Tag: v0.2.0~1 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=71b9286224a9549314cc43feb41bca396b690bd0;p=case fixed entering path from the addressbar By replacing ~ back to home dir path. Qt can't deal with ~ as a shortcut. Signed-off-by: Lukas Hrazky --- diff --git a/src/filelist.cpp b/src/filelist.cpp index 3d9c8c4..9b52332 100644 --- a/src/filelist.cpp +++ b/src/filelist.cpp @@ -23,6 +23,8 @@ #include #include +#include "fileoperator.h" + FileList::FileList(QWidget *parent) : QListView(parent), @@ -58,6 +60,7 @@ const QString FileList::path() const { bool FileList::changePath(QString path) { + path = FileOperator::unwindPath(path); QDir dir(fileSystemModel->rootPath()); if (dir.cd(path)) { setRootIndex(fileSystemModel->setRootPath(dir.absolutePath())); diff --git a/src/fileoperator.cpp b/src/fileoperator.cpp index a779a87..1dcdae8 100644 --- a/src/fileoperator.cpp +++ b/src/fileoperator.cpp @@ -106,9 +106,27 @@ FileOperator::FileOperator(QWidget *parent) : QWidget(parent) { QString FileOperator::shortenPath(const QString &path) { QString homePath = QFSFileEngine::homePath(); - QString result = path; + if (path.indexOf(homePath, 0) == 0) { + QString result = path; + result.replace(0, homePath.size(), "~"); + return result; + } + + return path; +} + + +QString FileOperator::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; diff --git a/src/fileoperator.h b/src/fileoperator.h index 4d2563b..76f5535 100644 --- a/src/fileoperator.h +++ b/src/fileoperator.h @@ -42,6 +42,7 @@ public: FileOperator(QWidget *parent = 0); static QString shortenPath(const QString &path); + static QString unwindPath(const QString &path); void deleteFiles(const QFileInfoList &files); void copyFiles(const QFileInfoList &files, QDir &destination);