AccountSettings: Add a "Force sync now" context menu option
authorChristian Kamm <mail@ckamm.de>
Fri, 25 Nov 2016 13:23:56 +0000 (14:23 +0100)
committerChristian Kamm <mail@ckamm.de>
Fri, 25 Nov 2016 13:23:56 +0000 (14:23 +0100)
src/gui/accountsettings.cpp
src/gui/accountsettings.h
src/gui/folderman.cpp
src/gui/folderman.h

index 2e0f41eba1c4d4b19b4a75a2e8afdad3648c4956..22c43fdea1c9fe0a9ceb5eccc01e1dc8d3dc436a 100644 (file)
@@ -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() )
index c936580ac7f52f8541d8724b77e8a69bc7d49279..f036d6ca353e072335911200eeae29f5ffd36861 100644 (file)
@@ -71,7 +71,8 @@ public slots:
 protected slots:
     void slotAddFolder();
     void slotEnableCurrentFolder();
-    void slotSyncCurrentFolderNow();
+    void slotScheduleCurrentFolder();
+    void slotForceSyncCurrentFolder();
     void slotRemoveCurrentFolder();
     void slotOpenCurrentFolder();
     void slotFolderWizardAccepted();
index dde3e10dcf9c43af415add0c4cf95914a3c1063e..2209088a1479e5c0de5690fa26bcb0f0c7b18ff9 100644 (file)
@@ -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*)));
index 3f58538fbf2118449232a8728e7a64c0839afff2..bc627587b88e18e301c956a4a980457c30c1123d 100644 (file)
@@ -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.