diff options
author | Klaas Freitag <freitag@owncloud.com> | 2013-10-21 16:00:17 +0400 |
---|---|---|
committer | Klaas Freitag <freitag@owncloud.com> | 2013-10-21 16:00:17 +0400 |
commit | 4e777aae3354b6ce7325f7a392d34627dd738e16 (patch) | |
tree | 8f7a4cc502cc1c0ebcce6f7771c10b9e01e15a2e | |
parent | 5a84452102dc73dae25e99651e39f882281a000a (diff) |
Add a flag to the folder class that reflects the en-/disable user button
The existing flag _syncEnabled was used to both carry the users wish and
also the system capability of being able to sync (ie. network not
existing...) Now there are two flags (one for system problems that
disable sync and one for the user interaction) which steer the sync
algorithm.
-rw-r--r-- | src/mirall/accountsettings.cpp | 6 | ||||
-rw-r--r-- | src/mirall/folder.cpp | 39 | ||||
-rw-r--r-- | src/mirall/folder.h | 8 | ||||
-rw-r--r-- | src/mirall/folderman.cpp | 4 | ||||
-rw-r--r-- | src/mirall/folderman.h | 2 |
5 files changed, 46 insertions, 13 deletions
diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index a1018afb6..b1d6996d8 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -219,7 +219,7 @@ void AccountSettings::folderToModelItem( QStandardItem *item, Folder *f ) item->setData( f->nativePath(), FolderStatusDelegate::FolderPathRole ); item->setData( f->secondPath(), FolderStatusDelegate::FolderSecondPathRole ); item->setData( f->alias(), FolderStatusDelegate::FolderAliasRole ); - item->setData( f->syncEnabled(), FolderStatusDelegate::FolderSyncEnabled ); + item->setData( f->userSyncEnabled() && f->syncEnabled(), FolderStatusDelegate::FolderSyncEnabled ); SyncResult res = f->syncResult(); SyncResult::Status status = res.status(); @@ -228,7 +228,7 @@ void AccountSettings::folderToModelItem( QStandardItem *item, Folder *f ) Theme *theme = Theme::instance(); item->setData( theme->statusHeaderText( status ), Qt::ToolTipRole ); - if( f->syncEnabled() ) { + if( f->syncEnabled() && f->userSyncEnabled() ) { if( status == SyncResult::SyncPrepare ) { if( _wasDisabledBefore ) { // if the folder was disabled before, set the sync icon @@ -445,7 +445,7 @@ void AccountSettings::slotEnableCurrentFolder() if ( f->isBusy() && terminate ) folderMan->terminateSyncProcess( alias ); - folderMan->slotEnableFolder( alias, !folderEnabled ); + folderMan->slotGuiPauseFolder( alias, !folderEnabled ); // keep state for the icon setting. if( !folderEnabled ) _wasDisabledBefore = true; diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 82cc504ec..4dde6156a 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -50,6 +50,7 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP , _secondPath(secondPath) , _alias(alias) , _enabled(true) + , _userSyncEnabled(true) , _thread(0) , _csync(0) , _csyncError(false) @@ -200,16 +201,32 @@ void Folder::setSyncEnabled( bool doit ) { _enabled = doit; - if( doit ) { + if( doit && userSyncEnabled() ) { // qDebug() << "Syncing enabled on folder " << name(); + _pollTimer.start(); + _watcher->clearPendingEvents(); // FIXME 1.5: Why isn't that happening in setEventsEnabled? + _watcher->setEventsEnabled(true); + _timeSinceLastSync.restart(); } 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. _pollTimer.stop(); + _watcher->setEventsEnabled(false); } } +bool Folder::userSyncEnabled() +{ + return _userSyncEnabled; +} + +void Folder::slotSetSyncUserEnabled( bool enable ) +{ + _userSyncEnabled = enable; + setSyncEnabled( syncEnabled() ); // no change on the system enable flag. +} + void Folder::setSyncState(SyncResult::Status state) { _syncResult.setStatus(state); @@ -222,11 +239,15 @@ SyncResult Folder::syncResult() const void Folder::evaluateSync(const QStringList &/*pathList*/) { - if( !_enabled ) { + if( !syncEnabled() ) { qDebug() << "*" << alias() << "sync skipped, disabled!"; return; } + if( !userSyncEnabled() ) { + qDebug() << "*" << alias() << "sync skipped, user disabled!"; + return; + } _syncResult.setStatus( SyncResult::NotYetStarted ); _syncResult.clearErrors(); emit scheduleToSync( alias() ); @@ -237,8 +258,9 @@ void Folder::slotPollTimerTimeout() { qDebug() << "* Polling" << alias() << "for changes. (time since next sync:" << (_timeSinceLastSync.elapsed() / 1000) << "s)"; + // Force sync if the last sync is a long time ago or if there was a serious problem. if (quint64(_timeSinceLastSync.elapsed()) > MirallConfigFile().forceSyncInterval() || - _syncResult.status() != SyncResult::Success ) { + !(_syncResult.status() == SyncResult::Success || _syncResult.status() == SyncResult::Problem)) { qDebug() << "** Force Sync now"; evaluateSync(QStringList()); } else { @@ -627,10 +649,13 @@ void Folder::slotCsyncUnavailable() void Folder::slotCSyncFinished() { - qDebug() << "-> CSync Finished slot with error " << _csyncError; - _watcher->setEventsEnabledDelayed(2000); - _pollTimer.start(); - _timeSinceLastSync.restart(); + qDebug() << "-> CSync Finished slot for" << alias() << "with error" << _csyncError; + if( syncEnabled() && userSyncEnabled() ) { + qDebug() << "Sync is enabled - starting the polltimer again."; + _watcher->setEventsEnabledDelayed(2000); + _pollTimer.start(); + _timeSinceLastSync.restart(); + } bubbleUpSyncResult(); diff --git a/src/mirall/folder.h b/src/mirall/folder.h index caf4b576c..b80e16571 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -153,6 +153,13 @@ public slots: void setProxyDirty(bool value); bool proxyDirty(); + /** + * @brief slotSetSyncUserEnabled - slot that sets the enable/disable flag from the GUI + * @param enable + */ + void slotSetSyncUserEnabled( bool enable ); + bool userSyncEnabled(); + private slots: void slotCSyncStarted(); void slotCSyncError(const QString& ); @@ -197,6 +204,7 @@ protected: QString _configFile; QFileSystemWatcher *_pathWatcher; bool _enabled; + bool _userSyncEnabled; // enabled by user interaction? FolderWatcher *_watcher; SyncResult _syncResult; QThread *_thread; diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index caf05ac28..f1b5f51db 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -269,7 +269,7 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) { return folder; } -void FolderMan::slotEnableFolder( const QString& alias, bool enable ) +void FolderMan::slotGuiPauseFolder( const QString& alias, bool enable ) { if( ! _folderMap.contains( alias ) ) { qDebug() << "!! Can not enable alias " << alias << ", can not be found in folderMap."; @@ -278,7 +278,7 @@ void FolderMan::slotEnableFolder( const QString& alias, bool enable ) Folder *f = _folderMap[alias]; if( f ) { - f->setSyncEnabled(enable); + f->slotSetSyncUserEnabled(enable); f->evaluateSync(QStringList()); } } diff --git a/src/mirall/folderman.h b/src/mirall/folderman.h index 7625b18c2..a6e649ed9 100644 --- a/src/mirall/folderman.h +++ b/src/mirall/folderman.h @@ -91,7 +91,7 @@ signals: public slots: void slotRemoveFolder( const QString& ); - void slotEnableFolder( const QString&, bool ); + void slotGuiPauseFolder( const QString&, bool ); void slotFolderSyncStarted(); void slotFolderSyncFinished( const SyncResult& ); |