Fix folder opening in ActivityListModel
authorMichael Schuster <michael@schuster.ms>
Sun, 22 Dec 2019 05:16:27 +0000 (06:16 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Tue, 24 Dec 2019 06:42:01 +0000 (07:42 +0100)
After fixing the crash in the previous commit, double-clicking on Activity list rows still didn't work.

This fix partly reverts commit 8546d53b05a76271e245f085d1caa5d405dadb8d in ActivityItemDelegate::PathRole
of ActivityListModel::data, but adds a new check for relPath's existence in line 74.

I'm assuming the previous change there has been done to shorten the code and avoid opening the user's home
folder upon clicking entries which file value is "App Password". The new path-check takes care of that too now.

Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/activitylistmodel.cpp

index 59598c71be1be5bdec5ad4ce65ee41dbf9d52144..eeb0cc836fe2dc201c093585ac7b388a8cc40cd4 100644 (file)
@@ -64,12 +64,19 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
     case ActivityItemDelegate::PathRole:
         if(!a._file.isEmpty()){
             auto folder = FolderMan::instance()->folder(a._folder);
-            if(!folder)
-                return QVariant();
-            list = FolderMan::instance()->findFileInLocalFolders(folder->remotePath(), ast->account());
+            QString relPath(a._file);
+            if(folder) relPath.prepend(folder->remotePath());
+            list = FolderMan::instance()->findFileInLocalFolders(relPath, ast->account());
             if (list.count() > 0) {
                 return QVariant(list.at(0));
             }
+            // File does not exist anymore? Let's try to open its path
+            if(QFileInfo(relPath).exists()) {
+                list = FolderMan::instance()->findFileInLocalFolders(QFileInfo(relPath).path(), ast->account());
+                if (list.count() > 0) {
+                    return QVariant(list.at(0));
+                }
+            }
         }
         return QVariant();
      case ActivityItemDelegate::ActionsLinksRole:{