UI: Prepare ServicesWindow

This commit is contained in:
Nodir Temirkhodjaev 2022-02-08 19:48:46 +03:00
parent 109aee7ff1
commit 6d0046e4cb
18 changed files with 450 additions and 239 deletions

View File

@ -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 \

View File

@ -1,134 +0,0 @@
#include "servicespage.h"
#include <QCheckBox>
#include <QHeaderView>
#include <QMenu>
#include <QPushButton>
#include <QVBoxLayout>
#include <conf/firewallconf.h>
#include <form/controls/controlutil.h>
#include <form/controls/tableview.h>
#include <form/opt/optionscontroller.h>
#include <model/servicelistmodel.h>
#include <serviceinfo/serviceinfomanager.h>
#include <user/iniuser.h>
#include <util/iconcache.h>
#include <util/ioc/ioccontainer.h>
ServicesPage::ServicesPage(OptionsController *ctrl, QWidget *parent) :
OptBasePage(ctrl, parent), m_serviceListModel(new ServiceListModel(this))
{
setupUi();
}
ServiceInfoManager *ServicesPage::serviceInfoManager() const
{
return IoC<ServiceInfoManager>();
}
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<QWidget *> 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);
}

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,39 @@
#include "servicescontroller.h"
#include <conf/confmanager.h>
#include <manager/translationmanager.h>
#include <manager/windowmanager.h>
#include <model/servicelistmodel.h>
#include <util/ioc/ioccontainer.h>
ServicesController::ServicesController(QObject *parent) :
QObject(parent), m_serviceListModel(new ServiceListModel(this))
{
connect(translationManager(), &TranslationManager::languageChanged, this,
&ServicesController::retranslateUi);
}
ConfManager *ServicesController::confManager() const
{
return IoC<ConfManager>();
}
IniUser *ServicesController::iniUser() const
{
return confManager()->iniUser();
}
TranslationManager *ServicesController::translationManager() const
{
return IoC<TranslationManager>();
}
WindowManager *ServicesController::windowManager() const
{
return IoC<WindowManager>();
}
void ServicesController::initialize()
{
serviceListModel()->initialize();
}

View File

@ -0,0 +1,34 @@
#ifndef SERVICESCONTROLLER_H
#define SERVICESCONTROLLER_H
#include <QObject>
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

View File

@ -0,0 +1,226 @@
#include "serviceswindow.h"
#include <QComboBox>
#include <QFormLayout>
#include <QHeaderView>
#include <QLabel>
#include <QMenu>
#include <QPushButton>
#include <QVBoxLayout>
#include <conf/confmanager.h>
#include <form/controls/controlutil.h>
#include <form/controls/tableview.h>
#include <form/opt/optionscontroller.h>
#include <manager/windowmanager.h>
#include <model/servicelistmodel.h>
#include <serviceinfo/serviceinfomanager.h>
#include <user/iniuser.h>
#include <util/guiutil.h>
#include <util/iconcache.h>
#include <util/ioc/ioccontainer.h>
#include <util/window/widgetwindowstatewatcher.h>
#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();
}

View File

@ -0,0 +1,58 @@
#ifndef SERVICESWINDOW_H
#define SERVICESWINDOW_H
#include <util/window/widgetwindow.h>
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

View File

@ -15,9 +15,9 @@ class IniUser;
class TableView;
class TaskManager;
class WidgetWindowStateWatcher;
class WindowManager;
class ZoneListModel;
class ZonesController;
class WindowManager;
class ZonesWindow : public WidgetWindow
{

View File

@ -29,7 +29,6 @@
#include <rpc/statmanagerrpc.h>
#include <rpc/taskmanagerrpc.h>
#include <rpc/windowmanagerfake.h>
#include <serviceinfo/serviceinfomanager.h>
#include <task/taskinfozonedownloader.h>
#include <user/usersettings.h>
#include <util/dateutil.h>
@ -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();

View File

@ -14,6 +14,7 @@
#include <form/opt/optionswindow.h>
#include <form/prog/programswindow.h>
#include <form/stat/statisticswindow.h>
#include <form/svc/serviceswindow.h>
#include <form/tray/trayicon.h>
#include <form/zone/zoneswindow.h>
#include <fortcompat.h>
@ -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))

View File

@ -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;
};

View File

@ -13,11 +13,6 @@ ConfManager *ServiceListModel::confManager() const
return IoC<ConfManager>();
}
ServiceInfoManager *ServiceListModel::serviceInfoManager() const
{
return IoC<ServiceInfoManager>();
}
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;

View File

@ -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<ServiceInfo> &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<ServiceInfo> &services() const { return m_services; }
const ServiceInfo &serviceInfoAt(int index) const;
private:
QVector<ServiceInfo> m_services;

View File

@ -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<ServiceInfo> getServiceInfoList(SC_HANDLE mngr, DWORD state = SERVICE_STATE_ALL)
{
QVector<ServiceInfo> infoList;
@ -45,6 +56,10 @@ QVector<ServiceInfo> 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<ServiceInfo> 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<ServiceInfo> ServiceInfoManager::loadServiceInfoList(ServiceInfo::State state)
{
QVector<ServiceInfo> 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;
}

View File

@ -1,29 +1,15 @@
#ifndef SERVICEINFOMANAGER_H
#define SERVICEINFOMANAGER_H
#include <QHash>
#include <QObject>
#include <util/ioc/iocservice.h>
#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<ServiceInfo> loadServiceInfoList(
ServiceInfo::State state = ServiceInfo::StateAlive);
static QString getSvcHostServiceDll(const QString &serviceName);
private:
QHash<QString, int> m_serviceGroups;
};
#endif // SERVICEINFOMANAGER_H

View File

@ -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); }