From fbc1fc142a3247d01e163480c56e6e4d11c3ceed Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 26 Sep 2024 10:53:48 +0500 Subject: [PATCH] UI: Options: Improve "Reset to default" --- src/ui/conf/addressgroup.cpp | 14 ++++++++++++++ src/ui/conf/addressgroup.h | 2 ++ src/ui/form/opt/pages/addressespage.cpp | 11 +++++++++++ src/ui/form/opt/pages/addressespage.h | 3 +++ src/ui/form/opt/pages/ifacepage.cpp | 2 ++ src/ui/form/opt/pages/optionspage.cpp | 9 +++++++++ src/ui/form/opt/pages/schedulepage.cpp | 16 ++++++++++++++++ src/ui/form/opt/pages/schedulepage.h | 3 +++ src/ui/form/opt/pages/statisticspage.h | 1 + src/ui/task/taskinfo.h | 4 +++- 10 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/ui/conf/addressgroup.cpp b/src/ui/conf/addressgroup.cpp index 7e84d02f..3056f0ec 100644 --- a/src/ui/conf/addressgroup.cpp +++ b/src/ui/conf/addressgroup.cpp @@ -103,3 +103,17 @@ void AddressGroup::fromVariant(const QVariant &v) m_includeText = map["includeText"].toString(); m_excludeText = map["excludeText"].toString(); } + +void AddressGroup::resetToDefault() +{ + setEdited(true); + + m_includeAll = true; + m_excludeAll = false; + + m_includeZones = 0; + m_excludeZones = 0; + + m_includeText.clear(); + m_excludeText.clear(); +} diff --git a/src/ui/conf/addressgroup.h b/src/ui/conf/addressgroup.h index 4e6c206e..5bd1bb92 100644 --- a/src/ui/conf/addressgroup.h +++ b/src/ui/conf/addressgroup.h @@ -41,6 +41,8 @@ public: QVariant toVariant() const; void fromVariant(const QVariant &v); + void resetToDefault(); + private: bool m_edited : 1 = false; diff --git a/src/ui/form/opt/pages/addressespage.cpp b/src/ui/form/opt/pages/addressespage.cpp index e4e38cfe..1e21bc38 100644 --- a/src/ui/form/opt/pages/addressespage.cpp +++ b/src/ui/form/opt/pages/addressespage.cpp @@ -49,6 +49,17 @@ void AddressesPage::setAddressGroupIndex(int v) } } +void AddressesPage::onResetToDefault() +{ + for (auto addressGroup : addressGroups()) { + addressGroup->resetToDefault(); + } + + conf()->setupDefaultAddressGroups(); + + updateGroup(); +} + void AddressesPage::onSaveWindowState(IniUser *ini) { ini->setOptWindowAddrSplit(m_splitter->saveState()); diff --git a/src/ui/form/opt/pages/addressespage.h b/src/ui/form/opt/pages/addressespage.h index e71da37f..c75cca80 100644 --- a/src/ui/form/opt/pages/addressespage.h +++ b/src/ui/form/opt/pages/addressespage.h @@ -23,6 +23,9 @@ public: signals: void addressGroupChanged(); +public slots: + void onResetToDefault() override; + protected slots: void onSaveWindowState(IniUser *ini) override; void onRestoreWindowState(IniUser *ini) override; diff --git a/src/ui/form/opt/pages/ifacepage.cpp b/src/ui/form/opt/pages/ifacepage.cpp index 0f1ddbe8..0666f93a 100644 --- a/src/ui/form/opt/pages/ifacepage.cpp +++ b/src/ui/form/opt/pages/ifacepage.cpp @@ -40,7 +40,9 @@ void IfacePage::onResetToDefault() { m_cbExcludeCapture->setChecked(false); m_cbUseSystemLocale->setChecked(true); + m_comboLanguage->setCurrentIndex(0); m_comboTheme->setCurrentIndex(0); + m_cbHotKeysEnabled->setChecked(false); m_cbHotKeysGlobal->setChecked(true); diff --git a/src/ui/form/opt/pages/optionspage.cpp b/src/ui/form/opt/pages/optionspage.cpp index 67297ca3..8ff2dec2 100644 --- a/src/ui/form/opt/pages/optionspage.cpp +++ b/src/ui/form/opt/pages/optionspage.cpp @@ -63,10 +63,19 @@ void OptionsPage::onResetToDefault() { m_cbFilterEnabled->setChecked(true); m_comboBlockTraffic->setCurrentIndex(0); + m_comboFilterMode->setCurrentIndex(0); + + m_cbBootFilter->setChecked(false); + m_cbNoServiceControl->setChecked(false); + m_cbCheckPasswordOnUninstall->setChecked(false); + m_cbPassword->setChecked(false); m_cbLogBlocked->setChecked(true); m_cbPurgeOnMounted->setChecked(false); + m_cbFilterLocals->setChecked(false); + m_cbFilterLocalNet->setChecked(false); + m_cbLogDebug->setChecked(false); m_cbLogConsole->setChecked(false); } diff --git a/src/ui/form/opt/pages/schedulepage.cpp b/src/ui/form/opt/pages/schedulepage.cpp index 1f59a6be..ab63fc4b 100644 --- a/src/ui/form/opt/pages/schedulepage.cpp +++ b/src/ui/form/opt/pages/schedulepage.cpp @@ -31,6 +31,22 @@ SchedulePage::SchedulePage(OptionsController *ctrl, QWidget *parent) : setupUi(); } +void SchedulePage::onResetToDefault() +{ + auto model = taskListModel(); + + const int n = model->rowCount(); + for (int i = 0; i < n; ++i) { + const auto index = model->index(i, 0); + + model->setData(index, false, TaskListModel::RoleEnabled); + model->setData(index, false, TaskListModel::RoleRunOnStartup); + model->setData(index, TaskDefaultIntervalHours, TaskListModel::RoleIntervalHours); + } + + model->refresh(); +} + void SchedulePage::onAboutToSave() { if (conf()->taskEdited()) { diff --git a/src/ui/form/opt/pages/schedulepage.h b/src/ui/form/opt/pages/schedulepage.h index 358f290e..f6f3c41d 100644 --- a/src/ui/form/opt/pages/schedulepage.h +++ b/src/ui/form/opt/pages/schedulepage.h @@ -19,6 +19,9 @@ public: TaskListModel *taskListModel() const { return m_taskListModel; } +public slots: + void onResetToDefault() override; + protected slots: void onAboutToSave() override; void onEditResetted() override; diff --git a/src/ui/form/opt/pages/statisticspage.h b/src/ui/form/opt/pages/statisticspage.h index dc742354..9e27f16b 100644 --- a/src/ui/form/opt/pages/statisticspage.h +++ b/src/ui/form/opt/pages/statisticspage.h @@ -44,6 +44,7 @@ private: QGroupBox *m_gbTraffic = nullptr; QGroupBox *m_gbBlockedConn = nullptr; QGroupBox *m_gbAllowedConn = nullptr; + QCheckBox *m_cbLogStat = nullptr; QCheckBox *m_cbLogStatNoFilter = nullptr; CheckTimePeriod *m_ctpActivePeriod = nullptr; diff --git a/src/ui/task/taskinfo.h b/src/ui/task/taskinfo.h index 9fe5b5fc..a18a159d 100644 --- a/src/ui/task/taskinfo.h +++ b/src/ui/task/taskinfo.h @@ -9,6 +9,8 @@ class TaskManager; class TaskWorker; +constexpr int TaskDefaultIntervalHours = 24; + class TaskInfo : public QObject { Q_OBJECT @@ -108,7 +110,7 @@ private: bool m_running : 1 = false; bool m_aborted : 1 = false; // transient - quint16 m_intervalHours = 24; + quint16 m_intervalHours = TaskDefaultIntervalHours; TaskType m_type = TypeNone;