ProgressInfo: Carry a sync status
authorChristian Kamm <mail@ckamm.de>
Tue, 11 Jul 2017 10:52:40 +0000 (12:52 +0200)
committerckamm <mail@ckamm.de>
Wed, 12 Jul 2017 07:04:27 +0000 (09:04 +0200)
* A bunch of code was determining sync status by ad-hoc comparing some
  progress info fields. It can now just check the status, making it
  easier to comprehend.
* There's a clear indication for "a new sync is starting", which helps
  wiping the issues tab at the right time.

src/gui/folder.cpp
src/gui/folder.h
src/gui/folderstatusmodel.cpp
src/gui/issueswidget.cpp
src/gui/owncloudgui.cpp
src/libsync/progressdispatcher.cpp
src/libsync/progressdispatcher.h
src/libsync/syncengine.cpp
src/libsync/syncengine.h

index 670e941dd0650e95076714677895eeef9d0a0ed4..cf91c6ac6d2bce09d4e59fd6a234eaf3ab9ee6a5 100644 (file)
@@ -97,7 +97,6 @@ Folder::Folder(const FolderDefinition &definition,
         SLOT(slotAboutToRemoveAllFiles(SyncFileItem::Direction, bool *)));
     connect(_engine.data(), SIGNAL(aboutToRestoreBackup(bool *)),
         SLOT(slotAboutToRestoreBackup(bool *)));
-    connect(_engine.data(), SIGNAL(folderDiscovered(bool, QString)), this, SLOT(slotFolderDiscovered(bool, QString)));
     connect(_engine.data(), SIGNAL(transmissionProgress(ProgressInfo)), this, SLOT(slotTransmissionProgress(ProgressInfo)));
     connect(_engine.data(), SIGNAL(itemCompleted(const SyncFileItemPtr &)),
         this, SLOT(slotItemCompleted(const SyncFileItemPtr &)));
@@ -824,16 +823,6 @@ void Folder::slotEmitFinishedDelayed()
     emit syncFinished(_syncResult);
 }
 
-
-void Folder::slotFolderDiscovered(bool, QString folderName)
-{
-    ProgressInfo pi;
-    pi._currentDiscoveredFolder = folderName;
-    emit progressInfo(pi);
-    ProgressDispatcher::instance()->setProgressInfo(alias(), pi);
-}
-
-
 // the progress comes without a folder and the valid path set. Add that here
 // and hand the result over to the progress dispatcher.
 void Folder::slotTransmissionProgress(const ProgressInfo &pi)
index 602d95b750c630fbb6382eaedc7c1015b38b5a98..29c21c76ffd5c2580b2b162109dd948ea5ea5e91 100644 (file)
@@ -286,8 +286,6 @@ private slots:
 
     void slotCsyncUnavailable();
 
-    void slotFolderDiscovered(bool local, QString folderName);
-
     void slotTransmissionProgress(const ProgressInfo &pi);
     void slotItemCompleted(const SyncFileItemPtr &);
 
index b0f83e9c8edc62ac3852afc876118fecda85d75b..7d443b6417513234eb6f83d1399fd8a781bba235 100644 (file)
@@ -891,12 +891,21 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
           << FolderStatusDelegate::WarningCount
           << Qt::ToolTipRole;
 
