Skip to content

Commit

Permalink
Selective Sync: Open sub folder context menu #5596
Browse files Browse the repository at this point in the history
  • Loading branch information
guruz committed May 8, 2017
1 parent 4697f02 commit fbe812b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
35 changes: 32 additions & 3 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;"
Expand Down
3 changes: 2 additions & 1 deletion src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folderstatusdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FolderStatusDelegate : public QStyledItemDelegate

enum datarole { FolderAliasRole = Qt::UserRole + 100,
HeaderRole,
FolderPathRole,
FolderPathRole, // for a SubFolder it's the complete path
FolderSecondPathRole,
FolderErrorMsg,
FolderSyncPaused,
Expand Down
6 changes: 6 additions & 0 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fbe812b

Please sign in to comment.