Added popup show/hide logic
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Mon, 30 Dec 2019 10:39:21 +0000 (11:39 +0100)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Mon, 30 Dec 2019 10:39:21 +0000 (11:39 +0100)
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
src/gui/owncloudgui.cpp
src/gui/systray.cpp
src/gui/systray.h
src/gui/tray/UserModel.cpp
src/gui/tray/UserModel.h
src/gui/tray/window.qml

index f48a8bb2728e228b55ee41c8a1d596acde5dc1d2..dd48dc0a3de871e608f2198c6fc88c5a213a50f3 100644 (file)
@@ -188,7 +188,8 @@ void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason)
                 raiseDialog(_settingsDialog.data());
             }
 #else
-            slotOpenSettingsDialog();
+            UserModel::instance()->showWindow();
+            //slotOpenSettingsDialog();
 #endif
         }
     }
index caabd6c29c662830e64dc697e6bfb452b5406278..3e12e83638de35444e5b96d84df0dc9f7b8f7332 100644 (file)
@@ -35,14 +35,15 @@ namespace OCC {
 
 Systray::Systray() // TODO: make singleton, provide ::instance()
     : _currentAccount(nullptr)
+    , _trayComponent(nullptr)
     , _trayContext(nullptr)
     , _accountMenuModel(nullptr)
 {
     // Create QML tray engine, build component, set C++ backend context used in window.qml
     // Use pointer instead of engine() helper function until Qt 5.12 is minimum standard
     QQmlEngine *engine = new QQmlEngine;
-    QQmlComponent systray(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/window.qml")));
-    _trayContext = engine->contextForObject(systray.create());
+    _trayComponent = new QQmlComponent(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/window.qml")));
+    _trayContext = engine->contextForObject(_trayComponent->create());
 
     _accountMenuModel = UserModel::instance();
 
@@ -54,12 +55,12 @@ Systray::Systray() // TODO: make singleton, provide ::instance()
     //ctxt->setContextProperty("filename", "state-offline");
 
     if (!AccountManager::instance()->accounts().isEmpty()) {
-
         slotChangeActivityModel(AccountManager::instance()->accounts().first());
     }
 
     //connect(AccountManager::instance(), &AccountManager::accountAdded,
     //    this, &Systray::slotChangeActivityModel);
+    UserModel::instance()->hideWindow();
 }
 
 Systray::~Systray()
index 2a0e22db7f6f5700c9a019b7ee26351f8cfb99b7..bf532d0d7281289c201aed439bb53096509201b8 100644 (file)
@@ -47,6 +47,8 @@ public:
     ~Systray();
     void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
     void setToolTip(const QString &tip);
+    void showWindow();
+    void hideWindow();
 
 signals:
     void currentUserChanged();
@@ -56,6 +58,7 @@ private slots:
 
 private:
     AccountStatePtr _currentAccount;
+    QQmlComponent *_trayComponent;
     QQmlContext *_trayContext;
     UserModel *_accountMenuModel;
 };
index 63513003f540cf04bd2f196b11c0428268cf7d3f..225cb241e0ec2ec1084a2520169c19ed1bd3f464 100644 (file)
@@ -114,7 +114,7 @@ Q_INVOKABLE bool UserModel::isCurrentUserConnected()
     return _users[_currentUserId].isConnected();
 }
 
-QImage UserModel::currentUserAvatar()
+Q_INVOKABLE QImage UserModel::currentUserAvatar()
 {
     return _users[_currentUserId].avatar();
 }
index 6d8a7d04f5367d4a87843046f23ba778f33711ef..aeb2716ee4e098b7c3b9a2fec2e9af78dc793827 100644 (file)
@@ -45,9 +45,9 @@ public:
 
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
-    QImage currentUserAvatar();
     QImage avatarById(const int &id);
 
+    Q_INVOKABLE QImage currentUserAvatar();
     Q_INVOKABLE int numUsers();
     Q_INVOKABLE bool isCurrentUserConnected();
     Q_INVOKABLE QString currentUserName();
@@ -72,6 +72,9 @@ signals:
     Q_INVOKABLE void newUserSelected();
     Q_INVOKABLE void refreshUserMenu();
 
+    Q_INVOKABLE void hideWindow();
+    Q_INVOKABLE void showWindow();
+
 protected:
     QHash<int, QByteArray> roleNames() const;
 
index 45d2455d3fb7fbfdeabebea52ebc5aa8540e5492..e59ae314b535c4c1074e1857bb29b0463f849bdd 100644 (file)
@@ -14,6 +14,12 @@ Window {
     color: "transparent"\r
     flags: Qt.FramelessWindowHint\r
 \r
+    onActiveChanged: {\r
+        if(!active) {\r
+            trayWindow.hide();\r
+        }\r
+    }\r
+\r
     Component.onCompleted: {\r
         /* desktopAvailableWidth and Height doesn't include the system tray bar\r
                but breaks application anyway on windows when using multi monitor setup,\r
@@ -32,6 +38,13 @@ Window {
         onNewUserSelected: {\r
             accountMenu.close()\r
         }\r
+        onShowWindow: {\r
+            trayWindow.show();\r
+            trayWindow.requestActivate();\r
+        }\r
+        onHideWindow: {\r
+            trayWindow.hide();\r
+        }\r
     }\r
 \r
     Rectangle {\r