mirror of
https://github.com/tnodir/fort
synced 2024-11-14 22:05:12 +00:00
UI: TrayIcon: Check Alert Window for Filter Modes
This commit is contained in:
parent
a46b59152e
commit
979a01212d
@ -34,31 +34,39 @@ void FirewallConf::setBlockTrafficIndex(int index)
|
||||
}
|
||||
}
|
||||
|
||||
int FirewallConf::filterModeIndex() const
|
||||
FirewallConf::FilterMode FirewallConf::filterMode() const
|
||||
{
|
||||
return m_allowAllNew ? 0 : (m_askToConnect ? 1 : (m_appBlockAll ? 2 : (m_appAllowAll ? 3 : 4)));
|
||||
if (m_allowAllNew)
|
||||
return ModeAutoLearn;
|
||||
if (m_askToConnect)
|
||||
return ModeAskToConnect;
|
||||
if (m_appBlockAll)
|
||||
return ModeBlockAll;
|
||||
if (m_appAllowAll)
|
||||
return ModeAllowAll;
|
||||
return ModeIgnore;
|
||||
}
|
||||
|
||||
void FirewallConf::setFilterModeIndex(int index)
|
||||
void FirewallConf::setFilterMode(FirewallConf::FilterMode mode)
|
||||
{
|
||||
m_allowAllNew = false;
|
||||
m_askToConnect = false;
|
||||
m_appBlockAll = false;
|
||||
m_appAllowAll = false;
|
||||
|
||||
switch (index) {
|
||||
case 0: { // Auto-Learn
|
||||
switch (mode) {
|
||||
case ModeAutoLearn: {
|
||||
m_allowAllNew = true;
|
||||
m_appBlockAll = true;
|
||||
} break;
|
||||
case 1: { // Ask
|
||||
case ModeAskToConnect: {
|
||||
m_askToConnect = true;
|
||||
m_appBlockAll = true;
|
||||
} break;
|
||||
case 2: { // Block
|
||||
case ModeBlockAll: {
|
||||
m_appBlockAll = true;
|
||||
} break;
|
||||
case 3: { // Allow
|
||||
case ModeAllowAll: {
|
||||
m_appAllowAll = true;
|
||||
} break;
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ public:
|
||||
enum FilterMode {
|
||||
ModeAutoLearn = 0,
|
||||
ModeAskToConnect,
|
||||
ModeAllowAll,
|
||||
ModeBlockAll,
|
||||
ModeAllowAll,
|
||||
ModeIgnore,
|
||||
};
|
||||
Q_ENUM(FilterMode)
|
||||
@ -107,8 +107,8 @@ public:
|
||||
int blockTrafficIndex() const;
|
||||
void setBlockTrafficIndex(int index);
|
||||
|
||||
int filterModeIndex() const;
|
||||
void setFilterModeIndex(int index);
|
||||
FirewallConf::FilterMode filterMode() const;
|
||||
void setFilterMode(FirewallConf::FilterMode mode);
|
||||
|
||||
static QStringList blockTrafficNames();
|
||||
static QStringList blockTrafficIconPaths();
|
||||
|
@ -69,8 +69,8 @@ void IfacePage::onResetToDefault()
|
||||
m_cbAppNotifyMessage->setChecked(true);
|
||||
m_cbAppAlertAutoShow->setChecked(true);
|
||||
m_cbAppAlertAutoLearn->setChecked(false);
|
||||
m_cbAppAlertAllowAll->setChecked(true);
|
||||
m_cbAppAlertBlockAll->setChecked(true);
|
||||
m_cbAppAlertAllowAll->setChecked(true);
|
||||
m_cbAppAlertAlwaysOnTop->setChecked(true);
|
||||
m_cbAppAlertAutoActive->setChecked(false);
|
||||
m_cbAppAlertSound->setChecked(true);
|
||||
@ -149,8 +149,8 @@ void IfacePage::onRetranslateUi()
|
||||
m_cbAppNotifyMessage->setText(tr("Use System Notifications for New Programs"));
|
||||
m_cbAppAlertAutoShow->setText(tr("Auto-Show Alert Window for New Programs"));
|
||||
setAlertModeText(m_cbAppAlertAutoLearn, FirewallConf::ModeAutoLearn);
|
||||
setAlertModeText(m_cbAppAlertAllowAll, FirewallConf::ModeAllowAll);
|
||||
setAlertModeText(m_cbAppAlertBlockAll, FirewallConf::ModeBlockAll);
|
||||
setAlertModeText(m_cbAppAlertAllowAll, FirewallConf::ModeAllowAll);
|
||||
m_cbAppAlertAlwaysOnTop->setText(tr("Alert Window is Always on top"));
|
||||
m_cbAppAlertAutoActive->setText(tr("Alert Window is auto-active"));
|
||||
m_cbAppAlertSound->setText(tr("Sound Alert"));
|
||||
@ -545,13 +545,6 @@ void IfacePage::setupAlertModes()
|
||||
});
|
||||
setAlertModeIcon(m_cbAppAlertAutoLearn, FirewallConf::ModeAutoLearn);
|
||||
|
||||
m_cbAppAlertAllowAll =
|
||||
ControlUtil::createCheckBox(iniUser()->progAlertWindowAllowAll(), [&](bool checked) {
|
||||
iniUser()->setProgAlertWindowAllowAll(checked);
|
||||
ctrl()->setIniUserEdited();
|
||||
});
|
||||
setAlertModeIcon(m_cbAppAlertAllowAll, FirewallConf::ModeAllowAll);
|
||||
|
||||
m_cbAppAlertBlockAll =
|
||||
ControlUtil::createCheckBox(iniUser()->progAlertWindowBlockAll(), [&](bool checked) {
|
||||
iniUser()->setProgAlertWindowBlockAll(checked);
|
||||
@ -559,6 +552,13 @@ void IfacePage::setupAlertModes()
|
||||
});
|
||||
setAlertModeIcon(m_cbAppAlertBlockAll, FirewallConf::ModeBlockAll);
|
||||
|
||||
m_cbAppAlertAllowAll =
|
||||
ControlUtil::createCheckBox(iniUser()->progAlertWindowAllowAll(), [&](bool checked) {
|
||||
iniUser()->setProgAlertWindowAllowAll(checked);
|
||||
ctrl()->setIniUserEdited();
|
||||
});
|
||||
setAlertModeIcon(m_cbAppAlertAllowAll, FirewallConf::ModeAllowAll);
|
||||
|
||||
// Setup Alert Modes Button
|
||||
setupAlertModesButton();
|
||||
}
|
||||
@ -567,7 +567,7 @@ void IfacePage::setupAlertModesButton()
|
||||
{
|
||||
// Menu
|
||||
auto layout = ControlUtil::createVLayoutByWidgets(
|
||||
{ m_cbAppAlertAutoLearn, m_cbAppAlertAllowAll, m_cbAppAlertBlockAll });
|
||||
{ m_cbAppAlertAutoLearn, m_cbAppAlertBlockAll, m_cbAppAlertAllowAll });
|
||||
|
||||
auto menu = ControlUtil::createMenuByLayout(layout, this);
|
||||
|
||||
|
@ -95,8 +95,8 @@ private:
|
||||
QCheckBox *m_cbAppNotifyMessage = nullptr;
|
||||
QCheckBox *m_cbAppAlertAutoShow = nullptr;
|
||||
QCheckBox *m_cbAppAlertAutoLearn = nullptr;
|
||||
QCheckBox *m_cbAppAlertAllowAll = nullptr;
|
||||
QCheckBox *m_cbAppAlertBlockAll = nullptr;
|
||||
QCheckBox *m_cbAppAlertAllowAll = nullptr;
|
||||
QPushButton *m_btAlertModes = nullptr;
|
||||
QCheckBox *m_cbAppAlertAlwaysOnTop = nullptr;
|
||||
QCheckBox *m_cbAppAlertAutoActive = nullptr;
|
||||
|
@ -202,7 +202,7 @@ void OptionsPage::retranslateComboBlockTraffic()
|
||||
void OptionsPage::retranslateComboFilterMode()
|
||||
{
|
||||
updateComboBox(m_comboFilterMode, FirewallConf::filterModeNames(),
|
||||
FirewallConf::filterModeIconPaths(), conf()->filterModeIndex());
|
||||
FirewallConf::filterModeIconPaths(), conf()->filterMode());
|
||||
}
|
||||
|
||||
void OptionsPage::retranslateEditPassword()
|
||||
@ -353,8 +353,8 @@ QLayout *OptionsPage::setupFilterModeLayout()
|
||||
|
||||
m_comboFilterMode =
|
||||
ControlUtil::createComboBox(FirewallConf::filterModeNames(), [&](int index) {
|
||||
if (conf()->filterModeIndex() != index) {
|
||||
conf()->setFilterModeIndex(index);
|
||||
if (conf()->filterMode() != index) {
|
||||
conf()->setFilterMode(FirewallConf::FilterMode(index));
|
||||
ctrl()->setFlagsEdited();
|
||||
}
|
||||
});
|
||||
|
@ -186,6 +186,22 @@ QAction *addAction(QWidget *widget, const QString &iconPath, const QObject *rece
|
||||
return action;
|
||||
}
|
||||
|
||||
bool checkAlertFilterMode(FirewallConf *conf, IniUser *iniUser)
|
||||
{
|
||||
switch (conf->filterMode()) {
|
||||
case FirewallConf::ModeAutoLearn:
|
||||
return iniUser->progAlertWindowAutoLearn();
|
||||
case FirewallConf::ModeAskToConnect:
|
||||
return true;
|
||||
case FirewallConf::ModeBlockAll:
|
||||
return iniUser->progAlertWindowBlockAll();
|
||||
case FirewallConf::ModeAllowAll:
|
||||
return iniUser->progAlertWindowAllowAll();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TrayIcon::TrayIcon(QObject *parent) : QSystemTrayIcon(parent), m_ctrl(new TrayController(this))
|
||||
@ -593,7 +609,7 @@ void TrayIcon::updateTrayMenuFlags()
|
||||
|
||||
m_filterModeMenu->setEnabled(editEnabled);
|
||||
{
|
||||
QAction *action = m_filterModeActions->actions().at(conf()->filterModeIndex());
|
||||
QAction *action = m_filterModeActions->actions().at(conf()->filterMode());
|
||||
if (!action->isChecked()) {
|
||||
action->setChecked(true);
|
||||
m_filterModeMenu->setIcon(action->icon());
|
||||
@ -636,8 +652,8 @@ void TrayIcon::updateAppGroupActions()
|
||||
|
||||
void TrayIcon::sendAlertMessage()
|
||||
{
|
||||
if (conf()->allowAllNew() && !iniUser()->progAlertWindowAutoLearn())
|
||||
return; // do not notify in Auto-Learn mode
|
||||
if (!checkAlertFilterMode(conf(), iniUser()))
|
||||
return;
|
||||
|
||||
if (iniUser()->progNotifyMessage()) {
|
||||
windowManager()->showTrayMessage(
|
||||
@ -738,8 +754,8 @@ void TrayIcon::saveTrayFlags()
|
||||
{
|
||||
QAction *action = m_filterModeActions->checkedAction();
|
||||
const int index = m_filterModeActions->actions().indexOf(action);
|
||||
if (conf()->filterModeIndex() != index) {
|
||||
conf()->setFilterModeIndex(index);
|
||||
if (conf()->filterMode() != index) {
|
||||
conf()->setFilterMode(FirewallConf::FilterMode(index));
|
||||
m_filterModeMenu->setIcon(action->icon());
|
||||
}
|
||||
}
|
||||
@ -803,7 +819,7 @@ void TrayIcon::switchBlockTraffic(QAction *action)
|
||||
void TrayIcon::switchFilterMode(QAction *action)
|
||||
{
|
||||
const int index = m_filterModeActions->actions().indexOf(action);
|
||||
if (index < 0 || index == conf()->filterModeIndex())
|
||||
if (index < 0 || index == conf()->filterMode())
|
||||
return;
|
||||
|
||||
if (iniUser()->confirmTrayFlags()) {
|
||||
@ -812,7 +828,7 @@ void TrayIcon::switchFilterMode(QAction *action)
|
||||
if (confirmed) {
|
||||
saveTrayFlags();
|
||||
} else {
|
||||
QAction *a = m_filterModeActions->actions().at(conf()->filterModeIndex());
|
||||
QAction *a = m_filterModeActions->actions().at(conf()->filterMode());
|
||||
a->setChecked(true);
|
||||
}
|
||||
},
|
||||
|
@ -144,12 +144,12 @@ public:
|
||||
bool progAlertWindowAutoLearn() const { return valueBool("progAlertWindow/modeAutoLearn"); }
|
||||
void setProgAlertWindowAutoLearn(bool on) { setValue("progAlertWindow/modeAutoLearn", on); }
|
||||
|
||||
bool progAlertWindowAllowAll() const { return valueBool("progAlertWindow/modeAllowAll", true); }
|
||||
void setProgAlertWindowAllowAll(bool on) { setValue("progAlertWindow/modeAllowAll", on, true); }
|
||||
|
||||
bool progAlertWindowBlockAll() const { return valueBool("progAlertWindow/modeBlockAll", true); }
|
||||
void setProgAlertWindowBlockAll(bool on) { setValue("progAlertWindow/modeBlockAll", on, true); }
|
||||
|
||||
bool progAlertWindowAllowAll() const { return valueBool("progAlertWindow/modeAllowAll", true); }
|
||||
void setProgAlertWindowAllowAll(bool on) { setValue("progAlertWindow/modeAllowAll", on, true); }
|
||||
|
||||
bool progAlertWindowAlwaysOnTop() const
|
||||
{
|
||||
return valueBool("progAlertWindow/alwaysOnTop", true);
|
||||
|
Loading…
Reference in New Issue
Block a user