From: Christian Kamm Date: Tue, 11 Jul 2017 10:52:40 +0000 (+0200) Subject: ProgressInfo: Carry a sync status X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~704^2^2~49 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c3cb1869526d4f6448712df44b7d38b471f3bcd2;p=nextcloud-desktop.git ProgressInfo: Carry a sync status * 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. --- diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 670e941dd..cf91c6ac6 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -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) diff --git a/src/gui/folder.h b/src/gui/folder.h index 602d95b75..29c21c76f 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -286,8 +286,6 @@ private slots: void slotCsyncUnavailable(); - void slotFolderDiscovered(bool local, QString folderName); - void slotTransmissionProgress(const ProgressInfo &pi); void slotItemCompleted(const SyncFileItemPtr &); diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index b0f83e9c8..7d443b641 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -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++; diff --git a/src/gui/issueswidget.cpp b/src/gui/issueswidget.cpp index ed1792a1c..8f56da4cd 100644 --- a/src/gui/issueswidget.cpp +++ b/src/gui/issueswidget.cpp @@ -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 } } diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 38d1caff9..65350f367 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -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() diff --git a/src/libsync/progressdispatcher.cpp b/src/libsync/progressdispatcher.cpp index 2f86888ae..d5b3f20f5 100644 --- a/src/libsync/progressdispatcher.cpp +++ b/src/libsync/progressdispatcher.cpp @@ -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); diff --git a/src/libsync/progressdispatcher.h b/src/libsync/progressdispatcher.h index 24764b2cb..e96821699 100644 --- a/src/libsync/progressdispatcher.h +++ b/src/libsync/progressdispatcher.h @@ -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; diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 7389a0ce2..e73777f96 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -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); diff --git a/src/libsync/syncengine.h b/src/libsync/syncengine.h index bc6b35bc6..deb87ef40 100644 --- a/src/libsync/syncengine.h +++ b/src/libsync/syncengine.h @@ -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);