UI: ProgramEdit: Prepare Rule field

This commit is contained in:
Nodir Temirkhodjaev 2024-03-31 13:13:16 +03:00
parent 30f2255a09
commit 458ff09733
4 changed files with 62 additions and 10 deletions

View File

@ -52,6 +52,7 @@ public:
QString appPath;
QString appName;
QString notes;
QString ruleName; // transient
QDateTime scheduleTime;
QDateTime creatTime;

View File

@ -117,7 +117,7 @@ void ProgramEditDialog::initialize(const AppRow &appRow, const QVector<qint64> &
m_comboScheduleAction->setCurrentIndex(appRow.scheduleAction);
m_comboScheduleType->setCurrentIndex(
appRow.scheduleTime.isNull() ? ScheduleTimeIn : ScheduleTimeAt);
m_scScheduleIn->spinBox()->setValue(30);
m_scScheduleIn->spinBox()->setValue(5);
m_dteScheduleAt->setDateTime(appRow.scheduleTime);
m_dteScheduleAt->setMinimumDateTime(DateUtil::now());
@ -131,6 +131,7 @@ void ProgramEditDialog::initializePathNameFields()
initializePathField(isSingleSelection, isPathEditable);
initializeNameField(isSingleSelection);
initializeRuleField(isSingleSelection);
}
void ProgramEditDialog::initializePathField(bool isSingleSelection, bool isPathEditable)
@ -169,6 +170,15 @@ void ProgramEditDialog::initializeNameField(bool isSingleSelection)
}
}
void ProgramEditDialog::initializeRuleField(bool isSingleSelection)
{
m_editRuleName->setText(isSingleSelection ? m_appRow.ruleName : QString());
m_editRuleName->setEnabled(isSingleSelection);
m_editRuleName->setClearButtonEnabled(isSingleSelection);
m_btSelectRule->setEnabled(isSingleSelection);
}
void ProgramEditDialog::initializeFocus()
{
if (!isEmpty()) {
@ -237,6 +247,9 @@ void ProgramEditDialog::retranslateUi()
m_cbLanOnly->setText(tr("Block Internet Traffic"));
m_btZones->retranslateUi();
m_editRuleName->setPlaceholderText(tr("Rule"));
m_btSelectRule->setToolTip(tr("Select Rule"));
m_cbSchedule->setText(tr("Schedule"));
retranslateScheduleAction();
retranslateScheduleType();
@ -331,7 +344,7 @@ QLayout *ProgramEditDialog::setupMainLayout()
setupActionsGroup();
// Zones
auto zonesRulesLayout = setupZonesRulesLayout();
auto zonesRulesLayout = setupZonesRuleLayout();
// Schedule
auto scheduleLayout = setupScheduleLayout();
@ -396,13 +409,14 @@ QLayout *ProgramEditDialog::setupFormLayout()
QLayout *ProgramEditDialog::setupPathLayout()
{
auto layout = new QHBoxLayout();
// Path
m_editPath = new QLineEdit();
m_editPath->setMaxLength(1024);
// Wildcard
m_editWildcard = new PlainTextEdit();
// Select File
m_btSelectFile = ControlUtil::createIconToolButton(":/icons/folder.png", [&] {
if (!isEmpty()) {
AppInfoUtil::openFolder(m_editPath->text());
@ -426,6 +440,7 @@ QLayout *ProgramEditDialog::setupPathLayout()
fillEditName(); // Auto-fill the name
});
auto layout = new QHBoxLayout();
layout->addWidget(m_editPath);
layout->addWidget(m_editWildcard);
layout->addWidget(m_btSelectFile, 0, Qt::AlignTop);
@ -551,7 +566,7 @@ void ProgramEditDialog::setupLogOptions()
m_cbLogConn->setVisible(false); // TODO: Collect allowed connections
}
QLayout *ProgramEditDialog::setupZonesRulesLayout()
QLayout *ProgramEditDialog::setupZonesRuleLayout()
{
// LAN Only
m_cbLanOnly = new QCheckBox();
@ -562,8 +577,37 @@ QLayout *ProgramEditDialog::setupZonesRulesLayout()
m_btZones->setIsTristate(true);
m_btZones->setMaxZoneCount(16); // sync with driver's FORT_APP_ENTRY
auto layout = ControlUtil::createHLayoutByWidgets(
{ m_cbLanOnly, ControlUtil::createVSeparator(), m_btZones, /*stretch*/ nullptr });
// Rule
auto ruleLayout = setupRuleLayout();
auto layout = new QHBoxLayout();
layout->addWidget(m_cbLanOnly);
layout->addWidget(ControlUtil::createVSeparator());
layout->addWidget(m_btZones);
layout->addStretch();
layout->addLayout(ruleLayout, 1);
return layout;
}
QLayout *ProgramEditDialog::setupRuleLayout()
{
m_editRuleName = new QLineEdit();
m_editRuleName->setReadOnly(true);
m_editRuleName->setMaximumWidth(300);
// Select Rule
m_btSelectRule = ControlUtil::createIconToolButton(":/icons/script.png", [&] {
if (m_appRow.ruleId == 0) {
// Edit the Rule
return;
}
// Select a Rule
});
auto layout = ControlUtil::createHLayoutByWidgets({ m_editRuleName, m_btSelectRule });
layout->setSpacing(0);
return layout;
}

View File

@ -56,6 +56,7 @@ private:
void initializePathNameFields();
void initializePathField(bool isSingleSelection, bool isPathEditable);
void initializeNameField(bool isSingleSelection);
void initializeRuleField(bool isSingleSelection);
void initializeFocus();
QPixmap appIcon(bool isSingleSelection) const;
@ -80,7 +81,8 @@ private:
void setupAdvancedOptions();
void setupChildOptions();
void setupLogOptions();
QLayout *setupZonesRulesLayout();
QLayout *setupZonesRuleLayout();
QLayout *setupRuleLayout();
QLayout *setupScheduleLayout();
void setupCbSchedule();
void setupComboScheduleType();
@ -127,6 +129,8 @@ private:
QCheckBox *m_cbLogConn = nullptr;
QCheckBox *m_cbLanOnly = nullptr;
ZonesSelector *m_btZones = nullptr;
QLineEdit *m_editRuleName = nullptr;
QToolButton *m_btSelectRule = nullptr;
QCheckBox *m_cbSchedule = nullptr;
QComboBox *m_comboScheduleAction = nullptr;
QComboBox *m_comboScheduleType = nullptr;

View File

@ -426,6 +426,7 @@ bool AppListModel::updateAppRow(const QString &sql, const QVariantHash &vars, Ap
appRow.creatTime = stmt.columnDateTime(20);
appRow.groupIndex = stmt.columnInt(21);
appRow.alerted = stmt.columnBool(22);
appRow.ruleName = stmt.columnText(23);
return true;
}
@ -490,10 +491,12 @@ QString AppListModel::sqlBase() const
" t.end_time,"
" t.creat_time,"
" g.order_index as group_index,"
" (alert.app_id IS NOT NULL) as alerted"
" (a.app_id IS NOT NULL) as alerted,"
" r.name as rule_name"
" FROM app t"
" JOIN app_group g ON g.app_group_id = t.app_group_id"
" LEFT JOIN app_alert alert ON alert.app_id = t.app_id";
" LEFT JOIN app_alert a ON a.app_id = t.app_id"
" LEFT JOIN rule r ON r.rule_id = t.rule_id";
}
QString AppListModel::sqlWhereFts() const