mirror of
https://github.com/tnodir/fort
synced 2024-11-15 10:35:10 +00:00
UI: ConfManager: Add app/zone edited signals.
This commit is contained in:
parent
12150dc54f
commit
f66aeee889
@ -372,21 +372,6 @@ void ConfManager::showErrorMessage(const QString &errorMessage)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::checkResult(bool ok, bool commit)
|
|
||||||
{
|
|
||||||
const auto errorMessage = ok ? QString() : sqliteDb()->errorMessage();
|
|
||||||
|
|
||||||
if (commit) {
|
|
||||||
sqliteDb()->endTransaction(ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
showErrorMessage(errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ConfManager::initialize()
|
bool ConfManager::initialize()
|
||||||
{
|
{
|
||||||
if (!sqliteDb()->open()) {
|
if (!sqliteDb()->open()) {
|
||||||
@ -603,8 +588,11 @@ qint64 ConfManager::appIdByPath(const QString &appPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
bool ConfManager::addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
||||||
qint64 groupId, bool useGroupPerm, bool blocked, bool alerted)
|
qint64 groupId, int groupIndex, bool useGroupPerm, bool blocked, bool alerted)
|
||||||
{
|
{
|
||||||
|
if (!updateDriverUpdateApp(appPath, groupIndex, useGroupPerm, blocked))
|
||||||
|
return false;
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
sqliteDb()->beginTransaction();
|
sqliteDb()->beginTransaction();
|
||||||
@ -628,16 +616,17 @@ bool ConfManager::addApp(const QString &appPath, const QString &appName, const Q
|
|||||||
m_appEndTimer.start();
|
m_appEndTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alerted) {
|
emit appAdded(alerted);
|
||||||
emit alertedAppAdded();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::deleteApp(qint64 appId)
|
bool ConfManager::deleteApp(qint64 appId, const QString &appPath)
|
||||||
{
|
{
|
||||||
|
if (!updateDriverDeleteApp(appPath))
|
||||||
|
return false;
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
sqliteDb()->beginTransaction();
|
sqliteDb()->beginTransaction();
|
||||||
@ -649,12 +638,21 @@ bool ConfManager::deleteApp(qint64 appId)
|
|||||||
sqliteDb()->executeEx(sqlDeleteAppAlert, vars, 0, &ok);
|
sqliteDb()->executeEx(sqlDeleteAppAlert, vars, 0, &ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkResult(ok, true);
|
checkResult(ok, true);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit appRemoved();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateApp(qint64 appId, const QString &appName, const QDateTime &endTime,
|
bool ConfManager::updateApp(qint64 appId, const QString &appPath, const QString &appName,
|
||||||
qint64 groupId, bool useGroupPerm, bool blocked)
|
const QDateTime &endTime, qint64 groupId, int groupIndex, bool useGroupPerm, bool blocked)
|
||||||
{
|
{
|
||||||
|
if (!updateDriverUpdateApp(appPath, groupIndex, useGroupPerm, blocked))
|
||||||
|
return false;
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
sqliteDb()->beginTransaction();
|
sqliteDb()->beginTransaction();
|
||||||
@ -669,8 +667,12 @@ bool ConfManager::updateApp(qint64 appId, const QString &appName, const QDateTim
|
|||||||
|
|
||||||
checkResult(ok, true);
|
checkResult(ok, true);
|
||||||
|
|
||||||
if (ok && !endTime.isNull()) {
|
if (ok) {
|
||||||
m_appEndTimer.start();
|
if (!endTime.isNull()) {
|
||||||
|
m_appEndTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit appUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
@ -684,7 +686,13 @@ bool ConfManager::updateAppName(qint64 appId, const QString &appName)
|
|||||||
|
|
||||||
sqliteDb()->executeEx(sqlUpdateAppName, vars, 0, &ok);
|
sqliteDb()->executeEx(sqlUpdateAppName, vars, 0, &ok);
|
||||||
|
|
||||||
return checkResult(ok);
|
checkResult(ok);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit appUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::walkApps(const std::function<walkAppsCallback> &func)
|
bool ConfManager::walkApps(const std::function<walkAppsCallback> &func)
|
||||||
@ -730,8 +738,8 @@ void ConfManager::updateAppEndTimes()
|
|||||||
const QString appName = stmt.columnText(4);
|
const QString appName = stmt.columnText(4);
|
||||||
const bool useGroupPerm = stmt.columnBool(5);
|
const bool useGroupPerm = stmt.columnBool(5);
|
||||||
|
|
||||||
if (updateDriverUpdateApp(appPath, groupIndex, useGroupPerm, true)
|
if (updateApp(appId, appPath, appName, QDateTime(), groupId, groupIndex, useGroupPerm,
|
||||||
&& updateApp(appId, appName, QDateTime(), groupId, useGroupPerm, true)) {
|
true)) {
|
||||||
isAppEndTimesUpdated = true;
|
isAppEndTimesUpdated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -762,7 +770,13 @@ bool ConfManager::addZone(const QString &zoneName, const QString &sourceCode, co
|
|||||||
|
|
||||||
sqliteDb()->executeEx(sqlInsertZone, vars, 0, &ok);
|
sqliteDb()->executeEx(sqlInsertZone, vars, 0, &ok);
|
||||||
|
|
||||||
return checkResult(ok);
|
checkResult(ok);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit zoneAdded();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfManager::getFreeZoneId()
|
int ConfManager::getFreeZoneId()
|
||||||
@ -796,12 +810,21 @@ bool ConfManager::deleteZone(int zoneId)
|
|||||||
sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok);
|
sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkResult(ok, true);
|
checkResult(ok, true);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit zoneRemoved(zoneId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZone(int zoneId, const QString &zoneName, const QString &sourceCode,
|
bool ConfManager::updateZone(int zoneId, const QString &zoneName, const QString &sourceCode,
|
||||||
const QString &url, const QString &formData, bool enabled, bool customUrl)
|
const QString &url, const QString &formData, bool enabled, bool customUrl)
|
||||||
{
|
{
|
||||||
|
if (!updateDriverZoneFlag(zoneId, enabled))
|
||||||
|
return false;
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
const auto vars = QVariantList()
|
const auto vars = QVariantList()
|
||||||
@ -809,7 +832,13 @@ bool ConfManager::updateZone(int zoneId, const QString &zoneName, const QString
|
|||||||
|
|
||||||
sqliteDb()->executeEx(sqlUpdateZone, vars, 0, &ok);
|
sqliteDb()->executeEx(sqlUpdateZone, vars, 0, &ok);
|
||||||
|
|
||||||
return checkResult(ok);
|
checkResult(ok);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit zoneUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZoneName(int zoneId, const QString &zoneName)
|
bool ConfManager::updateZoneName(int zoneId, const QString &zoneName)
|
||||||
@ -820,18 +849,33 @@ bool ConfManager::updateZoneName(int zoneId, const QString &zoneName)
|
|||||||
|
|
||||||
sqliteDb()->executeEx(sqlUpdateZoneName, vars, 0, &ok);
|
sqliteDb()->executeEx(sqlUpdateZoneName, vars, 0, &ok);
|
||||||
|
|
||||||
return checkResult(ok);
|
checkResult(ok);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit zoneUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZoneEnabled(int zoneId, bool enabled)
|
bool ConfManager::updateZoneEnabled(int zoneId, bool enabled)
|
||||||
{
|
{
|
||||||
|
if (!updateDriverZoneFlag(zoneId, enabled))
|
||||||
|
return false;
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
const auto vars = QVariantList() << zoneId << enabled;
|
const auto vars = QVariantList() << zoneId << enabled;
|
||||||
|
|
||||||
sqliteDb()->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok);
|
sqliteDb()->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok);
|
||||||
|
|
||||||
return checkResult(ok);
|
checkResult(ok);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit zoneUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZoneResult(int zoneId, const QString &textChecksum,
|
bool ConfManager::updateZoneResult(int zoneId, const QString &textChecksum,
|
||||||
@ -845,7 +889,13 @@ bool ConfManager::updateZoneResult(int zoneId, const QString &textChecksum,
|
|||||||
|
|
||||||
sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
|
sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
|
||||||
|
|
||||||
return checkResult(ok);
|
checkResult(ok);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
emit zoneUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::validateDriver()
|
bool ConfManager::validateDriver()
|
||||||
@ -865,7 +915,6 @@ bool ConfManager::updateDriverConf(bool onlyFlags)
|
|||||||
|
|
||||||
const int confSize = onlyFlags ? confUtil.writeFlags(*conf(), buf)
|
const int confSize = onlyFlags ? confUtil.writeFlags(*conf(), buf)
|
||||||
: confUtil.write(*conf(), this, *envManager(), buf);
|
: confUtil.write(*conf(), this, *envManager(), buf);
|
||||||
|
|
||||||
if (confSize == 0) {
|
if (confSize == 0) {
|
||||||
showErrorMessage(confUtil.errorMessage());
|
showErrorMessage(confUtil.errorMessage());
|
||||||
return false;
|
return false;
|
||||||
@ -1085,3 +1134,18 @@ bool ConfManager::saveTask(TaskInfo *taskInfo)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConfManager::checkResult(bool ok, bool commit)
|
||||||
|
{
|
||||||
|
const auto errorMessage = ok ? QString() : sqliteDb()->errorMessage();
|
||||||
|
|
||||||
|
if (commit) {
|
||||||
|
sqliteDb()->endTransaction(ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
showErrorMessage(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
@ -61,10 +61,11 @@ public:
|
|||||||
|
|
||||||
qint64 appIdByPath(const QString &appPath);
|
qint64 appIdByPath(const QString &appPath);
|
||||||
bool addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
bool addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
||||||
qint64 groupId, bool useGroupPerm, bool blocked, bool alerted = false);
|
qint64 groupId, int groupIndex, bool useGroupPerm, bool blocked, bool alerted = false);
|
||||||
bool deleteApp(qint64 appId);
|
bool deleteApp(qint64 appId, const QString &appPath);
|
||||||
bool updateApp(qint64 appId, const QString &appName, const QDateTime &endTime, qint64 groupId,
|
bool updateApp(qint64 appId, const QString &appPath, const QString &appName,
|
||||||
bool useGroupPerm, bool blocked);
|
const QDateTime &endTime, qint64 groupId, int groupIndex, bool useGroupPerm,
|
||||||
|
bool blocked);
|
||||||
bool updateAppName(qint64 appId, const QString &appName);
|
bool updateAppName(qint64 appId, const QString &appName);
|
||||||
|
|
||||||
bool walkApps(const std::function<walkAppsCallback> &func) override;
|
bool walkApps(const std::function<walkAppsCallback> &func) override;
|
||||||
@ -85,18 +86,21 @@ public:
|
|||||||
const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess);
|
const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess);
|
||||||
|
|
||||||
bool validateDriver();
|
bool validateDriver();
|
||||||
bool updateDriverConf(bool onlyFlags = false);
|
virtual bool updateDriverConf(bool onlyFlags = false);
|
||||||
bool updateDriverDeleteApp(const QString &appPath);
|
|
||||||
bool updateDriverUpdateApp(const QString &appPath, int groupIndex, bool useGroupPerm,
|
|
||||||
bool blocked, bool remove = false);
|
|
||||||
void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
||||||
const QList<QByteArray> &zonesData);
|
const QList<QByteArray> &zonesData);
|
||||||
bool updateDriverZoneFlag(int zoneId, bool enabled);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void confChanged(bool onlyFlags);
|
void confChanged(bool onlyFlags);
|
||||||
|
|
||||||
void appEndTimesUpdated();
|
void appEndTimesUpdated();
|
||||||
void alertedAppAdded();
|
void appAdded(bool alerted);
|
||||||
|
void appRemoved();
|
||||||
|
void appUpdated();
|
||||||
|
|
||||||
|
void zoneAdded();
|
||||||
|
void zoneRemoved(int zoneId);
|
||||||
|
void zoneUpdated();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setupAppEndTimer();
|
virtual void setupAppEndTimer();
|
||||||
@ -109,10 +113,13 @@ protected:
|
|||||||
void saveClientExtFlags(const IniOptions &ini);
|
void saveClientExtFlags(const IniOptions &ini);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool checkResult(bool ok, bool commit = false);
|
|
||||||
|
|
||||||
void setupDefault(FirewallConf &conf) const;
|
void setupDefault(FirewallConf &conf) const;
|
||||||
|
|
||||||
|
bool updateDriverDeleteApp(const QString &appPath);
|
||||||
|
bool updateDriverUpdateApp(const QString &appPath, int groupIndex, bool useGroupPerm,
|
||||||
|
bool blocked, bool remove = false);
|
||||||
|
bool updateDriverZoneFlag(int zoneId, bool enabled);
|
||||||
|
|
||||||
bool loadFromDb(FirewallConf &conf, bool &isNew);
|
bool loadFromDb(FirewallConf &conf, bool &isNew);
|
||||||
bool saveToDb(const FirewallConf &conf);
|
bool saveToDb(const FirewallConf &conf);
|
||||||
|
|
||||||
@ -126,6 +133,8 @@ private:
|
|||||||
bool loadTask(TaskInfo *taskInfo);
|
bool loadTask(TaskInfo *taskInfo);
|
||||||
bool saveTask(TaskInfo *taskInfo);
|
bool saveTask(TaskInfo *taskInfo);
|
||||||
|
|
||||||
|
bool checkResult(bool ok, bool commit = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FortManager *m_fortManager = nullptr;
|
FortManager *m_fortManager = nullptr;
|
||||||
SqliteDb *m_sqliteDb = nullptr;
|
SqliteDb *m_sqliteDb = nullptr;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "../../../conf/addressgroup.h"
|
#include "../../../conf/addressgroup.h"
|
||||||
|
#include "../../../conf/confmanager.h"
|
||||||
#include "../../../conf/firewallconf.h"
|
#include "../../../conf/firewallconf.h"
|
||||||
#include "../../../driver/drivercommon.h"
|
#include "../../../driver/drivercommon.h"
|
||||||
#include "../../../fortmanager.h"
|
#include "../../../fortmanager.h"
|
||||||
@ -344,7 +345,7 @@ void AddressesPage::setupZones()
|
|||||||
m_excludeAddresses->btSelectZones()->setMenu(m_menuZones);
|
m_excludeAddresses->btSelectZones()->setMenu(m_menuZones);
|
||||||
updateZonesMenuEnabled();
|
updateZonesMenuEnabled();
|
||||||
|
|
||||||
connect(zoneListModel(), &ZoneListModel::zoneRemoved, this, [&](int zoneId) {
|
connect(confManager(), &ConfManager::zoneRemoved, this, [&](int zoneId) {
|
||||||
for (auto addrGroup : addressGroups()) {
|
for (auto addrGroup : addressGroups()) {
|
||||||
addrGroup->removeIncludeZone(zoneId);
|
addrGroup->removeIncludeZone(zoneId);
|
||||||
addrGroup->removeExcludeZone(zoneId);
|
addrGroup->removeExcludeZone(zoneId);
|
||||||
|
@ -22,6 +22,11 @@ FortSettings *BasePage::settings() const
|
|||||||
return ctrl()->settings();
|
return ctrl()->settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfManager *BasePage::confManager() const
|
||||||
|
{
|
||||||
|
return ctrl()->confManager();
|
||||||
|
}
|
||||||
|
|
||||||
FirewallConf *BasePage::conf() const
|
FirewallConf *BasePage::conf() const
|
||||||
{
|
{
|
||||||
return ctrl()->conf();
|
return ctrl()->conf();
|
||||||
|
@ -14,6 +14,7 @@ QT_FORWARD_DECLARE_CLASS(QMenu)
|
|||||||
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||||
QT_FORWARD_DECLARE_CLASS(QTabBar)
|
QT_FORWARD_DECLARE_CLASS(QTabBar)
|
||||||
|
|
||||||
|
class ConfManager;
|
||||||
class DriverManager;
|
class DriverManager;
|
||||||
class FirewallConf;
|
class FirewallConf;
|
||||||
class FortManager;
|
class FortManager;
|
||||||
@ -35,6 +36,7 @@ protected:
|
|||||||
OptionsController *ctrl() const { return m_ctrl; }
|
OptionsController *ctrl() const { return m_ctrl; }
|
||||||
FortManager *fortManager() const;
|
FortManager *fortManager() const;
|
||||||
FortSettings *settings() const;
|
FortSettings *settings() const;
|
||||||
|
ConfManager *confManager() const;
|
||||||
FirewallConf *conf() const;
|
FirewallConf *conf() const;
|
||||||
IniOptions *ini() const;
|
IniOptions *ini() const;
|
||||||
DriverManager *driverManager() const;
|
DriverManager *driverManager() const;
|
||||||
|
@ -450,7 +450,7 @@ bool ZonesWindow::saveZoneEditForm()
|
|||||||
}
|
}
|
||||||
|
|
||||||
return zoneListModel()->updateZone(
|
return zoneListModel()->updateZone(
|
||||||
zoneRow.zoneId, zoneName, sourceCode, url, formData, enabled, customUrl, zoneEdited);
|
zoneRow.zoneId, zoneName, sourceCode, url, formData, enabled, customUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZonesWindow::updateZone(int row, bool enabled)
|
void ZonesWindow::updateZone(int row, bool enabled)
|
||||||
|
@ -358,8 +358,11 @@ void FortManager::setupTrayIcon()
|
|||||||
connect(m_trayIcon, &QSystemTrayIcon::messageClicked, this, &FortManager::onTrayMessageClicked);
|
connect(m_trayIcon, &QSystemTrayIcon::messageClicked, this, &FortManager::onTrayMessageClicked);
|
||||||
|
|
||||||
connect(confManager(), &ConfManager::confChanged, m_trayIcon, &TrayIcon::updateTrayMenu);
|
connect(confManager(), &ConfManager::confChanged, m_trayIcon, &TrayIcon::updateTrayMenu);
|
||||||
connect(confManager(), &ConfManager::alertedAppAdded, m_trayIcon,
|
connect(confManager(), &ConfManager::appAdded, m_trayIcon, [&](bool alerted) {
|
||||||
[&] { m_trayIcon->updateTrayIcon(true); });
|
if (alerted) {
|
||||||
|
m_trayIcon->updateTrayIcon(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
connect(qApp, &QCoreApplication::aboutToQuit, this, &FortManager::closeUi);
|
connect(qApp, &QCoreApplication::aboutToQuit, this, &FortManager::closeUi);
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,8 @@ void AppListModel::initialize()
|
|||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
connect(confManager(), &ConfManager::appEndTimesUpdated, this, &AppListModel::refresh);
|
connect(confManager(), &ConfManager::appEndTimesUpdated, this, &AppListModel::refresh);
|
||||||
|
connect(confManager(), &ConfManager::appAdded, this, &TableSqlModel::reset);
|
||||||
|
connect(confManager(), &ConfManager::appUpdated, this, &TableSqlModel::refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppListModel::handleLogBlocked(const LogEntryBlocked &logEntry)
|
void AppListModel::handleLogBlocked(const LogEntryBlocked &logEntry)
|
||||||
@ -70,10 +72,7 @@ void AppListModel::handleLogBlocked(const LogEntryBlocked &logEntry)
|
|||||||
const auto groupId = appGroupAt(0)->id();
|
const auto groupId = appGroupAt(0)->id();
|
||||||
const auto appName = appInfoCache()->appName(appPath);
|
const auto appName = appInfoCache()->appName(appPath);
|
||||||
|
|
||||||
if (confManager()->addApp(
|
confManager()->addApp(appPath, appName, QDateTime(), groupId, false, logEntry.blocked(), true);
|
||||||
appPath, appName, QDateTime(), groupId, false, logEntry.blocked(), true)) {
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int AppListModel::columnCount(const QModelIndex &parent) const
|
int AppListModel::columnCount(const QModelIndex &parent) const
|
||||||
@ -316,53 +315,31 @@ AppRow AppListModel::appRowByPath(const QString &appPath) const
|
|||||||
bool AppListModel::addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
bool AppListModel::addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
||||||
int groupIndex, bool useGroupPerm, bool blocked)
|
int groupIndex, bool useGroupPerm, bool blocked)
|
||||||
{
|
{
|
||||||
if (!confManager()->updateDriverUpdateApp(appPath, groupIndex, useGroupPerm, blocked))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const auto groupId = appGroupAt(groupIndex)->id();
|
const auto groupId = appGroupAt(groupIndex)->id();
|
||||||
|
|
||||||
if (confManager()->addApp(appPath, appName, endTime, groupId, useGroupPerm, blocked)) {
|
return confManager()->addApp(
|
||||||
reset();
|
appPath, appName, endTime, groupId, groupIndex, useGroupPerm, blocked);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppListModel::updateApp(qint64 appId, const QString &appPath, const QString &appName,
|
bool AppListModel::updateApp(qint64 appId, const QString &appPath, const QString &appName,
|
||||||
const QDateTime &endTime, int groupIndex, bool useGroupPerm, bool blocked)
|
const QDateTime &endTime, int groupIndex, bool useGroupPerm, bool blocked)
|
||||||
{
|
{
|
||||||
if (!confManager()->updateDriverUpdateApp(appPath, groupIndex, useGroupPerm, blocked))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const auto groupId = appGroupAt(groupIndex)->id();
|
const auto groupId = appGroupAt(groupIndex)->id();
|
||||||
|
|
||||||
if (confManager()->updateApp(appId, appName, endTime, groupId, useGroupPerm, blocked)) {
|
return confManager()->updateApp(
|
||||||
refresh();
|
appId, appPath, appName, endTime, groupId, groupIndex, useGroupPerm, blocked);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppListModel::updateAppName(qint64 appId, const QString &appName)
|
bool AppListModel::updateAppName(qint64 appId, const QString &appName)
|
||||||
{
|
{
|
||||||
if (confManager()->updateAppName(appId, appName)) {
|
return confManager()->updateAppName(appId, appName);
|
||||||
refresh();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppListModel::deleteApp(qint64 appId, const QString &appPath, int row)
|
void AppListModel::deleteApp(qint64 appId, const QString &appPath, int row)
|
||||||
{
|
{
|
||||||
if (!confManager()->updateDriverDeleteApp(appPath))
|
|
||||||
return;
|
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
|
|
||||||
if (confManager()->deleteApp(appId)) {
|
if (confManager()->deleteApp(appId, appPath)) {
|
||||||
invalidateRowCache();
|
invalidateRowCache();
|
||||||
removeRow(row);
|
removeRow(row);
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,11 @@ SqliteDb *ZoneListModel::sqliteDb() const
|
|||||||
|
|
||||||
void ZoneListModel::initialize()
|
void ZoneListModel::initialize()
|
||||||
{
|
{
|
||||||
initZoneTypes();
|
setupZoneTypes();
|
||||||
initZoneSources();
|
setupZoneSources();
|
||||||
|
|
||||||
|
connect(confManager(), &ConfManager::zoneAdded, this, &TableSqlModel::reset);
|
||||||
|
connect(confManager(), &ConfManager::zoneUpdated, this, &TableSqlModel::refresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZoneListModel::columnCount(const QModelIndex &parent) const
|
int ZoneListModel::columnCount(const QModelIndex &parent) const
|
||||||
@ -140,64 +143,32 @@ const ZoneRow &ZoneListModel::zoneRowAt(int row) const
|
|||||||
bool ZoneListModel::addZone(const QString &zoneName, const QString &sourceCode, const QString &url,
|
bool ZoneListModel::addZone(const QString &zoneName, const QString &sourceCode, const QString &url,
|
||||||
const QString &formData, bool enabled, bool customUrl, int &zoneId)
|
const QString &formData, bool enabled, bool customUrl, int &zoneId)
|
||||||
{
|
{
|
||||||
if (confManager()->addZone(zoneName, sourceCode, url, formData, enabled, customUrl, zoneId)) {
|
return confManager()->addZone(zoneName, sourceCode, url, formData, enabled, customUrl, zoneId);
|
||||||
reset();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZone(int zoneId, const QString &zoneName, const QString &sourceCode,
|
bool ZoneListModel::updateZone(int zoneId, const QString &zoneName, const QString &sourceCode,
|
||||||
const QString &url, const QString &formData, bool enabled, bool customUrl,
|
const QString &url, const QString &formData, bool enabled, bool customUrl)
|
||||||
bool updateDriver)
|
|
||||||
{
|
{
|
||||||
if (updateDriver && !confManager()->updateDriverZoneFlag(zoneId, enabled))
|
return confManager()->updateZone(
|
||||||
return false;
|
zoneId, zoneName, sourceCode, url, formData, enabled, customUrl);
|
||||||
|
|
||||||
if (confManager()->updateZone(
|
|
||||||
zoneId, zoneName, sourceCode, url, formData, enabled, customUrl)) {
|
|
||||||
refresh();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZoneName(int zoneId, const QString &zoneName)
|
bool ZoneListModel::updateZoneName(int zoneId, const QString &zoneName)
|
||||||
{
|
{
|
||||||
if (confManager()->updateZoneName(zoneId, zoneName)) {
|
return confManager()->updateZoneName(zoneId, zoneName);
|
||||||
refresh();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZoneEnabled(int zoneId, bool enabled)
|
bool ZoneListModel::updateZoneEnabled(int zoneId, bool enabled)
|
||||||
{
|
{
|
||||||
if (!confManager()->updateDriverZoneFlag(zoneId, enabled))
|
return confManager()->updateZoneEnabled(zoneId, enabled);
|
||||||
return false;
|
|
||||||
|
|
||||||
if (confManager()->updateZoneEnabled(zoneId, enabled)) {
|
|
||||||
refresh();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZoneResult(int zoneId, const QString &textChecksum,
|
bool ZoneListModel::updateZoneResult(int zoneId, const QString &textChecksum,
|
||||||
const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun,
|
const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun,
|
||||||
const QDateTime &lastSuccess)
|
const QDateTime &lastSuccess)
|
||||||
{
|
{
|
||||||
if (confManager()->updateZoneResult(
|
return confManager()->updateZoneResult(
|
||||||
zoneId, textChecksum, binChecksum, sourceModTime, lastRun, lastSuccess)) {
|
zoneId, textChecksum, binChecksum, sourceModTime, lastRun, lastSuccess);
|
||||||
refresh();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneListModel::deleteZone(int zoneId, int row)
|
void ZoneListModel::deleteZone(int zoneId, int row)
|
||||||
@ -205,7 +176,6 @@ void ZoneListModel::deleteZone(int zoneId, int row)
|
|||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
|
|
||||||
if (confManager()->deleteZone(zoneId)) {
|
if (confManager()->deleteZone(zoneId)) {
|
||||||
emit zoneRemoved(zoneId);
|
|
||||||
invalidateRowCache();
|
invalidateRowCache();
|
||||||
removeRow(row);
|
removeRow(row);
|
||||||
}
|
}
|
||||||
@ -275,7 +245,7 @@ QString ZoneListModel::sqlBase() const
|
|||||||
" FROM zone";
|
" FROM zone";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneListModel::initZoneTypes()
|
void ZoneListModel::setupZoneTypes()
|
||||||
{
|
{
|
||||||
const auto data = FileUtil::readFileData(":/zone/types.json");
|
const auto data = FileUtil::readFileData(":/zone/types.json");
|
||||||
if (data.isEmpty())
|
if (data.isEmpty())
|
||||||
@ -297,7 +267,7 @@ void ZoneListModel::initZoneTypes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneListModel::initZoneSources()
|
void ZoneListModel::setupZoneSources()
|
||||||
{
|
{
|
||||||
const auto data = FileUtil::readFileData(":/zone/sources.json");
|
const auto data = FileUtil::readFileData(":/zone/sources.json");
|
||||||
if (data.isEmpty())
|
if (data.isEmpty())
|
||||||
|
@ -56,8 +56,7 @@ public:
|
|||||||
bool addZone(const QString &zoneName, const QString &sourceCode, const QString &url,
|
bool addZone(const QString &zoneName, const QString &sourceCode, const QString &url,
|
||||||
const QString &formData, bool enabled, bool customUrl, int &zoneId);
|
const QString &formData, bool enabled, bool customUrl, int &zoneId);
|
||||||
bool updateZone(int zoneId, const QString &zoneName, const QString &sourceCode,
|
bool updateZone(int zoneId, const QString &zoneName, const QString &sourceCode,
|
||||||
const QString &url, const QString &formData, bool enabled, bool customUrl,
|
const QString &url, const QString &formData, bool enabled, bool customUrl);
|
||||||
bool updateDriver = true);
|
|
||||||
bool updateZoneName(int zoneId, const QString &zoneName);
|
bool updateZoneName(int zoneId, const QString &zoneName);
|
||||||
bool updateZoneEnabled(int zoneId, bool enabled);
|
bool updateZoneEnabled(int zoneId, bool enabled);
|
||||||
bool updateZoneResult(int zoneId, const QString &textChecksum, const QString &binChecksum,
|
bool updateZoneResult(int zoneId, const QString &textChecksum, const QString &binChecksum,
|
||||||
@ -71,9 +70,6 @@ public:
|
|||||||
QVariant zoneSourceByCode(const QString &sourceCode) const;
|
QVariant zoneSourceByCode(const QString &sourceCode) const;
|
||||||
const QVariantList &zoneSources() const { return m_zoneSources; }
|
const QVariantList &zoneSources() const { return m_zoneSources; }
|
||||||
|
|
||||||
signals:
|
|
||||||
void zoneRemoved(int zoneId);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool updateTableRow(int row) const override;
|
bool updateTableRow(int row) const override;
|
||||||
TableRow &tableRow() const override { return m_zoneRow; }
|
TableRow &tableRow() const override { return m_zoneRow; }
|
||||||
@ -84,9 +80,9 @@ private:
|
|||||||
QVariant dataDisplay(const QModelIndex &index) const;
|
QVariant dataDisplay(const QModelIndex &index) const;
|
||||||
QVariant dataCheckState(const QModelIndex &index) const;
|
QVariant dataCheckState(const QModelIndex &index) const;
|
||||||
|
|
||||||
void initZoneTypes();
|
void setupZoneTypes();
|
||||||
void initZoneSources();
|
void setupZoneSources();
|
||||||
void initZoneSourceNames();
|
void setupZoneSourceNames();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConfManager *m_confManager = nullptr;
|
ConfManager *m_confManager = nullptr;
|
||||||
|
@ -15,6 +15,8 @@ public:
|
|||||||
|
|
||||||
RpcManager *rpcManager() const;
|
RpcManager *rpcManager() const;
|
||||||
|
|
||||||
|
bool updateDriverConf(bool /*onlyFlags*/ = false) override { return false; }
|
||||||
|
|
||||||
void onConfChanged(const QVariant &confVar);
|
void onConfChanged(const QVariant &confVar);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user