diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index f48a8bb27..dd48dc0a3 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -188,7 +188,8 @@ void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason) raiseDialog(_settingsDialog.data()); } #else - slotOpenSettingsDialog(); + UserModel::instance()->showWindow(); + //slotOpenSettingsDialog(); #endif } } diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index caabd6c29..3e12e8363 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -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() diff --git a/src/gui/systray.h b/src/gui/systray.h index 2a0e22db7..bf532d0d7 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -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; }; diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index 63513003f..225cb241e 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -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(); } diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index 6d8a7d04f..aeb2716ee 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -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 roleNames() const; diff --git a/src/gui/tray/window.qml b/src/gui/tray/window.qml index 45d2455d3..e59ae314b 100644 --- a/src/gui/tray/window.qml +++ b/src/gui/tray/window.qml @@ -14,6 +14,12 @@ Window { color: "transparent" flags: Qt.FramelessWindowHint + onActiveChanged: { + if(!active) { + trayWindow.hide(); + } + } + Component.onCompleted: { /* desktopAvailableWidth and Height doesn't include the system tray bar but breaks application anyway on windows when using multi monitor setup, @@ -32,6 +38,13 @@ Window { onNewUserSelected: { accountMenu.close() } + onShowWindow: { + trayWindow.show(); + trayWindow.requestActivate(); + } + onHideWindow: { + trayWindow.hide(); + } } Rectangle {