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.
This commit is contained in:
Christian Kamm 2016-03-02 11:06:03 +01:00
parent 6e9019120f
commit 40c109597e
5 changed files with 14 additions and 16 deletions

View 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;

View 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();
}

View 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:

View 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;

View 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& );