From 800f1ace0c5bc89119a8712ec977a82c741e89ac Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 21 Feb 2018 13:55:33 +0100 Subject: [PATCH] SyncResult: Make sure the number of conflicts is correct #6226 If the SyncResult incorrectly believes that there are no conflicts, the tray icon won't be correct and there will be no warning about unresolved conflicts on the account. Nevertheless, it's pretty awkward that the IssuesWidget is better informed about pending conflicts than the Folder itself. This kind of backwards data flow is very confusing. Unfortunately the only alternative I see is to either keep track of this information in two places (also in Folder), or create a common data-holding class that can serve as a model instance for the issues view as well as provide data directly to the Folder - which would have been a much larger change. --- src/gui/folder.cpp | 14 ++++++++++++++ src/gui/folder.h | 7 +++++++ src/gui/issueswidget.cpp | 14 ++++++++++++++ src/gui/issueswidget.h | 1 + src/libsync/progressdispatcher.h | 5 +++++ src/libsync/syncresult.h | 1 + 6 files changed, 42 insertions(+) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 81a782db1..cc526290d 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -107,6 +107,9 @@ Folder::Folder(const FolderDefinition &definition, _scheduleSelfTimer.setInterval(SyncEngine::minimumFileAgeForUpload); connect(&_scheduleSelfTimer, &QTimer::timeout, this, &Folder::slotScheduleThisFolder); + + connect(ProgressDispatcher::instance(), &ProgressDispatcher::folderConflicts, + this, &Folder::slotFolderConflicts); } Folder::~Folder() @@ -963,6 +966,17 @@ void Folder::slotNextSyncFullLocalDiscovery() _timeSinceLastFullLocalDiscovery.invalidate(); } +void Folder::slotFolderConflicts(const QString &folder, const QStringList &conflictPaths) +{ + if (folder != _definition.alias) + return; + auto &r = _syncResult; + + // If the number of conflicts is too low, adjust it upwards + if (conflictPaths.size() > r.numNewConflictItems() + r.numOldConflictItems()) + r.setNumOldConflictItems(conflictPaths.size() - r.numNewConflictItems()); +} + void Folder::scheduleThisFolderSoon() { if (!_scheduleSelfTimer.isActive()) { diff --git a/src/gui/folder.h b/src/gui/folder.h index ef4d70541..fedaa46a5 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -315,6 +315,13 @@ private slots: /** Ensures that the next sync performs a full local discovery. */ void slotNextSyncFullLocalDiscovery(); + /** Adjust sync result based on conflict data from IssuesWidget. + * + * This is pretty awkward, but IssuesWidget just keeps better track + * of conflicts across partial local discovery. + */ + void slotFolderConflicts(const QString &folder, const QStringList &conflictPaths); + private: bool reloadExcludes(); diff --git a/src/gui/issueswidget.cpp b/src/gui/issueswidget.cpp index 15de3f107..9896373ee 100644 --- a/src/gui/issueswidget.cpp +++ b/src/gui/issueswidget.cpp @@ -241,6 +241,20 @@ void IssuesWidget::slotProgressInfo(const QString &folder, const ProgressInfo &p return engine.shouldDiscoverLocally(path); }); } + if (progress.status() == ProgressInfo::Done) { + // We keep track very well of pending conflicts. + // Inform other components about them. + QStringList conflicts; + auto tree = _ui->_treeWidget; + for (int i = 0; i < tree->topLevelItemCount(); ++i) { + auto item = tree->topLevelItem(i); + if (ProtocolItem::folderName(item) == folder + && ProtocolItem::status(item) == SyncFileItem::Conflict) { + conflicts.append(ProtocolItem::filePath(item)); + } + } + emit ProgressDispatcher::instance()->folderConflicts(folder, conflicts); + } } void IssuesWidget::slotItemCompleted(const QString &folder, const SyncFileItemPtr &item) diff --git a/src/gui/issueswidget.h b/src/gui/issueswidget.h index b30964751..7d4cbcb39 100644 --- a/src/gui/issueswidget.h +++ b/src/gui/issueswidget.h @@ -63,6 +63,7 @@ protected: signals: void copyToClipboard(); void issueCountUpdated(int); + void folderConflicts(QString folder, QStringList conflictPaths); private slots: void slotRefreshIssues(); diff --git a/src/libsync/progressdispatcher.h b/src/libsync/progressdispatcher.h index a05564a40..e011b5b60 100644 --- a/src/libsync/progressdispatcher.h +++ b/src/libsync/progressdispatcher.h @@ -296,6 +296,11 @@ signals: */ void syncError(const QString &folder, const QString &message, ErrorCategory category); + /** + * @brief Emitted for a folder when a sync is done, listing all pending conflicts + */ + void folderConflicts(const QString &folder, const QStringList &conflictPaths); + protected: void setProgressInfo(const QString &folder, const ProgressInfo &progress); diff --git a/src/libsync/syncresult.h b/src/libsync/syncresult.h index ab53c8dba..00bf6f949 100644 --- a/src/libsync/syncresult.h +++ b/src/libsync/syncresult.h @@ -68,6 +68,7 @@ public: int numRenamedItems() const { return _numRenamedItems; } int numNewConflictItems() const { return _numNewConflictItems; } int numOldConflictItems() const { return _numOldConflictItems; } + void setNumOldConflictItems(int n) { _numOldConflictItems = n; } int numErrorItems() const { return _numErrorItems; } const SyncFileItemPtr &firstItemNew() const { return _firstItemNew; }