FolderStatus: Show 'waiting for other folder' #3619
authorChristian Kamm <mail@ckamm.de>
Fri, 4 Sep 2015 08:33:48 +0000 (10:33 +0200)
committerChristian Kamm <mail@ckamm.de>
Fri, 4 Sep 2015 08:42:21 +0000 (10:42 +0200)
We monitor the scheduling queue and show messages like
"Waiting for 5 other folders...".

src/gui/folderman.cpp
src/gui/folderman.h
src/gui/folderstatusmodel.cpp
src/gui/folderstatusmodel.h

index 3d0428b82bf8070d4e20f27f15e5aa6d4b7a1717..b5edbe673e98678bbeeec33f1da7211bad43466f 100644 (file)
@@ -134,6 +134,7 @@ int FolderMan::unloadAndDeleteAllFolders()
     _lastSyncFolder = 0;
     _currentSyncFolder = 0;
     _scheduleQueue.clear();
+    emit scheduleQueueChanged();
 
     Q_ASSERT(_folderMap.count() == 0);
     return cnt;
@@ -254,7 +255,7 @@ int FolderMan::setupFoldersMigration()
         Folder *f = setupFolderFromOldConfigFile( alias, accountState );
         if( f ) {
             slotScheduleSync(f);
-            emit( folderSyncStateChange( f ) );
+            emit folderSyncStateChange(f);
         }
     }
 
@@ -502,16 +503,17 @@ void FolderMan::slotScheduleSync( Folder *f )
     qDebug() << "Schedule folder " << alias << " to sync!";
 
     if( ! _scheduleQueue.contains(f) ) {
-        if(f->canSync()) {
-            f->prepareToSync();
-        } else {
+        if( !f->canSync() ) {
             qDebug() << "Folder is not ready to sync, not scheduled!";
             if( _socketApi ) {
                 _socketApi->slotUpdateFolderView(f);
             }
             return;
         }
+        f->prepareToSync();
+        emit folderSyncStateChange(f);
         _scheduleQueue.enqueue(f);
+        emit scheduleQueueChanged();
     } else {
         qDebug() << " II> Sync for folder " << alias << " already scheduled, do not enqueue!";
     }
@@ -593,6 +595,7 @@ void FolderMan::slotAccountStateChanged()
                 it.remove();
             }
         }
+        emit scheduleQueueChanged();
     }
 }
 
@@ -685,6 +688,7 @@ void FolderMan::slotStartScheduledFolderSync()
 
     // Try to start the top scheduled sync.
     Folder *f = _scheduleQueue.dequeue();
+    emit scheduleQueueChanged();
     Q_ASSERT(f);
 
     // Start syncing this folder!
@@ -843,7 +847,9 @@ void FolderMan::slotRemoveFolder( Folder *f )
         terminateSyncProcess();
     }
 
-    _scheduleQueue.removeAll(f);
+    if (_scheduleQueue.removeAll(f) > 0) {
+        emit scheduleQueueChanged();
+    }
 
     f->wipe();
     f->setSyncPaused(true);
@@ -1194,6 +1200,16 @@ void FolderMan::setIgnoreHiddenFiles(bool ignore)
     }
 }
 
