Selective Sync: Open sub folder context menu #5596
authorMarkus Goetz <markus@woboq.com>
Wed, 26 Apr 2017 18:03:55 +0000 (20:03 +0200)
committerMarkus Goetz <markus@woboq.com>
Mon, 8 May 2017 09:24:02 +0000 (11:24 +0200)
src/gui/accountsettings.cpp
src/gui/accountsettings.h
src/gui/folderstatusdelegate.h
src/gui/folderstatusmodel.cpp

index 7d040b1892d33f98efb8e47a0fd27f5ebd659938..92b451520f6dfd0e3dc3fca630c1a4bcf6001019 100644 (file)
@@ -98,7 +98,8 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) :
             SLOT(slotAccountAdded(AccountState*)));
     connect(ui->_folderList, SIGNAL(customContextMenuRequested(QPoint)),
             this, SLOT(slotCustomContextMenuRequested(QPoint)));
-
+    connect(ui->_folderList, SIGNAL(clicked(const QModelIndex &)),
+            this, SLOT(slotFolderListClicked(const QModelIndex&)));
     connect(ui->_folderList, SIGNAL(expanded(QModelIndex)) , this, SLOT(refreshSelectiveSyncStatus()));
     connect(ui->_folderList, SIGNAL(collapsed(QModelIndex)) , this, SLOT(refreshSelectiveSyncStatus()));
     connect(ui->selectiveSyncNotification, SIGNAL(linkActivated(QString)),
@@ -119,8 +120,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) :
     connect(syncNowWithRemoteDiscovery, SIGNAL(triggered()), SLOT(slotScheduleCurrentFolderForceRemoteDiscovery()));
     addAction(syncNowWithRemoteDiscovery);
 
-    connect(ui->_folderList, SIGNAL(clicked(const QModelIndex &)),
-            this, SLOT(slotFolderListClicked(const QModelIndex&)));
+
 
     connect(ui->selectiveSyncApply, SIGNAL(clicked()), _model, SLOT(slotApplySelectiveSync()));
     connect(ui->selectiveSyncCancel, SIGNAL(clicked()), _model, SLOT(resetFolders()));
@@ -222,6 +222,24 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
         return;
     }
 
+    if (_model->classify(index) == FolderStatusModel::SubFolder) {
+        QTreeView *tv = ui->_folderList;
+        QMenu *menu = new QMenu(tv);
+        menu->setAttribute(Qt::WA_DeleteOnClose);
+
+        QAction *ac = menu->addAction(tr("Open folder"));
+        connect(ac, SIGNAL(triggered(bool)), this, SLOT(slotOpenCurrentLocalSubFolder()));
+
+        QString fileName = _model->data( index, FolderStatusDelegate::FolderPathRole ).toString();
+        if (!QFile::exists(fileName)) {
+            ac->setEnabled(false);
+        }
+
+        menu->exec(QCursor::pos());
+
+        return;
+    }
+
     if (_model->classify(index) != FolderStatusModel::RootFolder) {
         return;
     }
@@ -264,6 +282,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
 void AccountSettings::slotFolderListClicked(const QModelIndex& indx)
 {
     if (indx.data(FolderStatusDelegate::AddButton).toBool()) {
+        // "Add Folder Sync Connection"
         if (indx.flags() & Qt::ItemIsEnabled) {
             slotAddFolder();
         } else {
@@ -403,6 +422,16 @@ void AccountSettings::slotOpenCurrentFolder()
     }
 }
 
+void AccountSettings::slotOpenCurrentLocalSubFolder()
+{
+    QModelIndex selected = ui->_folderList->selectionModel()->currentIndex();
+    if( !selected.isValid() || _model->classify(selected) != FolderStatusModel::SubFolder)
+        return;
+    QString fileName = _model->data( selected, FolderStatusDelegate::FolderPathRole ).toString();
+    QUrl url = QUrl::fromLocalFile(fileName);
+    QDesktopServices::openUrl(url);
+}
+
 void AccountSettings::showConnectionLabel( const QString& message, QStringList errors )
 {
     const QString errStyle = QLatin1String("color:#ffffff; background-color:#bb4d4d;padding:5px;"
index e5729409d37f34e2a1d4573bcf32ef8ecc258cfd..5ad47239733ef426f4ebb126c77bca7a73e37926 100644 (file)
@@ -75,7 +75,8 @@ protected slots:
     void slotScheduleCurrentFolderForceRemoteDiscovery();
     void slotForceSyncCurrentFolder();
     void slotRemoveCurrentFolder();
-    void slotOpenCurrentFolder();
+    void slotOpenCurrentFolder(); // sync folder
+    void slotOpenCurrentLocalSubFolder(); // selected subfolder in sync folder
     void slotFolderWizardAccepted();
     void slotFolderWizardRejected();
     void slotDeleteAccount();
index 85dab6ec536583be45f5e4077bca460ac28ae623..6d533258d1cfcb65abe522391d12d2455f39f682 100644 (file)
@@ -31,7 +31,7 @@ public:
 
     enum datarole { FolderAliasRole = Qt::UserRole + 100,
                     HeaderRole,
-                    FolderPathRole,
+                    FolderPathRole, // for a SubFolder it's the complete path
                     FolderSecondPathRole,
                     FolderErrorMsg,
                     FolderSyncPaused,
index 42c34d1e4f3412936faca2b18bcebbcc5accf2e7..8eca32b61cc96abac2b9f392f3cc01f139d23117 100644 (file)
@@ -178,6 +178,12 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
                 return QColor(Qt::red);
             }
             break;
+        case FolderStatusDelegate::FolderPathRole: {
+            auto f = x._folder;
+            if (!f)
+                return QVariant();
+            return QVariant(f->path() + x._path);
+            }
         }
     }
         return QVariant();