From 84741adc16e03bc9f70f113e27c80e2d44357efc Mon Sep 17 00:00:00 2001 From: Jani Mustonen Date: Thu, 2 Nov 2017 22:00:43 +0200 Subject: [PATCH] Implement a setting for the tray icon (#108) --- include/UserSettingsPage.h | 1 + src/MainWindow.cc | 6 +++++- src/TrayIcon.cc | 3 --- src/UserSettingsPage.cc | 13 +++++++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/UserSettingsPage.h b/include/UserSettingsPage.h index 9a4c01dd..6f6da2c5 100644 --- a/include/UserSettingsPage.h +++ b/include/UserSettingsPage.h @@ -66,6 +66,7 @@ protected: signals: void moveBack(); + void trayOptionChanged(bool value); private: // Layouts diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 5c188903..fd44e405 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -94,6 +94,8 @@ MainWindow::MainWindow(QWidget *parent) pageStack_->setCurrentWidget(chat_page_); }); + connect(userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool))); + connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, @@ -113,6 +115,8 @@ MainWindow::MainWindow(QWidget *parent) QSettings settings; + trayIcon_->setVisible(userSettings_->isTrayEnabled()); + if (hasActiveUser()) { QString token = settings.value("auth/access_token").toString(); QString home_server = settings.value("auth/home_server").toString(); @@ -253,7 +257,7 @@ MainWindow::showUserSettingsPage() void MainWindow::closeEvent(QCloseEvent *event) { - if (isVisible()) { + if (isVisible() && userSettings_->isTrayEnabled()) { event->ignore(); hide(); } diff --git a/src/TrayIcon.cc b/src/TrayIcon.cc index ad644ed9..ac84aaca 100644 --- a/src/TrayIcon.cc +++ b/src/TrayIcon.cc @@ -123,9 +123,6 @@ TrayIcon::TrayIcon(const QString &filename, QWidget *parent) menu->addAction(quitAction_); setContextMenu(menu); - - // We wait a little for the icon to load. - QTimer::singleShot(500, this, [=]() { show(); }); } void diff --git a/src/UserSettingsPage.cc b/src/UserSettingsPage.cc index ff4714f5..d18b76be 100644 --- a/src/UserSettingsPage.cc +++ b/src/UserSettingsPage.cc @@ -32,7 +32,7 @@ void UserSettings::load() { QSettings settings; - isTrayEnabled_ = settings.value("user/tray", true).toBool(); + isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); theme_ = settings.value("user/theme", "default").toString(); } @@ -41,7 +41,11 @@ UserSettings::save() { QSettings settings; settings.beginGroup("user"); + + settings.beginGroup("window"); settings.setValue("tray", isTrayEnabled_); + settings.endGroup(); + settings.setValue("theme", theme()); settings.endGroup(); } @@ -122,8 +126,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge static_cast(&QComboBox::activated), [=](const QString &text) { settings_->setTheme(text.toLower()); }); - connect(trayToggle_, &Toggle::toggled, this, [=](bool isEnabled) { - settings_->setTray(isEnabled); + connect(trayToggle_, &Toggle::toggled, this, [=](bool isDisabled) { + settings_->setTray(!isDisabled); + emit trayOptionChanged(!isDisabled); }); connect(backBtn_, &QPushButton::clicked, this, [=]() { @@ -136,5 +141,5 @@ void UserSettingsPage::showEvent(QShowEvent *) { themeCombo_->setCurrentIndex((settings_->theme() == "default" ? 0 : 1)); - trayToggle_->setState(settings_->isTrayEnabled()); + trayToggle_->setState(!settings_->isTrayEnabled()); // Treats true as "off" }