Clean up systray methods, make more QML-friendly
authorClaudio Cambra <claudio.cambra@gmail.com>
Thu, 30 Jun 2022 14:20:13 +0000 (16:20 +0200)
committerClaudio Cambra <claudio.cambra@gmail.com>
Wed, 6 Jul 2022 09:26:53 +0000 (11:26 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
src/gui/systray.cpp
src/gui/systray.h
src/gui/tray/Window.qml

index 04400ee2130895df08904ee9f9d1852e0b47ae0d..9db7ef835c58876066a8eba1d45eaa561a9dd223 100644 (file)
@@ -280,11 +280,6 @@ void Systray::setPauseOnAllFoldersHelper(bool pause)
     }
 }
 
-bool Systray::isOpen()
-{
-    return _isOpen;
-}
-
 QString Systray::windowTitle() const
 {
     return Theme::instance()->appNameGUI();
@@ -300,14 +295,15 @@ bool Systray::useNormalWindow() const
     return cfg.showMainDialogAsNormalWindow();
 }
 
-Q_INVOKABLE void Systray::setOpened()
+bool Systray::isOpen() const
 {
-    _isOpen = true;
+    return _isOpen;
 }
 
-Q_INVOKABLE void Systray::setClosed()
+void Systray::setIsOpen(const bool isOpen)
 {
-    _isOpen = false;
+    _isOpen = isOpen;
+    Q_EMIT isOpenChanged();
 }
 
 void Systray::showMessage(const QString &title, const QString &message, MessageIcon icon)
@@ -347,19 +343,18 @@ void Systray::setToolTip(const QString &tip)
     QSystemTrayIcon::setToolTip(tr("%1: %2").arg(Theme::instance()->appNameGUI(), tip));
 }
 
-bool Systray::syncIsPaused()
+bool Systray::syncIsPaused() const
 {
     return _syncIsPaused;
 }
 
-void Systray::pauseResumeSync()
+void Systray::setSyncIsPaused(const bool syncIsPaused)
 {
+    _syncIsPaused = syncIsPaused;
     if (_syncIsPaused) {
-        _syncIsPaused = false;
-        slotUnpauseAllFolders();
-    } else {
-        _syncIsPaused = true;
         slotPauseAllFolders();
+    } else {
+        slotUnpauseAllFolders();
     }
 }
 
index 40dfa36f989f80d545765ecb0cb92223c0da2e04..716f13e438653a79e10c1db24fc692b8af362778 100644 (file)
@@ -66,6 +66,8 @@ class Systray
 
     Q_PROPERTY(QString windowTitle READ windowTitle CONSTANT)
     Q_PROPERTY(bool useNormalWindow READ useNormalWindow CONSTANT)
+    Q_PROPERTY(bool syncIsPaused READ syncIsPaused WRITE setSyncIsPaused NOTIFY syncIsPausedChanged)
+    Q_PROPERTY(bool isOpen READ isOpen WRITE setIsOpen NOTIFY isOpenChanged)
 
 public:
     static Systray *instance();
@@ -85,17 +87,13 @@ public:
     void showMessage(const QString &title, const QString &message, MessageIcon icon = Information);
     void showUpdateMessage(const QString &title, const QString &message, const QUrl &webUrl);
     void setToolTip(const QString &tip);
-    bool isOpen();
-    QString windowTitle() const;
-    bool useNormalWindow() const;
     void createCallDialog(const Activity &callNotification, const AccountStatePtr accountState);
 
-    Q_INVOKABLE void pauseResumeSync();
-    Q_INVOKABLE bool syncIsPaused();
-    Q_INVOKABLE void setOpened();
-    Q_INVOKABLE void setClosed();
-    Q_INVOKABLE void forceWindowInit(QQuickWindow *window) const;
-    Q_INVOKABLE void positionNotificationWindow(QQuickWindow *window) const;
+    Q_REQUIRED_RESULT QString windowTitle() const;
+    Q_REQUIRED_RESULT bool useNormalWindow() const;
+
+    Q_REQUIRED_RESULT bool syncIsPaused() const;
+    Q_REQUIRED_RESULT bool isOpen() const;
 
 signals:
     void currentUserChanged();
@@ -114,11 +112,20 @@ signals:
     void sendChatMessage(const QString &token, const QString &message, const QString &replyTo);
     void showErrorMessageDialog(const QString &error);
 
+    void syncIsPausedChanged();
+    void isOpenChanged();
+
 public slots:
     void slotNewUserSelected();
     void positionWindowAtTray(QQuickWindow *window) const;
     void positionWindowAtScreenCenter(QQuickWindow *window) const;
 
+    void setSyncIsPaused(const bool syncIsPaused);
+    void setIsOpen(const bool isOpen);
+
+    void forceWindowInit(QQuickWindow *window) const;
+    void positionNotificationWindow(QQuickWindow *window) const;
+
 private slots:
     void slotUnpauseAllFolders();
     void slotPauseAllFolders();
index 81629711f98ad0ccb2df25448c760a9bce82f320..6419e651ed9c19ab930d92082b230a0bf47151ab 100644 (file)
@@ -39,13 +39,11 @@ Window {
     onActiveChanged: {\r
         if (!Systray.useNormalWindow && !active) {\r
             hide();\r
-            Systray.setClosed();\r
+            Systray.isOpen = false;\r
         }\r
    }\r
 \r
-    onClosing: {\r
-        Systray.setClosed()\r
-    }\r
+    onClosing: Systray.isOpen = false\r
 \r
     onVisibleChanged: {\r
         // HACK: reload account Instantiator immediately by restting it - could be done better I guess\r
@@ -97,13 +95,13 @@ Window {
             trayWindow.raise();\r
             trayWindow.requestActivate();\r
 \r
-            Systray.setOpened();\r
+            Systray.isOpen = true;\r
             UserModel.fetchCurrentActivityModel();\r
         }\r
 \r
         function onHideWindow() {\r
             trayWindow.hide();\r
-            Systray.setClosed();\r
+            Systray.isOpen = false;\r
         }\r
 \r
         function onShowFileActivityDialog(objectName, objectId) {\r
@@ -178,7 +176,7 @@ Window {
                     // We call open() instead of popup() because we want to position it\r
                     // exactly below the dropdown button, not the mouse\r
                     onClicked: {\r
-                        syncPauseButton.text = Systray.syncIsPaused() ? qsTr("Resume sync for all") : qsTr("Pause sync for all")\r
+                        syncPauseButton.text = Systray.syncIsPaused ? qsTr("Resume sync for all") : qsTr("Pause sync for all")\r
                         if (accountMenu.visible) {\r
                             accountMenu.close()\r
                         } else {\r
@@ -322,7 +320,7 @@ Window {
                             font.pixelSize: Style.topLinePixelSize\r
                             palette.windowText: Style.ncTextColor\r
                             hoverEnabled: true\r
-                            onClicked: Systray.pauseResumeSync()\r
+                            onClicked: Systray.syncIsPaused = !Systray.syncIsPaused\r
 \r
                             background: Item {\r
                                 height: parent.height\r
@@ -335,7 +333,7 @@ Window {
                             }\r
 \r
                             Accessible.role: Accessible.MenuItem\r
-                            Accessible.name: Systray.syncIsPaused() ? qsTr("Resume sync for all") : qsTr("Pause sync for all")\r
+                            Accessible.name: Systray.syncIsPaused ? qsTr("Resume sync for all") : qsTr("Pause sync for all")\r
                             Accessible.onPressAction: syncPauseButton.clicked()\r
                         }\r
 \r