+QQueue<Folder*> FolderMan::scheduleQueue() const
+{
+    return _scheduleQueue;
+}
+
+Folder *FolderMan::currentSyncFolder() const
+{
+    return _currentSyncFolder;
+}
+
 void FolderMan::restartApplication()
 {
     if( Utility::isLinux() ) {
index 013ce8323056439362d699cec2ad042fa7aff80b..0dd0522629eb5f1433e2ea392e99f1872b914a24 100644 (file)
@@ -109,6 +109,16 @@ public:
     bool ignoreHiddenFiles() const;
     void setIgnoreHiddenFiles(bool ignore);
 
+    /**
+     * Access to the current queue of scheduled folders.
+     */
+    QQueue<Folder*> scheduleQueue() const;
+
+    /**
+     * Access to the currently syncing folder.
+     */
+    Folder* currentSyncFolder() const;
+
 signals:
     /**
       * signal to indicate a folder has changed its sync state.
@@ -117,6 +127,11 @@ signals:
       */
     void folderSyncStateChange(Folder*);
 
+    /**
+     * Indicates when the schedule queue changes.
+     */
+    void scheduleQueueChanged();
+
     void folderListLoaded(const Folder::Map &);
 
 public slots:
index e7f57055709b4fb4a1fdf88aa21d29007021cdd9..19f5b5a7c1bfde93cc8e5e5a75b1632067496377 100644 (file)
@@ -45,6 +45,11 @@ void FolderStatusModel::setAccountState(const AccountState* accountState)
     _folders.clear();
     _accountState = accountState;
 
+    connect(FolderMan::instance(), SIGNAL(folderSyncStateChange(Folder*)),
+            SLOT(slotFolderSyncStateChange(Folder*)), Qt::UniqueConnection);
+    connect(FolderMan::instance(), SIGNAL(scheduleQueueChanged()),
+            SLOT(slotFolderScheduleQueueChanged()), Qt::UniqueConnection);
+
     auto folders = FolderMan::instance()->map();
     foreach (auto f, folders) {
         if (f->accountState() != accountState)
@@ -58,7 +63,6 @@ void FolderStatusModel::setAccountState(const AccountState* accountState)
         _folders << info;
 
         connect(f, SIGNAL(progressInfo(ProgressInfo)), this, SLOT(slotSetProgress(ProgressInfo)), Qt::UniqueConnection);
-        connect(f, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection);
         connect(f, SIGNAL(newBigFolderDiscovered(QString)), this, SLOT(slotNewBigFolder()), Qt::UniqueConnection);
     }
 
@@ -840,9 +844,8 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
     emit dataChanged(index(folderIndex), index(folderIndex), roles);
 }
 
-void FolderStatusModel::slotFolderSyncStateChange()
+void FolderStatusModel::slotFolderSyncStateChange(Folder *f)
 {
-    Folder *f = qobject_cast<Folder*>(sender());
     if( !f ) { return; }
 
     int folderIndex = -1;
@@ -855,10 +858,26 @@ void FolderStatusModel::slotFolderSyncStateChange()
     if (folderIndex < 0) { return; }
 
     SyncResult::Status state = f->syncResult().status();
-    if (state == SyncResult::SyncPrepare
-            || state == SyncResult::Problem
-            || state == SyncResult::Success)  {
-        // Reset the progress info before and after a sync.
+    if (state == SyncResult::NotYetStarted) {
+        FolderMan* folderMan = FolderMan::instance();
+        int pos = folderMan->scheduleQueue().indexOf(f);
+        if (folderMan->currentSyncFolder()
+                && folderMan->currentSyncFolder() != f) {
+            pos += 1;
+        }
+        QString message;
+        if (pos <= 0) {
+            message = tr("Waiting...");
+        } else {
+            message = tr("Waiting for %n other folder(s)...", "", pos);
+        }
+        _folders[folderIndex]._progress = SubFolderInfo::Progress();
+        _folders[folderIndex]._progress._progressString = message;
+    } else if (state == SyncResult::SyncPrepare) {
+        _folders[folderIndex]._progress = SubFolderInfo::Progress();
+        _folders[folderIndex]._progress._progressString = tr("Preparing to sync...");
+    } else if (state == SyncResult::Problem || state == SyncResult::Success) {
+        // Reset the progress info after a sync.
         _folders[folderIndex]._progress = SubFolderInfo::Progress();
     } else if (state == SyncResult::Error) {
         _folders[folderIndex]._progress._progressString = f->syncResult().errorString();
@@ -885,6 +904,16 @@ void FolderStatusModel::slotFolderSyncStateChange()
     }
 }
 
+void FolderStatusModel::slotFolderScheduleQueueChanged()
+{
+    // Update messages on waiting folders.
+    // It's ok to only update folders currently in the queue, because folders
+    // are only removed from the queue if they are deleted.
+    foreach (Folder* f, FolderMan::instance()->scheduleQueue()) {
+        slotFolderSyncStateChange(f);
+    }
+}
+
 void FolderStatusModel::resetFolders()
 {
     setAccountState(_accountState);
index c19f0fe08b298c9189d7a22199a09f41ff98b2aa..c36ffc10f45b8cc3aec26a9ef579a8dab3f0b61d 100644 (file)
@@ -101,7 +101,8 @@ public slots:
 private slots:
     void slotUpdateDirectories(const QStringList &);
     void slotLscolFinishedWithError(QNetworkReply *r);
-    void slotFolderSyncStateChange();
+    void slotFolderSyncStateChange(Folder* f);
+    void slotFolderScheduleQueueChanged();
     void slotNewBigFolder();
 
 private: