From 9399a309d300b7830bedae4b5b8803d33273abb0 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 24 Feb 2022 11:07:26 +0300 Subject: [PATCH] UI: Tray: Fix confirmation checking --- src/ui/form/tray/trayicon.cpp | 36 +++++++++++++++++++++-------------- src/ui/form/tray/trayicon.h | 2 ++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/ui/form/tray/trayicon.cpp b/src/ui/form/tray/trayicon.cpp index d2cb3e46..e1a05a3e 100644 --- a/src/ui/form/tray/trayicon.cpp +++ b/src/ui/form/tray/trayicon.cpp @@ -329,24 +329,25 @@ void TrayIcon::setupTrayMenu() m_menu->addSeparator(); m_filterEnabledAction = - addAction(m_menu, QIcon(), QString(), this, SLOT(saveTrayFlags()), true); + addAction(m_menu, QIcon(), QString(), this, SLOT(switchTrayFlag(bool)), true); addHotKey(m_filterEnabledAction, iniUser()->hotKeyFilter()); - m_stopTrafficAction = addAction(m_menu, QIcon(), QString(), this, SLOT(saveTrayFlags()), true); + m_stopTrafficAction = + addAction(m_menu, QIcon(), QString(), this, SLOT(switchTrayFlag(bool)), true); addHotKey(m_stopTrafficAction, iniUser()->hotKeyStopTraffic()); m_stopInetTrafficAction = - addAction(m_menu, QIcon(), QString(), this, SLOT(saveTrayFlags()), true); + addAction(m_menu, QIcon(), QString(), this, SLOT(switchTrayFlag(bool)), true); addHotKey(m_stopInetTrafficAction, iniUser()->hotKeyStopInetTraffic()); m_autoAllowProgsAction = - addAction(m_menu, QIcon(), QString(), this, SLOT(saveTrayFlags()), true); + addAction(m_menu, QIcon(), QString(), this, SLOT(switchTrayFlag(bool)), true); addHotKey(m_autoAllowProgsAction, iniUser()->hotKeyAllowAllNew()); m_menu->addSeparator(); for (int i = 0; i < MAX_APP_GROUP_COUNT; ++i) { - QAction *a = addAction(m_menu, QIcon(), QString(), this, SLOT(saveTrayFlags()), true); + QAction *a = addAction(m_menu, QIcon(), QString(), this, SLOT(switchTrayFlag(bool)), true); if (i < 12) { const QString shortcutText = @@ -412,15 +413,6 @@ void TrayIcon::updateAppGroupActions() void TrayIcon::saveTrayFlags() { - if (iniUser()->confirmTrayFlags()) { - const auto action = qobject_cast(sender()); - Q_ASSERT(action); - - if (!windowManager()->showQuestionBox( - tr("Are you sure to switch \"%1\"?").arg(action->text()))) - return; - } - conf()->setFilterEnabled(m_filterEnabledAction->isChecked()); conf()->setStopTraffic(m_stopTrafficAction->isChecked()); conf()->setStopInetTraffic(m_stopInetTrafficAction->isChecked()); @@ -435,6 +427,22 @@ void TrayIcon::saveTrayFlags() confManager()->saveFlags(); } +void TrayIcon::switchTrayFlag(bool checked) +{ + if (iniUser()->confirmTrayFlags()) { + const auto action = qobject_cast(sender()); + Q_ASSERT(action); + + if (!windowManager()->showQuestionBox( + tr("Are you sure to switch \"%1\"?").arg(action->text()))) { + action->setChecked(!checked); + return; + } + } + + saveTrayFlags(); +} + void TrayIcon::quitProgram() { if (iniUser()->confirmQuit()) { diff --git a/src/ui/form/tray/trayicon.h b/src/ui/form/tray/trayicon.h index 391e5241..378ec420 100644 --- a/src/ui/form/tray/trayicon.h +++ b/src/ui/form/tray/trayicon.h @@ -58,6 +58,8 @@ protected slots: void onTrayActivated(QSystemTrayIcon::ActivationReason reason); void saveTrayFlags(); + + void switchTrayFlag(bool checked); void quitProgram(); private: