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.
This commit is contained in:
Christian Kamm 2018-02-21 13:55:33 +01:00 committed by Camila San
parent 75194d1821
commit 800f1ace0c
No known key found for this signature in database
GPG key ID: 7A4A6121E88E2AD4
6 changed files with 42 additions and 0 deletions

View file

@ -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()) {

View file

@ -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();

View file

@ -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)

View file

@ -63,6 +63,7 @@ protected:
signals:
void copyToClipboard();
void issueCountUpdated(int);
void folderConflicts(QString folder, QStringList conflictPaths);
private slots:
void slotRefreshIssues();

View file

@ -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);

View file

@ -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; }