diff --git a/src/controller.cpp b/src/controller.cpp index c1f8fda6a..a757ee78e 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -136,23 +136,6 @@ Controller &Controller::instance() return _instance; } -void Controller::toggleWindow() -{ - auto &instance = WindowController::instance(); - auto window = instance.window(); - if (window->isVisible()) { - if (window->windowStates() & Qt::WindowMinimized) { - window->showNormal(); - window->requestActivate(); - } else { - window->close(); - } - } else { - instance.showAndRaiseWindow({}); - instance.window()->requestActivate(); - } -} - void Controller::addConnection(NeoChatConnection *c) { Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection"); @@ -314,10 +297,8 @@ void Controller::setQuitOnLastWindowClosed() if (NeoChatConfig::self()->systemTray()) { m_trayIcon = new TrayIcon(this); m_trayIcon->show(); - connect(m_trayIcon, &TrayIcon::toggleWindow, this, &Controller::toggleWindow); } else { if (m_trayIcon) { - disconnect(m_trayIcon, &TrayIcon::toggleWindow, this, &Controller::toggleWindow); delete m_trayIcon; m_trayIcon = nullptr; } diff --git a/src/controller.h b/src/controller.h index 9960b54ea..1082b5abe 100644 --- a/src/controller.h +++ b/src/controller.h @@ -9,23 +9,15 @@ #include "neochatconnection.h" #include -#include #include #ifdef HAVE_KUNIFIEDPUSH #include #endif -class NeoChatRoom; class TrayIcon; class QQuickTextDocument; -namespace Quotient -{ -class Room; -class User; -} - namespace QKeychain { class ReadPasswordJob; @@ -135,7 +127,6 @@ private: private Q_SLOTS: void invokeLogin(); - void toggleWindow(); void setQuitOnLastWindowClosed(); Q_SIGNALS: diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 454e14051..015bf8e16 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -9,6 +9,8 @@ #include +#include "windowcontroller.h" + TrayIcon::TrayIcon(QObject *parent) : QSystemTrayIcon(parent) { @@ -16,10 +18,12 @@ TrayIcon::TrayIcon(QObject *parent) QMenu *menu = new QMenu(); auto viewAction_ = new QAction(i18n("Show"), parent); - connect(viewAction_, &QAction::triggered, this, &TrayIcon::toggleWindow); - connect(this, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) { + connect(viewAction_, &QAction::triggered, this, [] { + WindowController::instance().toggleWindow(); + }); + connect(this, &QSystemTrayIcon::activated, this, [](QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger) { - Q_EMIT toggleWindow(); + WindowController::instance().toggleWindow(); } }); diff --git a/src/trayicon.h b/src/trayicon.h index 4cb073447..0e8f745bf 100644 --- a/src/trayicon.h +++ b/src/trayicon.h @@ -21,10 +21,4 @@ class TrayIcon : public QSystemTrayIcon Q_OBJECT public: TrayIcon(QObject *parent = nullptr); - -Q_SIGNALS: - /** - * @brief Triggered when the system tray icon is clicked to request NeoChat be shown or hidden. - */ - void toggleWindow(); }; diff --git a/src/trayicon_sni.cpp b/src/trayicon_sni.cpp index 045521c74..149b98f17 100644 --- a/src/trayicon_sni.cpp +++ b/src/trayicon_sni.cpp @@ -13,7 +13,7 @@ TrayIcon::TrayIcon(QObject *parent) setIconByName(QStringLiteral("org.kde.neochat.tray")); connect(this, &KStatusNotifierItem::activateRequested, this, [this] { KWindowSystem::setCurrentXdgActivationToken(providedToken()); - Q_EMIT toggleWindow(); + WindowController::instance().toggleWindow(); }); connect(&WindowController::instance(), &WindowController::windowChanged, this, [this] { diff --git a/src/trayicon_sni.h b/src/trayicon_sni.h index d078dcb0f..eb1fe008d 100644 --- a/src/trayicon_sni.h +++ b/src/trayicon_sni.h @@ -27,10 +27,4 @@ public: * @brief Hide the tray icon. */ void hide(); - -Q_SIGNALS: - /** - * @brief Triggered when the system tray icon is clicked to request NeoChat be shown or hidden. - */ - void toggleWindow(); }; diff --git a/src/windowcontroller.cpp b/src/windowcontroller.cpp index c3fcb47f9..97237d02c 100644 --- a/src/windowcontroller.cpp +++ b/src/windowcontroller.cpp @@ -102,4 +102,19 @@ void WindowController::setBlur(QQuickItem *item, bool blur) #endif } +void WindowController::toggleWindow() +{ + if (window()->isVisible()) { + if (window()->windowStates() & Qt::WindowMinimized) { + window()->showNormal(); + window()->requestActivate(); + } else { + window()->close(); + } + } else { + showAndRaiseWindow({}); + window()->requestActivate(); + } +} + #include "moc_windowcontroller.cpp" diff --git a/src/windowcontroller.h b/src/windowcontroller.h index cdcb1c7c5..564af930b 100644 --- a/src/windowcontroller.h +++ b/src/windowcontroller.h @@ -66,6 +66,11 @@ public: */ Q_INVOKABLE void setBlur(QQuickItem *item, bool blur); + /** + * Toggles the window between hidden and visible. + */ + void toggleWindow(); + Q_SIGNALS: /** * @brief Triggered if the managed window is changed.