diff --git a/src/ui/control/controlworker.cpp b/src/ui/control/controlworker.cpp index 334416fd..4c60b49a 100644 --- a/src/ui/control/controlworker.cpp +++ b/src/ui/control/controlworker.cpp @@ -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; diff --git a/src/ui/form/controls/zonesselector.cpp b/src/ui/form/controls/zonesselector.cpp index 9dfa9c48..f206d28d 100644 --- a/src/ui/form/controls/zonesselector.cpp +++ b/src/ui/form/controls/zonesselector.cpp @@ -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(); diff --git a/src/ui/form/controls/zonesselector.h b/src/ui/form/controls/zonesselector.h index 722e8084..b8f9dca6 100644 --- a/src/ui/form/controls/zonesselector.h +++ b/src/ui/form/controls/zonesselector.h @@ -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; }; diff --git a/src/ui/form/prog/programeditdialog.cpp b/src/ui/form/prog/programeditdialog.cpp index b0151a7f..ed96ef8d 100644 --- a/src/ui/form/prog/programeditdialog.cpp +++ b/src/ui/form/prog/programeditdialog.cpp @@ -17,6 +17,7 @@ #include #include
#include +#include #include #include #include @@ -77,16 +78,22 @@ void ProgramEditDialog::initialize(const AppRow &appRow, const QVector & 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); diff --git a/src/ui/form/prog/programeditdialog.h b/src/ui/form/prog/programeditdialog.h index c5c5784b..9b818a0a 100644 --- a/src/ui/form/prog/programeditdialog.h +++ b/src/ui/form/prog/programeditdialog.h @@ -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; diff --git a/src/ui/model/applistmodel.cpp b/src/ui/model/applistmodel.cpp index 6f7d6be9..4403d254 100644 --- a/src/ui/model/applistmodel.cpp +++ b/src/ui/model/applistmodel.cpp @@ -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);