From 0ca2eb4008a01118a3b3b74724c6c64b9740e3fb Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Thu, 11 Feb 2021 22:52:46 +0100 Subject: [PATCH] Add option to disable system tray integration Implements #59 --- imports/NeoChat/Page/SettingsPage.qml | 9 +++++++++ src/controller.cpp | 19 +++++++++++++++---- src/neochatconfig.kcfg | 4 ++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/imports/NeoChat/Page/SettingsPage.qml b/imports/NeoChat/Page/SettingsPage.qml index a350ad6f5..068ba5cfc 100644 --- a/imports/NeoChat/Page/SettingsPage.qml +++ b/imports/NeoChat/Page/SettingsPage.qml @@ -16,6 +16,15 @@ Kirigami.ScrollablePage { title: i18n("Settings") Kirigami.FormLayout { + QQC2.CheckBox { + Kirigami.FormData.label: i18nc("General settings:") + text: i18n("Close to sytem tray") + checked: Config.systemTray + onToggled: { + Config.systemTray = checked + Config.save() + } + } QQC2.CheckBox { // TODO: When there are enough notification and timeline event // settings, make 2 separate groups with FormData labels. diff --git a/src/controller.cpp b/src/controller.cpp index cc61c84af..c7926664a 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -55,15 +55,26 @@ Controller::Controller(QObject *parent) : QObject(parent) { - QApplication::setQuitOnLastWindowClosed(false); - Connection::setRoomType(); Connection::setUserType(); #ifndef Q_OS_ANDROID TrayIcon *trayIcon = new TrayIcon(this); - trayIcon->show(); - connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + if(NeoChatConfig::self()->systemTray()) { + trayIcon->show(); + connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + QApplication::setQuitOnLastWindowClosed(false); + } + connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, [=](){ + if(NeoChatConfig::self()->systemTray()) { + trayIcon->show(); + connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + } else { + trayIcon->hide(); + disconnect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + } + QApplication::setQuitOnLastWindowClosed(!NeoChatConfig::self()->systemTray()); + }); #endif QTimer::singleShot(0, this, [=] { diff --git a/src/neochatconfig.kcfg b/src/neochatconfig.kcfg index 57cc96074..7104e189c 100644 --- a/src/neochatconfig.kcfg +++ b/src/neochatconfig.kcfg @@ -40,6 +40,10 @@ true + + + true +