mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:45:22 +00:00
UI: ProgramEditDialog: Add Zones
This commit is contained in:
parent
668d0e4279
commit
a3d01a9c07
@ -9,7 +9,7 @@ namespace {
|
||||
|
||||
const QLoggingCategory LC("controlWorker");
|
||||
|
||||
constexpr int commandMaxArgs = 16;
|
||||
constexpr int commandMaxArgs = 32;
|
||||
constexpr int commandArgMaxSize = 4 * 1024;
|
||||
constexpr quint32 dataMaxSize = 1 * 1024 * 1024;
|
||||
|
||||
|
@ -30,7 +30,17 @@ void ZonesSelector::setZones(quint32 zones)
|
||||
|
||||
m_zones = zones;
|
||||
|
||||
retranslateZonesText();
|
||||
resetZonesMenu();
|
||||
}
|
||||
|
||||
void ZonesSelector::setUncheckedZones(quint32 uncheckedZones)
|
||||
{
|
||||
if (m_uncheckedZones == uncheckedZones)
|
||||
return;
|
||||
|
||||
m_uncheckedZones = uncheckedZones;
|
||||
|
||||
resetZonesMenu();
|
||||
}
|
||||
|
||||
int ZonesSelector::zonesCount() const
|
||||
@ -38,6 +48,11 @@ int ZonesSelector::zonesCount() const
|
||||
return DriverCommon::bitCount(m_zones);
|
||||
}
|
||||
|
||||
int ZonesSelector::uncheckedZonesCount() const
|
||||
{
|
||||
return DriverCommon::bitCount(m_uncheckedZones);
|
||||
}
|
||||
|
||||
void ZonesSelector::retranslateUi()
|
||||
{
|
||||
retranslateZonesText();
|
||||
@ -47,7 +62,10 @@ void ZonesSelector::retranslateUi()
|
||||
|
||||
void ZonesSelector::retranslateZonesText()
|
||||
{
|
||||
this->setText(tr("Zones") + QString(" (%1)").arg(zonesCount()));
|
||||
const auto countText = QString::number(zonesCount())
|
||||
+ (isTristate() ? '/' + QString::number(uncheckedZonesCount()) : QString());
|
||||
|
||||
this->setText(tr("Zones") + " (" + countText + ')');
|
||||
}
|
||||
|
||||
void ZonesSelector::setupUi()
|
||||
@ -81,6 +99,12 @@ void ZonesSelector::setupZones()
|
||||
updateZonesMenuEnabled();
|
||||
}
|
||||
|
||||
void ZonesSelector::resetZonesMenu()
|
||||
{
|
||||
clearZonesMenu();
|
||||
retranslateZonesText();
|
||||
}
|
||||
|
||||
void ZonesSelector::clearZonesMenu()
|
||||
{
|
||||
m_menuZones->close();
|
||||
|
@ -10,15 +10,23 @@ class ZonesSelector : public QPushButton
|
||||
public:
|
||||
explicit ZonesSelector(QWidget *parent = nullptr);
|
||||
|
||||
bool isTristate() const { return m_isTristate; }
|
||||
void setIsTristate(bool isTristate) { m_isTristate = isTristate; }
|
||||
|
||||
quint32 zones() const { return m_zones; }
|
||||
void setZones(quint32 zones);
|
||||
|
||||
quint32 uncheckedZones() const { return m_uncheckedZones; }
|
||||
void setUncheckedZones(quint32 uncheckedZones);
|
||||
|
||||
int zonesCount() const;
|
||||
int uncheckedZonesCount() const;
|
||||
|
||||
void retranslateUi();
|
||||
|
||||
signals:
|
||||
void zonesChanged();
|
||||
void uncheckedZonesChanged();
|
||||
|
||||
private:
|
||||
void retranslateZonesText();
|
||||
@ -26,6 +34,7 @@ private:
|
||||
void setupUi();
|
||||
void setupZones();
|
||||
|
||||
void resetZonesMenu();
|
||||
void clearZonesMenu();
|
||||
void createZonesMenu();
|
||||
void updateZonesMenu();
|
||||
@ -37,7 +46,10 @@ private:
|
||||
void onZoneClicked(bool checked);
|
||||
|
||||
private:
|
||||
bool m_isTristate = false;
|
||||
|
||||
quint32 m_zones = 0;
|
||||
quint32 m_uncheckedZones = 0;
|
||||
|
||||
QMenu *m_menuZones = nullptr;
|
||||
};
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <conf/firewallconf.h>
|
||||
#include <form/controls/checkspincombo.h>
|
||||
#include <form/controls/controlutil.h>
|
||||
#include <form/controls/zonesselector.h>
|
||||
#include <form/dialog/dialogutil.h>
|
||||
#include <fortmanager.h>
|
||||
#include <manager/windowmanager.h>
|
||||
@ -77,16 +78,22 @@ void ProgramEditDialog::initialize(const AppRow &appRow, const QVector<qint64> &
|
||||
m_editName->setEnabled(isSingleSelection);
|
||||
m_editName->setClearButtonEnabled(isSingleSelection);
|
||||
m_btGetName->setEnabled(isSingleSelection);
|
||||
|
||||
m_comboAppGroup->setCurrentIndex(appRow.groupIndex);
|
||||
m_cbUseGroupPerm->setChecked(appRow.useGroupPerm);
|
||||
m_cbApplyChild->setChecked(appRow.applyChild);
|
||||
m_cbKillChild->setChecked(appRow.killChild);
|
||||
|
||||
m_cbLanOnly->setChecked(appRow.lanOnly);
|
||||
m_cbLogBlocked->setChecked(appRow.logBlocked);
|
||||
m_cbLogConn->setChecked(appRow.logConn);
|
||||
m_rbAllowApp->setChecked(!appRow.blocked);
|
||||
m_rbBlockApp->setChecked(appRow.blocked);
|
||||
m_rbKillProcess->setChecked(appRow.killProcess);
|
||||
|
||||
m_btZones->setZones(appRow.acceptZones);
|
||||
m_btZones->setUncheckedZones(appRow.rejectZones);
|
||||
|
||||
m_cscBlockAppIn->checkBox()->setChecked(false);
|
||||
m_cscBlockAppIn->spinBox()->setValue(1);
|
||||
m_cbBlockAppAt->setChecked(!appRow.endTime.isNull());
|
||||
@ -138,6 +145,8 @@ void ProgramEditDialog::retranslateUi()
|
||||
m_rbBlockApp->setText(tr("Block"));
|
||||
m_rbKillProcess->setText(tr("Kill Process"));
|
||||
|
||||
m_btZones->retranslateUi();
|
||||
|
||||
m_cscBlockAppIn->checkBox()->setText(tr("Block In:"));
|
||||
retranslateAppBlockInHours();
|
||||
m_cbBlockAppAt->setText(tr("Block At:"));
|
||||
@ -361,8 +370,8 @@ QLayout *ProgramEditDialog::setupAllowLayout()
|
||||
|
||||
QLayout *ProgramEditDialog::setupExtraLayout()
|
||||
{
|
||||
// LAN Only
|
||||
m_cbLanOnly = new QCheckBox();
|
||||
// Zones
|
||||
auto zonesLayout = setupZonesLayout();
|
||||
|
||||
// Block after N hours
|
||||
m_cscBlockAppIn = new CheckSpinCombo();
|
||||
@ -380,7 +389,7 @@ QLayout *ProgramEditDialog::setupExtraLayout()
|
||||
setupAllowEclusiveGroup();
|
||||
|
||||
auto layout = new QVBoxLayout();
|
||||
layout->addWidget(m_cbLanOnly);
|
||||
layout->addLayout(zonesLayout);
|
||||
layout->addWidget(m_cscBlockAppIn);
|
||||
layout->addLayout(blockAtLayout);
|
||||
layout->addWidget(m_cbBlockAppNone);
|
||||
@ -388,6 +397,24 @@ QLayout *ProgramEditDialog::setupExtraLayout()
|
||||
return layout;
|
||||
}
|
||||
|
||||
QLayout *ProgramEditDialog::setupZonesLayout()
|
||||
{
|
||||
// LAN Only
|
||||
m_cbLanOnly = new QCheckBox();
|
||||
|
||||
// Zones
|
||||
m_btZones = new ZonesSelector();
|
||||
m_btZones->setIsTristate(true);
|
||||
|
||||
auto layout = new QHBoxLayout();
|
||||
layout->addWidget(m_cbLanOnly);
|
||||
layout->addWidget(ControlUtil::createSeparator(Qt::Vertical));
|
||||
layout->addWidget(m_btZones);
|
||||
layout->addStretch();
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
QLayout *ProgramEditDialog::setupCheckDateTimeEdit()
|
||||
{
|
||||
m_cbBlockAppAt = new QCheckBox();
|
||||
@ -411,6 +438,7 @@ void ProgramEditDialog::setupAllowConnections()
|
||||
{
|
||||
connect(m_rbAllowApp, &QRadioButton::toggled, this, [&](bool checked) {
|
||||
m_cbLanOnly->setEnabled(checked);
|
||||
m_btZones->setEnabled(checked);
|
||||
m_cbBlockAppNone->setEnabled(checked);
|
||||
m_cscBlockAppIn->setEnabled(checked);
|
||||
m_cbBlockAppAt->setEnabled(checked);
|
||||
@ -517,6 +545,9 @@ void ProgramEditDialog::fillApp(App &app) const
|
||||
app.groupIndex = m_comboAppGroup->currentIndex();
|
||||
app.appName = m_editName->text();
|
||||
|
||||
app.acceptZones = m_btZones->zones();
|
||||
app.rejectZones = m_btZones->uncheckedZones();
|
||||
|
||||
const QString appPath = m_editPath->text();
|
||||
app.appOriginPath = appPath;
|
||||
app.appPath = FileUtil::normalizePath(appPath);
|
||||
|
@ -19,6 +19,7 @@ class ConfManager;
|
||||
class FirewallConf;
|
||||
class FortManager;
|
||||
class ProgramsController;
|
||||
class ZonesSelector;
|
||||
|
||||
class ProgramEditDialog : public QDialog
|
||||
{
|
||||
@ -52,6 +53,7 @@ private:
|
||||
QLayout *setupLogLayout();
|
||||
QLayout *setupAllowLayout();
|
||||
QLayout *setupExtraLayout();
|
||||
QLayout *setupZonesLayout();
|
||||
QLayout *setupCheckDateTimeEdit();
|
||||
void setupAllowEclusiveGroup();
|
||||
void setupAllowConnections();
|
||||
@ -89,6 +91,7 @@ private:
|
||||
QRadioButton *m_rbAllowApp = nullptr;
|
||||
QRadioButton *m_rbBlockApp = nullptr;
|
||||
QRadioButton *m_rbKillProcess = nullptr;
|
||||
ZonesSelector *m_btZones = nullptr;
|
||||
CheckSpinCombo *m_cscBlockAppIn = nullptr;
|
||||
QCheckBox *m_cbBlockAppAt = nullptr;
|
||||
QDateTimeEdit *m_dteBlockAppAt = nullptr;
|
||||
|
@ -328,8 +328,8 @@ bool AppListModel::updateAppRow(const QString &sql, const QVariantList &vars, Ap
|
||||
appRow.logConn = stmt.columnBool(11);
|
||||
appRow.blocked = stmt.columnBool(12);
|
||||
appRow.killProcess = stmt.columnBool(13);
|
||||
appRow.acceptZones = stmt.columnBool(14);
|
||||
appRow.rejectZones = stmt.columnBool(15);
|
||||
appRow.acceptZones = stmt.columnUInt(14);
|
||||
appRow.rejectZones = stmt.columnUInt(15);
|
||||
appRow.alerted = stmt.columnBool(16);
|
||||
appRow.endTime = stmt.columnDateTime(17);
|
||||
appRow.creatTime = stmt.columnDateTime(18);
|
||||
|
Loading…
Reference in New Issue
Block a user