Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined sync status reporting in tray icon #5565

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ void FolderMan::trayOverallStatus(const QList<Folder *> &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:
Expand All @@ -1613,7 +1613,7 @@ void FolderMan::trayOverallStatus(const QList<Folder *> &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()) {
Expand All @@ -1635,52 +1635,66 @@ void FolderMan::trayOverallStatus(const QList<Folder *> &folders,
*unresolvedConflicts = syncResult.hasUnresolvedConflicts();
}
} else {
int errorsSeen = 0;
int goodSeen = 0;
int abortOrPausedSeen = 0;
int runSeen = 0;
auto errorsSeen = false;
auto goodSeen = false;
auto abortOrPausedSeen = false;
auto runSeen = false;
auto various = false;

for (const Folder *folder : qAsConst(folders)) {
SyncResult folderResult = folder->syncResult();
// 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++;
abortOrPausedSeen = true;
} else {
SyncResult::Status syncStatus = folderResult.status();
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())

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) {
*status = SyncResult::Undefined;
}
}
}
Expand Down
Loading