diff --git a/src/ui/FortFirewallUI.pro b/src/ui/FortFirewallUI.pro index 46620ce4..b7f29741 100644 --- a/src/ui/FortFirewallUI.pro +++ b/src/ui/FortFirewallUI.pro @@ -57,7 +57,6 @@ 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 \ @@ -68,6 +67,8 @@ SOURCES += \ form/stat/pages/trafficpage.cpp \ form/stat/statisticscontroller.cpp \ form/stat/statisticswindow.cpp \ + form/svc/servicescontroller.cpp \ + form/svc/serviceswindow.cpp \ form/tray/traycontroller.cpp \ form/tray/trayicon.cpp \ form/zone/zonescontroller.cpp \ @@ -209,7 +210,6 @@ 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 \ @@ -220,6 +220,8 @@ HEADERS += \ form/stat/pages/trafficpage.h \ form/stat/statisticscontroller.h \ form/stat/statisticswindow.h \ + form/svc/servicescontroller.h \ + form/svc/serviceswindow.h \ form/tray/traycontroller.h \ form/tray/trayicon.h \ form/zone/zonescontroller.h \ diff --git a/src/ui/form/opt/pages/servicespage.cpp b/src/ui/form/opt/pages/servicespage.cpp deleted file mode 100644 index e18fa4b2..00000000 --- a/src/ui/form/opt/pages/servicespage.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "servicespage.h" - -#include -#include -#include -#include -#include - -#include -#include
-#include -#include -#include -#include -#include -#include -#include - -ServicesPage::ServicesPage(OptionsController *ctrl, QWidget *parent) : - OptBasePage(ctrl, parent), m_serviceListModel(new ServiceListModel(this)) -{ - setupUi(); -} - -ServiceInfoManager *ServicesPage::serviceInfoManager() const -{ - return IoC(); -} - -void ServicesPage::onPageActivated() -{ - serviceListModel()->initialize(); -} - -void ServicesPage::onRetranslateUi() -{ - m_btRefresh->setText(tr("Refresh")); - m_btEdit->setText(tr("Edit")); - m_actEditService->setText(tr("Edit Service")); - - m_btOptions->setText(tr("Options")); - - serviceListModel()->refresh(); -} - -void ServicesPage::setupUi() -{ - auto layout = new QVBoxLayout(); - layout->setContentsMargins(6, 6, 6, 6); - - // Header - auto header = setupHeader(); - layout->addLayout(header); - - // Table - setupTableServiceList(); - setupTableServiceListHeader(); - layout->addWidget(m_serviceListView, 1); - - this->setLayout(layout); -} - -QLayout *ServicesPage::setupHeader() -{ - auto layout = new QHBoxLayout(); - - m_btRefresh = ControlUtil::createButton( - ":/icons/arrow_refresh_small.png", [&] { serviceListModel()->initialize(); }); - - // Edit Menu - auto editMenu = new QMenu(this); - - m_actEditService = editMenu->addAction(IconCache::icon(":/icons/pencil.png"), QString()); - m_actEditService->setShortcut(Qt::Key_Return); - - connect(m_actEditService, &QAction::triggered, this, [&] { - // const auto connIndex = serviceListCurrentIndex(); - // const auto connRow = serviceListModel()->connRowAt(connIndex); - - // showServiceEditForm(connRow.appPath); - }); - - m_btEdit = ControlUtil::createButton(":/icons/pencil.png"); - m_btEdit->setMenu(editMenu); - - // Options - setupOptions(); - - layout->addWidget(m_btRefresh); - layout->addWidget(m_btEdit); - layout->addStretch(); - layout->addWidget(m_btOptions); - - return layout; -} - -void ServicesPage::setupOptions() -{ - // Menu - const QList menuWidgets = {}; - auto layout = ControlUtil::createLayoutByWidgets(menuWidgets); - - auto menu = ControlUtil::createMenuByLayout(layout, this); - - m_btOptions = ControlUtil::createButton(":/icons/gear_in.png"); - m_btOptions->setMenu(menu); -} - -void ServicesPage::setupTableServiceList() -{ - m_serviceListView = new TableView(); - m_serviceListView->setAlternatingRowColors(true); - m_serviceListView->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_serviceListView->setSelectionBehavior(QAbstractItemView::SelectItems); - - m_serviceListView->setModel(serviceListModel()); - - m_serviceListView->setMenu(m_btEdit->menu()); -} - -void ServicesPage::setupTableServiceListHeader() -{ - auto header = m_serviceListView->horizontalHeader(); - - header->setSectionResizeMode(0, QHeaderView::Interactive); - header->setSectionResizeMode(1, QHeaderView::Stretch); - header->setSectionResizeMode(2, QHeaderView::Interactive); - header->setSectionResizeMode(3, QHeaderView::Interactive); - - header->resizeSection(0, 240); - header->resizeSection(1, 290); - header->resizeSection(2, 80); - header->resizeSection(3, 90); -} diff --git a/src/ui/form/opt/pages/servicespage.h b/src/ui/form/opt/pages/servicespage.h deleted file mode 100644 index 45f5596d..00000000 --- a/src/ui/form/opt/pages/servicespage.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef SERVICESPAGE_H -#define SERVICESPAGE_H - -#include "optbasepage.h" - -class ServiceInfoManager; -class ServiceListModel; -class TableView; - -class ServicesPage : public OptBasePage -{ - Q_OBJECT - -public: - explicit ServicesPage(OptionsController *ctrl = nullptr, QWidget *parent = nullptr); - - ServiceListModel *serviceListModel() const { return m_serviceListModel; } - ServiceInfoManager *serviceInfoManager() const; - -public slots: - void onPageActivated() override; - -protected slots: - void onRetranslateUi() override; - -private: - void setupUi(); - QLayout *setupHeader(); - void setupOptions(); - void setupTableServiceList(); - void setupTableServiceListHeader(); - -private: - ServiceListModel *m_serviceListModel; - - QPushButton *m_btRefresh = nullptr; - QPushButton *m_btEdit = nullptr; - QAction *m_actEditService = nullptr; - QPushButton *m_btOptions = nullptr; - TableView *m_serviceListView = nullptr; -}; - -#endif // SERVICESPAGE_H diff --git a/src/ui/form/prog/programswindow.cpp b/src/ui/form/prog/programswindow.cpp index d4aeb23b..28617241 100644 --- a/src/ui/form/prog/programswindow.cpp +++ b/src/ui/form/prog/programswindow.cpp @@ -128,6 +128,8 @@ void ProgramsWindow::retranslateUi() m_btBlockApp->setText(tr("Block")); m_btRemoveApp->setText(tr("Remove")); + m_btServices->setText(tr("Services")); + m_btLogOptions->setText(tr("Options")); m_cbLogBlocked->setText(tr("Collect New Blocked Programs")); @@ -227,6 +229,12 @@ QLayout *ProgramsWindow::setupHeader() connect(m_btBlockApp, &QAbstractButton::clicked, m_actBlockApp, &QAction::trigger); connect(m_btRemoveApp, &QAbstractButton::clicked, m_actRemoveApp, &QAction::trigger); + // Services button + m_btServices = ControlUtil::createLinkButton(":/icons/windows-48.png"); + + connect(m_btServices, &QAbstractButton::clicked, windowManager(), + &WindowManager::showServicesWindow); + // Log Options setupLogOptions(); @@ -237,6 +245,8 @@ QLayout *ProgramsWindow::setupHeader() layout->addWidget(ControlUtil::createSeparator(Qt::Vertical)); layout->addWidget(m_btRemoveApp); layout->addStretch(); + layout->addWidget(m_btServices); + layout->addWidget(ControlUtil::createSeparator(Qt::Vertical)); layout->addWidget(m_btLogOptions); return layout; diff --git a/src/ui/form/prog/programswindow.h b/src/ui/form/prog/programswindow.h index 4f818baa..83ad1ca1 100644 --- a/src/ui/form/prog/programswindow.h +++ b/src/ui/form/prog/programswindow.h @@ -89,6 +89,7 @@ private: QPushButton *m_btBlockApp = nullptr; QPushButton *m_btRemoveApp = nullptr; QPushButton *m_btEdit = nullptr; + QPushButton *m_btServices = nullptr; QPushButton *m_btLogOptions = nullptr; QCheckBox *m_cbLogBlocked = nullptr; ProgramEditDialog *m_formAppEdit = nullptr; diff --git a/src/ui/form/svc/servicescontroller.cpp b/src/ui/form/svc/servicescontroller.cpp new file mode 100644 index 00000000..83a2591c --- /dev/null +++ b/src/ui/form/svc/servicescontroller.cpp @@ -0,0 +1,39 @@ +#include "servicescontroller.h" + +#include +#include +#include +#include +#include + +ServicesController::ServicesController(QObject *parent) : + QObject(parent), m_serviceListModel(new ServiceListModel(this)) +{ + connect(translationManager(), &TranslationManager::languageChanged, this, + &ServicesController::retranslateUi); +} + +ConfManager *ServicesController::confManager() const +{ + return IoC(); +} + +IniUser *ServicesController::iniUser() const +{ + return confManager()->iniUser(); +} + +TranslationManager *ServicesController::translationManager() const +{ + return IoC(); +} + +WindowManager *ServicesController::windowManager() const +{ + return IoC(); +} + +void ServicesController::initialize() +{ + serviceListModel()->initialize(); +} diff --git a/src/ui/form/svc/servicescontroller.h b/src/ui/form/svc/servicescontroller.h new file mode 100644 index 00000000..f86b9add --- /dev/null +++ b/src/ui/form/svc/servicescontroller.h @@ -0,0 +1,34 @@ +#ifndef SERVICESCONTROLLER_H +#define SERVICESCONTROLLER_H + +#include + +class ConfManager; +class IniUser; +class ServiceListModel; +class TranslationManager; +class WindowManager; + +class ServicesController : public QObject +{ + Q_OBJECT + +public: + explicit ServicesController(QObject *parent = nullptr); + + ConfManager *confManager() const; + IniUser *iniUser() const; + TranslationManager *translationManager() const; + WindowManager *windowManager() const; + ServiceListModel *serviceListModel() const { return m_serviceListModel; } + + void initialize(); + +signals: + void retranslateUi(); + +private: + ServiceListModel *m_serviceListModel = nullptr; +}; + +#endif // SERVICESCONTROLLER_H diff --git a/src/ui/form/svc/serviceswindow.cpp b/src/ui/form/svc/serviceswindow.cpp new file mode 100644 index 00000000..7ecf7ee5 --- /dev/null +++ b/src/ui/form/svc/serviceswindow.cpp @@ -0,0 +1,226 @@ +#include "serviceswindow.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "servicescontroller.h" + +namespace { + +#define SERVICES_HEADER_VERSION 1 + +} + +ServicesWindow::ServicesWindow(QWidget *parent) : + WidgetWindow(parent), + m_ctrl(new ServicesController(this)), + m_stateWatcher(new WidgetWindowStateWatcher(this)) +{ + setupUi(); + setupController(); + setupStateWatcher(); +} + +ConfManager *ServicesWindow::confManager() const +{ + return ctrl()->confManager(); +} + +IniUser *ServicesWindow::iniUser() const +{ + return ctrl()->iniUser(); +} + +WindowManager *ServicesWindow::windowManager() const +{ + return ctrl()->windowManager(); +} + +ServiceListModel *ServicesWindow::serviceListModel() const +{ + return ctrl()->serviceListModel(); +} + +void ServicesWindow::saveWindowState() +{ + iniUser()->setServiceWindowGeometry(m_stateWatcher->geometry()); + iniUser()->setServiceWindowMaximized(m_stateWatcher->maximized()); + + auto header = m_serviceListView->horizontalHeader(); + iniUser()->setServicesHeader(header->saveState()); + iniUser()->setServicesHeaderVersion(SERVICES_HEADER_VERSION); + + confManager()->saveIniUser(); +} + +void ServicesWindow::restoreWindowState() +{ + m_stateWatcher->restore(this, QSize(1024, 768), iniUser()->serviceWindowGeometry(), + iniUser()->serviceWindowMaximized()); + + if (iniUser()->servicesHeaderVersion() == SERVICES_HEADER_VERSION) { + auto header = m_serviceListView->horizontalHeader(); + header->restoreState(iniUser()->servicesHeader()); + } +} + +void ServicesWindow::retranslateUi() +{ + this->unsetLocale(); + + m_btRefresh->setText(tr("Refresh")); + m_btEdit->setText(tr("Edit")); + m_actEditService->setText(tr("Edit Service")); + m_actAddProgram->setText(tr("Add Program")); + + serviceListModel()->refresh(); + + this->setWindowTitle(tr("Services")); +} + +void ServicesWindow::setupController() +{ + ctrl()->initialize(); + + connect(ctrl(), &ServicesController::retranslateUi, this, &ServicesWindow::retranslateUi); + + retranslateUi(); +} + +void ServicesWindow::setupStateWatcher() +{ + m_stateWatcher->install(this); +} + +void ServicesWindow::setupUi() +{ + auto layout = new QVBoxLayout(); + layout->setContentsMargins(6, 6, 6, 6); + + // Header + auto header = setupHeader(); + layout->addLayout(header); + + // Table + setupTableServiceList(); + setupTableServiceListHeader(); + layout->addWidget(m_serviceListView, 1); + + this->setLayout(layout); + + // Actions on conns table's current changed + setupTableServicesChanged(); + + // Font + this->setFont(WindowManager::defaultFont()); + + // Icon + this->setWindowIcon(GuiUtil::overlayIcon(":/icons/sheild-96.png", ":/icons/windows-48.png")); + + // Size + this->setMinimumSize(500, 400); +} + +QLayout *ServicesWindow::setupHeader() +{ + auto layout = new QHBoxLayout(); + + m_btRefresh = ControlUtil::createButton( + ":/icons/arrow_refresh_small.png", [&] { serviceListModel()->initialize(); }); + + // Edit Menu + auto editMenu = new QMenu(this); + + m_actEditService = editMenu->addAction(IconCache::icon(":/icons/pencil.png"), QString()); + m_actEditService->setShortcut(Qt::Key_Return); + + m_actAddProgram = editMenu->addAction(IconCache::icon(":/icons/application.png"), QString()); + m_actAddProgram->setShortcut(Qt::Key_Insert); + + connect(m_actEditService, &QAction::triggered, this, [&] { + // const auto connIndex = serviceListCurrentIndex(); + // const auto connRow = serviceListModel()->connRowAt(connIndex); + + // showServiceEditForm(connRow.appPath); + }); + connect(m_actAddProgram, &QAction::triggered, this, [&] { + const auto serviceIndex = serviceListCurrentIndex(); + const auto serviceInfo = serviceListModel()->serviceInfoAt(serviceIndex); + + const QString appPath = QStringLiteral(R"(\SvcHost\)") + serviceInfo.serviceName; + + windowManager()->showProgramEditForm(appPath); + }); + + m_btEdit = ControlUtil::createButton(":/icons/pencil.png"); + m_btEdit->setMenu(editMenu); + + layout->addWidget(m_btEdit); + layout->addWidget(ControlUtil::createSeparator(Qt::Vertical)); + layout->addWidget(m_btRefresh); + layout->addStretch(); + + return layout; +} + +void ServicesWindow::setupTableServiceList() +{ + m_serviceListView = new TableView(); + m_serviceListView->setAlternatingRowColors(true); + m_serviceListView->setSelectionMode(QAbstractItemView::ExtendedSelection); + m_serviceListView->setSelectionBehavior(QAbstractItemView::SelectItems); + + m_serviceListView->setModel(serviceListModel()); + + m_serviceListView->setMenu(m_btEdit->menu()); +} + +void ServicesWindow::setupTableServiceListHeader() +{ + auto header = m_serviceListView->horizontalHeader(); + + header->setSectionResizeMode(0, QHeaderView::Interactive); + header->setSectionResizeMode(1, QHeaderView::Stretch); + header->setSectionResizeMode(2, QHeaderView::Interactive); + + header->resizeSection(0, 250); + header->resizeSection(1, 350); + header->resizeSection(2, 100); +} + +void ServicesWindow::setupTableServicesChanged() +{ + const auto refreshTableServicesChanged = [&] { + const int serviceIndex = serviceListCurrentIndex(); + const bool serviceSelected = (serviceIndex >= 0); + m_actEditService->setEnabled(serviceSelected); + m_actAddProgram->setEnabled(serviceSelected); + }; + + refreshTableServicesChanged(); + + connect(m_serviceListView, &TableView::currentIndexChanged, this, refreshTableServicesChanged); +} + +int ServicesWindow::serviceListCurrentIndex() const +{ + return m_serviceListView->currentRow(); +} diff --git a/src/ui/form/svc/serviceswindow.h b/src/ui/form/svc/serviceswindow.h new file mode 100644 index 00000000..2c9859ec --- /dev/null +++ b/src/ui/form/svc/serviceswindow.h @@ -0,0 +1,58 @@ +#ifndef SERVICESWINDOW_H +#define SERVICESWINDOW_H + +#include + +QT_FORWARD_DECLARE_CLASS(QPushButton) + +class ConfManager; +class IniUser; +class ServiceListModel; +class ServicesController; +class TableView; +class WidgetWindowStateWatcher; +class WindowManager; + +class ServicesWindow : public WidgetWindow +{ + Q_OBJECT + +public: + explicit ServicesWindow(QWidget *parent = nullptr); + + ServicesController *ctrl() const { return m_ctrl; } + ConfManager *confManager() const; + IniUser *iniUser() const; + WindowManager *windowManager() const; + ServiceListModel *serviceListModel() const; + + void saveWindowState(); + void restoreWindowState(); + +private: + void setupController(); + void setupStateWatcher(); + + void retranslateUi(); + + void setupUi(); + QLayout *setupHeader(); + void setupOptions(); + void setupTableServiceList(); + void setupTableServiceListHeader(); + void setupTableServicesChanged(); + + int serviceListCurrentIndex() const; + +private: + ServicesController *m_ctrl = nullptr; + WidgetWindowStateWatcher *m_stateWatcher = nullptr; + + QPushButton *m_btRefresh = nullptr; + QPushButton *m_btEdit = nullptr; + QAction *m_actEditService = nullptr; + QAction *m_actAddProgram = nullptr; + TableView *m_serviceListView = nullptr; +}; + +#endif // SERVICESWINDOW_H diff --git a/src/ui/form/zone/zoneswindow.h b/src/ui/form/zone/zoneswindow.h index 5c51bbb2..dbd8236e 100644 --- a/src/ui/form/zone/zoneswindow.h +++ b/src/ui/form/zone/zoneswindow.h @@ -15,9 +15,9 @@ class IniUser; class TableView; class TaskManager; class WidgetWindowStateWatcher; +class WindowManager; class ZoneListModel; class ZonesController; -class WindowManager; class ZonesWindow : public WidgetWindow { diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 0761aa86..3ef11bf6 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -175,7 +174,6 @@ void FortManager::createManagers() ioc->setService(new NativeEventFilter()); ioc->setService(new AppInfoCache()); ioc->setService(new HostInfoCache()); - ioc->setService(new ServiceInfoManager()); ioc->setService(new ZoneListModel()); ioc->setUpAll(); diff --git a/src/ui/manager/windowmanager.cpp b/src/ui/manager/windowmanager.cpp index 067d8114..86deeecd 100644 --- a/src/ui/manager/windowmanager.cpp +++ b/src/ui/manager/windowmanager.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -138,6 +139,15 @@ void WindowManager::setupOptionsWindow() connect(m_optWindow, &OptionsWindow::aboutToClose, this, &WindowManager::closeOptionsWindow); } +void WindowManager::setupServicesWindow() +{ + m_serviceWindow = new ServicesWindow(); + m_serviceWindow->restoreWindowState(); + + connect(m_serviceWindow, &ServicesWindow::aboutToClose, this, + &WindowManager::closeServicesWindow); +} + void WindowManager::setupZonesWindow() { m_zoneWindow = new ZonesWindow(); @@ -173,6 +183,7 @@ void WindowManager::closeAll() closeGraphWindow(true); closeOptionsWindow(); closeProgramsWindow(); + closeServicesWindow(); closeZonesWindow(); closeStatisticsWindow(); closeTrayIcon(); @@ -304,6 +315,30 @@ void WindowManager::closeStatisticsWindow() m_statWindow = nullptr; } +void WindowManager::showServicesWindow() +{ + if (!widgetVisibleByCheckPassword(m_serviceWindow)) + return; + + if (!m_serviceWindow) { + setupServicesWindow(); + } + + showWidget(m_serviceWindow); +} + +void WindowManager::closeServicesWindow() +{ + if (!m_serviceWindow) + return; + + m_serviceWindow->saveWindowState(); + m_serviceWindow->hide(); + + m_serviceWindow->deleteLater(); + m_serviceWindow = nullptr; +} + void WindowManager::showZonesWindow() { if (!widgetVisibleByCheckPassword(m_zoneWindow)) diff --git a/src/ui/manager/windowmanager.h b/src/ui/manager/windowmanager.h index 2ec3d917..f52e4818 100644 --- a/src/ui/manager/windowmanager.h +++ b/src/ui/manager/windowmanager.h @@ -9,6 +9,7 @@ class GraphWindow; class MainWindow; class OptionsWindow; class ProgramsWindow; +class ServicesWindow; class StatisticsWindow; class TrayIcon; class ZonesWindow; @@ -27,6 +28,7 @@ public: ProgramsWindow *progWindow() const { return m_progWindow; } OptionsWindow *optWindow() const { return m_optWindow; } StatisticsWindow *connWindow() const { return m_statWindow; } + ServicesWindow *serviceWindow() const { return m_serviceWindow; } ZonesWindow *zoneWindow() const { return m_zoneWindow; } GraphWindow *graphWindow() const { return m_graphWindow; } @@ -59,6 +61,9 @@ public slots: void showStatisticsWindow(); void closeStatisticsWindow(); + void showServicesWindow(); + void closeServicesWindow(); + void showZonesWindow(); void closeZonesWindow(); @@ -86,6 +91,7 @@ private: void setupProgramsWindow(); void setupOptionsWindow(); + void setupServicesWindow(); void setupZonesWindow(); void setupGraphWindow(); void setupStatisticsWindow(); @@ -104,6 +110,7 @@ private: ProgramsWindow *m_progWindow = nullptr; OptionsWindow *m_optWindow = nullptr; StatisticsWindow *m_statWindow = nullptr; + ServicesWindow *m_serviceWindow = nullptr; ZonesWindow *m_zoneWindow = nullptr; GraphWindow *m_graphWindow = nullptr; }; diff --git a/src/ui/model/servicelistmodel.cpp b/src/ui/model/servicelistmodel.cpp index 3c0ed887..f56a1147 100644 --- a/src/ui/model/servicelistmodel.cpp +++ b/src/ui/model/servicelistmodel.cpp @@ -13,11 +13,6 @@ ConfManager *ServiceListModel::confManager() const return IoC(); } -ServiceInfoManager *ServiceListModel::serviceInfoManager() const -{ - return IoC(); -} - FirewallConf *ServiceListModel::conf() const { return confManager()->conf(); @@ -25,7 +20,7 @@ FirewallConf *ServiceListModel::conf() const void ServiceListModel::initialize() { - m_services = serviceInfoManager()->loadServiceInfoList(); + m_services = ServiceInfoManager::loadServiceInfoList(); reset(); } @@ -39,7 +34,7 @@ int ServiceListModel::rowCount(const QModelIndex &parent) const int ServiceListModel::columnCount(const QModelIndex &parent) const { - return parent.isValid() ? 0 : 4; + return parent.isValid() ? 0 : 3; } QVariant ServiceListModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -52,8 +47,6 @@ QVariant ServiceListModel::headerData(int section, Qt::Orientation orientation, return tr("Display Name"); case 2: return tr("Process ID"); - case 3: - return tr("Group"); } } return QVariant(); @@ -88,8 +81,6 @@ QVariant ServiceListModel::dataDisplay(const QModelIndex &index) const return info.displayName; case 2: return dataDisplayProcessId(info); - case 3: - return dataDisplayAppGroup(info); } return QVariant(); @@ -100,13 +91,6 @@ QVariant ServiceListModel::dataDisplayProcessId(const ServiceInfo &info) const return (info.processId == 0) ? QVariant() : QVariant(info.processId); } -QVariant ServiceListModel::dataDisplayAppGroup(const ServiceInfo &info) const -{ - const int groupIndex = serviceInfoManager()->groupIndexByName(info.serviceName); - - return (groupIndex < 0) ? QVariant() : conf()->appGroupAt(groupIndex)->name(); -} - bool ServiceListModel::updateTableRow(int /*row*/) const { return true; diff --git a/src/ui/model/servicelistmodel.h b/src/ui/model/servicelistmodel.h index ce133b69..25dfab1f 100644 --- a/src/ui/model/servicelistmodel.h +++ b/src/ui/model/servicelistmodel.h @@ -9,7 +9,6 @@ class ConfManager; class FirewallConf; class ServiceInfo; -class ServiceInfoManager; class ServiceListModel : public TableItemModel { @@ -19,7 +18,6 @@ public: explicit ServiceListModel(QObject *parent = nullptr); ConfManager *confManager() const; - ServiceInfoManager *serviceInfoManager() const; FirewallConf *conf() const; void initialize(); @@ -31,6 +29,9 @@ public: int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + const QVector &services() const { return m_services; } + const ServiceInfo &serviceInfoAt(int index) const; + protected: bool updateTableRow(int row) const override; TableRow &tableRow() const override { return m_serviceRow; } @@ -38,10 +39,6 @@ protected: private: QVariant dataDisplay(const QModelIndex &index) const; QVariant dataDisplayProcessId(const ServiceInfo &info) const; - QVariant dataDisplayAppGroup(const ServiceInfo &info) const; - - const QVector &services() const { return m_services; } - const ServiceInfo &serviceInfoAt(int index) const; private: QVector m_services; diff --git a/src/ui/serviceinfo/serviceinfomanager.cpp b/src/ui/serviceinfo/serviceinfomanager.cpp index e195c526..02149c48 100644 --- a/src/ui/serviceinfo/serviceinfomanager.cpp +++ b/src/ui/serviceinfo/serviceinfomanager.cpp @@ -14,6 +14,17 @@ const QLoggingCategory LC("serviceInfo.serviceInfoManager"); const char *const servicesSubKey = R"(SYSTEM\CurrentControlSet\Services)"; +QString getServiceDll(const RegKey &svcReg, bool *expand = nullptr) +{ + QVariant dllPathVar = svcReg.value("ServiceDll", expand); + if (dllPathVar.isNull()) { + const RegKey paramsReg(svcReg, "Parameters"); + dllPathVar = paramsReg.value("ServiceDll", expand); + } + + return dllPathVar.toString(); +} + QVector getServiceInfoList(SC_HANDLE mngr, DWORD state = SERVICE_STATE_ALL) { QVector infoList; @@ -45,6 +56,10 @@ QVector getServiceInfoList(SC_HANDLE mngr, DWORD state = SERVICE_ST if (!imagePath.contains(R"(\system32\svchost.exe)", Qt::CaseInsensitive)) continue; + const QString dllPath = getServiceDll(svcReg); + if (dllPath.isEmpty()) + continue; + ServiceInfo info; info.processId = service->ServiceStatusProcess.dwProcessId; info.serviceName = serviceName; @@ -62,13 +77,6 @@ QVector getServiceInfoList(SC_HANDLE mngr, DWORD state = SERVICE_ST } -ServiceInfoManager::ServiceInfoManager(QObject *parent) : QObject(parent) { } - -int ServiceInfoManager::groupIndexByName(const QString &name) const -{ - return m_serviceGroups.value(name, -1); -} - QVector ServiceInfoManager::loadServiceInfoList(ServiceInfo::State state) { QVector list; @@ -87,16 +95,7 @@ QString ServiceInfoManager::getSvcHostServiceDll(const QString &serviceName) const RegKey svcReg(servicesReg, serviceName); bool expand = false; - QVariant dllPathVar = svcReg.value("ServiceDll", &expand); - if (dllPathVar.isNull()) { - const RegKey paramsReg(svcReg, "Parameters"); - dllPathVar = paramsReg.value("ServiceDll", &expand); - } + const QString dllPath = getServiceDll(svcReg, &expand); - QString path = dllPathVar.toString(); - if (expand) { - path = FileUtil::expandPath(path); - } - - return path; + return expand ? FileUtil::expandPath(dllPath) : dllPath; } diff --git a/src/ui/serviceinfo/serviceinfomanager.h b/src/ui/serviceinfo/serviceinfomanager.h index 40472e72..a49a22cf 100644 --- a/src/ui/serviceinfo/serviceinfomanager.h +++ b/src/ui/serviceinfo/serviceinfomanager.h @@ -1,29 +1,15 @@ #ifndef SERVICEINFOMANAGER_H #define SERVICEINFOMANAGER_H -#include -#include - -#include - #include "serviceinfo.h" -class ServiceInfoManager : public QObject, public IocService +class ServiceInfoManager { - Q_OBJECT - public: - explicit ServiceInfoManager(QObject *parent = nullptr); - - int groupIndexByName(const QString &name) const; - static QVector loadServiceInfoList( ServiceInfo::State state = ServiceInfo::StateAlive); static QString getSvcHostServiceDll(const QString &serviceName); - -private: - QHash m_serviceGroups; }; #endif // SERVICEINFOMANAGER_H diff --git a/src/ui/user/iniuser.h b/src/ui/user/iniuser.h index e0574131..57a256c4 100644 --- a/src/ui/user/iniuser.h +++ b/src/ui/user/iniuser.h @@ -62,6 +62,18 @@ public: QByteArray optWindowAppsSplit() const { return valueByteArray("optWindow/appsSplit"); } void setOptWindowAppsSplit(const QByteArray &v) { setValue("optWindow/appsSplit", v); } + QRect serviceWindowGeometry() const { return value("serviceWindow/geometry").toRect(); } + void setServiceWindowGeometry(const QRect &v) { setValue("serviceWindow/geometry", v); } + + bool serviceWindowMaximized() const { return valueBool("serviceWindow/maximized"); } + void setServiceWindowMaximized(bool on) { setValue("serviceWindow/maximized", on); } + + int servicesHeaderVersion() const { return valueInt("serviceWindow/servicesHeaderVersion"); } + void setServicesHeaderVersion(int v) { setValue("serviceWindow/servicesHeaderVersion", v); } + + QByteArray servicesHeader() const { return valueByteArray("serviceWindow/servicesHeader"); } + void setServicesHeader(const QByteArray &v) { setValue("serviceWindow/servicesHeader", v); } + QRect zoneWindowGeometry() const { return value("zoneWindow/geometry").toRect(); } void setZoneWindowGeometry(const QRect &v) { setValue("zoneWindow/geometry", v); }