Add main properties to FileProviderDomainSyncStatus
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 9 Jan 2024 17:04:52 +0000 (01:04 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 19 Feb 2024 14:45:20 +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 fc299a10bdd7d69f997413bfbf1a620922306b3a..11573e013e7a02fed179387b22dc9061f401ac0a 100644 (file)
@@ -22,11 +22,63 @@ namespace OCC::Mac
 class FileProviderDomainSyncStatus : public QObject
 {
     Q_OBJECT
+    Q_PROPERTY(bool syncing READ syncing NOTIFY syncingChanged)
+    Q_PROPERTY(bool downloading READ downloading NOTIFY downloadingChanged)
+    Q_PROPERTY(bool uploading READ uploading NOTIFY uploadingChanged)
+    Q_PROPERTY(double fractionCompleted READ fractionCompleted NOTIFY fractionCompletedChanged)
+    Q_PROPERTY(double downloadFractionCompleted READ downloadFractionCompleted NOTIFY downloadFractionCompletedChanged)
+    Q_PROPERTY(double uploadFractionCompleted READ uploadFractionCompleted NOTIFY uploadFractionCompletedChanged)
+    Q_PROPERTY(int downloadFileTotalCount READ downloadFileTotalCount NOTIFY downloadFileTotalCountChanged)
+    Q_PROPERTY(int downloadFileCompletedCount READ downloadFileCompletedCount NOTIFY downloadFileCompletedCountChanged)
+    Q_PROPERTY(int uploadFileTotalCount READ uploadFileTotalCount NOTIFY uploadFileTotalCountChanged)
+    Q_PROPERTY(int uploadFileCompletedCount READ uploadFileCompletedCount NOTIFY uploadFileCompletedCountChanged)
+    // TODO: more detailed reporting (time remaining, megabytes, etc.)
 
 public:
     explicit FileProviderDomainSyncStatus(const QString &domainIdentifier, QObject *parent = nullptr);
 
+    bool syncing() const;
+    bool downloading() const;
+    bool uploading() const;
+    double fractionCompleted() const;
+    double downloadFractionCompleted() const;
+    double uploadFractionCompleted() const;
+    int downloadFileTotalCount() const;
+    int downloadFileCompletedCount() const;
+    int uploadFileTotalCount() const;
+    int uploadFileCompletedCount() const;
+
+signals:
+    void syncingChanged(bool syncing);
+    void downloadingChanged(bool downloading);
+    void uploadingChanged(bool uploading);
+    void fractionCompletedChanged(double fractionCompleted);
+    void downloadFractionCompletedChanged(double downloadFractionCompleted);
+    void uploadFractionCompletedChanged(double uploadFractionCompleted);
+    void downloadFileTotalCountChanged(int downloadFileTotalCount);
+    void downloadFileCompletedCountChanged(int downloadFileCompletedCount);
+    void uploadFileTotalCountChanged(int uploadFileTotalCount);
+    void uploadFileCompletedCountChanged(int uploadFileCompletedCount);
+
 private:
+    void setDownloading(const bool syncing);
+    void setUploading(const bool syncing);
+    void setDownloadFractionCompleted(const double fractionCompleted);
+    void setUploadFractionCompleted(const double fractionCompleted);
+    void setDownloadFileTotalCount(const int fileTotalCount);
+    void setDownloadFileCompletedCount(const int fileCompletedCount);
+    void setUploadFileTotalCount(const int fileTotalCount);
+    void setUploadFileCompletedCount(const int fileCompletedCount);
+
+    bool _downloading = false;
+    bool _uploading = false;
+    double _downloadFractionCompleted = 0.0;
+    double _uploadFractionCompleted = 0.0;
+    int _downloadFileTotalCount = 0;
+    int _downloadFileCompletedCount = 0;
+    int _uploadFileTotalCount = 0;
+    int _uploadFileCompletedCount = 0;
+
     class MacImplementation;
     std::unique_ptr<MacImplementation> d;
 };
index 065bc79e779080c7cfc7f0a937b68a05aad8e9cf..f81ebb01e0f1b98d349e3e45a95690b76aa550b8 100644 (file)
@@ -60,4 +60,140 @@ FileProviderDomainSyncStatus::FileProviderDomainSyncStatus(const QString &domain
 {
 }
 
+FileProviderDomainSyncStatus::~FileProviderDomainSyncStatus() = default;
+
+bool FileProviderDomainSyncStatus::syncing() const
+{
+    return downloading() || uploading();
+}
+
+bool FileProviderDomainSyncStatus::downloading() const
+{
+    return _downloading;
+}
+
+bool FileProviderDomainSyncStatus::uploading() const
+{
+    return _uploading;
+}
+
+double FileProviderDomainSyncStatus::fractionCompleted() const
+{
+    return (downloadFractionCompleted() + uploadFractionCompleted()) / 2;
+}
+
+double FileProviderDomainSyncStatus::downloadFractionCompleted() const
+{
+    return _downloadFractionCompleted;
+}
+
+double FileProviderDomainSyncStatus::uploadFractionCompleted() const
+{
+    return _uploadFractionCompleted;
+}
+
+int FileProviderDomainSyncStatus::downloadFileTotalCount() const
+{
+    return _downloadFileTotalCount;
+}
+
+int FileProviderDomainSyncStatus::downloadFileCompletedCount() const
+{
+    return _downloadFileCompletedCount;
+}
+
+int FileProviderDomainSyncStatus::uploadFileTotalCount() const
+{
+    return _uploadFileTotalCount;
+}
+
+int FileProviderDomainSyncStatus::uploadFileCompletedCount() const
+{
+    return _uploadFileCompletedCount;
+}
+
+void FileProviderDomainSyncStatus::setDownloading(const bool downloading)
+{
+    if (_downloading == downloading) {
+        return;
+    }
+
+    _downloading = downloading;
+    emit downloadingChanged(_downloading);
+    emit syncingChanged(syncing());
+}
+
+void FileProviderDomainSyncStatus::setUploading(const bool uploading)
+{
+    if (_uploading == uploading) {
+        return;
+    }
+
+    _uploading = uploading;
+    emit uploadingChanged(_uploading);
+    emit syncingChanged(syncing());
+}
+
+void FileProviderDomainSyncStatus::setDownloadFractionCompleted(const double fractionCompleted)
+{
+    if (_downloadFractionCompleted == fractionCompleted) {
+        return;
+    }
+
+    _downloadFractionCompleted = fractionCompleted;
+    emit downloadFractionCompletedChanged(_downloadFractionCompleted);
+    emit fractionCompletedChanged(fractionCompleted());
+}
+
+void FileProviderDomainSyncStatus::setUploadFractionCompleted(const double fractionCompleted)
+{
+    if (_uploadFractionCompleted == fractionCompleted) {
+        return;
+    }
+
+    _uploadFractionCompleted = fractionCompleted;
+    emit uploadFractionCompletedChanged(_uploadFractionCompleted);
+    emit fractionCompletedChanged(fractionCompleted());
+}
+
+void FileProviderDomainSyncStatus::setDownloadFileTotalCount(const int fileTotalCount)
+{
+    if (_downloadFileTotalCount == fileTotalCount) {
+        return;
+    }
+
+    _downloadFileTotalCount = fileTotalCount;
+    emit downloadFileTotalCountChanged(_downloadFileTotalCount);
+}
+
+void FileProviderDomainSyncStatus::setDownloadFileCompletedCount(const int fileCompletedCount)
+{
+    if (_downloadFileCompletedCount == fileCompletedCount) {
+        return;
+    }
+
+    _downloadFileCompletedCount = fileCompletedCount;
+    emit downloadFileCompletedCountChanged(_downloadFileCompletedCount);
+}
+
+void FileProviderDomainSyncStatus::setUploadFileTotalCount(const int fileTotalCount)
+{
+    if (_uploadFileTotalCount == fileTotalCount) {
+        return;
+    }
+
+    _uploadFileTotalCount = fileTotalCount;
+    emit uploadFileTotalCountChanged(_uploadFileTotalCount);
+}
+
+void FileProviderDomainSyncStatus::setUploadFileCompletedCount(const int fileCompletedCount)
+{
+    if (_uploadFileCompletedCount == fileCompletedCount) {
+        return;
+    }
+
+    _uploadFileCompletedCount = fileCompletedCount;
+    emit uploadFileCompletedCountChanged(_uploadFileCompletedCount);
+}
+
 } // OCC::Mac