Skip to content

Commit

Permalink
Merge pull request #7865 from nextcloud/bugfix/tray-sync-status-file-…
Browse files Browse the repository at this point in the history
…provider

Provide macOS VFS sync states in tray window GUI
  • Loading branch information
mgallien authored Feb 18, 2025
2 parents 00b02cf + 746e349 commit 77b622c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 7 deletions.
87 changes: 80 additions & 7 deletions src/gui/tray/syncstatussummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include "syncresult.h"
#include "tray/usermodel.h"

#ifdef BUILD_FILE_PROVIDER_MODULE
#include "gui/macOS/fileprovider.h"
#include "gui/macOS/fileprovidersocketserver.h"
#endif

#include <theme.h>

namespace {
Expand Down Expand Up @@ -50,6 +55,9 @@ SyncStatusSummary::SyncStatusSummary(QObject *parent)
const auto folderMan = FolderMan::instance();
connect(folderMan, &FolderMan::folderListChanged, this, &SyncStatusSummary::onFolderListChanged);
connect(folderMan, &FolderMan::folderSyncStateChange, this, &SyncStatusSummary::onFolderSyncStateChanged);
#ifdef BUILD_FILE_PROVIDER_MODULE
connect(Mac::FileProvider::instance()->socketServer(), &Mac::FileProviderSocketServer::syncStateChanged, this, &SyncStatusSummary::onFileProviderDomainSyncStateChanged);
#endif
}

bool SyncStatusSummary::reloadNeeded(AccountState *accountState) const
Expand Down Expand Up @@ -104,7 +112,7 @@ void SyncStatusSummary::markFolderAsSuccess(const Folder *folder)

bool SyncStatusSummary::folderErrors() const
{
return _foldersWithErrors.size() != 0;
return !_foldersWithErrors.empty();
}

bool SyncStatusSummary::folderError(const Folder *folder) const
Expand All @@ -118,6 +126,34 @@ void SyncStatusSummary::clearFolderErrors()
}

void SyncStatusSummary::setSyncStateForFolder(const Folder *folder)
{
if (_accountState && !_accountState->isConnected()) {
return;
}

const auto state = determineSyncStatus(folder->syncResult());

switch (state) {
case SyncResult::Success:
case SyncResult::SyncPrepare:
markFolderAsSuccess(folder);
break;
case SyncResult::Error:
case SyncResult::SetupError:
case SyncResult::Problem:
case SyncResult::Undefined:
markFolderAsError(folder);
case SyncResult::SyncRunning:
case SyncResult::NotYetStarted:
case SyncResult::Paused:
case SyncResult::SyncAbortRequested:
break;
}

setSyncState(state);
}

void SyncStatusSummary::setSyncState(const SyncResult::Status state)
{
if (_accountState && !_accountState->isConnected()) {
setSyncing(false);
Expand All @@ -128,19 +164,20 @@ void SyncStatusSummary::setSyncStateForFolder(const Folder *folder)
return;
}

const auto state = determineSyncStatus(folder->syncResult());

switch (state) {
case SyncResult::Success:
case SyncResult::SyncPrepare:
// Success should only be shown if all folders were fine
if (!folderErrors() || folderError(folder)) {
if (!folderErrors()
#ifdef BUILD_FILE_PROVIDER_MODULE
&& _fileProviderDomainsWithErrors.empty()
#endif
) {
setSyncing(false);
setTotalFiles(0);
setSyncStatusString(tr("All synced!"));
setSyncStatusDetailString("");
setSyncIcon(Theme::instance()->syncStatusOk());
markFolderAsSuccess(folder);
}
break;
case SyncResult::Error:
Expand All @@ -150,7 +187,6 @@ void SyncStatusSummary::setSyncStateForFolder(const Folder *folder)
setSyncStatusString(tr("Some files couldn't be synced!"));
setSyncStatusDetailString(tr("See below for errors"));
setSyncIcon(Theme::instance()->syncStatusError());
markFolderAsError(folder);
break;
case SyncResult::SyncRunning:
case SyncResult::NotYetStarted:
Expand Down Expand Up @@ -178,7 +214,6 @@ void SyncStatusSummary::setSyncStateForFolder(const Folder *folder)
setSyncStatusString(tr("Some files could not be synced!"));
setSyncStatusDetailString(tr("See below for warnings"));
setSyncIcon(Theme::instance()->syncStatusWarning());
markFolderAsError(folder);
break;
}
}
Expand All @@ -196,6 +231,35 @@ void SyncStatusSummary::onFolderSyncStateChanged(const Folder *folder)
setSyncStateForFolder(folder);
}

#ifdef BUILD_FILE_PROVIDER_MODULE
void SyncStatusSummary::onFileProviderDomainSyncStateChanged(const AccountPtr &account, SyncResult::Status state)
{
if (!_accountState || !_accountState->isConnected() || account != _accountState->account()) {
return;
}

switch (state) {
case SyncResult::Success:
case SyncResult::SyncPrepare:
// Success should only be shown if all folders were fine
_fileProviderDomainsWithErrors.erase(account->userIdAtHostWithPort());
break;
case SyncResult::Error:
case SyncResult::SetupError:
case SyncResult::Problem:
case SyncResult::Undefined:
_fileProviderDomainsWithErrors.insert(account->userIdAtHostWithPort());
case SyncResult::SyncRunning:
case SyncResult::NotYetStarted:
case SyncResult::Paused:
case SyncResult::SyncAbortRequested:
break;
}

setSyncState(state);
}
#endif

constexpr double calculateOverallPercent(
qint64 totalFileCount, qint64 completedFile, qint64 totalSize, qint64 completedSize)
{
Expand Down Expand Up @@ -368,6 +432,15 @@ void SyncStatusSummary::initSyncState()
syncStateFallbackNeeded = false;
}

#ifdef BUILD_FILE_PROVIDER_MODULE
const auto accounts = AccountManager::instance()->accounts();
for (const auto &accountState : accounts) {
const auto account = accountState->account();
onFileProviderDomainSyncStateChanged(account, Mac::FileProvider::instance()->socketServer()->latestReceivedSyncStatusForAccount(account));
syncStateFallbackNeeded = false;
}
#endif

if (syncStateFallbackNeeded) {
setSyncStateToConnectedState();
}
Expand Down
8 changes: 8 additions & 0 deletions src/gui/tray/syncstatussummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public slots:
void onFolderSyncStateChanged(const Folder *folder);
void onIsConnectedChanged();

#ifdef BUILD_FILE_PROVIDER_MODULE
void onFileProviderDomainSyncStateChanged(const AccountPtr &account, const SyncResult::Status status);
#endif

void setSyncState(const SyncResult::Status state);
void setSyncStateForFolder(const Folder *folder);
void markFolderAsError(const Folder *folder);
void markFolderAsSuccess(const Folder *folder);
Expand All @@ -86,6 +91,9 @@ public slots:

AccountStatePtr _accountState;
std::set<QString> _foldersWithErrors;
#ifdef BUILD_FILE_PROVIDER_MODULE
std::set<QString> _fileProviderDomainsWithErrors;
#endif

QUrl _syncIcon = Theme::instance()->syncStatusOk();
double _progress = 1.0;
Expand Down

0 comments on commit 77b622c

Please sign in to comment.