From: Christian Kamm Date: Wed, 2 Mar 2016 10:06:03 +0000 (+0100) Subject: Improve folder pausing API X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~1335 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=40c109597e57c3425337b71bb43a906b59b0a4b9;p=nextcloud-desktop.git Improve folder pausing API 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. --- diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index fa4018f0c..9cf0fe3aa 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -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; diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index ce9ab60d6..da6eedf85 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -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(); } diff --git a/src/gui/folder.h b/src/gui/folder.h index 510fd0f20..2310debaf 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -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: diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index a0ea57f4a..50659bf72 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -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; diff --git a/src/gui/folderman.h b/src/gui/folderman.h index b120ea5b3..7eca2919a 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -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& );