fixed entering path from the addressbar
authorLukas Hrazky <lukkash@email.cz>
Fri, 30 Jul 2010 20:39:01 +0000 (22:39 +0200)
committerLukas Hrazky <lukkash@email.cz>
Fri, 30 Jul 2010 20:39:01 +0000 (22:39 +0200)
By replacing ~ back to home dir path. Qt can't deal with ~ as a
shortcut.

Signed-off-by: Lukas Hrazky <lukkash@email.cz>

src/filelist.cpp
src/fileoperator.cpp
src/fileoperator.h

index 3d9c8c4..9b52332 100644 (file)
@@ -23,6 +23,8 @@
 #include <hildon-mime.h>
 #include <dbus/dbus.h>
 
+#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()));
index a779a87..1dcdae8 100644 (file)
@@ -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;
index 4d2563b..76f5535 100644 (file)
@@ -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);