From 3733819936116c88ef1e9960bc9ca1126ec66d8b Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 1 Feb 2024 20:21:52 +0300 Subject: [PATCH] UI: ProgramEditDialog: Reorganize for advanced mode --- src/ui/form/prog/programeditdialog.cpp | 154 ++++++++++++++----------- src/ui/form/prog/programeditdialog.h | 19 +-- src/ui/form/prog/programswindow.cpp | 5 +- 3 files changed, 100 insertions(+), 78 deletions(-) diff --git a/src/ui/form/prog/programeditdialog.cpp b/src/ui/form/prog/programeditdialog.cpp index 50b67390..b60fcad7 100644 --- a/src/ui/form/prog/programeditdialog.cpp +++ b/src/ui/form/prog/programeditdialog.cpp @@ -90,19 +90,21 @@ void ProgramEditDialog::initialize(const AppRow &appRow, const QVector & initializePathNameFields(); 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_cbParked->setChecked(appRow.parked); - m_cbParked->setEnabled(!isWildcard()); - 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_cbUseGroupPerm->setChecked(appRow.useGroupPerm); + m_cbApplyChild->setChecked(appRow.applyChild); + m_cbKillChild->setChecked(appRow.killChild); + + m_cbParked->setChecked(appRow.parked); + m_cbParked->setEnabled(!isWildcard()); + m_cbLogBlocked->setChecked(appRow.logBlocked); + m_cbLogConn->setChecked(appRow.logConn); + + m_cbLanOnly->setChecked(appRow.lanOnly); m_btZones->setZones(appRow.acceptZones); m_btZones->setUncheckedZones(appRow.rejectZones); @@ -122,6 +124,8 @@ void ProgramEditDialog::initializePathNameFields() initializePathField(isSingleSelection, isPathEditable); initializeNameField(isSingleSelection, isPathEditable); + + initializeFocus(); } void ProgramEditDialog::initializePathField(bool isSingleSelection, bool isPathEditable) @@ -160,11 +164,11 @@ void ProgramEditDialog::initializeNameField(bool isSingleSelection, bool isPathE } } -void ProgramEditDialog::activate() +void ProgramEditDialog::initializeFocus() { - WidgetWindow::showWidget(this); - - if (isWildcard()) { + if (!isEmpty()) { + m_rbAllowApp->setFocus(); + } else if (isWildcard()) { m_editWildcard->setFocus(); } else { m_editPath->selectAll(); @@ -199,22 +203,22 @@ void ProgramEditDialog::retranslateUi() m_btGetName->setToolTip(tr("Get Program Name")); m_editNotes->setPlaceholderText(tr("Notes")); - m_labelAppGroup->setText(tr("Application Group:")); + + m_rbAllowApp->setText(tr("Allow")); + m_rbBlockApp->setText(tr("Block")); + m_rbKillProcess->setText(tr("Kill Process")); + m_cbUseGroupPerm->setText(tr("Use Application Group's Enabled State")); m_cbApplyChild->setText(tr("Apply same rules to child processes")); m_cbKillChild->setText(tr("Kill child processes")); m_cbParked->setText(tr("Parked")); m_cbParked->setToolTip(tr("Don't purge as obsolete")); - m_cbLanOnly->setText(tr("Block Internet Traffic")); m_cbLogBlocked->setText(tr("Collect blocked connections")); m_cbLogConn->setText(tr("Collect connection statistics")); - m_rbAllowApp->setText(tr("Allow")); - m_rbBlockApp->setText(tr("Block")); - m_rbKillProcess->setText(tr("Kill Process")); - + m_cbLanOnly->setText(tr("Block Internet Traffic")); m_btZones->retranslateUi(); m_cbSchedule->setText(tr("Schedule")); @@ -286,14 +290,14 @@ void ProgramEditDialog::setupUi() // Form Layout auto appLayout = setupAppLayout(); - // Log - auto logLayout = setupLogLayout(); - // Allow/Block/etc Actions Layout auto actionsLayout = setupActionsLayout(); - // Options - auto optionsLayout = setupOptionsLayout(); + // Advanced Options + setupFrameAdvanced(); + + // Schedule + auto scheduleLayout = setupScheduleLayout(); // OK/Cancel auto buttonsLayout = setupButtonsLayout(); @@ -302,12 +306,12 @@ void ProgramEditDialog::setupUi() auto layout = new QVBoxLayout(); layout->addLayout(appLayout); layout->addWidget(ControlUtil::createSeparator()); - layout->addLayout(logLayout); - layout->addWidget(ControlUtil::createSeparator()); layout->addLayout(actionsLayout); - layout->addWidget(ControlUtil::createSeparator()); - layout->addLayout(optionsLayout); layout->addStretch(); + layout->addWidget(m_frameAdvanced); + layout->addStretch(); + layout->addWidget(ControlUtil::createSeparator()); + layout->addLayout(scheduleLayout); layout->addWidget(ControlUtil::createSeparator()); layout->addLayout(buttonsLayout); @@ -353,22 +357,6 @@ QLayout *ProgramEditDialog::setupAppLayout() layout->addRow("Application Group:", m_comboAppGroup); m_labelAppGroup = qobject_cast(layout->labelForField(m_comboAppGroup)); - // Use Group Perm. - m_cbUseGroupPerm = new QCheckBox(); - - layout->addRow(QString(), m_cbUseGroupPerm); - - // Apply Child - m_cbApplyChild = new QCheckBox(); - - layout->addRow(QString(), m_cbApplyChild); - - // Kill Child - m_cbKillChild = new QCheckBox(); - connect(m_cbKillChild, &QCheckBox::clicked, this, &ProgramEditDialog::warnDangerousOption); - - layout->addRow(QString(), m_cbKillChild); - return layout; } @@ -445,24 +433,6 @@ void ProgramEditDialog::setupComboAppGroups() connect(confManager(), &ConfManager::confChanged, this, refreshComboAppGroups); } -QLayout *ProgramEditDialog::setupLogLayout() -{ - // Parked - m_cbParked = new QCheckBox(); - - // Log Blocked - m_cbLogBlocked = new QCheckBox(); - - // Log Conn - m_cbLogConn = new QCheckBox(); - m_cbLogConn->setVisible(false); // TODO: Collect allowed connections - - auto layout = ControlUtil::createHLayoutByWidgets({ m_cbParked, ControlUtil::createVSeparator(), - m_cbLogBlocked, m_cbLogConn, /*stretch*/ nullptr }); - - return layout; -} - QLayout *ProgramEditDialog::setupActionsLayout() { m_rbAllowApp = new QRadioButton(); @@ -484,17 +454,63 @@ QLayout *ProgramEditDialog::setupActionsLayout() return layout; } -QLayout *ProgramEditDialog::setupOptionsLayout() +void ProgramEditDialog::setupFrameAdvanced() { + // Use Group Perm. + m_cbUseGroupPerm = new QCheckBox(); + + // Child Options + auto childLayout = setupChildLayout(); + + // Log + auto logLayout = setupLogLayout(); + // Zones auto zonesLayout = setupZonesLayout(); - // Schedule - auto scheduleLayout = setupScheduleLayout(); - auto layout = new QVBoxLayout(); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(ControlUtil::createHSeparator()); + layout->addWidget(m_cbUseGroupPerm); + layout->addLayout(childLayout); + layout->addWidget(ControlUtil::createHSeparator()); + layout->addLayout(logLayout); + layout->addWidget(ControlUtil::createHSeparator()); layout->addLayout(zonesLayout); - layout->addLayout(scheduleLayout); + + m_frameAdvanced = new QFrame(); + m_frameAdvanced->setLayout(layout); +} + +QLayout *ProgramEditDialog::setupChildLayout() +{ + // Apply Child + m_cbApplyChild = new QCheckBox(); + + // Kill Child + m_cbKillChild = new QCheckBox(); + connect(m_cbKillChild, &QCheckBox::clicked, this, &ProgramEditDialog::warnDangerousOption); + + auto layout = ControlUtil::createHLayoutByWidgets( + { m_cbApplyChild, ControlUtil::createVSeparator(), m_cbKillChild }); + + return layout; +} + +QLayout *ProgramEditDialog::setupLogLayout() +{ + // Parked + m_cbParked = new QCheckBox(); + + // Log Blocked + m_cbLogBlocked = new QCheckBox(); + + // Log Conn + m_cbLogConn = new QCheckBox(); + m_cbLogConn->setVisible(false); // TODO: Collect allowed connections + + auto layout = ControlUtil::createHLayoutByWidgets({ m_cbParked, ControlUtil::createVSeparator(), + m_cbLogBlocked, m_cbLogConn, /*stretch*/ nullptr }); return layout; } @@ -597,8 +613,10 @@ void ProgramEditDialog::setupAdvancedMode() m_btAdvancedMode->setCheckable(true); m_btAdvancedMode->setChecked(true); - connect(m_btAdvancedMode, &QToolButton::toggled, this, - [&](bool checked) { m_rbKillProcess->setVisible(checked); }); + connect(m_btAdvancedMode, &QToolButton::toggled, this, [&](bool checked) { + m_rbKillProcess->setVisible(checked); + m_frameAdvanced->setVisible(checked); + }); } void ProgramEditDialog::fillEditName() diff --git a/src/ui/form/prog/programeditdialog.h b/src/ui/form/prog/programeditdialog.h index 42e9227f..6f76959c 100644 --- a/src/ui/form/prog/programeditdialog.h +++ b/src/ui/form/prog/programeditdialog.h @@ -7,6 +7,7 @@ QT_FORWARD_DECLARE_CLASS(QCheckBox) QT_FORWARD_DECLARE_CLASS(QComboBox) QT_FORWARD_DECLARE_CLASS(QDateTimeEdit) +QT_FORWARD_DECLARE_CLASS(QFrame) QT_FORWARD_DECLARE_CLASS(QLabel) QT_FORWARD_DECLARE_CLASS(QLineEdit) QT_FORWARD_DECLARE_CLASS(QPushButton) @@ -43,8 +44,6 @@ public: void initialize(const AppRow &appRow, const QVector &appIdList = {}); - void activate(); - protected: virtual void closeOnSave(); @@ -55,6 +54,8 @@ private: void initializePathField(bool isSingleSelection, bool isPathEditable); void initializeNameField(bool isSingleSelection, bool isPathEditable); + void initializeFocus(); + void setupController(); void retranslateUi(); @@ -70,9 +71,10 @@ private: QLayout *setupAppNameLayout(); QLayout *setupNotesLayout(); void setupComboAppGroups(); - QLayout *setupLogLayout(); QLayout *setupActionsLayout(); - QLayout *setupOptionsLayout(); + void setupFrameAdvanced(); + QLayout *setupChildLayout(); + QLayout *setupLogLayout(); QLayout *setupZonesLayout(); QLayout *setupScheduleLayout(); void setupCbSchedule(); @@ -109,16 +111,17 @@ private: PlainTextEdit *m_editNotes = nullptr; QLabel *m_labelAppGroup = nullptr; QComboBox *m_comboAppGroup = nullptr; + QRadioButton *m_rbAllowApp = nullptr; + QRadioButton *m_rbBlockApp = nullptr; + QRadioButton *m_rbKillProcess = nullptr; + QFrame *m_frameAdvanced = nullptr; QCheckBox *m_cbUseGroupPerm = nullptr; QCheckBox *m_cbApplyChild = nullptr; QCheckBox *m_cbKillChild = nullptr; QCheckBox *m_cbParked = nullptr; - QCheckBox *m_cbLanOnly = nullptr; QCheckBox *m_cbLogBlocked = nullptr; QCheckBox *m_cbLogConn = nullptr; - QRadioButton *m_rbAllowApp = nullptr; - QRadioButton *m_rbBlockApp = nullptr; - QRadioButton *m_rbKillProcess = nullptr; + QCheckBox *m_cbLanOnly = nullptr; ZonesSelector *m_btZones = nullptr; QCheckBox *m_cbSchedule = nullptr; QComboBox *m_comboScheduleAction = nullptr; diff --git a/src/ui/form/prog/programswindow.cpp b/src/ui/form/prog/programswindow.cpp index d5936350..b53b368b 100644 --- a/src/ui/form/prog/programswindow.cpp +++ b/src/ui/form/prog/programswindow.cpp @@ -452,14 +452,15 @@ void ProgramsWindow::openAppEditForm(const AppRow &appRow, const QVector m_formAppEdit->initialize(appRow, appIdList); - m_formAppEdit->activate(); + WidgetWindow::showWidget(m_formAppEdit); + m_formAppEdit->centerTo(this); } bool ProgramsWindow::checkAppEditFormOpened() const { if (m_formAppEdit && m_formAppEdit->isVisible()) { - m_formAppEdit->activate(); + WidgetWindow::showWidget(m_formAppEdit); return true; } return false;