From 71a9186beabd0c7a2eb968fa609bd29a6a8d578d Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 21 May 2021 12:23:46 +0300 Subject: [PATCH] UI: Options: Prepare Services page. --- src/ui/FortFirewallUI.pro | 4 ++ src/ui/conf/firewallconf.cpp | 12 ++++++ src/ui/conf/firewallconf.h | 5 +++ src/ui/form/opt/pages/optmainpage.cpp | 9 +++- src/ui/form/opt/pages/servicespage.cpp | 48 ++++++++++++++++++++++ src/ui/form/opt/pages/servicespage.h | 32 +++++++++++++++ src/ui/form/stat/pages/connectionspage.cpp | 20 ++++----- src/ui/form/stat/pages/connectionspage.h | 6 +-- src/ui/fortsettings.cpp | 1 + src/ui/model/servicelistmodel.cpp | 3 ++ src/ui/model/servicelistmodel.h | 14 +++++++ 11 files changed, 139 insertions(+), 15 deletions(-) create mode 100644 src/ui/form/opt/pages/servicespage.cpp create mode 100644 src/ui/form/opt/pages/servicespage.h create mode 100644 src/ui/model/servicelistmodel.cpp create mode 100644 src/ui/model/servicelistmodel.h diff --git a/src/ui/FortFirewallUI.pro b/src/ui/FortFirewallUI.pro index f7e970de..3b239951 100644 --- a/src/ui/FortFirewallUI.pro +++ b/src/ui/FortFirewallUI.pro @@ -56,6 +56,7 @@ SOURCES += \ form/opt/pages/optmainpage.cpp \ form/opt/pages/rulespage.cpp \ form/opt/pages/schedulepage.cpp \ + form/opt/pages/servicespage.cpp \ form/opt/pages/statisticspage.cpp \ form/prog/programeditdialog.cpp \ form/prog/programscontroller.cpp \ @@ -83,6 +84,7 @@ SOURCES += \ model/applistmodel.cpp \ model/appstatmodel.cpp \ model/connlistmodel.cpp \ + model/servicelistmodel.cpp \ model/traflistmodel.cpp \ model/zonelistmodel.cpp \ model/zonesourcewrapper.cpp \ @@ -200,6 +202,7 @@ HEADERS += \ form/opt/pages/optmainpage.h \ form/opt/pages/rulespage.h \ form/opt/pages/schedulepage.h \ + form/opt/pages/servicespage.h \ form/opt/pages/statisticspage.h \ form/prog/programeditdialog.h \ form/prog/programscontroller.h \ @@ -228,6 +231,7 @@ HEADERS += \ model/applistmodel.h \ model/appstatmodel.h \ model/connlistmodel.h \ + model/servicelistmodel.h \ model/traflistmodel.h \ model/zonelistmodel.h \ model/zonesourcewrapper.h \ diff --git a/src/ui/conf/firewallconf.cpp b/src/ui/conf/firewallconf.cpp index 745d456b..063ce776 100644 --- a/src/ui/conf/firewallconf.cpp +++ b/src/ui/conf/firewallconf.cpp @@ -22,6 +22,7 @@ FirewallConf::FirewallConf(FortSettings *settings, QObject *parent) : m_logBlockedIp(false), m_appBlockAll(true), m_appAllowAll(false), + m_filterServices(false), m_activePeriodEnabled(false), m_ini(settings) { @@ -101,6 +102,11 @@ void FirewallConf::setAppAllowAll(bool appAllowAll) m_appAllowAll = appAllowAll; } +void FirewallConf::setFilterServices(bool filterServices) +{ + m_filterServices = filterServices; +} + void FirewallConf::setActivePeriodEnabled(bool activePeriodEnabled) { m_activePeriodEnabled = activePeriodEnabled; @@ -266,6 +272,8 @@ void FirewallConf::copyFlags(const FirewallConf &o) m_appBlockAll = o.appBlockAll(); m_appAllowAll = o.appAllowAll(); + m_filterServices = o.filterServices(); + m_activePeriodEnabled = o.activePeriodEnabled(); m_activePeriodFrom = o.activePeriodFrom(); m_activePeriodTo = o.activePeriodTo(); @@ -312,6 +320,8 @@ QVariant FirewallConf::flagsToVariant() const map["appBlockAll"] = appBlockAll(); map["appAllowAll"] = appAllowAll(); + map["filterServices"] = filterServices(); + map["activePeriodEnabled"] = activePeriodEnabled(); map["activePeriodFrom"] = activePeriodFrom(); map["activePeriodTo"] = activePeriodTo(); @@ -342,6 +352,8 @@ void FirewallConf::flagsFromVariant(const QVariant &v) m_appBlockAll = map["appBlockAll"].toBool(); m_appAllowAll = map["appAllowAll"].toBool(); + m_filterServices = map["filterServices"].toBool(); + m_activePeriodEnabled = map["activePeriodEnabled"].toBool(); m_activePeriodFrom = map["activePeriodFrom"].toString(); m_activePeriodTo = map["activePeriodTo"].toString(); diff --git a/src/ui/conf/firewallconf.h b/src/ui/conf/firewallconf.h index 56271f35..83959564 100644 --- a/src/ui/conf/firewallconf.h +++ b/src/ui/conf/firewallconf.h @@ -78,6 +78,9 @@ public: bool appAllowAll() const { return m_appAllowAll; } void setAppAllowAll(bool appAllowAll); + bool filterServices() const { return m_filterServices; } + void setFilterServices(bool filterServices); + bool activePeriodEnabled() const { return m_activePeriodEnabled; } void setActivePeriodEnabled(bool activePeriodEnabled); @@ -169,6 +172,8 @@ private: uint m_appBlockAll : 1; uint m_appAllowAll : 1; + uint m_filterServices : 1; + uint m_activePeriodEnabled : 1; quint32 m_appGroupBits = 0; diff --git a/src/ui/form/opt/pages/optmainpage.cpp b/src/ui/form/opt/pages/optmainpage.cpp index f9834f80..df1d15f6 100644 --- a/src/ui/form/opt/pages/optmainpage.cpp +++ b/src/ui/form/opt/pages/optmainpage.cpp @@ -18,6 +18,7 @@ #include "optionspage.h" #include "rulespage.h" #include "schedulepage.h" +#include "servicespage.h" #include "statisticspage.h" OptMainPage::OptMainPage(OptionsController *ctrl, QWidget *parent) : OptBasePage(ctrl, parent) @@ -31,8 +32,9 @@ void OptMainPage::onRetranslateUi() m_tabBar->setTabText(1, tr("IPv4 Addresses")); m_tabBar->setTabText(2, tr("Network Rules")); m_tabBar->setTabText(3, tr("Application Groups")); - m_tabBar->setTabText(4, tr("Statistics")); - m_tabBar->setTabText(5, tr("Schedule")); + m_tabBar->setTabText(4, tr("Services")); + m_tabBar->setTabText(5, tr("Statistics")); + m_tabBar->setTabText(6, tr("Schedule")); m_btLogs->setText(tr("Logs")); m_btProfile->setText(tr("Profile")); @@ -66,6 +68,7 @@ void OptMainPage::setupTabBar() auto addressesPage = new AddressesPage(ctrl()); auto rulesPage = new RulesPage(ctrl()); auto applicationsPage = new ApplicationsPage(ctrl()); + auto servicesPage = new ServicesPage(ctrl()); auto statisticsPage = new StatisticsPage(ctrl()); auto schedulePage = new SchedulePage(ctrl()); @@ -74,11 +77,13 @@ void OptMainPage::setupTabBar() m_tabBar->addTab(addressesPage, IconCache::icon(":/icons/map-marker.png"), QString()); m_tabBar->addTab(rulesPage, IconCache::icon(":/icons/task-list.png"), QString()); m_tabBar->addTab(applicationsPage, IconCache::icon(":/icons/window.png"), QString()); + m_tabBar->addTab(servicesPage, IconCache::icon(":/icons/windows-48.png"), QString()); m_tabBar->addTab(statisticsPage, IconCache::icon(":/icons/chart-bar.png"), QString()); m_tabBar->addTab(schedulePage, IconCache::icon(":/icons/clock.png"), QString()); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) m_tabBar->setTabVisible(2, false); // TODO: Impl. Network Rules + // m_tabBar->setTabVisible(4, false); // TODO: Impl. Services #endif } diff --git a/src/ui/form/opt/pages/servicespage.cpp b/src/ui/form/opt/pages/servicespage.cpp new file mode 100644 index 00000000..0fb66c89 --- /dev/null +++ b/src/ui/form/opt/pages/servicespage.cpp @@ -0,0 +1,48 @@ +#include "servicespage.h" + +#include +#include +#include +#include +#include + +#include "../../../conf/firewallconf.h" +#include "../../../model/servicelistmodel.h" +#include "../../../user/iniuser.h" +#include "../../controls/controlutil.h" +#include "../../controls/tableview.h" +#include "../optionscontroller.h" + +ServicesPage::ServicesPage(OptionsController *ctrl, QWidget *parent) : OptBasePage(ctrl, parent) +{ + setupUi(); +} + +void ServicesPage::onRetranslateUi() +{ +} + +void ServicesPage::setupUi() +{ +} + +QLayout *ServicesPage::setupHeader() +{ + return nullptr; +} + +void ServicesPage::setupOptions() +{ +} + +void ServicesPage::setupFilterServices() +{ +} + +void ServicesPage::setupTableServList() +{ +} + +void ServicesPage::setupTableServListHeader() +{ +} diff --git a/src/ui/form/opt/pages/servicespage.h b/src/ui/form/opt/pages/servicespage.h new file mode 100644 index 00000000..c107f6db --- /dev/null +++ b/src/ui/form/opt/pages/servicespage.h @@ -0,0 +1,32 @@ +#ifndef SERVICESPAGE_H +#define SERVICESPAGE_H + +#include "optbasepage.h" + +class TableView; + +class ServicesPage : public OptBasePage +{ + Q_OBJECT + +public: + explicit ServicesPage(OptionsController *ctrl = nullptr, QWidget *parent = nullptr); + +protected slots: + void onRetranslateUi() override; + +private: + void setupUi(); + QLayout *setupHeader(); + void setupOptions(); + void setupFilterServices(); + void setupTableServList(); + void setupTableServListHeader(); + +private: + QPushButton *m_btOptions = nullptr; + QCheckBox *m_cbFilterServices = nullptr; + TableView *m_servListView = nullptr; +}; + +#endif // SERVICESPAGE_H diff --git a/src/ui/form/stat/pages/connectionspage.cpp b/src/ui/form/stat/pages/connectionspage.cpp index 0a86a338..00cc5ff0 100644 --- a/src/ui/form/stat/pages/connectionspage.cpp +++ b/src/ui/form/stat/pages/connectionspage.cpp @@ -63,9 +63,9 @@ void ConnectionsPage::onRetranslateUi() m_actCopy->setText(tr("Copy")); m_actAddProgram->setText(tr("Add Program")); m_actRemoveConn->setText(tr("Remove")); - m_actClearConns->setText(tr("Clear All")); + m_actClearAll->setText(tr("Clear All")); - m_btLogOptions->setText(tr("Options")); + m_btOptions->setText(tr("Options")); m_cbAutoScroll->setText(tr("Auto scroll")); m_cbShowHostNames->setText(tr("Show host names")); @@ -114,7 +114,7 @@ QLayout *ConnectionsPage::setupHeader() m_actRemoveConn = editMenu->addAction(IconCache::icon(":/icons/sign-delete.png"), QString()); m_actRemoveConn->setShortcut(Qt::Key_Delete); - m_actClearConns = editMenu->addAction(IconCache::icon(":/icons/trashcan-full.png"), QString()); + m_actClearAll = editMenu->addAction(IconCache::icon(":/icons/trashcan-full.png"), QString()); connect(m_actCopy, &QAction::triggered, this, [&] { GuiUtil::setClipboardData(m_connListView->selectedText()); }); @@ -130,7 +130,7 @@ QLayout *ConnectionsPage::setupHeader() deleteConn(m_connListView->currentRow()); } }); - connect(m_actClearConns, &QAction::triggered, this, [&] { + connect(m_actClearAll, &QAction::triggered, this, [&] { if (fortManager()->showQuestionBox(tr("Are you sure to remove all connections?"))) { connListModel()->clear(); } @@ -139,17 +139,17 @@ QLayout *ConnectionsPage::setupHeader() m_btEdit = ControlUtil::createButton(":/icons/pencil.png"); m_btEdit->setMenu(editMenu); - // Log Options - setupLogOptions(); + // Options + setupOptions(); layout->addWidget(m_btEdit); layout->addStretch(); - layout->addWidget(m_btLogOptions); + layout->addWidget(m_btOptions); return layout; } -void ConnectionsPage::setupLogOptions() +void ConnectionsPage::setupOptions() { setupAutoScroll(); setupShowHostNames(); @@ -160,8 +160,8 @@ void ConnectionsPage::setupLogOptions() auto menu = ControlUtil::createMenuByLayout(layout, this); - m_btLogOptions = ControlUtil::createButton(":/icons/wrench.png"); - m_btLogOptions->setMenu(menu); + m_btOptions = ControlUtil::createButton(":/icons/wrench.png"); + m_btOptions->setMenu(menu); } void ConnectionsPage::setupAutoScroll() diff --git a/src/ui/form/stat/pages/connectionspage.h b/src/ui/form/stat/pages/connectionspage.h index 988a7846..33c4f37b 100644 --- a/src/ui/form/stat/pages/connectionspage.h +++ b/src/ui/form/stat/pages/connectionspage.h @@ -37,7 +37,7 @@ protected slots: private: void setupUi(); QLayout *setupHeader(); - void setupLogOptions(); + void setupOptions(); void setupAutoScroll(); void setupShowHostNames(); void setupTableConnList(); @@ -58,8 +58,8 @@ private: QAction *m_actCopy = nullptr; QAction *m_actAddProgram = nullptr; QAction *m_actRemoveConn = nullptr; - QAction *m_actClearConns = nullptr; - QPushButton *m_btLogOptions = nullptr; + QAction *m_actClearAll = nullptr; + QPushButton *m_btOptions = nullptr; QCheckBox *m_cbAutoScroll = nullptr; QCheckBox *m_cbShowHostNames = nullptr; TableView *m_connListView = nullptr; diff --git a/src/ui/fortsettings.cpp b/src/ui/fortsettings.cpp index 7999e512..e2a2dcf3 100644 --- a/src/ui/fortsettings.cpp +++ b/src/ui/fortsettings.cpp @@ -337,6 +337,7 @@ void FortSettings::writeConfIni(const FirewallConf &conf) setIniValue("logBlockedIp", conf.logBlockedIp()); setIniValue("appBlockAll", conf.appBlockAll()); setIniValue("appAllowAll", conf.appAllowAll()); + setIniValue("filterServices", conf.filterServices()); setIniValue("appGroupBits", conf.appGroupBits(), DEFAULT_APP_GROUP_BITS); ini()->endGroup(); diff --git a/src/ui/model/servicelistmodel.cpp b/src/ui/model/servicelistmodel.cpp new file mode 100644 index 00000000..573b38e9 --- /dev/null +++ b/src/ui/model/servicelistmodel.cpp @@ -0,0 +1,3 @@ +#include "servicelistmodel.h" + +ServiceListModel::ServiceListModel(QObject *parent) : QObject(parent) { } diff --git a/src/ui/model/servicelistmodel.h b/src/ui/model/servicelistmodel.h new file mode 100644 index 00000000..8fc12903 --- /dev/null +++ b/src/ui/model/servicelistmodel.h @@ -0,0 +1,14 @@ +#ifndef SERVICELISTMODEL_H +#define SERVICELISTMODEL_H + +#include + +class ServiceListModel : public QObject +{ + Q_OBJECT + +public: + explicit ServiceListModel(QObject *parent = nullptr); +}; + +#endif // SERVICELISTMODEL_H