UI: Update tray context menu.

This commit is contained in:
Nodir Temirkhodjaev 2017-09-03 13:18:30 +05:00
parent e7a29cdb26
commit d656e989a2
3 changed files with 67 additions and 1 deletions

View File

@ -123,6 +123,25 @@ bool FortManager::saveSettings(FirewallConf *newConf)
return true; return true;
} }
void FortManager::saveTrayFlags()
{
m_firewallConf->setFilterEnabled(m_filterEnabledAction->isChecked());
m_firewallConf->ipInclude()->setUseAll(m_ipIncludeAllAction->isChecked());
m_firewallConf->ipExclude()->setUseAll(m_ipExcludeAllAction->isChecked());
m_firewallConf->setAppBlockAll(m_appBlockAllAction->isChecked());
m_firewallConf->setAppAllowAll(m_appAllowAllAction->isChecked());
int i = 0;
const QList<QAction*> groupActions = m_appGroupsMenu->actions();
foreach (AppGroup *appGroup, m_firewallConf->appGroupsList()) {
const QAction *action = groupActions.at(i);
appGroup->setEnabled(action->isChecked());
++i;
}
m_fortSettings->writeConfFlags(*m_firewallConf);
}
FirewallConf *FortManager::cloneConf(const FirewallConf &conf) FirewallConf *FortManager::cloneConf(const FirewallConf &conf)
{ {
FirewallConf *newConf = new FirewallConf(this); FirewallConf *newConf = new FirewallConf(this);
@ -137,6 +156,8 @@ FirewallConf *FortManager::cloneConf(const FirewallConf &conf)
void FortManager::updateTrayMenu() void FortManager::updateTrayMenu()
{ {
const FirewallConf &conf = *m_firewallConf;
QMenu *menu = m_trayIcon->contextMenu(); QMenu *menu = m_trayIcon->contextMenu();
if (menu) { if (menu) {
menu->deleteLater(); menu->deleteLater();
@ -144,6 +165,41 @@ void FortManager::updateTrayMenu()
menu = new QMenu(&m_window); menu = new QMenu(&m_window);
m_filterEnabledAction = addAction(
menu, QIcon(), tr("Filter Enabled"),
this, SLOT(saveTrayFlags()),
true, conf.filterEnabled());
menu->addSeparator();
m_ipIncludeAllAction = addAction(
menu, QIcon(), tr("Include All Addresses"),
this, SLOT(saveTrayFlags()),
true, conf.ipInclude()->useAll());
m_ipExcludeAllAction = addAction(
menu, QIcon(), tr("Exclude All Addresses"),
this, SLOT(saveTrayFlags()),
true, conf.ipExclude()->useAll());
menu->addSeparator();
m_appBlockAllAction = addAction(
menu, QIcon(), tr("Block All Applications"),
this, SLOT(saveTrayFlags()),
true, conf.appBlockAll());
m_appAllowAllAction = addAction(
menu, QIcon(), tr("Allow All Applications"),
this, SLOT(saveTrayFlags()),
true, conf.appAllowAll());
m_appGroupsMenu = new QMenu(tr("Application Groups"), menu);
menu->addMenu(m_appGroupsMenu);
foreach (const AppGroup *appGroup, conf.appGroupsList()) {
addAction(m_appGroupsMenu, QIcon(), appGroup->name(),
this, SLOT(saveTrayFlags()),
true, appGroup->enabled());
}
menu->addSeparator();
addAction(menu, QIcon(), tr("Show"), this, SLOT(showWindow())); addAction(menu, QIcon(), tr("Show"), this, SLOT(showWindow()));
menu->addSeparator(); menu->addSeparator();

View File

@ -37,6 +37,9 @@ public slots:
bool saveConf(); bool saveConf();
bool applyConf(); bool applyConf();
private slots:
void saveTrayFlags();
private: private:
FirewallConf *nullConf() const { return nullptr; } FirewallConf *nullConf() const { return nullptr; }
@ -70,6 +73,13 @@ private:
FortSettings *m_fortSettings; FortSettings *m_fortSettings;
FirewallConf *m_firewallConf; FirewallConf *m_firewallConf;
FirewallConf *m_firewallConfToEdit; FirewallConf *m_firewallConfToEdit;
QAction *m_filterEnabledAction;
QAction *m_ipIncludeAllAction;
QAction *m_ipExcludeAllAction;
QAction *m_appBlockAllAction;
QAction *m_appAllowAllAction;
QMenu *m_appGroupsMenu;
}; };
#endif // FORTMANAGER_H #endif // FORTMANAGER_H

View File

@ -19,7 +19,7 @@ BasePage {
} }
CheckBox { CheckBox {
id: cbFilter id: cbFilter
text: QT_TRANSLATE_NOOP("qml", "Filtering enabled") text: QT_TRANSLATE_NOOP("qml", "Filter Enabled")
checked: firewallConf.filterEnabled checked: firewallConf.filterEnabled
onToggled: { onToggled: {
firewallConf.filterEnabled = checked; firewallConf.filterEnabled = checked;