diff --git a/src/ui/FortFirewallUI.pro b/src/ui/FortFirewallUI.pro index 70fe2d0a..584fee25 100644 --- a/src/ui/FortFirewallUI.pro +++ b/src/ui/FortFirewallUI.pro @@ -22,6 +22,7 @@ SOURCES += \ conf/appgroup.cpp \ conf/confappmanager.cpp \ conf/confmanager.cpp \ + conf/confzonemanager.cpp \ conf/firewallconf.cpp \ conf/inioptions.cpp \ conf/rules/policy.cpp \ @@ -136,6 +137,7 @@ SOURCES += \ rpc/askpendingmanagerrpc.cpp \ rpc/confappmanagerrpc.cpp \ rpc/confmanagerrpc.cpp \ + rpc/confzonemanagerrpc.cpp \ rpc/drivermanagerrpc.cpp \ rpc/logmanagerrpc.cpp \ rpc/quotamanagerrpc.cpp \ @@ -220,6 +222,7 @@ HEADERS += \ conf/appgroup.h \ conf/confappmanager.h \ conf/confmanager.h \ + conf/confzonemanager.h \ conf/firewallconf.h \ conf/inioptions.h \ conf/rules/policy.h \ @@ -336,6 +339,7 @@ HEADERS += \ rpc/askpendingmanagerrpc.h \ rpc/confappmanagerrpc.h \ rpc/confmanagerrpc.h \ + rpc/confzonemanagerrpc.h \ rpc/drivermanagerrpc.h \ rpc/logmanagerrpc.h \ rpc/quotamanagerrpc.h \ diff --git a/src/ui/conf/confappmanager.h b/src/ui/conf/confappmanager.h index 73df51ff..5cdcfcfa 100644 --- a/src/ui/conf/confappmanager.h +++ b/src/ui/conf/confappmanager.h @@ -13,8 +13,6 @@ class App; class ConfManager; class FirewallConf; -class IniOptions; -class IniUser; class LogEntryBlocked; class ConfAppManager : public QObject, public ConfAppsWalker, public IocService diff --git a/src/ui/conf/confmanager.cpp b/src/ui/conf/confmanager.cpp index 0d282320..f142cfb9 100644 --- a/src/ui/conf/confmanager.cpp +++ b/src/ui/conf/confmanager.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -109,38 +108,6 @@ const char *const sqlUpdateTask = "UPDATE task" " last_run = ?5, last_success = ?6, data = ?7" " WHERE task_id = ?1;"; -const char *const sqlInsertZone = "INSERT INTO zone(zone_id, name, enabled, custom_url," - " source_code, url, form_data, text_inline)" - " VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8);"; - -const char *const sqlSelectZoneIds = "SELECT zone_id FROM zone ORDER BY zone_id;"; - -const char *const sqlDeleteZone = "DELETE FROM zone WHERE zone_id = ?1;"; - -const char *const sqlDeleteAddressGroupZone = "UPDATE address_group" - " SET include_zones = include_zones & ?1," - " exclude_zones = exclude_zones & ?1;"; - -const char *const sqlDeleteAppZone = "UPDATE app" - " SET accept_zones = accept_zones & ?1," - " reject_zones = reject_zones & ?1;"; - -const char *const sqlUpdateZone = "UPDATE zone" - " SET name = ?2, enabled = ?3, custom_url = ?4," - " source_code = ?5, url = ?6," - " form_data = ?7, text_inline = ?8" - " WHERE zone_id = ?1;"; - -const char *const sqlUpdateZoneName = "UPDATE zone SET name = ?2 WHERE zone_id = ?1;"; - -const char *const sqlUpdateZoneEnabled = "UPDATE zone SET enabled = ?2 WHERE zone_id = ?1;"; - -const char *const sqlUpdateZoneResult = - "UPDATE zone" - " SET address_count = ?2, text_checksum = ?3, bin_checksum = ?4," - " source_modtime = ?5, last_run = ?6, last_success = ?7" - " WHERE zone_id = ?1;"; - using AppsMap = QHash; using AppIdsArray = QVector; @@ -770,149 +737,6 @@ bool ConfManager::importBackup(const QString &path) return false; } -bool ConfManager::addZone(Zone &zone) -{ - bool ok = false; - - zone.zoneId = getFreeZoneId(); - - const auto vars = QVariantList() - << zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode - << zone.url << zone.formData << zone.textInline; - - sqliteDb()->executeEx(sqlInsertZone, vars, 0, &ok); - - checkEndTransaction(ok); - - if (ok) { - emit zoneAdded(); - } - - return ok; -} - -int ConfManager::getFreeZoneId() -{ - int zoneId = 1; - - SqliteStmt stmt; - if (stmt.prepare(sqliteDb()->db(), sqlSelectZoneIds)) { - while (stmt.step() == SqliteStmt::StepRow) { - const int id = stmt.columnInt(0); - if (id > zoneId) - break; - - zoneId = id + 1; - } - } - - return zoneId; -} - -bool ConfManager::deleteZone(int zoneId) -{ - bool ok = false; - - beginTransaction(); - - sqliteDb()->executeEx(sqlDeleteZone, { zoneId }, 0, &ok); - if (ok) { - const quint32 zoneUnMask = ~(quint32(1) << (zoneId - 1)); - - // Delete the Zone from Address Groups - sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok); - - // Delete the Zone from Programs - sqliteDb()->executeEx(sqlDeleteAppZone, { qint64(zoneUnMask) }, 0, &ok); - } - - commitTransaction(ok); - - if (ok) { - emit zoneRemoved(zoneId); - } - - return ok; -} - -bool ConfManager::updateZone(const Zone &zone) -{ - if (!updateDriverZoneFlag(zone.zoneId, zone.enabled)) - return false; - - bool ok = false; - - const auto vars = QVariantList() - << zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode - << zone.url << zone.formData << zone.textInline; - - sqliteDb()->executeEx(sqlUpdateZone, vars, 0, &ok); - - checkEndTransaction(ok); - - if (ok) { - emit zoneUpdated(); - } - - return ok; -} - -bool ConfManager::updateZoneName(int zoneId, const QString &zoneName) -{ - bool ok = false; - - const auto vars = QVariantList() << zoneId << zoneName; - - sqliteDb()->executeEx(sqlUpdateZoneName, vars, 0, &ok); - - checkEndTransaction(ok); - - if (ok) { - emit zoneUpdated(); - } - - return ok; -} - -bool ConfManager::updateZoneEnabled(int zoneId, bool enabled) -{ - if (!updateDriverZoneFlag(zoneId, enabled)) - return false; - - bool ok = false; - - const auto vars = QVariantList() << zoneId << enabled; - - sqliteDb()->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok); - - checkEndTransaction(ok); - - if (ok) { - emit zoneUpdated(); - } - - return ok; -} - -bool ConfManager::updateZoneResult(const Zone &zone) -{ - bool ok = false; - - const auto vars = QVariantList() - << zone.zoneId << zone.addressCount << zone.textChecksum << zone.binChecksum - << zone.sourceModTime << zone.lastRun << zone.lastSuccess; - - sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok); - - checkEndTransaction(ok); - - if (ok) { - emit zoneUpdated(); - } - - return ok; -} - bool ConfManager::checkPassword(const QString &password) { return IoC()->checkPassword(password); @@ -974,27 +798,6 @@ void ConfManager::updateDriverServices( driverManager->writeServices(buf, outSize); } -void ConfManager::updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize, - const QList &zonesData) -{ - ConfUtil confUtil; - QByteArray buf; - - const int entrySize = confUtil.writeZones(zonesMask, enabledMask, dataSize, zonesData, buf); - - driverWriteZones(confUtil, buf, entrySize); -} - -bool ConfManager::updateDriverZoneFlag(int zoneId, bool enabled) -{ - ConfUtil confUtil; - QByteArray buf; - - const int entrySize = confUtil.writeZoneFlag(zoneId, enabled, buf); - - return driverWriteZones(confUtil, buf, entrySize, /*onlyFlags=*/true); -} - bool ConfManager::loadFromDb(FirewallConf &conf, bool &isNew) { // Load Address Groups diff --git a/src/ui/conf/confmanager.h b/src/ui/conf/confmanager.h index 16378e46..e4e96948 100644 --- a/src/ui/conf/confmanager.h +++ b/src/ui/conf/confmanager.h @@ -13,7 +13,6 @@ class FirewallConf; class IniOptions; class IniUser; class TaskInfo; -class Zone; class ConfManager : public QObject, public IocService { @@ -59,14 +58,6 @@ public: virtual bool exportBackup(const QString &path); virtual bool importBackup(const QString &path); - virtual bool addZone(Zone &zone); - int getFreeZoneId(); - virtual bool deleteZone(int zoneId); - virtual bool updateZone(const Zone &zone); - virtual bool updateZoneName(int zoneId, const QString &zoneName); - virtual bool updateZoneEnabled(int zoneId, bool enabled); - bool updateZoneResult(const Zone &zone); - virtual bool checkPassword(const QString &password); bool validateDriver(); @@ -74,18 +65,11 @@ public: void updateServices(); void updateDriverServices(const QVector &services, int runningServicesCount); - void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize, - const QList &zonesData); - signals: void confChanged(bool onlyFlags); void iniChanged(const IniOptions &ini); void iniUserChanged(const IniUser &ini, bool onlyFlags); - void zoneAdded(); - void zoneRemoved(int zoneId); - void zoneUpdated(); - protected: void setConf(FirewallConf *newConf); FirewallConf *createConf(); @@ -95,8 +79,6 @@ private: bool validateConf(const FirewallConf &newConf); - bool updateDriverZoneFlag(int zoneId, bool enabled); - bool loadFromDb(FirewallConf &conf, bool &isNew); bool saveToDb(const FirewallConf &conf); diff --git a/src/ui/conf/confzonemanager.cpp b/src/ui/conf/confzonemanager.cpp new file mode 100644 index 00000000..9c4420d8 --- /dev/null +++ b/src/ui/conf/confzonemanager.cpp @@ -0,0 +1,276 @@ +#include "confzonemanager.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "confmanager.h" + +namespace { + +const QLoggingCategory LC("confZone"); + +const char *const sqlInsertZone = "INSERT INTO zone(zone_id, name, enabled, custom_url," + " source_code, url, form_data, text_inline)" + " VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8);"; + +const char *const sqlSelectZoneIds = "SELECT zone_id FROM zone ORDER BY zone_id;"; + +const char *const sqlDeleteZone = "DELETE FROM zone WHERE zone_id = ?1;"; + +const char *const sqlDeleteAddressGroupZone = "UPDATE address_group" + " SET include_zones = include_zones & ?1," + " exclude_zones = exclude_zones & ?1;"; + +const char *const sqlDeleteAppZone = "UPDATE app" + " SET accept_zones = accept_zones & ?1," + " reject_zones = reject_zones & ?1;"; + +const char *const sqlUpdateZone = "UPDATE zone" + " SET name = ?2, enabled = ?3, custom_url = ?4," + " source_code = ?5, url = ?6," + " form_data = ?7, text_inline = ?8" + " WHERE zone_id = ?1;"; + +const char *const sqlUpdateZoneName = "UPDATE zone SET name = ?2 WHERE zone_id = ?1;"; + +const char *const sqlUpdateZoneEnabled = "UPDATE zone SET enabled = ?2 WHERE zone_id = ?1;"; + +const char *const sqlUpdateZoneResult = + "UPDATE zone" + " SET address_count = ?2, text_checksum = ?3, bin_checksum = ?4," + " source_modtime = ?5, last_run = ?6, last_success = ?7" + " WHERE zone_id = ?1;"; + +void showErrorMessage(const QString &errorMessage) +{ + IoC()->showErrorBox( + errorMessage, ConfZoneManager::tr("Zone Configuration Error")); +} + +bool driverWriteZones(ConfUtil &confUtil, QByteArray &buf, int entrySize, bool onlyFlags = false) +{ + if (entrySize == 0) { + showErrorMessage(confUtil.errorMessage()); + return false; + } + + auto driverManager = IoC(); + if (!driverManager->writeZones(buf, entrySize, onlyFlags)) { + showErrorMessage(driverManager->errorMessage()); + return false; + } + + return true; +} + +} + +ConfZoneManager::ConfZoneManager(QObject *parent) : QObject(parent) { } + +ConfManager *ConfZoneManager::confManager() const +{ + return m_confManager; +} + +SqliteDb *ConfZoneManager::sqliteDb() const +{ + return confManager()->sqliteDb(); +} + +void ConfZoneManager::setUp() +{ + m_confManager = IoC()->setUpDependency(); +} + +bool ConfZoneManager::addZone(Zone &zone) +{ + bool ok = false; + + zone.zoneId = getFreeZoneId(); + + const auto vars = QVariantList() + << zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode + << zone.url << zone.formData << zone.textInline; + + sqliteDb()->executeEx(sqlInsertZone, vars, 0, &ok); + + checkEndTransaction(ok); + + if (ok) { + emit zoneAdded(); + } + + return ok; +} + +int ConfZoneManager::getFreeZoneId() +{ + int zoneId = 1; + + SqliteStmt stmt; + if (stmt.prepare(sqliteDb()->db(), sqlSelectZoneIds)) { + while (stmt.step() == SqliteStmt::StepRow) { + const int id = stmt.columnInt(0); + if (id > zoneId) + break; + + zoneId = id + 1; + } + } + + return zoneId; +} + +bool ConfZoneManager::deleteZone(int zoneId) +{ + bool ok = false; + + beginTransaction(); + + sqliteDb()->executeEx(sqlDeleteZone, { zoneId }, 0, &ok); + if (ok) { + const quint32 zoneUnMask = ~(quint32(1) << (zoneId - 1)); + + // Delete the Zone from Address Groups + sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok); + + // Delete the Zone from Programs + sqliteDb()->executeEx(sqlDeleteAppZone, { qint64(zoneUnMask) }, 0, &ok); + } + + commitTransaction(ok); + + if (ok) { + emit zoneRemoved(zoneId); + } + + return ok; +} + +bool ConfZoneManager::updateZone(const Zone &zone) +{ + if (!updateDriverZoneFlag(zone.zoneId, zone.enabled)) + return false; + + bool ok = false; + + const auto vars = QVariantList() + << zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode + << zone.url << zone.formData << zone.textInline; + + sqliteDb()->executeEx(sqlUpdateZone, vars, 0, &ok); + + checkEndTransaction(ok); + + if (ok) { + emit zoneUpdated(); + } + + return ok; +} + +bool ConfZoneManager::updateZoneName(int zoneId, const QString &zoneName) +{ + bool ok = false; + + const auto vars = QVariantList() << zoneId << zoneName; + + sqliteDb()->executeEx(sqlUpdateZoneName, vars, 0, &ok); + + checkEndTransaction(ok); + + if (ok) { + emit zoneUpdated(); + } + + return ok; +} + +bool ConfZoneManager::updateZoneEnabled(int zoneId, bool enabled) +{ + if (!updateDriverZoneFlag(zoneId, enabled)) + return false; + + bool ok = false; + + const auto vars = QVariantList() << zoneId << enabled; + + sqliteDb()->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok); + + checkEndTransaction(ok); + + if (ok) { + emit zoneUpdated(); + } + + return ok; +} + +bool ConfZoneManager::updateZoneResult(const Zone &zone) +{ + bool ok = false; + + const auto vars = QVariantList() + << zone.zoneId << zone.addressCount << zone.textChecksum << zone.binChecksum + << zone.sourceModTime << zone.lastRun << zone.lastSuccess; + + sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok); + + checkEndTransaction(ok); + + if (ok) { + emit zoneUpdated(); + } + + return ok; +} + +void ConfZoneManager::updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize, + const QList &zonesData) +{ + ConfUtil confUtil; + QByteArray buf; + + const int entrySize = confUtil.writeZones(zonesMask, enabledMask, dataSize, zonesData, buf); + + driverWriteZones(confUtil, buf, entrySize); +} + +bool ConfZoneManager::updateDriverZoneFlag(int zoneId, bool enabled) +{ + ConfUtil confUtil; + QByteArray buf; + + const int entrySize = confUtil.writeZoneFlag(zoneId, enabled, buf); + + return driverWriteZones(confUtil, buf, entrySize, /*onlyFlags=*/true); +} + +bool ConfZoneManager::beginTransaction() +{ + return sqliteDb()->beginTransaction(); +} + +bool ConfZoneManager::commitTransaction(bool ok) +{ + ok = sqliteDb()->endTransaction(ok); + + return checkEndTransaction(ok); +} + +bool ConfZoneManager::checkEndTransaction(bool ok) +{ + if (!ok) { + showErrorMessage(sqliteDb()->errorMessage()); + } + + return ok; +} diff --git a/src/ui/conf/confzonemanager.h b/src/ui/conf/confzonemanager.h new file mode 100644 index 00000000..a73b5beb --- /dev/null +++ b/src/ui/conf/confzonemanager.h @@ -0,0 +1,55 @@ +#ifndef CONFZONEMANAGER_H +#define CONFZONEMANAGER_H + +#include + +#include + +#include +#include +#include + +class ConfManager; +class Zone; + +class ConfZoneManager : public QObject, public IocService +{ + Q_OBJECT + +public: + explicit ConfZoneManager(QObject *parent = nullptr); + CLASS_DELETE_COPY_MOVE(ConfZoneManager) + + ConfManager *confManager() const; + SqliteDb *sqliteDb() const; + + void setUp() override; + + virtual bool addZone(Zone &zone); + int getFreeZoneId(); + virtual bool deleteZone(int zoneId); + virtual bool updateZone(const Zone &zone); + virtual bool updateZoneName(int zoneId, const QString &zoneName); + virtual bool updateZoneEnabled(int zoneId, bool enabled); + bool updateZoneResult(const Zone &zone); + + void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize, + const QList &zonesData); + +signals: + void zoneAdded(); + void zoneRemoved(int zoneId); + void zoneUpdated(); + +private: + bool updateDriverZoneFlag(int zoneId, bool enabled); + + bool beginTransaction(); + bool commitTransaction(bool ok); + bool checkEndTransaction(bool ok); + +private: + ConfManager *m_confManager = nullptr; +}; + +#endif // CONFZONEMANAGER_H diff --git a/src/ui/control/control.cpp b/src/ui/control/control.cpp index 5b555cb4..afdf63c6 100644 --- a/src/ui/control/control.cpp +++ b/src/ui/control/control.cpp @@ -23,16 +23,17 @@ const char *const commandString(Command cmd) CASE_STRING(Rpc_ConfManager_saveVariant) CASE_STRING(Rpc_ConfManager_exportBackup) CASE_STRING(Rpc_ConfManager_importBackup) - CASE_STRING(Rpc_ConfManager_addZone) - CASE_STRING(Rpc_ConfManager_deleteZone) - CASE_STRING(Rpc_ConfManager_updateZone) - CASE_STRING(Rpc_ConfManager_updateZoneName) - CASE_STRING(Rpc_ConfManager_updateZoneEnabled) CASE_STRING(Rpc_ConfManager_checkPassword) CASE_STRING(Rpc_ConfManager_confChanged) - CASE_STRING(Rpc_ConfManager_zoneAdded) - CASE_STRING(Rpc_ConfManager_zoneRemoved) - CASE_STRING(Rpc_ConfManager_zoneUpdated) + + CASE_STRING(Rpc_ConfZoneManager_addZone) + CASE_STRING(Rpc_ConfZoneManager_deleteZone) + CASE_STRING(Rpc_ConfZoneManager_updateZone) + CASE_STRING(Rpc_ConfZoneManager_updateZoneName) + CASE_STRING(Rpc_ConfZoneManager_updateZoneEnabled) + CASE_STRING(Rpc_ConfZoneManager_zoneAdded) + CASE_STRING(Rpc_ConfZoneManager_zoneRemoved) + CASE_STRING(Rpc_ConfZoneManager_zoneUpdated) CASE_STRING(Rpc_ConfAppManager_addApp) CASE_STRING(Rpc_ConfAppManager_deleteApps) @@ -82,6 +83,7 @@ const char *const rpcManagerString(RpcManager rpcManager) CASE_STRING(Rpc_AppInfoManager) CASE_STRING(Rpc_ConfManager) CASE_STRING(Rpc_ConfAppManager) + CASE_STRING(Rpc_ConfZoneManager) CASE_STRING(Rpc_DriverManager) CASE_STRING(Rpc_QuotaManager) CASE_STRING(Rpc_StatManager) @@ -111,16 +113,17 @@ RpcManager managerByCommand(Command cmd) Rpc_ConfManager, // Rpc_ConfManager_saveVariant, Rpc_ConfManager, // Rpc_ConfManager_exportBackup, Rpc_ConfManager, // Rpc_ConfManager_importBackup, - Rpc_ConfManager, // Rpc_ConfManager_addZone, - Rpc_ConfManager, // Rpc_ConfManager_deleteZone, - Rpc_ConfManager, // Rpc_ConfManager_updateZone, - Rpc_ConfManager, // Rpc_ConfManager_updateZoneName, - Rpc_ConfManager, // Rpc_ConfManager_updateZoneEnabled, Rpc_ConfManager, // Rpc_ConfManager_checkPassword, Rpc_ConfManager, // Rpc_ConfManager_confChanged, - Rpc_ConfManager, // Rpc_ConfManager_zoneAdded, - Rpc_ConfManager, // Rpc_ConfManager_zoneRemoved, - Rpc_ConfManager, // Rpc_ConfManager_zoneUpdated, + + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_addZone, + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_deleteZone, + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_updateZone, + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_updateZoneName, + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_updateZoneEnabled, + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_zoneAdded, + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_zoneRemoved, + Rpc_ConfZoneManager, // Rpc_ConfZoneManager_zoneUpdated, Rpc_ConfAppManager, // Rpc_ConfAppManager_addApp, Rpc_ConfAppManager, // Rpc_ConfAppManager_deleteApps, @@ -181,16 +184,17 @@ bool commandRequiresValidation(Command cmd) true, // Rpc_ConfManager_saveVariant, true, // Rpc_ConfManager_exportBackup, true, // Rpc_ConfManager_importBackup, - true, // Rpc_ConfManager_addZone, - true, // Rpc_ConfManager_deleteZone, - true, // Rpc_ConfManager_updateZone, - true, // Rpc_ConfManager_updateZoneName, - true, // Rpc_ConfManager_updateZoneEnabled, 0, // Rpc_ConfManager_checkPassword, 0, // Rpc_ConfManager_confChanged, - 0, // Rpc_ConfManager_zoneAdded, - 0, // Rpc_ConfManager_zoneRemoved, - 0, // Rpc_ConfManager_zoneUpdated, + + true, // Rpc_ConfZoneManager_addZone, + true, // Rpc_ConfZoneManager_deleteZone, + true, // Rpc_ConfZoneManager_updateZone, + true, // Rpc_ConfZoneManager_updateZoneName, + true, // Rpc_ConfZoneManager_updateZoneEnabled, + 0, // Rpc_ConfZoneManager_zoneAdded, + 0, // Rpc_ConfZoneManager_zoneRemoved, + 0, // Rpc_ConfZoneManager_zoneUpdated, true, // Rpc_ConfAppManager_addApp, true, // Rpc_ConfAppManager_deleteApps, diff --git a/src/ui/control/control.h b/src/ui/control/control.h index cd33e786..b8724407 100644 --- a/src/ui/control/control.h +++ b/src/ui/control/control.h @@ -22,16 +22,17 @@ enum Command : qint8 { Rpc_ConfManager_saveVariant, Rpc_ConfManager_exportBackup, Rpc_ConfManager_importBackup, - Rpc_ConfManager_addZone, - Rpc_ConfManager_deleteZone, - Rpc_ConfManager_updateZone, - Rpc_ConfManager_updateZoneName, - Rpc_ConfManager_updateZoneEnabled, Rpc_ConfManager_checkPassword, Rpc_ConfManager_confChanged, - Rpc_ConfManager_zoneAdded, - Rpc_ConfManager_zoneRemoved, - Rpc_ConfManager_zoneUpdated, + + Rpc_ConfZoneManager_addZone, + Rpc_ConfZoneManager_deleteZone, + Rpc_ConfZoneManager_updateZone, + Rpc_ConfZoneManager_updateZoneName, + Rpc_ConfZoneManager_updateZoneEnabled, + Rpc_ConfZoneManager_zoneAdded, + Rpc_ConfZoneManager_zoneRemoved, + Rpc_ConfZoneManager_zoneUpdated, Rpc_ConfAppManager_addApp, Rpc_ConfAppManager_deleteApps, @@ -76,6 +77,7 @@ enum RpcManager : qint8 { Rpc_AppInfoManager, Rpc_ConfManager, Rpc_ConfAppManager, + Rpc_ConfZoneManager, Rpc_DriverManager, Rpc_QuotaManager, Rpc_StatManager, diff --git a/src/ui/form/basecontroller.cpp b/src/ui/form/basecontroller.cpp index da08df7b..bed6b41b 100644 --- a/src/ui/form/basecontroller.cpp +++ b/src/ui/form/basecontroller.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,11 @@ ConfAppManager *BaseController::confAppManager() const return IoC(); } +ConfZoneManager *BaseController::confZoneManager() const +{ + return IoC(); +} + FirewallConf *BaseController::conf() const { return confManager()->conf(); diff --git a/src/ui/form/basecontroller.h b/src/ui/form/basecontroller.h index 69b67860..fb46b37a 100644 --- a/src/ui/form/basecontroller.h +++ b/src/ui/form/basecontroller.h @@ -5,6 +5,7 @@ class ConfAppManager; class ConfManager; +class ConfZoneManager; class DriverManager; class FirewallConf; class FortManager; @@ -27,6 +28,7 @@ public: FortSettings *settings() const; ConfManager *confManager() const; ConfAppManager *confAppManager() const; + ConfZoneManager *confZoneManager() const; FirewallConf *conf() const; IniOptions *ini() const; IniUser *iniUser() const; diff --git a/src/ui/form/controls/zonesselector.cpp b/src/ui/form/controls/zonesselector.cpp index e5659b9d..b94bdc1d 100644 --- a/src/ui/form/controls/zonesselector.cpp +++ b/src/ui/form/controls/zonesselector.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include
#include @@ -107,9 +107,9 @@ void ZonesSelector::setupZones() connect(m_menuZones, &QMenu::aboutToShow, this, &ZonesSelector::updateZonesMenu); - auto confManager = IoC(); + auto confZoneManager = IoC(); - connect(confManager, &ConfManager::zoneRemoved, this, [&](int zoneId) { + connect(confZoneManager, &ConfZoneManager::zoneRemoved, this, [&](int zoneId) { removeZone(zoneId); retranslateZonesText(); }); diff --git a/src/ui/form/zone/zoneswindow.cpp b/src/ui/form/zone/zoneswindow.cpp index 1e701d2f..6db5d4e3 100644 --- a/src/ui/form/zone/zoneswindow.cpp +++ b/src/ui/form/zone/zoneswindow.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -64,6 +65,11 @@ ConfManager *ZonesWindow::confManager() const return ctrl()->confManager(); } +ConfZoneManager *ZonesWindow::confZoneManager() const +{ + return ctrl()->confZoneManager(); +} + IniOptions *ZonesWindow::ini() const { return ctrl()->ini(); @@ -562,7 +568,7 @@ bool ZonesWindow::saveZoneEditFormValidate(const Zone &zone, const ZoneSourceWra bool ZonesWindow::saveZoneEditFormNew(Zone &zone) { - if (confManager()->addZone(zone)) { + if (confZoneManager()->addZone(zone)) { m_zoneListView->selectCell(zone.zoneId - 1); return true; } @@ -577,14 +583,14 @@ bool ZonesWindow::saveZoneEditFormEdit(Zone &zone) if (zone.isOptionsEqual(zoneRow)) { if (!zone.isNameEqual(zoneRow)) { - return confManager()->updateZoneName(zoneRow.zoneId, zone.zoneName); + return confZoneManager()->updateZoneName(zoneRow.zoneId, zone.zoneName); } return true; } zone.zoneId = zoneRow.zoneId; - return confManager()->updateZone(zone); + return confZoneManager()->updateZone(zone); } void ZonesWindow::updateZone(int row, bool enabled) @@ -596,7 +602,7 @@ void ZonesWindow::updateZone(int row, bool enabled) Zone zone = zoneRow; zone.enabled = enabled; - confManager()->updateZone(zone); + confZoneManager()->updateZone(zone); } void ZonesWindow::deleteZone(int row) @@ -605,7 +611,7 @@ void ZonesWindow::deleteZone(int row) if (zoneRow.isNull()) return; - confManager()->deleteZone(zoneRow.zoneId); + confZoneManager()->deleteZone(zoneRow.zoneId); } void ZonesWindow::updateSelectedZone(bool enabled) diff --git a/src/ui/form/zone/zoneswindow.h b/src/ui/form/zone/zoneswindow.h index fc05d8b4..04ce299a 100644 --- a/src/ui/form/zone/zoneswindow.h +++ b/src/ui/form/zone/zoneswindow.h @@ -13,6 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QPushButton) QT_FORWARD_DECLARE_CLASS(QStackedLayout) class ConfManager; +class ConfZoneManager; class IniOptions; class IniUser; class PlainTextEdit; @@ -36,6 +37,7 @@ public: ZonesController *ctrl() const { return m_ctrl; } ConfManager *confManager() const; + ConfZoneManager *confZoneManager() const; IniOptions *ini() const; IniUser *iniUser() const; WindowManager *windowManager() const; diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 33f0a8b8..61a21a49 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -138,6 +139,7 @@ void FortManager::createManagers() ConfManager *confManager; ConfAppManager *confAppManager; + ConfZoneManager *confZoneManager; QuotaManager *quotaManager; StatManager *statManager; StatBlockManager *statBlockManager; @@ -155,6 +157,7 @@ void FortManager::createManagers() confManager = new ConfManager(settings->confFilePath()); confAppManager = new ConfAppManager(); + confZoneManager = new ConfZoneManager(); quotaManager = new QuotaManager(); statManager = new StatManager(settings->statFilePath()); statBlockManager = new StatBlockManager(settings->statBlockFilePath()); @@ -170,6 +173,7 @@ void FortManager::createManagers() } else { confManager = new ConfManagerRpc(settings->confFilePath()); confAppManager = new ConfAppManagerRpc(); + confZoneManager = new ConfZoneManagerRpc(); quotaManager = new QuotaManagerRpc(); statManager = new StatManagerRpc(settings->statFilePath()); statBlockManager = new StatBlockManagerRpc(settings->statBlockFilePath()); @@ -197,6 +201,7 @@ void FortManager::createManagers() ioc->setService(confManager); ioc->setService(confAppManager); + ioc->setService(confZoneManager); ioc->setService(quotaManager); ioc->setService(statManager); ioc->setService(statBlockManager); @@ -374,8 +379,8 @@ void FortManager::setupTaskManager() WindowManager::MessageZones); }); - connect(taskManager, &TaskManager::zonesUpdated, IoC(), - &ConfManager::updateDriverZones); + connect(taskManager, &TaskManager::zonesUpdated, IoC(), + &ConfZoneManager::updateDriverZones); connect(taskManager, &TaskManager::taskDoubleClicked, this, [&](qint8 taskType) { switch (taskType) { diff --git a/src/ui/model/zonelistmodel.cpp b/src/ui/model/zonelistmodel.cpp index 03de7794..10338358 100644 --- a/src/ui/model/zonelistmodel.cpp +++ b/src/ui/model/zonelistmodel.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,11 @@ ConfManager *ZoneListModel::confManager() const return IoC(); } +ConfZoneManager *ZoneListModel::confZoneManager() const +{ + return IoC(); +} + SqliteDb *ZoneListModel::sqliteDb() const { return confManager()->sqliteDb(); @@ -36,9 +42,9 @@ void ZoneListModel::setUp() setupZoneTypes(); setupZoneSources(); - connect(confManager(), &ConfManager::zoneAdded, this, &TableSqlModel::reset); - connect(confManager(), &ConfManager::zoneRemoved, this, &ZoneListModel::reset); - connect(confManager(), &ConfManager::zoneUpdated, this, &TableSqlModel::refresh); + connect(confZoneManager(), &ConfZoneManager::zoneAdded, this, &TableSqlModel::reset); + connect(confZoneManager(), &ConfZoneManager::zoneRemoved, this, &ZoneListModel::reset); + connect(confZoneManager(), &ConfZoneManager::zoneUpdated, this, &TableSqlModel::refresh); } int ZoneListModel::columnCount(const QModelIndex &parent) const @@ -135,7 +141,7 @@ bool ZoneListModel::setData(const QModelIndex &index, const QVariant &value, int switch (role) { case Qt::CheckStateRole: const auto zoneRow = zoneRowAt(index.row()); - return confManager()->updateZoneEnabled(zoneRow.zoneId, !zoneRow.enabled); + return confZoneManager()->updateZoneEnabled(zoneRow.zoneId, !zoneRow.enabled); } return false; diff --git a/src/ui/model/zonelistmodel.h b/src/ui/model/zonelistmodel.h index f16af0c4..80cb7b0f 100644 --- a/src/ui/model/zonelistmodel.h +++ b/src/ui/model/zonelistmodel.h @@ -10,6 +10,7 @@ #include class ConfManager; +class ConfZoneManager; class ZoneSourceWrapper; struct ZoneRow : TableRow, public Zone @@ -24,6 +25,7 @@ public: explicit ZoneListModel(QObject *parent = nullptr); ConfManager *confManager() const; + ConfZoneManager *confZoneManager() const; SqliteDb *sqliteDb() const override; void setUp() override; diff --git a/src/ui/rpc/confmanagerrpc.cpp b/src/ui/rpc/confmanagerrpc.cpp index 3b2c332f..cc7e5467 100644 --- a/src/ui/rpc/confmanagerrpc.cpp +++ b/src/ui/rpc/confmanagerrpc.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -26,45 +25,6 @@ bool ConfManagerRpc::importBackup(const QString &path) return IoC()->doOnServer(Control::Rpc_ConfManager_importBackup, { path }); } -bool ConfManagerRpc::addZone(Zone &zone) -{ - QVariantList resArgs; - - if (!IoC()->doOnServer(Control::Rpc_ConfManager_addZone, - { zone.enabled, zone.customUrl, zone.zoneName, zone.sourceCode, zone.url, - zone.formData, zone.textInline }, - &resArgs)) - return false; - - zone.zoneId = resArgs.value(0).toInt(); - - return true; -} - -bool ConfManagerRpc::deleteZone(int zoneId) -{ - return IoC()->doOnServer(Control::Rpc_ConfManager_deleteZone, { zoneId }); -} - -bool ConfManagerRpc::updateZone(const Zone &zone) -{ - return IoC()->doOnServer(Control::Rpc_ConfManager_updateZone, - { zone.enabled, zone.customUrl, zone.zoneId, zone.zoneName, zone.sourceCode, zone.url, - zone.formData, zone.textInline }); -} - -bool ConfManagerRpc::updateZoneName(int zoneId, const QString &zoneName) -{ - return IoC()->doOnServer( - Control::Rpc_ConfManager_updateZoneName, { zoneId, zoneName }); -} - -bool ConfManagerRpc::updateZoneEnabled(int zoneId, bool enabled) -{ - return IoC()->doOnServer( - Control::Rpc_ConfManager_updateZoneEnabled, { zoneId, enabled }); -} - bool ConfManagerRpc::checkPassword(const QString &password) { return IoC()->doOnServer(Control::Rpc_ConfManager_checkPassword, { password }); diff --git a/src/ui/rpc/confmanagerrpc.h b/src/ui/rpc/confmanagerrpc.h index 3f1e99c0..d62e42be 100644 --- a/src/ui/rpc/confmanagerrpc.h +++ b/src/ui/rpc/confmanagerrpc.h @@ -16,12 +16,6 @@ public: bool exportBackup(const QString &path) override; bool importBackup(const QString &path) override; - bool addZone(Zone &zone) override; - bool deleteZone(int zoneId) override; - bool updateZone(const Zone &zone) override; - bool updateZoneName(int zoneId, const QString &zoneName) override; - bool updateZoneEnabled(int zoneId, bool enabled) override; - bool checkPassword(const QString &password) override; void onConfChanged(const QVariant &confVar); diff --git a/src/ui/rpc/confzonemanagerrpc.cpp b/src/ui/rpc/confzonemanagerrpc.cpp new file mode 100644 index 00000000..a6b6c1cd --- /dev/null +++ b/src/ui/rpc/confzonemanagerrpc.cpp @@ -0,0 +1,48 @@ +#include "confzonemanagerrpc.h" + +#include + +#include +#include +#include + +ConfZoneManagerRpc::ConfZoneManagerRpc(QObject *parent) : ConfZoneManager(parent) { } + +bool ConfZoneManagerRpc::addZone(Zone &zone) +{ + QVariantList resArgs; + + if (!IoC()->doOnServer(Control::Rpc_ConfZoneManager_addZone, + { zone.enabled, zone.customUrl, zone.zoneName, zone.sourceCode, zone.url, + zone.formData, zone.textInline }, + &resArgs)) + return false; + + zone.zoneId = resArgs.value(0).toInt(); + + return true; +} + +bool ConfZoneManagerRpc::deleteZone(int zoneId) +{ + return IoC()->doOnServer(Control::Rpc_ConfZoneManager_deleteZone, { zoneId }); +} + +bool ConfZoneManagerRpc::updateZone(const Zone &zone) +{ + return IoC()->doOnServer(Control::Rpc_ConfZoneManager_updateZone, + { zone.enabled, zone.customUrl, zone.zoneId, zone.zoneName, zone.sourceCode, zone.url, + zone.formData, zone.textInline }); +} + +bool ConfZoneManagerRpc::updateZoneName(int zoneId, const QString &zoneName) +{ + return IoC()->doOnServer( + Control::Rpc_ConfZoneManager_updateZoneName, { zoneId, zoneName }); +} + +bool ConfZoneManagerRpc::updateZoneEnabled(int zoneId, bool enabled) +{ + return IoC()->doOnServer( + Control::Rpc_ConfZoneManager_updateZoneEnabled, { zoneId, enabled }); +} diff --git a/src/ui/rpc/confzonemanagerrpc.h b/src/ui/rpc/confzonemanagerrpc.h new file mode 100644 index 00000000..9e50111b --- /dev/null +++ b/src/ui/rpc/confzonemanagerrpc.h @@ -0,0 +1,22 @@ +#ifndef CONFZONEMANAGERRPC_H +#define CONFZONEMANAGERRPC_H + +#include + +class RpcManager; + +class ConfZoneManagerRpc : public ConfZoneManager +{ + Q_OBJECT + +public: + explicit ConfZoneManagerRpc(QObject *parent = nullptr); + + bool addZone(Zone &zone) override; + bool deleteZone(int zoneId) override; + bool updateZone(const Zone &zone) override; + bool updateZoneName(int zoneId, const QString &zoneName) override; + bool updateZoneEnabled(int zoneId, bool enabled) override; +}; + +#endif // CONFZONEMANAGERRPC_H diff --git a/src/ui/rpc/rpcmanager.cpp b/src/ui/rpc/rpcmanager.cpp index b07c8de4..4b25ea42 100644 --- a/src/ui/rpc/rpcmanager.cpp +++ b/src/ui/rpc/rpcmanager.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -81,57 +82,6 @@ bool processConfManager_importBackup( return confManager->importBackup(p.args.value(0).toString()); } -bool processConfManager_addZone( - ConfManager *confManager, const ProcessCommandArgs &p, QVariantList &resArgs) -{ - Zone zone; - zone.enabled = p.args.value(0).toBool(); - zone.customUrl = p.args.value(1).toBool(); - zone.zoneName = p.args.value(2).toString(); - zone.sourceCode = p.args.value(3).toString(); - zone.url = p.args.value(4).toString(); - zone.formData = p.args.value(5).toString(); - zone.textInline = p.args.value(6).toString(); - - const bool ok = confManager->addZone(zone); - resArgs = { zone.zoneId }; - return ok; -} - -bool processConfManager_deleteZone( - ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) -{ - return confManager->deleteZone(p.args.value(0).toLongLong()); -} - -bool processConfManager_updateZone( - ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) -{ - Zone zone; - zone.enabled = p.args.value(0).toBool(); - zone.customUrl = p.args.value(1).toBool(); - zone.zoneId = p.args.value(2).toInt(); - zone.zoneName = p.args.value(3).toString(); - zone.sourceCode = p.args.value(4).toString(); - zone.url = p.args.value(5).toString(); - zone.formData = p.args.value(6).toString(); - zone.textInline = p.args.value(7).toString(); - - return confManager->updateZone(zone); -} - -bool processConfManager_updateZoneName( - ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) -{ - return confManager->updateZoneName(p.args.value(0).toLongLong(), p.args.value(1).toString()); -} - -bool processConfManager_updateZoneEnabled( - ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) -{ - return confManager->updateZoneEnabled(p.args.value(0).toLongLong(), p.args.value(1).toBool()); -} - bool processConfManager_checkPassword( ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) { @@ -149,11 +99,6 @@ static processConfManager_func processConfManager_funcList[] = { &processConfManager_saveVariant, // Rpc_ConfManager_saveVariant, &processConfManager_exportBackup, // Rpc_ConfManager_exportBackup, &processConfManager_importBackup, // Rpc_ConfManager_importBackup, - &processConfManager_addZone, // Rpc_ConfManager_addZone, - &processConfManager_deleteZone, // Rpc_ConfManager_deleteZone, - &processConfManager_updateZone, // Rpc_ConfManager_updateZone, - &processConfManager_updateZoneName, // Rpc_ConfManager_updateZoneName, - &processConfManager_updateZoneEnabled, // Rpc_ConfManager_updateZoneEnabled, &processConfManager_checkPassword, // Rpc_ConfManager_checkPassword, }; @@ -238,6 +183,85 @@ inline bool processConfAppManagerRpcResult( return false; } +bool processConfZoneManager_addZone( + ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList &resArgs) +{ + Zone zone; + zone.enabled = p.args.value(0).toBool(); + zone.customUrl = p.args.value(1).toBool(); + zone.zoneName = p.args.value(2).toString(); + zone.sourceCode = p.args.value(3).toString(); + zone.url = p.args.value(4).toString(); + zone.formData = p.args.value(5).toString(); + zone.textInline = p.args.value(6).toString(); + + const bool ok = confZoneManager->addZone(zone); + resArgs = { zone.zoneId }; + return ok; +} + +bool processConfZoneManager_deleteZone( + ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) +{ + return confZoneManager->deleteZone(p.args.value(0).toLongLong()); +} + +bool processConfZoneManager_updateZone( + ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) +{ + Zone zone; + zone.enabled = p.args.value(0).toBool(); + zone.customUrl = p.args.value(1).toBool(); + zone.zoneId = p.args.value(2).toInt(); + zone.zoneName = p.args.value(3).toString(); + zone.sourceCode = p.args.value(4).toString(); + zone.url = p.args.value(5).toString(); + zone.formData = p.args.value(6).toString(); + zone.textInline = p.args.value(7).toString(); + + return confZoneManager->updateZone(zone); +} + +bool processConfZoneManager_updateZoneName( + ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) +{ + return confZoneManager->updateZoneName( + p.args.value(0).toLongLong(), p.args.value(1).toString()); +} + +bool processConfZoneManager_updateZoneEnabled( + ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/) +{ + return confZoneManager->updateZoneEnabled( + p.args.value(0).toLongLong(), p.args.value(1).toBool()); +} + +using processConfZoneManager_func = bool (*)( + ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList &resArgs); + +static processConfZoneManager_func processConfZoneManager_funcList[] = { + &processConfZoneManager_addZone, // Rpc_ConfZoneManager_addZone, + &processConfZoneManager_deleteZone, // Rpc_ConfZoneManager_deleteZone, + &processConfZoneManager_updateZone, // Rpc_ConfZoneManager_updateZone, + &processConfZoneManager_updateZoneName, // Rpc_ConfZoneManager_updateZoneName, + &processConfZoneManager_updateZoneEnabled, // Rpc_ConfZoneManager_updateZoneEnabled, +}; + +inline bool processConfZoneManagerRpcResult( + ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList &resArgs) +{ + if (p.command >= Control::Rpc_ConfZoneManager_addZone + && p.command <= Control::Rpc_ConfZoneManager_updateZoneEnabled) { + + const int funcIndex = p.command - Control::Rpc_ConfZoneManager_addZone; + const processConfZoneManager_func func = processConfZoneManager_funcList[funcIndex]; + + return func(confZoneManager, p, resArgs); + } + + return false; +} + bool processStatManager_trafficCleared(StatManager *statManager, const ProcessCommandArgs & /*p*/) { emit statManager->trafficCleared(); @@ -382,15 +406,6 @@ bool processConfManagerRpc( switch (p.command) { case Control::Rpc_ConfManager_confChanged: return processConfManager_confChanged(confManager, p); - case Control::Rpc_ConfManager_zoneAdded: - emit confManager->zoneAdded(); - return true; - case Control::Rpc_ConfManager_zoneRemoved: - emit confManager->zoneRemoved(p.args.value(0).toInt()); - return true; - case Control::Rpc_ConfManager_zoneUpdated: - emit confManager->zoneUpdated(); - return true; default: { ok = processConfManagerRpcResult(confManager, p, resArgs); isSendResult = true; @@ -422,6 +437,29 @@ bool processConfAppManagerRpc( } } +bool processConfZoneManagerRpc( + const ProcessCommandArgs &p, QVariantList &resArgs, bool &ok, bool &isSendResult) +{ + auto confZoneManager = IoC(); + + switch (p.command) { + case Control::Rpc_ConfZoneManager_zoneAdded: + emit confZoneManager->zoneAdded(); + return true; + case Control::Rpc_ConfZoneManager_zoneRemoved: + emit confZoneManager->zoneRemoved(p.args.value(0).toInt()); + return true; + case Control::Rpc_ConfZoneManager_zoneUpdated: + emit confZoneManager->zoneUpdated(); + return true; + default: { + ok = processConfZoneManagerRpcResult(confZoneManager, p, resArgs); + isSendResult = true; + return true; + } + } +} + bool processDriverManagerRpc(const ProcessCommandArgs &p, QVariantList & /*resArgs*/, bool & /*ok*/, bool & /*isSendResult*/) { @@ -553,6 +591,7 @@ void RpcManager::setupServerSignals() setupAppInfoManagerSignals(); setupConfManagerSignals(); setupConfAppManagerSignals(); + setupConfZoneManagerSignals(); setupDriverManagerSignals(); setupQuotaManagerSignals(); setupStatManagerSignals(); @@ -578,13 +617,6 @@ void RpcManager::setupConfManagerSignals() const QVariant confVar = IoC()->toPatchVariant(onlyFlags); invokeOnClients(Control::Rpc_ConfManager_confChanged, { confVar }); }); - - connect(confManager, &ConfManager::zoneAdded, this, - [&] { invokeOnClients(Control::Rpc_ConfManager_zoneAdded); }); - connect(confManager, &ConfManager::zoneRemoved, this, - [&](int zoneId) { invokeOnClients(Control::Rpc_ConfManager_zoneRemoved, { zoneId }); }); - connect(confManager, &ConfManager::zoneUpdated, this, - [&] { invokeOnClients(Control::Rpc_ConfManager_zoneUpdated); }); } void RpcManager::setupConfAppManagerSignals() @@ -599,6 +631,19 @@ void RpcManager::setupConfAppManagerSignals() [&] { invokeOnClients(Control::Rpc_ConfAppManager_appUpdated); }); } +void RpcManager::setupConfZoneManagerSignals() +{ + auto confZoneManager = IoC(); + + connect(confZoneManager, &ConfZoneManager::zoneAdded, this, + [&] { invokeOnClients(Control::Rpc_ConfZoneManager_zoneAdded); }); + connect(confZoneManager, &ConfZoneManager::zoneRemoved, this, [&](int zoneId) { + invokeOnClients(Control::Rpc_ConfZoneManager_zoneRemoved, { zoneId }); + }); + connect(confZoneManager, &ConfZoneManager::zoneUpdated, this, + [&] { invokeOnClients(Control::Rpc_ConfZoneManager_zoneUpdated); }); +} + void RpcManager::setupDriverManagerSignals() { auto driverManager = IoC(); @@ -804,6 +849,7 @@ static processManager_func processManager_funcList[] = { &processAppInfoManagerRpc, // Control::Rpc_AppInfoManager, &processConfManagerRpc, // Control::Rpc_ConfManager, &processConfAppManagerRpc, // Control::Rpc_ConfAppManager, + &processConfZoneManagerRpc, // Control::Rpc_ConfZoneManager, &processDriverManagerRpc, // Control::Rpc_DriverManager, &processQuotaManagerRpc, // Control::Rpc_QuotaManager, &processStatManagerRpc, // Control::Rpc_StatManager, diff --git a/src/ui/rpc/rpcmanager.h b/src/ui/rpc/rpcmanager.h index 0e48d598..1123c1db 100644 --- a/src/ui/rpc/rpcmanager.h +++ b/src/ui/rpc/rpcmanager.h @@ -39,6 +39,7 @@ private: void setupAppInfoManagerSignals(); void setupConfManagerSignals(); void setupConfAppManagerSignals(); + void setupConfZoneManagerSignals(); void setupDriverManagerSignals(); void setupQuotaManagerSignals(); void setupStatManagerSignals(); diff --git a/src/ui/task/taskinfozonedownloader.cpp b/src/ui/task/taskinfozonedownloader.cpp index e4ede2a7..07aebdec 100644 --- a/src/ui/task/taskinfozonedownloader.cpp +++ b/src/ui/task/taskinfozonedownloader.cpp @@ -2,7 +2,7 @@ #include -#include +#include #include #include #include @@ -153,7 +153,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success) zone.lastRun = QDateTime::currentDateTime(); zone.lastSuccess = success ? zone.lastRun : worker->lastSuccess(); - IoC()->updateZoneResult(zone); + IoC()->updateZoneResult(zone); addSubResult(worker, success); }