From: Markus Goetz Date: Wed, 26 Apr 2017 18:03:55 +0000 (+0200) Subject: Selective Sync: Open sub folder context menu #5596 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~753 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=fbe812b9bc725f598c088ec0713755f838fca82c;p=nextcloud-desktop.git Selective Sync: Open sub folder context menu #5596 --- diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 7d040b189..92b451520 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -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;" diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index e5729409d..5ad472397 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -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(); diff --git a/src/gui/folderstatusdelegate.h b/src/gui/folderstatusdelegate.h index 85dab6ec5..6d533258d 100644 --- a/src/gui/folderstatusdelegate.h +++ b/src/gui/folderstatusdelegate.h @@ -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, diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 42c34d1e4..8eca32b61 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -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();