UI: Tray: Fix confirmation checking

This commit is contained in:
Nodir Temirkhodjaev 2022-02-24 11:07:26 +03:00
parent 9b6dcb8a9e
commit 9399a309d3
2 changed files with 24 additions and 14 deletions

View File

@ -329,24 +329,25 @@ void TrayIcon::setupTrayMenu()
m_menu->addSeparator(); m_menu->addSeparator();
m_filterEnabledAction = 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()); 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()); addHotKey(m_stopTrafficAction, iniUser()->hotKeyStopTraffic());
m_stopInetTrafficAction = 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()); addHotKey(m_stopInetTrafficAction, iniUser()->hotKeyStopInetTraffic());
m_autoAllowProgsAction = 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()); addHotKey(m_autoAllowProgsAction, iniUser()->hotKeyAllowAllNew());
m_menu->addSeparator(); m_menu->addSeparator();
for (int i = 0; i < MAX_APP_GROUP_COUNT; ++i) { 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) { if (i < 12) {
const QString shortcutText = const QString shortcutText =
@ -412,15 +413,6 @@ void TrayIcon::updateAppGroupActions()
void TrayIcon::saveTrayFlags() void TrayIcon::saveTrayFlags()
{ {
if (iniUser()->confirmTrayFlags()) {
const auto action = qobject_cast<QAction *>(sender());
Q_ASSERT(action);
if (!windowManager()->showQuestionBox(
tr("Are you sure to switch \"%1\"?").arg(action->text())))
return;
}
conf()->setFilterEnabled(m_filterEnabledAction->isChecked()); conf()->setFilterEnabled(m_filterEnabledAction->isChecked());
conf()->setStopTraffic(m_stopTrafficAction->isChecked()); conf()->setStopTraffic(m_stopTrafficAction->isChecked());
conf()->setStopInetTraffic(m_stopInetTrafficAction->isChecked()); conf()->setStopInetTraffic(m_stopInetTrafficAction->isChecked());
@ -435,6 +427,22 @@ void TrayIcon::saveTrayFlags()
confManager()->saveFlags(); confManager()->saveFlags();
} }
void TrayIcon::switchTrayFlag(bool checked)
{
if (iniUser()->confirmTrayFlags()) {
const auto action = qobject_cast<QAction *>(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() void TrayIcon::quitProgram()
{ {
if (iniUser()->confirmQuit()) { if (iniUser()->confirmQuit()) {

View File

@ -58,6 +58,8 @@ protected slots:
void onTrayActivated(QSystemTrayIcon::ActivationReason reason); void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
void saveTrayFlags(); void saveTrayFlags();
void switchTrayFlag(bool checked);
void quitProgram(); void quitProgram();
private: private: