Improve folder pausing API
authorChristian Kamm <mail@ckamm.de>
Wed, 2 Mar 2016 10:06:03 +0000 (11:06 +0100)
committerChristian Kamm <mail@ckamm.de>
Wed, 2 Mar 2016 10:06:03 +0000 (11:06 +0100)
Previously one could accidentally call Folder::setSyncPaused() and miss
some expected side effects. Before, the correct call was to FolderMan::
slotSetFolderPaused(). Now the setter on Folder has the expected effect.

src/gui/accountsettings.cpp
src/gui/folder.cpp
src/gui/folder.h
src/gui/folderman.cpp
src/gui/folderman.h

index fa4018f0cfdb6141e5a2965a0132cd48ac09490a..9cf0fe3aa412b19226faf67aae15721d25304d41 100644 (file)
@@ -437,8 +437,7 @@ void AccountSettings::slotEnableCurrentFolder()
         if ( f->isBusy() && terminate ) {
             f->slotTerminateSync();
         }
-        f->setSyncPaused(!currentlyPaused); // toggle the pause setting
-        folderMan->slotSetFolderPaused( f, !currentlyPaused );
+        f->setSyncPaused(!currentlyPaused);
 
         // keep state for the icon setting.
         if( currentlyPaused ) _wasDisabledBefore = true;
index ce9ab60d608fe959757c9830e9d032ba8e3706a1..da6eedf85751a6658edec453a80ca5c7326eec20 100644 (file)
@@ -265,20 +265,19 @@ bool Folder::canSync() const
 
 void Folder::setSyncPaused( bool paused )
 {
-    if (paused != _definition.paused) {
-        _definition.paused = paused;
-        saveToSettings();
+    if (paused == _definition.paused) {
+        return;
     }
 
+    _definition.paused = paused;
+    saveToSettings();
+
     if( !paused ) {
-        // qDebug() << "Syncing enabled on folder " << name();
         setSyncState(SyncResult::NotYetStarted);
     } else {
-        // do not stop or start the watcher here, that is done internally by
-        // folder class. Even if the watcher fires, the folder does not
-        // schedule itself because it checks the var. _enabled before.
         setSyncState(SyncResult::Paused);
     }
+    emit syncPausedChanged(this, paused);
     emit syncStateChange();
 }
 
index 510fd0f2095c3eb9ce6b20c7e3aa23e3bcf9b2f5..2310debaf5a87f4cb71ed104166e1b5017621bc0 100644 (file)
@@ -133,8 +133,6 @@ public:
 
     /**
      * switch sync on or off
-     * If the sync is switched off, the startSync method is not going to
-     * be called.
      */
     void setSyncPaused( bool );
 
@@ -214,6 +212,7 @@ signals:
     void scheduleToSync(Folder*);
     void progressInfo(const ProgressInfo& progress);
     void newBigFolderDiscovered(const QString &); // A new folder bigger than the threshold was discovered
+    void syncPausedChanged(Folder*, bool paused);
 
 public slots:
 
index a0ea57f4a6cf7f6539f8859ca578ebd84e0867f7..50659bf72c972d570ef56aebb75603b9b91adf4f 100644 (file)
@@ -106,6 +106,8 @@ void FolderMan::unloadFolder( Folder *f )
                this, SLOT(slotFolderSyncFinished(SyncResult)));
     disconnect(f, SIGNAL(syncStateChange()),
                this, SLOT(slotForwardFolderSyncStateChange()));
+    disconnect(f, SIGNAL(syncPausedChanged(Folder*,bool)),
+               this, SLOT(slotFolderSyncPaused(Folder*,bool)));
 }
 
 int FolderMan::unloadAndDeleteAllFolders()
@@ -411,21 +413,19 @@ Folder* FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat
     return folder;
 }
 
-void FolderMan::slotSetFolderPaused( Folder *f, bool paused )
+void FolderMan::slotFolderSyncPaused( Folder *f, bool paused )
 {
     if( !f ) {
-        qWarning() << "!! slotSetFolderPaused called with empty folder";
+        qWarning() << "!! slotFolderSyncPaused called with empty folder";
         return;
     }
 
-    f->setSyncPaused(paused);
     if (!paused) {
         _disabledFolders.remove(f);
         slotScheduleSync(f);
     } else {
         _disabledFolders.insert(f);
     }
-    emit folderSyncStateChange(f);
 }
 
 // this really terminates the current sync process
@@ -796,6 +796,7 @@ Folder* FolderMan::addFolderInternal(const FolderDefinition& folderDefinition)
     connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
     connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult)));
     connect(folder, SIGNAL(syncStateChange()), SLOT(slotForwardFolderSyncStateChange()));
+    connect(folder, SIGNAL(syncPausedChanged(Folder*,bool)), SLOT(slotFolderSyncPaused(Folder*,bool)));
 
     registerFolderMonitor(folder);
     return folder;
index b120ea5b328c54eee41b26ccaf41433e965ef280..7eca2919aed46c0f598778660c596712ee305332 100644 (file)
@@ -143,7 +143,7 @@ signals:
 
 public slots:
     void slotRemoveFolder( Folder* );
-    void slotSetFolderPaused(Folder *, bool paused);
+    void slotFolderSyncPaused(Folder *, bool paused);
 
     void slotFolderSyncStarted();
     void slotFolderSyncFinished( const SyncResult& );