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

Provide macOS VFS sync states in tray window GUI #7865

Merged
merged 6 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
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
87 changes: 80 additions & 7 deletions src/gui/tray/syncstatussummary.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/tray/syncstatussummary.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/tray/syncstatussummary.cpp

File src/gui/tray/syncstatussummary.cpp does not conform to Custom style guidelines. (lines 59, 257)
* Copyright (C) by Felix Weilbach <felix.weilbach@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -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 @@
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 @@

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::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 @@
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 @@
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 @@
setSyncStatusString(tr("Some files could not be synced!"));
setSyncStatusDetailString(tr("See below for warnings"));
setSyncIcon(Theme::instance()->syncStatusWarning());
markFolderAsError(folder);
break;
}
}
Expand All @@ -196,7 +231,36 @@
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(

Check warning on line 263 in src/gui/tray/syncstatussummary.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/syncstatussummary.cpp:263:18 [modernize-use-trailing-return-type]

use a trailing return type for this function
qint64 totalFileCount, qint64 completedFile, qint64 totalSize, qint64 completedSize)
{
int overallPercent = 0;
Expand Down Expand Up @@ -368,6 +432,15 @@
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 @@ -14,7 +14,7 @@

#pragma once

#include "account.h"

Check failure on line 17 in src/gui/tray/syncstatussummary.h

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/syncstatussummary.h:17:10 [clang-diagnostic-error]

'account.h' file not found
#include "accountfwd.h"
#include "accountstate.h"
#include "folderman.h"
Expand Down Expand Up @@ -66,6 +66,11 @@
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 @@

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
Loading