Progress info: Reset between syncs #4856 (PR #4872)
authorckamm <mail@ckamm.de>
Fri, 20 May 2016 13:07:54 +0000 (15:07 +0200)
committerJocelyn Turcotte <jturcotte@woboq.com>
Fri, 20 May 2016 13:07:54 +0000 (15:07 +0200)
src/gui/folder.cpp
src/gui/owncloudgui.cpp
src/gui/protocolwidget.cpp
src/libsync/progressdispatcher.cpp
src/libsync/progressdispatcher.h
src/libsync/syncengine.cpp

index 47c2c29441616eb7b390c1bb4a2962ec863330a5..5b8c01957d1b3f7dcd25c111be4d1e87fadb91eb 100644 (file)
@@ -915,7 +915,7 @@ void Folder::slotFolderDiscovered(bool, QString folderName)
 // and hand the result over to the progress dispatcher.
 void Folder::slotTransmissionProgress(const ProgressInfo &pi)
 {
-    if( !pi.hasStarted() ) {
+    if( !pi.isUpdatingEstimates() ) {
         // this is the beginning of a sync, set the warning level to 0
         _syncResult.setWarnCount(0);
     }
index d32995455539cca3e77b1665841f7d387b0f7012..63e4e32aede50ae3cd421c405e5004fa9c43639a 100644 (file)
@@ -685,7 +685,7 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const ProgressInfo&
         slotRebuildRecentMenus();
     }
 
-    if (progress.hasStarted()
+    if (progress.isUpdatingEstimates()
             && progress.completedFiles() >= progress.totalFiles()
             && progress._currentDiscoveredFolder.isEmpty()) {
         QTimer::singleShot(2000, this, SLOT(slotDisplayIdle()));
index 34e91ccff5b6ccbfc67f2a7ac4ca41b5300f6b24..c96fa1de33ba666c4ec12e5c20c2641a5665f1b8 100644 (file)
@@ -219,7 +219,7 @@ QTreeWidgetItem* ProtocolWidget::createCompletedTreewidgetItem(const QString& fo
 
 void ProtocolWidget::slotProgressInfo( const QString& folder, const ProgressInfo& progress )
 {
-    if( !progress.hasStarted() ) {
+    if( !progress.isUpdatingEstimates() ) {
         // The sync is restarting, clean the old items
         cleanItems(folder);
     } else if (progress.completedFiles() >= progress.totalFiles()) {
index 517507167875c66a3c9bdf0aca90be36fe92d73f..560c1ff8ba074915a11293234fcee92ae3a29d7e 100644 (file)
@@ -127,13 +127,30 @@ void ProgressDispatcher::setProgressInfo(const QString& folder, const ProgressIn
     emit progressInfo( folder, progress );
 }
 
-void ProgressInfo::start()
+ProgressInfo::ProgressInfo()
 {
     connect(&_updateEstimatesTimer, SIGNAL(timeout()), SLOT(updateEstimates()));
+    reset();
+}
+
+void ProgressInfo::reset()
+{
+    _currentItems.clear();
+    _currentDiscoveredFolder.clear();
+    _sizeProgress = Progress();
+    _fileProgress = Progress();
+    _totalSizeOfCompletedJobs = 0;
+    _maxBytesPerSecond = 100000.0;
+    _maxFilesPerSecond = 2.0;
+    _updateEstimatesTimer.stop();
+}
+
+void ProgressInfo::startEstimateUpdates()
+{
     _updateEstimatesTimer.start(1000);
 }
 
-bool ProgressInfo::hasStarted() const
+bool ProgressInfo::isUpdatingEstimates() const
 {
     return _updateEstimatesTimer.isActive();
 }
index ec555c3131985e40aa43f1f0088ac14bad764ea4..7ea3f3b8fe8fb2b02ea1bcb930108d4fe024dbdc 100644 (file)
@@ -37,27 +37,27 @@ class OWNCLOUDSYNC_EXPORT ProgressInfo : public QObject
 {
     Q_OBJECT
 public:
-    ProgressInfo()
-        : _totalSizeOfCompletedJobs(0)
-        , _maxFilesPerSecond(2.0)
-        , _maxBytesPerSecond(100000.0)
-    {}
+    ProgressInfo();
+
+    /** Resets for a new sync run.
+     */
+    void reset();
 
     /**
      * Called when propagation starts.
      *
-     * hasStarted() will return true afterwards.
+     * isUpdatingEstimates() will return true afterwards.
      */
-    void start();
+    void startEstimateUpdates();
 
     /**
-     * Returns true when propagation has started (start() was called).
+     * Returns true when startEstimateUpdates() was called.
      *
      * This is used when the SyncEngine wants to indicate a new sync
      * is about to start via the transmissionProgress() signal. The
-     * first ProgressInfo will have hasStarted() == false.
+     * first ProgressInfo will have isUpdatingEstimates() == false.
      */
-    bool hasStarted() const;
+    bool isUpdatingEstimates() const;
 
     /**
      * Increase the file and size totals by the amount indicated in item.
index 66425cb35749888c91ce0850af91c7d25fb3b96a..89c1c9d89b8b48879fca8f7a9d11c2a5e0a904b2 100644 (file)
@@ -673,6 +673,8 @@ void SyncEngine::startSync()
     _syncRunning = true;
     _anotherSyncNeeded = false;
 
+    _progressInfo->reset();
+
     if (!QDir(_localPath).exists()) {
         // No _tr, it should only occur in non-mirall
         emit csyncError("Unable to find local sync folder.");
@@ -909,7 +911,7 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
     emit aboutToPropagate(_syncedItems);
     // it's important to do this before ProgressInfo::start(), to announce start of new sync
     emit transmissionProgress(*_progressInfo);
-    _progressInfo->start();
+    _progressInfo->startEstimateUpdates();
 
     // post update phase script: allow to tweak stuff by a custom script in debug mode.
     if( !qgetenv("OWNCLOUD_POST_UPDATE_SCRIPT").isEmpty() ) {