[Pkg-owncloud-commits] [owncloud-client] 224/498: Sync scheduling: fix per-account scheduling. #3379

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:52 UTC 2015


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

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 2fa00168cf05a6f1783b41c3b107d23139eaaf72
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Wed Jul 1 11:39:57 2015 +0200

    Sync scheduling: fix per-account scheduling. #3379
    
    application.cpp still had a global folder syncing on/off switch
    when an account connected or disconnected. That couldn't work with
    multiaccount.
    
    Instead FolderMan listens to accountStateChanged messages and
    schedules or de-schedules the folders for accounts that change state.
---
 src/gui/accountsettings.cpp |  4 +--
 src/gui/application.cpp     | 40 ++++++++++++-----------------
 src/gui/folder.cpp          |  5 ++++
 src/gui/folder.h            | 13 +++++++---
 src/gui/folderman.cpp       | 62 +++++++++++++++++++++++++++++++++++++--------
 src/gui/folderman.h         |  6 +++++
 6 files changed, 90 insertions(+), 40 deletions(-)

diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index 8a3fa0a..c3d69f6 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -190,10 +190,11 @@ void AccountSettings::slotFolderWizardAccepted()
     definition.targetPath   = folderWizard->property("targetPath").toString();
     auto selectiveSyncBlackList = folderWizard->property("selectiveSyncBlackList").toStringList();
 
+    folderMan->setSyncEnabled(true);
+
     Folder *f = folderMan->addFolder(_accountState, definition);
     if( f ) {
         f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, selectiveSyncBlackList);
-        folderMan->setSyncEnabled(true);
         folderMan->slotScheduleAllFolders();
         emit folderChanged();
     }
@@ -204,7 +205,6 @@ void AccountSettings::slotFolderWizardRejected()
     qDebug() << "* Folder wizard cancelled";
     FolderMan *folderMan = FolderMan::instance();
     folderMan->setSyncEnabled(true);
-    folderMan->slotScheduleAllFolders();
 }
 
 void AccountSettings::setGeneralErrors( const QStringList& errors )
diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index 2b83897..f4682fa 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -134,7 +134,7 @@ Application::Application(int &argc, char **argv) :
 
     AccountManager::instance()->restore();
 
-    FolderMan::instance()->setSyncEnabled(false);
+    FolderMan::instance()->setSyncEnabled(true);
 
     setQuitOnLastWindowClosed(false);
 
@@ -206,7 +206,6 @@ void Application::slotLogout()
         a->credentials()->invalidateToken();
         // terminate all syncs and unload folders
         FolderMan *folderMan = FolderMan::instance();
-        folderMan->setSyncEnabled(false);
         folderMan->terminateSyncProcess();
         ai->setSignedOut(true);
         // show result