-    if (!progress._currentDiscoveredFolder.isEmpty()) {
+    if (progress.status() == ProgressInfo::Discovery
+        && !progress._currentDiscoveredFolder.isEmpty()) {
         pi->_overallSyncString = tr("Checking for changes in '%1'").arg(progress._currentDiscoveredFolder);
         emit dataChanged(index(folderIndex), index(folderIndex), roles);
         return;
     }
 
+    if (progress.status() == ProgressInfo::Reconcile) {
+        pi->_overallSyncString = tr("Reconciling changes");
+        emit dataChanged(index(folderIndex), index(folderIndex), roles);
+        return;
+    }
+
+    // Status is Starting, Propagation or Done
+
     if (!progress._lastCompletedItem.isEmpty()
         && Progress::isWarningKind(progress._lastCompletedItem._status)) {
         pi->_warningCount++;
index ed1792a1ceca01aa3444af3eadc1624a5dea037d..8f56da4cd68e290114eb4960d2375a2f834d68fd 100644 (file)
@@ -160,11 +160,9 @@ void IssuesWidget::slotOpenFile(QTreeWidgetItem *item, int)
 
 void IssuesWidget::slotProgressInfo(const QString &folder, const ProgressInfo &progress)
 {
-    if (!progress.isUpdatingEstimates()) {
+    if (progress.status() == ProgressInfo::Starting) {
         // The sync is restarting, clean the old items
         cleanItems(folder);
-    } else if (progress.completedFiles() >= progress.totalFiles()) {
-        //Sync completed
     }
 }
 
index 38d1caff92cb79689f43f73a731e5a3285e17fd1..65350f3677649e8439a5a5cf2c1c82d304c331be 100644 (file)
@@ -748,10 +748,19 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const ProgressInfo &
 {
     Q_UNUSED(folder);
 
-    if (!progress._currentDiscoveredFolder.isEmpty()) {
-        _actionStatus->setText(tr("Checking for changes in '%1'")
-                                   .arg(progress._currentDiscoveredFolder));
-    } else if (progress.totalSize() == 0) {
+    if (progress.status() == ProgressInfo::Discovery) {
+        if (!progress._currentDiscoveredFolder.isEmpty()) {
+            _actionStatus->setText(tr("Checking for changes in '%1'")
+                                       .arg(progress._currentDiscoveredFolder));
+        }
+    } else if (progress.status() == ProgressInfo::Done) {
+        QTimer::singleShot(2000, this, SLOT(slotDisplayIdle()));
+    }
+    if (progress.status() != ProgressInfo::Propagation) {
+        return;
+    }
+
+    if (progress.totalSize() == 0) {
         quint64 currentFile = progress.currentFile();
         quint64 totalFileCount = qMax(progress.totalFiles(), currentFile);
         QString msg;
@@ -814,12 +823,6 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const ProgressInfo &
             slotRebuildRecentMenus();
         }
     }
-
-    if (progress.isUpdatingEstimates()
-        && progress.completedFiles() >= progress.totalFiles()
-        && progress._currentDiscoveredFolder.isEmpty()) {
-        QTimer::singleShot(2000, this, SLOT(slotDisplayIdle()));
-    }
 }
 
 void ownCloudGui::slotDisplayIdle()
index 2f86888ae4376f4a67a8d6e628f53c8ab1024518..d5b3f20f5027ad547f0bb658c04336f1466c9f65 100644 (file)
@@ -136,6 +136,8 @@ ProgressInfo::ProgressInfo()
 
 void ProgressInfo::reset()
 {
+    _status = Starting;
+
     _currentItems.clear();
     _currentDiscoveredFolder.clear();
     _sizeProgress = Progress();
@@ -151,6 +153,11 @@ void ProgressInfo::reset()
     _lastCompletedItem = SyncFileItem();
 }
 
+ProgressInfo::Status ProgressInfo::status() const
+{
+    return _status;
+}
+
 void ProgressInfo::startEstimateUpdates()
 {
     _updateEstimatesTimer.start(1000);
index 24764b2cb91edcbba7aed2fcea7e7bd8dba3a9c2..e968216996868a273f665a18b7d41924cc30e76c 100644 (file)
@@ -41,6 +41,35 @@ public:
      */
     void reset();
 
+    /** Records the status of the sync run
+     */
+    enum Status {
+        /// Emitted once at start
+        Starting,
+
+        /**
+         * Emitted once without _currentDiscoveredFolder when it starts,
+         * then for each folder.
+         */
+        Discovery,
+
+        /// Emitted once when reconcile starts
+        Reconcile,
+
+        /// Emitted during propagation, with progress data
+        Propagation,
+
+        /**
+         * Emitted once when done
+         *
+         * Except when SyncEngine jumps directly to finalize() without going
+         * through slotFinished().
+         */
+        Done
+    };
+
+    Status status() const;
+
     /**
      * Called when propagation starts.
      *
@@ -140,6 +169,8 @@ public:
         friend class ProgressInfo;
     };
 
+    Status _status;
+
     struct OWNCLOUDSYNC_EXPORT ProgressItem
     {
         SyncFileItem _item;
index 7389a0ce229c638c5ff10bf214366d3ea34bc577..e73777f9647500bfcb1a31d10c28bc43132c299d 100644 (file)
@@ -820,8 +820,12 @@ void SyncEngine::startSync()
     _csync_ctx->callbacks.checksum_userdata = &_checksum_hook;
 
     _stopWatch.start();
+    _progressInfo->_status = ProgressInfo::Starting;
+    emit transmissionProgress(*_progressInfo);
 
     qCInfo(lcEngine) << "#### Discovery start ####################################################";
+    _progressInfo->_status = ProgressInfo::Discovery;
+    emit transmissionProgress(*_progressInfo);
 
     // Usually the discovery runs in the background: We want to avoid
     // stealing too much time from other processes that the user might
@@ -855,7 +859,7 @@ void SyncEngine::startSync()
     discoveryJob->moveToThread(&_thread);
     connect(discoveryJob, SIGNAL(finished(int)), this, SLOT(slotDiscoveryJobFinished(int)));
     connect(discoveryJob, SIGNAL(folderDiscovered(bool, QString)),
-        this, SIGNAL(folderDiscovered(bool, QString)));
+        this, SLOT(slotFolderDiscovered(bool, QString)));
 
     connect(discoveryJob, SIGNAL(newBigFolder(QString, bool)),
         this, SIGNAL(newBigFolder(QString, bool)));
@@ -869,6 +873,12 @@ void SyncEngine::startSync()
     QMetaObject::invokeMethod(discoveryJob, "start", Qt::QueuedConnection);
 }
 
+void SyncEngine::slotFolderDiscovered(bool /*local*/, const QString &folder)
+{
+    _progressInfo->_currentDiscoveredFolder = folder;
+    emit transmissionProgress(*_progressInfo);
+}
+
 void SyncEngine::slotRootEtagReceived(const QString &e)
 {
     if (_remoteRootEtag.isEmpty()) {
@@ -880,9 +890,6 @@ void SyncEngine::slotRootEtagReceived(const QString &e)
 
 void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
 {
-    // To clean the progress info
-    emit folderDiscovered(false, QString());
-
     if (discoveryResult < 0) {
         handleSyncError(_csync_ctx, "csync_update");
         return;
@@ -900,6 +907,10 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
         _journal->commitIfNeededAndStartNewTransaction("Post discovery");
     }
 
+    _progressInfo->_currentDiscoveredFolder.clear();
+    _progressInfo->_status = ProgressInfo::Reconcile;
+    emit transmissionProgress(*_progressInfo);
+
     if (csync_reconcile(_csync_ctx) < 0) {
         handleSyncError(_csync_ctx, "csync_reconcile");
         return;
@@ -997,7 +1008,9 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
 
     // To announce the beginning of the sync
     emit aboutToPropagate(syncItems);
+
     // it's important to do this before ProgressInfo::start(), to announce start of new sync
+    _progressInfo->_status = ProgressInfo::Propagation;
     emit transmissionProgress(*_progressInfo);
     _progressInfo->startEstimateUpdates();
 
@@ -1111,6 +1124,7 @@ void SyncEngine::slotFinished(bool success)
     // files needed propagation, but clear the lastCompletedItem
     // so we don't count this twice (like Recent Files)
     _progressInfo->_lastCompletedItem = SyncFileItem();
+    _progressInfo->_status = ProgressInfo::Done;
     emit transmissionProgress(*_progressInfo);
 
     finalize(success);
index bc6b35bc6728264413fc55539fc5d5f161d7ff1d..deb87ef40928acc7ca96d3957203834eba69ac2f 100644 (file)
@@ -109,7 +109,6 @@ signals:
 
     // During update, before reconcile
     void rootEtag(QString);
-    void folderDiscovered(bool local, const QString &folderUrl);
 
     // before actual syncing (after update+reconcile) for each item
     void syncItemDiscovered(const SyncFileItem &);
@@ -150,6 +149,7 @@ signals:
     void seenLockedFile(const QString &fileName);
 
 private slots:
+    void slotFolderDiscovered(bool local, const QString &folder);
     void slotRootEtagReceived(const QString &);
     void slotItemCompleted(const SyncFileItemPtr &item);
     void slotFinished(bool success);