From 68f99bcc27261f3d6a8dccb776864f328cf1560d Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 25 Nov 2016 14:23:56 +0100 Subject: [PATCH] AccountSettings: Add a "Force sync now" context menu option --- src/gui/accountsettings.cpp | 27 +++++++++++++++++++++++++-- src/gui/accountsettings.h | 3 ++- src/gui/folderman.cpp | 20 ++++++++++++++++++++ src/gui/folderman.h | 16 ++++++++++------ 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 2e0f41eba..22c43fdea 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -111,7 +111,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) : QAction *syncNowAction = new QAction(this); syncNowAction->setShortcut(QKeySequence(Qt::Key_F6)); - connect(syncNowAction, SIGNAL(triggered()), SLOT(slotSyncCurrentFolderNow())); + connect(syncNowAction, SIGNAL(triggered()), SLOT(slotScheduleCurrentFolder())); addAction(syncNowAction); connect(ui->_folderList, SIGNAL(clicked(const QModelIndex &)), @@ -229,6 +229,11 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) connect(ac, SIGNAL(triggered(bool)), this, SLOT(doExpand())); } + if (!folderPaused) { + ac = menu->addAction(tr("Force sync now")); + connect(ac, SIGNAL(triggered(bool)), this, SLOT(slotForceSyncCurrentFolder())); + } + ac = menu->addAction(folderPaused ? tr("Resume sync") : tr("Pause sync")); connect(ac, SIGNAL(triggered(bool)), this, SLOT(slotEnableCurrentFolder())); @@ -463,7 +468,7 @@ void AccountSettings::slotEnableCurrentFolder() } } -void AccountSettings::slotSyncCurrentFolderNow() +void AccountSettings::slotScheduleCurrentFolder() { QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); if( !selected.isValid() ) @@ -474,6 +479,24 @@ void AccountSettings::slotSyncCurrentFolderNow() folderMan->scheduleFolder(folderMan->folder(alias)); } +void AccountSettings::slotForceSyncCurrentFolder() +{ + QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); + if( !selected.isValid() ) + return; + QString alias = _model->data( selected, FolderStatusDelegate::FolderAliasRole ).toString(); + FolderMan *folderMan = FolderMan::instance(); + + // Terminate and reschedule any running sync + if (Folder* current = folderMan->currentSyncFolder()) { + folderMan->terminateSyncProcess(); + folderMan->scheduleFolder(current); + } + + // Insert the selected folder at the front of the queue + folderMan->scheduleFolderNext(folderMan->folder(alias)); +} + void AccountSettings::slotOpenOC() { if( _OCUrl.isValid() ) diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index c936580ac..f036d6ca3 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -71,7 +71,8 @@ public slots: protected slots: void slotAddFolder(); void slotEnableCurrentFolder(); - void slotSyncCurrentFolderNow(); + void slotScheduleCurrentFolder(); + void slotForceSyncCurrentFolder(); void slotRemoveCurrentFolder(); void slotOpenCurrentFolder(); void slotFolderWizardAccepted(); diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index dde3e10dc..2209088a1 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -520,6 +520,26 @@ void FolderMan::scheduleFolder( Folder *f ) startScheduledSyncSoon(); } +void FolderMan::scheduleFolderNext(Folder* f) +{ + auto alias = f->alias(); + qDebug() << "Schedule folder " << alias << " to sync! Front-of-queue."; + + if( !f->canSync() ) { + qDebug() << "Folder is not ready to sync, not scheduled!"; + return; + } + + _scheduledFolders.removeAll(f); + + f->prepareToSync(); + emit folderSyncStateChange(f); + _scheduledFolders.prepend(f); + emit scheduleQueueChanged(); + + startScheduledSyncSoon(); +} + void FolderMan::slotScheduleETagJob(const QString &/*alias*/, RequestEtagJob *job) { QObject::connect(job, SIGNAL(destroyed(QObject*)), this, SLOT(slotEtagJobDestroyed(QObject*))); diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 3f58538fb..bc627587b 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -161,12 +161,22 @@ public: /** Queues a folder for syncing. */ void scheduleFolder(Folder*); + /** Puts a folder in the very front of the queue. */ + void scheduleFolderNext(Folder*); + /** Queues all folders for syncing. */ void scheduleAllFolders(); void setDirtyProxy(bool value = true); void setDirtyNetworkLimits(); + /** + * Terminates the current folder sync. + * + * It does not switch the folder to paused state. + */ + void terminateSyncProcess(); + signals: /** * signal to indicate a folder has changed its sync state. @@ -247,12 +257,6 @@ private slots: void slotScheduleFolderByTime(); private: - /** - * Terminates the current folder sync. - * - * It does not switch the folder to paused state. - */ - void terminateSyncProcess(); /** Adds a new folder, does not add it to the account settings and * does not set an account on the new folder. -- 2.30.2