Provide correct sync state icon in file provider domain sync status

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-01-15 16:35:49 +08:00
parent 7d8778d12a
commit a469d44123
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 31 additions and 0 deletions

View file

@ -36,6 +36,7 @@ class FileProviderDomainSyncStatus : public QObject
Q_PROPERTY(int uploadFileTotalCount READ uploadFileTotalCount NOTIFY uploadFileTotalCountChanged)
Q_PROPERTY(int uploadFileCompletedCount READ uploadFileCompletedCount NOTIFY uploadFileCompletedCountChanged)
// TODO: more detailed reporting (time remaining, megabytes, etc.)
Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged)
public:
explicit FileProviderDomainSyncStatus(const QString &domainIdentifier, QObject *parent = nullptr);
@ -51,6 +52,7 @@ public:
int downloadFileCompletedCount() const;
int uploadFileTotalCount() const;
int uploadFileCompletedCount() const;
QUrl icon() const;
signals:
void syncingChanged(bool syncing);
@ -63,6 +65,7 @@ signals:
void downloadFileCompletedCountChanged(int downloadFileCompletedCount);
void uploadFileTotalCountChanged(int uploadFileTotalCount);
void uploadFileCompletedCountChanged(int uploadFileCompletedCount);
void iconChanged(const QUrl &icon);
private:
void setDownloading(const bool syncing);
@ -73,6 +76,8 @@ private:
void setDownloadFileCompletedCount(const int fileCompletedCount);
void setUploadFileTotalCount(const int fileTotalCount);
void setUploadFileCompletedCount(const int fileCompletedCount);
void setIcon(const QUrl &icon);
void updateIcon();
bool _downloading = false;
bool _uploading = false;
@ -82,6 +87,7 @@ private:
int _downloadFileCompletedCount = 0;
int _uploadFileTotalCount = 0;
int _uploadFileCompletedCount = 0;
QUrl _icon;
class MacImplementation;
std::unique_ptr<MacImplementation> d;

View file

@ -17,6 +17,7 @@
#include <QLoggingCategory>
#include "gui/macOS/fileproviderutils.h"
#include "libsync/theme.h"
#import <FileProvider/FileProvider.h>
@ -67,6 +68,7 @@ public:
q->setDownloadFractionCompleted(progress.fractionCompleted);
q->setDownloadFileTotalCount(progress.fileTotalCount.intValue);
q->setDownloadFileCompletedCount(progress.fileCompletedCount.intValue);
q->updateIcon();
}
void updateUpload(NSProgress *const progress) const
@ -80,6 +82,7 @@ public:
q->setUploadFractionCompleted(progress.fractionCompleted);
q->setUploadFileTotalCount(progress.fileTotalCount.intValue);
q->setUploadFileCompletedCount(progress.fileCompletedCount.intValue);
q->updateIcon();
}
private:
@ -95,6 +98,7 @@ FileProviderDomainSyncStatus::FileProviderDomainSyncStatus(const QString &domain
, d(std::make_unique<MacImplementation>(domainIdentifier, this))
{
qRegisterMetaType<FileProviderDomainSyncStatus*>("FileProviderDomainSyncStatus*");
updateIcon();
}
FileProviderDomainSyncStatus::~FileProviderDomainSyncStatus() = default;
@ -149,6 +153,11 @@ int FileProviderDomainSyncStatus::uploadFileCompletedCount() const
return _uploadFileCompletedCount;
}
QUrl FileProviderDomainSyncStatus::icon() const
{
return _icon;
}
void FileProviderDomainSyncStatus::setDownloading(const bool downloading)
{
if (_downloading == downloading) {
@ -233,4 +242,20 @@ void FileProviderDomainSyncStatus::setUploadFileCompletedCount(const int fileCom
emit uploadFileCompletedCountChanged(_uploadFileCompletedCount);
}
void FileProviderDomainSyncStatus::setIcon(const QUrl &icon)
{
if (_icon == icon) {
return;
}
_icon = icon;
emit iconChanged(_icon);
}
void FileProviderDomainSyncStatus::updateIcon()
{
const auto iconUrl = syncing() ? Theme::instance()->syncStatusRunning() : Theme::instance()->syncStatusOk();
setIcon(iconUrl);
}
} // OCC::Mac