From 76ff41f3e0d32539d39fa4953d232f6bb3fc97d3 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 4 Apr 2023 14:36:11 +0800 Subject: [PATCH 1/4] Properly report Undefined sync status when multiple folders syncing Signed-off-by: Claudio Cambra --- src/gui/folderman.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 2361862fddc4c..1dd600a6279b3 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1681,6 +1681,8 @@ void FolderMan::trayOverallStatus(const QList &folders, *status = SyncResult::SyncRunning; } else if (goodSeen > 0) { *status = SyncResult::Success; + } else if (various > 0) { + *status = SyncResult::Undefined; } } } From 165bf97b4801c5358238f4bf12ade688fe64a3b1 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 4 Apr 2023 14:41:42 +0800 Subject: [PATCH 2/4] Use auto and const auto where possible in trayOverallStatus Signed-off-by: Claudio Cambra --- src/gui/folderman.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 1dd600a6279b3..4bd027f96e12b 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1604,7 +1604,7 @@ void FolderMan::trayOverallStatus(const QList &folders, *status = SyncResult::Undefined; *unresolvedConflicts = false; - int cnt = folders.count(); + const auto cnt = folders.count(); // if one folder: show the state of the one folder. // if more folders: @@ -1613,7 +1613,7 @@ void FolderMan::trayOverallStatus(const QList &folders, // do not show "problem" in the tray // if (cnt == 1) { - Folder *folder = folders.at(0); + const auto folder = folders.at(0); if (folder) { auto syncResult = folder->syncResult(); if (folder->syncPaused()) { @@ -1635,17 +1635,18 @@ void FolderMan::trayOverallStatus(const QList &folders, *unresolvedConflicts = syncResult.hasUnresolvedConflicts(); } } else { - int errorsSeen = 0; - int goodSeen = 0; - int abortOrPausedSeen = 0; - int runSeen = 0; + auto errorsSeen = 0; + auto goodSeen = 0; + auto abortOrPausedSeen = 0; + auto runSeen = 0; + auto various = 0; for (const Folder *folder : qAsConst(folders)) { - SyncResult folderResult = folder->syncResult(); + const auto folderResult = folder->syncResult(); if (folder->syncPaused()) { abortOrPausedSeen++; } else { - SyncResult::Status syncStatus = folderResult.status(); + const auto syncStatus = folderResult.status(); switch (syncStatus) { case SyncResult::Undefined: From 28874ec25cc103c8a5278e8b2580d223c739fb3c Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 4 Apr 2023 14:42:18 +0800 Subject: [PATCH 3/4] Use bools rather than unnecessary ints in folderman trayoverallstatus Signed-off-by: Claudio Cambra f --- src/gui/folderman.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 4bd027f96e12b..03314a205fe8a 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1635,54 +1635,55 @@ void FolderMan::trayOverallStatus(const QList &folders, *unresolvedConflicts = syncResult.hasUnresolvedConflicts(); } } else { - auto errorsSeen = 0; - auto goodSeen = 0; - auto abortOrPausedSeen = 0; - auto runSeen = 0; - auto various = 0; + auto errorsSeen = false; + auto goodSeen = false; + auto abortOrPausedSeen = false; + auto runSeen = false; + auto various = false; for (const Folder *folder : qAsConst(folders)) { const auto folderResult = folder->syncResult(); if (folder->syncPaused()) { - abortOrPausedSeen++; + abortOrPausedSeen = true; } else { const auto syncStatus = folderResult.status(); switch (syncStatus) { case SyncResult::Undefined: case SyncResult::NotYetStarted: + various = true; break; case SyncResult::SyncPrepare: case SyncResult::SyncRunning: - runSeen++; + runSeen = true; break; case SyncResult::Problem: // don't show the problem icon in tray. case SyncResult::Success: - goodSeen++; + goodSeen = true; break; case SyncResult::Error: case SyncResult::SetupError: - errorsSeen++; + errorsSeen = true; break; case SyncResult::SyncAbortRequested: case SyncResult::Paused: - abortOrPausedSeen++; + abortOrPausedSeen = true; // no default case on purpose, check compiler warnings } } if (folderResult.hasUnresolvedConflicts()) *unresolvedConflicts = true; } - if (errorsSeen > 0) { + if (errorsSeen) { *status = SyncResult::Error; - } else if (abortOrPausedSeen > 0 && abortOrPausedSeen == cnt) { + } else if (abortOrPausedSeen) { // only if all folders are paused *status = SyncResult::Paused; - } else if (runSeen > 0) { + } else if (runSeen) { *status = SyncResult::SyncRunning; - } else if (goodSeen > 0) { + } else if (goodSeen) { *status = SyncResult::Success; - } else if (various > 0) { + } else if (various) { *status = SyncResult::Undefined; } } From d52ad2d27bc1dbd9ea9a25c995111f63410c40b1 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 4 Apr 2023 14:48:15 +0800 Subject: [PATCH 4/4] Do an early break of folder state check loop when errors seen Signed-off-by: Claudio Cambra --- src/gui/folderman.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 03314a205fe8a..36aedb2b29464 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1642,7 +1642,14 @@ void FolderMan::trayOverallStatus(const QList &folders, auto various = false; for (const Folder *folder : qAsConst(folders)) { + // We've already seen an error, worst case met. + // No need to check the remaining folders. + if (errorsSeen) { + break; + } + const auto folderResult = folder->syncResult(); + if (folder->syncPaused()) { abortOrPausedSeen = true; } else { @@ -1671,9 +1678,12 @@ void FolderMan::trayOverallStatus(const QList &folders, // no default case on purpose, check compiler warnings } } - if (folderResult.hasUnresolvedConflicts()) + + if (folderResult.hasUnresolvedConflicts()) { *unresolvedConflicts = true; + } } + if (errorsSeen) { *status = SyncResult::Error; } else if (abortOrPausedSeen) {