[Pkg-owncloud-commits] [owncloud-client] 04/05: Add a flag to the folder class that reflects the en-/disable user button

Gaudenz Steinlin gaudenz at moszumanska.debian.org
Fri Nov 4 10:38:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

gaudenz pushed a commit to annotated tag v1.4.2
in repository owncloud-client.

commit 4e777aae3354b6ce7325f7a392d34627dd738e16
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Mon Oct 21 14:00:17 2013 +0200

    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.
---
 src/mirall/accountsettings.cpp |  6 +++---
 src/mirall/folder.cpp          | 39 ++++++++++++++++++++++++++++++++-------
 src/mirall/folder.h            |  8 ++++++++
 src/mirall/folderman.cpp       |  4 ++--
 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 a1018af..b1d6996 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 82cc504..4dde615 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 caf4b57..b80e165 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 caf05ac..f1b5f51 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 7625b18..a6e649e 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& );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list