Move Controller::toggleWindow to WindowController
This commit is contained in:
@@ -136,23 +136,6 @@ Controller &Controller::instance()
|
|||||||
return _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)
|
void Controller::addConnection(NeoChatConnection *c)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection");
|
Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection");
|
||||||
@@ -314,10 +297,8 @@ void Controller::setQuitOnLastWindowClosed()
|
|||||||
if (NeoChatConfig::self()->systemTray()) {
|
if (NeoChatConfig::self()->systemTray()) {
|
||||||
m_trayIcon = new TrayIcon(this);
|
m_trayIcon = new TrayIcon(this);
|
||||||
m_trayIcon->show();
|
m_trayIcon->show();
|
||||||
connect(m_trayIcon, &TrayIcon::toggleWindow, this, &Controller::toggleWindow);
|
|
||||||
} else {
|
} else {
|
||||||
if (m_trayIcon) {
|
if (m_trayIcon) {
|
||||||
disconnect(m_trayIcon, &TrayIcon::toggleWindow, this, &Controller::toggleWindow);
|
|
||||||
delete m_trayIcon;
|
delete m_trayIcon;
|
||||||
m_trayIcon = nullptr;
|
m_trayIcon = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,23 +9,15 @@
|
|||||||
|
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
#include <Quotient/accountregistry.h>
|
#include <Quotient/accountregistry.h>
|
||||||
#include <Quotient/jobs/basejob.h>
|
|
||||||
#include <Quotient/settings.h>
|
#include <Quotient/settings.h>
|
||||||
|
|
||||||
#ifdef HAVE_KUNIFIEDPUSH
|
#ifdef HAVE_KUNIFIEDPUSH
|
||||||
#include <kunifiedpush/connector.h>
|
#include <kunifiedpush/connector.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class NeoChatRoom;
|
|
||||||
class TrayIcon;
|
class TrayIcon;
|
||||||
class QQuickTextDocument;
|
class QQuickTextDocument;
|
||||||
|
|
||||||
namespace Quotient
|
|
||||||
{
|
|
||||||
class Room;
|
|
||||||
class User;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace QKeychain
|
namespace QKeychain
|
||||||
{
|
{
|
||||||
class ReadPasswordJob;
|
class ReadPasswordJob;
|
||||||
@@ -135,7 +127,6 @@ private:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void invokeLogin();
|
void invokeLogin();
|
||||||
void toggleWindow();
|
|
||||||
void setQuitOnLastWindowClosed();
|
void setQuitOnLastWindowClosed();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
|
#include "windowcontroller.h"
|
||||||
|
|
||||||
TrayIcon::TrayIcon(QObject *parent)
|
TrayIcon::TrayIcon(QObject *parent)
|
||||||
: QSystemTrayIcon(parent)
|
: QSystemTrayIcon(parent)
|
||||||
{
|
{
|
||||||
@@ -16,10 +18,12 @@ TrayIcon::TrayIcon(QObject *parent)
|
|||||||
QMenu *menu = new QMenu();
|
QMenu *menu = new QMenu();
|
||||||
auto viewAction_ = new QAction(i18n("Show"), parent);
|
auto viewAction_ = new QAction(i18n("Show"), parent);
|
||||||
|
|
||||||
connect(viewAction_, &QAction::triggered, this, &TrayIcon::toggleWindow);
|
connect(viewAction_, &QAction::triggered, this, [] {
|
||||||
connect(this, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
WindowController::instance().toggleWindow();
|
||||||
|
});
|
||||||
|
connect(this, &QSystemTrayIcon::activated, this, [](QSystemTrayIcon::ActivationReason reason) {
|
||||||
if (reason == QSystemTrayIcon::Trigger) {
|
if (reason == QSystemTrayIcon::Trigger) {
|
||||||
Q_EMIT toggleWindow();
|
WindowController::instance().toggleWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,4 @@ class TrayIcon : public QSystemTrayIcon
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TrayIcon(QObject *parent = nullptr);
|
TrayIcon(QObject *parent = nullptr);
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief Triggered when the system tray icon is clicked to request NeoChat be shown or hidden.
|
|
||||||
*/
|
|
||||||
void toggleWindow();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ TrayIcon::TrayIcon(QObject *parent)
|
|||||||
setIconByName(QStringLiteral("org.kde.neochat.tray"));
|
setIconByName(QStringLiteral("org.kde.neochat.tray"));
|
||||||
connect(this, &KStatusNotifierItem::activateRequested, this, [this] {
|
connect(this, &KStatusNotifierItem::activateRequested, this, [this] {
|
||||||
KWindowSystem::setCurrentXdgActivationToken(providedToken());
|
KWindowSystem::setCurrentXdgActivationToken(providedToken());
|
||||||
Q_EMIT toggleWindow();
|
WindowController::instance().toggleWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&WindowController::instance(), &WindowController::windowChanged, this, [this] {
|
connect(&WindowController::instance(), &WindowController::windowChanged, this, [this] {
|
||||||
|
|||||||
@@ -27,10 +27,4 @@ public:
|
|||||||
* @brief Hide the tray icon.
|
* @brief Hide the tray icon.
|
||||||
*/
|
*/
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* @brief Triggered when the system tray icon is clicked to request NeoChat be shown or hidden.
|
|
||||||
*/
|
|
||||||
void toggleWindow();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -102,4 +102,19 @@ void WindowController::setBlur(QQuickItem *item, bool blur)
|
|||||||
#endif
|
#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"
|
#include "moc_windowcontroller.cpp"
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE void setBlur(QQuickItem *item, bool blur);
|
Q_INVOKABLE void setBlur(QQuickItem *item, bool blur);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the window between hidden and visible.
|
||||||
|
*/
|
||||||
|
void toggleWindow();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* @brief Triggered if the managed window is changed.
|
* @brief Triggered if the managed window is changed.
|
||||||
|
|||||||
Reference in New Issue
Block a user