@@ -219,16 +218,26 @@ void Application::slotLogout()
 
 void Application::slotAccountStateRemoved(AccountState *accountState)
 {
-    disconnect(accountState, SIGNAL(stateChanged(int)), this, SLOT(slotAccountStateChanged(int)));
+    disconnect(accountState, SIGNAL(stateChanged(int)),
+               this, SLOT(slotAccountStateChanged(int)));
     if (_gui) {
-        disconnect(accountState, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
+        disconnect(accountState, SIGNAL(stateChanged(int)),
+                   _gui, SLOT(slotAccountStateChanged()));
+    }
+    if (_folderManager) {
+        disconnect(accountState, SIGNAL(stateChanged(int)),
+                   _folderManager.data(), SLOT(slotAccountStateChanged()));
     }
 }
 
 void Application::slotAccountStateAdded(AccountState *accountState)
 {
-    connect(accountState, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
-    connect(accountState, SIGNAL(stateChanged(int)), this, SLOT(slotAccountStateChanged(int)));
+    connect(accountState, SIGNAL(stateChanged(int)),
+            this, SLOT(slotAccountStateChanged(int)));
+    connect(accountState, SIGNAL(stateChanged(int)),
+            _gui, SLOT(slotAccountStateChanged()));
+    connect(accountState, SIGNAL(stateChanged(int)),
+            _folderManager.data(), SLOT(slotAccountStateChanged()));
 }
 
 void Application::slotCleanup()
@@ -263,24 +272,7 @@ void Application::slotCheckConnection()
 
 void Application::slotAccountStateChanged(int state)
 {
-    FolderMan* folderMan = FolderMan::instance();
-    switch (state) {
-    case AccountState::Connected:
-        qDebug() << "Enabling sync scheduler, scheduling all folders";
-#warning FIXME: this should schedule a sync for the folders of the account that connected
-        folderMan->setSyncEnabled(true);
-        folderMan->slotScheduleAllFolders();
-        break;
-    case AccountState::ServiceUnavailable:
-    case AccountState::SignedOut:
-    case AccountState::ConfigurationError:
-    case AccountState::NetworkError:
-    case AccountState::Disconnected:
-        qDebug() << "Disabling sync scheduler, terminating sync";
-        folderMan->setSyncEnabled(false);
-        folderMan->terminateSyncProcess();
-        break;
-    }
+    // THE FOLLOWING STILL NEEDS FIXING!
 
     // Stop checking the connection if we're manually signed out or
     // when the error is permanent.
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index 06e0086..39329cb 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -227,6 +227,11 @@ bool Folder::syncPaused() const
   return _definition.paused;
 }
 
+bool Folder::canSync() const
+{
+    return !syncPaused() && accountState()->isConnected();
+}
+
 void Folder::setSyncPaused( bool paused )
 {
     if (paused != _definition.paused) {
diff --git a/src/gui/folder.h b/src/gui/folder.h
index b0cedb9..72843ed 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -129,11 +129,18 @@ public:
      * If the sync is switched off, the startSync method is not going to
      * be called.
      */
-     void setSyncPaused( bool );
+    void setSyncPaused( bool );
 
-     bool syncPaused() const;
+    bool syncPaused() const;
 
-     void prepareToSync();
+    /**
+     * Returns true when the folder may sync.
+     *
+     * !syncPaused() && accountState->isConnected().
+     */
+    bool canSync() const;
+
+    void prepareToSync();
 
     /**
      * True if the folder is busy and can't initiate
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index 6ed55f8..2c27745 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -460,7 +460,7 @@ Folder *FolderMan::folder( const QString& alias )
 void FolderMan::slotScheduleAllFolders()
 {
     foreach( Folder *f, _folderMap.values() ) {
-        if (f && ! f->syncPaused()) {
+        if (f && f->canSync()) {
             slotScheduleSync( f );
         }
     }
@@ -488,10 +488,10 @@ void FolderMan::slotScheduleSync( Folder *f )
     qDebug() << "Schedule folder " << alias << " to sync!";
 
     if( ! _scheduleQueue.contains(f) ) {
-        if( !f->syncPaused() ) {
+        if(f->canSync()) {
             f->prepareToSync();
         } else {
-            qDebug() << "Folder is not enabled, not scheduled!";
+            qDebug() << "Folder is not ready to sync, not scheduled!";
             if( _socketApi ) {
                 _socketApi->slotUpdateFolderView(f);
             }
@@ -540,6 +540,43 @@ void FolderMan::slotRunOneEtagJob()
     }
 }
 
+void FolderMan::slotAccountStateChanged()
+{
+    AccountState * accountState = qobject_cast<AccountState*>(sender());
+    if (! accountState) {
+        return;
+    }
+    QString accountName = accountState->account()->displayName();
+
+    if (accountState->isConnected()) {
+        qDebug() << "Account" << accountName << "connected, scheduling its folders";
+
+        foreach (Folder *f, _folderMap.values()) {
+            if (f
+                    && f->canSync()
+                    && f->accountState() == accountState) {
+                slotScheduleSync(f);
+            }
+        }
+    } else {
+        qDebug() << "Account" << accountName << "disconnected, "
+                    "terminating or descheduling sync folders";
+
+        if (_currentSyncFolder
+                && _currentSyncFolder->accountState() == accountState) {
+            _currentSyncFolder->slotTerminateSync();
+        }
+
+        QMutableListIterator<Folder*> it(_scheduleQueue);
+        while (it.hasNext()) {
+            Folder* f = it.next();
+            if (f->accountState() == accountState) {
+                it.remove();
+            }
+        }
+    }
+}
+
 // only enable or disable foldermans will to schedule and do syncs.
 // this is not the same as Pause and Resume of folders.
 void FolderMan::setSyncEnabled( bool enabled )
@@ -632,7 +669,7 @@ void FolderMan::slotStartScheduledFolderSync()
     Q_ASSERT(f);
 
     // Start syncing this folder!
-    if( !f->syncPaused() ) {
+    if(f->canSync()) {
         _currentSyncFolder = f;
 
         f->startSync( QStringList() );
@@ -653,19 +690,22 @@ void FolderMan::slotEtagPollTimerTimeout()
     int polltime = cfg.remotePollInterval();
 
     foreach (Folder *f, _folderMap) {
+        if (!f) {
+            continue;
+        }
         if (_currentSyncFolder == f) {
             continue;
         }
         if (_scheduleQueue.contains(f)) {
             continue;
         }
-        if (f && _disabledFolders.contains(f)) {
+        if (_disabledFolders.contains(f)) {
             continue;
         }
-        if (f && (f->etagJob() || f->isBusy() || f->syncPaused())) {
+        if (f->etagJob() || f->isBusy() || !f->canSync()) {
             continue;
         }
-        if (f && f->msecSinceLastSync() < polltime) {
+        if (f->msecSinceLastSync() < polltime) {
             continue;
         }
         QMetaObject::invokeMethod(f, "slotRunEtagJob", Qt::QueuedConnection);
@@ -956,13 +996,13 @@ SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
     } else {
         int errorsSeen = 0;
         int goodSeen = 0;
-        int abortSeen = 0;
+        int abortOrPausedSeen = 0;
         int runSeen = 0;
         int various = 0;
 
         foreach ( Folder *folder, folders ) {
             if( folder->syncPaused() ) {
-                abortSeen++;
+                abortOrPausedSeen++;
             } else {
                 SyncResult folderResult = folder->syncResult();
                 SyncResult::Status syncStatus = folderResult.status();
@@ -986,7 +1026,7 @@ SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
                     break;
                 case SyncResult::SyncAbortRequested:
                 case SyncResult::Paused:
-                    abortSeen++;
+                    abortOrPausedSeen++;
                     // no default case on purpose, check compiler warnings
                 }
             }
@@ -996,7 +1036,7 @@ SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
             overallResult.setStatus(SyncResult::Error);
             set = true;
         }
-        if( !set && abortSeen > 0 && abortSeen == cnt ) {
+        if( !set && abortOrPausedSeen > 0 && abortOrPausedSeen == cnt ) {
             // only if all folders are paused
             overallResult.setStatus(SyncResult::Paused);
             set = true;
diff --git a/src/gui/folderman.h b/src/gui/folderman.h
index 3862e08..e834427 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -131,6 +131,12 @@ public slots:
     void slotEtagJobDestroyed (QObject*);
     void slotRunOneEtagJob();
 
+    /**
+     * Schedules folders of newly connected accounts, terminates and
+     * de-schedules folders of disconnected accounts.
+     */
+    void slotAccountStateChanged();
+
 private slots:
 
     // slot to take the next folder from queue and start syncing.

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