Provide correct sync state icon in file provider domain sync status
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 15 Jan 2024 08:35:49 +0000 (16:35 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 19 Feb 2024 14:45:22 +0000 (22:45 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileproviderdomainsyncstatus.h
src/gui/macOS/fileproviderdomainsyncstatus_mac.mm

index db0f377161b4bacecf14b6184d6fa320e01dbe84..d92c2c5536c52e69ab1e5b6df474e83dc4e40d97 100644 (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;
index 1455f93b1613a155b9670bcdbd745441e0bff7ab..6cc7efd42ae4c4923a25ba8464764d3f3c552f9d 100644 (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