From 66e7c88448b139b9bb9a407f1894a0d65d61a212 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Wed, 9 Oct 2019 13:56:41 +0500 Subject: [PATCH] UI: Rename Database* to Stat*. --- src/tests/FortFirewallTest.pro | 4 +- src/tests/{db/Db.pro => stat/Stat.pro} | 16 +- src/tests/{db => stat}/data.qrc | 0 src/tests/{db => stat}/data/migrations/1.sql | 0 src/tests/{db => stat}/data/migrations/2.sql | 0 src/tests/{db => stat}/data/migrations/3.sql | 0 src/tests/{db => stat}/test.cpp | 31 ++-- src/tests/{db => stat}/test.h | 0 src/ui/3rdparty/sqlite/sqlitedb.cpp | 2 +- src/ui/FortFirewall.pro | 16 +- src/ui/db/migrations/2.sql | 1 - src/ui/fortmanager.cpp | 26 +-- src/ui/fortmanager.h | 8 +- src/ui/i18n/i18n_ru.ts | 6 +- src/ui/log/logmanager.cpp | 4 +- src/ui/log/logmanager.h | 4 +- src/ui/log/model/appstatmodel.cpp | 22 +-- src/ui/log/model/appstatmodel.h | 7 +- src/ui/log/model/traflistmodel.cpp | 56 +++--- src/ui/log/model/traflistmodel.h | 6 +- src/ui/{db => stat}/migrations/1.sql | 0 src/ui/{db => stat}/quotamanager.cpp | 0 src/ui/{db => stat}/quotamanager.h | 0 .../stat-migrations.qrc} | 3 +- .../statmanager.cpp} | 173 +++++++++--------- .../databasemanager.h => stat/statmanager.h} | 18 +- .../{db/databasesql.cpp => stat/statsql.cpp} | 94 +++++----- src/ui/{db/databasesql.h => stat/statsql.h} | 8 +- src/ui/util/app/appinfomanager.cpp | 5 +- 29 files changed, 254 insertions(+), 256 deletions(-) rename src/tests/{db/Db.pro => stat/Stat.pro} (75%) rename src/tests/{db => stat}/data.qrc (100%) rename src/tests/{db => stat}/data/migrations/1.sql (100%) rename src/tests/{db => stat}/data/migrations/2.sql (100%) rename src/tests/{db => stat}/data/migrations/3.sql (100%) rename src/tests/{db => stat}/test.cpp (87%) rename src/tests/{db => stat}/test.h (100%) delete mode 100644 src/ui/db/migrations/2.sql rename src/ui/{db => stat}/migrations/1.sql (100%) rename src/ui/{db => stat}/quotamanager.cpp (100%) rename src/ui/{db => stat}/quotamanager.h (100%) rename src/ui/{db/db-migrations.qrc => stat/stat-migrations.qrc} (50%) rename src/ui/{db/databasemanager.cpp => stat/statmanager.cpp} (69%) rename src/ui/{db/databasemanager.h => stat/statmanager.h} (88%) rename src/ui/{db/databasesql.cpp => stat/statsql.cpp} (65%) rename src/ui/{db/databasesql.h => stat/statsql.h} (96%) diff --git a/src/tests/FortFirewallTest.pro b/src/tests/FortFirewallTest.pro index 45b7c6ce..5f5195f7 100644 --- a/src/tests/FortFirewallTest.pro +++ b/src/tests/FortFirewallTest.pro @@ -2,8 +2,8 @@ TEMPLATE = subdirs SUBDIRS = \ confutil \ - db \ fileutil \ logbuffer \ logreader \ - netutil + netutil \ + stat diff --git a/src/tests/db/Db.pro b/src/tests/stat/Stat.pro similarity index 75% rename from src/tests/db/Db.pro rename to src/tests/stat/Stat.pro index 56dbe1db..c0e06394 100644 --- a/src/tests/db/Db.pro +++ b/src/tests/stat/Stat.pro @@ -6,11 +6,11 @@ SOURCES += \ $$UIPATH/conf/addressgroup.cpp \ $$UIPATH/conf/appgroup.cpp \ $$UIPATH/conf/firewallconf.cpp \ - $$UIPATH/db/databasemanager.cpp \ - $$UIPATH/db/databasesql.cpp \ - $$UIPATH/db/quotamanager.cpp \ $$UIPATH/fortcommon.cpp \ $$UIPATH/fortsettings.cpp \ + $$UIPATH/stat/quotamanager.cpp \ + $$UIPATH/stat/statmanager.cpp \ + $$UIPATH/stat/statsql.cpp \ $$UIPATH/util/dateutil.cpp \ $$UIPATH/util/fileutil.cpp \ $$UIPATH/util/net/netutil.cpp \ @@ -21,11 +21,11 @@ HEADERS += \ $$UIPATH/conf/addressgroup.h \ $$UIPATH/conf/appgroup.h \ $$UIPATH/conf/firewallconf.h \ - $$UIPATH/db/databasemanager.h \ - $$UIPATH/db/databasesql.h \ - $$UIPATH/db/quotamanager.h \ $$UIPATH/fortcommon.h \ $$UIPATH/fortsettings.h \ + $$UIPATH/stat/quotamanager.h \ + $$UIPATH/stat/statmanager.h \ + $$UIPATH/stat/statsql.h \ $$UIPATH/util/dateutil.h \ $$UIPATH/util/fileutil.h \ $$UIPATH/util/net/netutil.h \ @@ -35,8 +35,8 @@ HEADERS += \ # Test Data RESOURCES += data.qrc -# Database Migrations -RESOURCES += $$UIPATH/db/db-migrations.qrc +# Stat Migrations +RESOURCES += $$UIPATH/stat/stat-migrations.qrc # 3rd party integrations CONFIG += sqlite diff --git a/src/tests/db/data.qrc b/src/tests/stat/data.qrc similarity index 100% rename from src/tests/db/data.qrc rename to src/tests/stat/data.qrc diff --git a/src/tests/db/data/migrations/1.sql b/src/tests/stat/data/migrations/1.sql similarity index 100% rename from src/tests/db/data/migrations/1.sql rename to src/tests/stat/data/migrations/1.sql diff --git a/src/tests/db/data/migrations/2.sql b/src/tests/stat/data/migrations/2.sql similarity index 100% rename from src/tests/db/data/migrations/2.sql rename to src/tests/stat/data/migrations/2.sql diff --git a/src/tests/db/data/migrations/3.sql b/src/tests/stat/data/migrations/3.sql similarity index 100% rename from src/tests/db/data/migrations/3.sql rename to src/tests/stat/data/migrations/3.sql diff --git a/src/tests/db/test.cpp b/src/tests/stat/test.cpp similarity index 87% rename from src/tests/db/test.cpp rename to src/tests/stat/test.cpp index 6808a8a6..6145fe70 100644 --- a/src/tests/db/test.cpp +++ b/src/tests/stat/test.cpp @@ -2,23 +2,24 @@ #include -#include "commontest.h" -#include "db/databasemanager.h" -#include "db/quotamanager.h" -#include "fortsettings.h" -#include "util/dateutil.h" -#include "util/fileutil.h" #include #include +#include "commontest.h" +#include "fortsettings.h" +#include "stat/quotamanager.h" +#include "stat/statmanager.h" +#include "util/dateutil.h" +#include "util/fileutil.h" + void Test::dbWriteRead() { QStringList args("test"); FortSettings fortSettings(args); QuotaManager quotaManager(&fortSettings); - DatabaseManager databaseManager(":memory:", "aManager); + StatManager statManager(":memory:", "aManager); - QVERIFY(databaseManager.initialize()); + QVERIFY(statManager.initialize()); const QStringList appPaths = QStringList() << "C:\\test\\test.exe" @@ -30,11 +31,11 @@ void Test::dbWriteRead() // Add apps quint32 index = 0; - foreach (const QString &appPath, appPaths) { - databaseManager.logProcNew(++index * 10, appPath); + for (const QString &appPath : appPaths) { + statManager.logProcNew(++index * 10, appPath); } - debugProcNew(databaseManager.sqliteDb()); + debugProcNew(statManager.sqliteDb()); QElapsedTimer timer; timer.start(); @@ -47,8 +48,8 @@ void Test::dbWriteRead() 30, 500, 600 }; - databaseManager.logStatTraf(procCount, trafBytes); - databaseManager.logStatTraf(procCount, trafBytes); + statManager.logStatTraf(procCount, trafBytes); + statManager.logStatTraf(procCount, trafBytes); } qDebug() << "elapsed>" << timer.restart() << "msec"; @@ -61,12 +62,12 @@ void Test::dbWriteRead() 31, 50, 60 }; - databaseManager.logStatTraf(procCount, trafBytes); + statManager.logStatTraf(procCount, trafBytes); } qDebug() << "elapsed>" << timer.elapsed() << "msec"; - debugStatTraf(databaseManager.sqliteDb()); + debugStatTraf(statManager.sqliteDb()); } void Test::debugProcNew(SqliteDb *sqliteDb) diff --git a/src/tests/db/test.h b/src/tests/stat/test.h similarity index 100% rename from src/tests/db/test.h rename to src/tests/stat/test.h diff --git a/src/ui/3rdparty/sqlite/sqlitedb.cpp b/src/ui/3rdparty/sqlite/sqlitedb.cpp index c739cd56..d6e827c7 100644 --- a/src/ui/3rdparty/sqlite/sqlitedb.cpp +++ b/src/ui/3rdparty/sqlite/sqlitedb.cpp @@ -338,7 +338,7 @@ bool SqliteDb::migrate(const QString &sqlDir, int version, QFile file(filePath); if (!file.exists()) - break; + continue; if (!file.open(QFile::ReadOnly | QFile::Text)) { qWarning() << "SQLite: Cannot open migration file" << filePath diff --git a/src/ui/FortFirewall.pro b/src/ui/FortFirewall.pro index 83204b20..f397a943 100644 --- a/src/ui/FortFirewall.pro +++ b/src/ui/FortFirewall.pro @@ -16,9 +16,6 @@ SOURCES += \ conf/firewallconf.cpp \ control/controlmanager.cpp \ control/controlworker.cpp \ - db/databasemanager.cpp \ - db/databasesql.cpp \ - db/quotamanager.cpp \ driver/drivermanager.cpp \ driver/driverworker.cpp \ fortcommon.cpp \ @@ -40,6 +37,9 @@ SOURCES += \ log/model/stringlistmodel.cpp \ log/model/traflistmodel.cpp \ mainwindow.cpp \ + stat/quotamanager.cpp \ + stat/statmanager.cpp \ + stat/statsql.cpp \ task/taskdownloader.cpp \ task/taskinfo.cpp \ task/taskmanager.cpp \ @@ -87,9 +87,6 @@ HEADERS += \ conf/firewallconf.h \ control/controlmanager.h \ control/controlworker.h \ - db/databasemanager.h \ - db/databasesql.h \ - db/quotamanager.h \ driver/drivermanager.h \ driver/driverworker.h \ fortcommon.h \ @@ -111,6 +108,9 @@ HEADERS += \ log/model/stringlistmodel.h \ log/model/traflistmodel.h \ mainwindow.h \ + stat/quotamanager.h \ + stat/statmanager.h \ + stat/statsql.h \ task/taskdownloader.h \ task/taskinfo.h \ task/taskmanager.h \ @@ -175,11 +175,11 @@ RESOURCES += fort_images.qrc # Database Migrations OTHER_FILES += \ - db/migrations/*.sql \ + stat/migrations/*.sql \ util/app/migrations/*.sql RESOURCES += \ - db/db-migrations.qrc \ + stat/stat-migrations.qrc \ util/app/app-migrations.qrc # Shadow Build: Copy i18n/ to build path diff --git a/src/ui/db/migrations/2.sql b/src/ui/db/migrations/2.sql deleted file mode 100644 index 81497510..00000000 --- a/src/ui/db/migrations/2.sql +++ /dev/null @@ -1 +0,0 @@ -PRAGMA user_version = 2; diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 091ad15d..24fb17b8 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -15,8 +15,6 @@ #include "conf/addressgroup.h" #include "conf/appgroup.h" #include "conf/firewallconf.h" -#include "db/databasemanager.h" -#include "db/quotamanager.h" #include "driver/drivermanager.h" #include "fortsettings.h" #include "graph/graphwindow.h" @@ -25,6 +23,8 @@ #include "log/model/appstatmodel.h" #include "log/model/iplistmodel.h" #include "log/model/traflistmodel.h" +#include "stat/quotamanager.h" +#include "stat/statmanager.h" #include "task/taskinfo.h" #include "task/taskmanager.h" #include "translationmanager.h" @@ -61,10 +61,10 @@ FortManager::FortManager(FortSettings *fortSettings, m_stopTrafficAction(nullptr), m_stopInetTrafficAction(nullptr), m_quotaManager(new QuotaManager(fortSettings, this)), - m_databaseManager(new DatabaseManager(fortSettings->statFilePath(), - m_quotaManager, this)), + m_statManager(new StatManager(fortSettings->statFilePath(), + m_quotaManager, this)), m_driverManager(new DriverManager(this)), - m_logManager(new LogManager(m_databaseManager, + m_logManager(new LogManager(m_statManager, m_driverManager->driverWorker(), this)), m_nativeEventFilter(new NativeEventFilter(this)), m_hotKeyManager(new HotKeyManager(m_nativeEventFilter, this)), @@ -75,7 +75,7 @@ FortManager::FortManager(FortSettings *fortSettings, setupLogger(); setupAppInfoCache(); - setupDatabaseManager(); + setupStatManager(); setupLogManager(); setupDriver(); @@ -179,7 +179,7 @@ bool FortManager::setupDriver() void FortManager::closeDriver() { updateLogManager(false); - updateDatabaseManager(nullptr); + updateStatManager(nullptr); m_driverManager->closeDevice(); } @@ -194,9 +194,9 @@ void FortManager::closeLogManager() m_logManager->close(); } -void FortManager::setupDatabaseManager() +void FortManager::setupStatManager() { - m_databaseManager->initialize(); + m_statManager->initialize(); connect(m_quotaManager, &QuotaManager::alert, this, &FortManager::showInfoBox); @@ -377,7 +377,7 @@ void FortManager::showGraphWindow() connect(m_graphWindow, &GraphWindow::mouseRightClick, this, &FortManager::showTrayMenu); - connect(m_databaseManager, &DatabaseManager::trafficAdded, + connect(m_statManager, &StatManager::trafficAdded, m_graphWindow, &GraphWindow::addTraffic); } @@ -563,7 +563,7 @@ bool FortManager::updateDriverConf(FirewallConf *conf, bool onlyFlags) : m_driverManager->writeConf(*conf); if (res) { - updateDatabaseManager(conf); + updateStatManager(conf); updateLogManager(true); } else { closeDriver(); @@ -577,9 +577,9 @@ void FortManager::updateLogManager(bool active) m_logManager->setActive(active); } -void FortManager::updateDatabaseManager(FirewallConf *conf) +void FortManager::updateStatManager(FirewallConf *conf) { - m_databaseManager->setFirewallConf(conf); + m_statManager->setFirewallConf(conf); } void FortManager::setLanguage(int language) diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index ab88df20..9949645f 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -10,7 +10,6 @@ QT_FORWARD_DECLARE_CLASS(QQmlApplicationEngine) QT_FORWARD_DECLARE_CLASS(QSystemTrayIcon) QT_FORWARD_DECLARE_CLASS(AppInfoCache) -QT_FORWARD_DECLARE_CLASS(DatabaseManager) QT_FORWARD_DECLARE_CLASS(DriverManager) QT_FORWARD_DECLARE_CLASS(FirewallConf) QT_FORWARD_DECLARE_CLASS(FortSettings) @@ -19,6 +18,7 @@ QT_FORWARD_DECLARE_CLASS(HotKeyManager) QT_FORWARD_DECLARE_CLASS(LogManager) QT_FORWARD_DECLARE_CLASS(NativeEventFilter) QT_FORWARD_DECLARE_CLASS(QuotaManager) +QT_FORWARD_DECLARE_CLASS(StatManager) QT_FORWARD_DECLARE_CLASS(TaskManager) QT_FORWARD_DECLARE_CLASS(WidgetWindowStateWatcher) QT_FORWARD_DECLARE_CLASS(WindowStateWatcher) @@ -107,7 +107,7 @@ private: void setupLogManager(); void closeLogManager(); - void setupDatabaseManager(); + void setupStatManager(); void setupLogger(); @@ -129,7 +129,7 @@ private: bool updateDriverConf(FirewallConf *conf, bool onlyFlags = false); void updateLogManager(bool active); - void updateDatabaseManager(FirewallConf *conf); + void updateStatManager(FirewallConf *conf); FirewallConf *cloneConf(const FirewallConf &conf); @@ -176,7 +176,7 @@ private: QList m_appGroupActions; QuotaManager *m_quotaManager; - DatabaseManager *m_databaseManager; + StatManager *m_statManager; DriverManager *m_driverManager; LogManager *m_logManager; NativeEventFilter *m_nativeEventFilter; diff --git a/src/ui/i18n/i18n_ru.ts b/src/ui/i18n/i18n_ru.ts index 28d769c5..fdbafdb5 100644 --- a/src/ui/i18n/i18n_ru.ts +++ b/src/ui/i18n/i18n_ru.ts @@ -145,17 +145,17 @@ QuotaManager - + Day traffic quota exceeded! Квота трафика на день исчерпана! - + Month traffic quota exceeded! Квота трафика на месяц исчерпана! - + Quota Alert Предупреждение о квоте трафика diff --git a/src/ui/log/logmanager.cpp b/src/ui/log/logmanager.cpp index cdf6b478..b39ebd40 100644 --- a/src/ui/log/logmanager.cpp +++ b/src/ui/log/logmanager.cpp @@ -13,14 +13,14 @@ #include "model/appblockedmodel.h" #include "model/appstatmodel.h" -LogManager::LogManager(DatabaseManager *databaseManager, +LogManager::LogManager(StatManager *statManager, DriverWorker *driverWorker, QObject *parent) : QObject(parent), m_active(false), m_driverWorker(driverWorker), m_appBlockedModel(new AppBlockedModel(this)), - m_appStatModel(new AppStatModel(databaseManager, this)) + m_appStatModel(new AppStatModel(statManager, this)) { } diff --git a/src/ui/log/logmanager.h b/src/ui/log/logmanager.h index 7dfeafa6..31fe5f91 100644 --- a/src/ui/log/logmanager.h +++ b/src/ui/log/logmanager.h @@ -5,7 +5,7 @@ QT_FORWARD_DECLARE_CLASS(AppBlockedModel) QT_FORWARD_DECLARE_CLASS(AppStatModel) -QT_FORWARD_DECLARE_CLASS(DatabaseManager) +QT_FORWARD_DECLARE_CLASS(StatManager) QT_FORWARD_DECLARE_CLASS(DriverWorker) QT_FORWARD_DECLARE_CLASS(LogBuffer) QT_FORWARD_DECLARE_CLASS(LogEntry) @@ -18,7 +18,7 @@ class LogManager : public QObject Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) public: - explicit LogManager(DatabaseManager *databaseManager, + explicit LogManager(StatManager *statManager, DriverWorker *driverWorker, QObject *parent = nullptr); diff --git a/src/ui/log/model/appstatmodel.cpp b/src/ui/log/model/appstatmodel.cpp index 33e191f9..fbab1410 100644 --- a/src/ui/log/model/appstatmodel.cpp +++ b/src/ui/log/model/appstatmodel.cpp @@ -1,17 +1,17 @@ #include "appstatmodel.h" -#include "../../db/databasemanager.h" +#include "../../stat/statmanager.h" #include "../logentryprocnew.h" #include "../logentrystattraf.h" #include "traflistmodel.h" -AppStatModel::AppStatModel(DatabaseManager *databaseManager, +AppStatModel::AppStatModel(StatManager *statManager, QObject *parent) : StringListModel(parent), - m_databaseManager(databaseManager), - m_trafListModel(new TrafListModel(databaseManager, this)) + m_statManager(statManager), + m_trafListModel(new TrafListModel(statManager, this)) { - connect(m_databaseManager, &DatabaseManager::appCreated, + connect(m_statManager, &StatManager::appCreated, this, &AppStatModel::handleCreatedApp); } @@ -48,7 +48,7 @@ void AppStatModel::remove(int row) const qint64 appId = m_appIds.at(row); - m_databaseManager->deleteApp(appId); + m_statManager->deleteApp(appId); m_appIds.remove(row); @@ -65,7 +65,7 @@ void AppStatModel::updateList() m_appIds.clear(); m_appIds.append(0); // All - m_databaseManager->getAppList(list, m_appIds); + m_statManager->getAppList(list, m_appIds); setList(list); } @@ -78,12 +78,12 @@ void AppStatModel::handleCreatedApp(qint64 appId, const QString &appPath) void AppStatModel::handleProcNew(const LogEntryProcNew &procNewEntry) { - m_databaseManager->logProcNew(procNewEntry.pid(), - procNewEntry.path()); + m_statManager->logProcNew(procNewEntry.pid(), + procNewEntry.path()); } void AppStatModel::handleStatTraf(const LogEntryStatTraf &statTrafEntry) { - m_databaseManager->logStatTraf(statTrafEntry.procCount(), - statTrafEntry.procTrafBytes()); + m_statManager->logStatTraf(statTrafEntry.procCount(), + statTrafEntry.procTrafBytes()); } diff --git a/src/ui/log/model/appstatmodel.h b/src/ui/log/model/appstatmodel.h index ca0b0006..e7c44f71 100644 --- a/src/ui/log/model/appstatmodel.h +++ b/src/ui/log/model/appstatmodel.h @@ -3,9 +3,9 @@ #include "stringlistmodel.h" -QT_FORWARD_DECLARE_CLASS(DatabaseManager) QT_FORWARD_DECLARE_CLASS(LogEntryProcNew) QT_FORWARD_DECLARE_CLASS(LogEntryStatTraf) +QT_FORWARD_DECLARE_CLASS(StatManager) QT_FORWARD_DECLARE_CLASS(TrafListModel) class AppStatModel : public StringListModel @@ -13,7 +13,7 @@ class AppStatModel : public StringListModel Q_OBJECT public: - explicit AppStatModel(DatabaseManager *databaseManager, + explicit AppStatModel(StatManager *statManager, QObject *parent = nullptr); void initialize(); @@ -38,8 +38,7 @@ private: void updateList(); private: - DatabaseManager *m_databaseManager; - + StatManager *m_statManager; TrafListModel *m_trafListModel; QVector m_appIds; diff --git a/src/ui/log/model/traflistmodel.cpp b/src/ui/log/model/traflistmodel.cpp index bbdb1a07..2bf2293a 100644 --- a/src/ui/log/model/traflistmodel.cpp +++ b/src/ui/log/model/traflistmodel.cpp @@ -3,12 +3,12 @@ #include #include "../../conf/firewallconf.h" -#include "../../db/databasemanager.h" -#include "../../db/databasesql.h" +#include "../../stat/statmanager.h" +#include "../../stat/statsql.h" #include "../../util/dateutil.h" #include "../../util/net/netutil.h" -TrafListModel::TrafListModel(DatabaseManager *databaseManager, +TrafListModel::TrafListModel(StatManager *statManager, QObject *parent) : QAbstractItemModel(parent), m_isEmpty(false), @@ -17,7 +17,7 @@ TrafListModel::TrafListModel(DatabaseManager *databaseManager, m_minTrafTime(0), m_maxTrafTime(0), m_trafCount(0), - m_databaseManager(databaseManager) + m_statManager(statManager) { } @@ -98,14 +98,14 @@ Qt::ItemFlags TrafListModel::flags(const QModelIndex &index) const void TrafListModel::clear() { - m_databaseManager->clear(); + m_statManager->clear(); reset(); } void TrafListModel::resetAppTotals() { - m_databaseManager->resetAppTotals(); + m_statManager->resetAppTotals(); reset(); } @@ -116,8 +116,7 @@ void TrafListModel::reset() beginResetModel(); - m_minTrafTime = m_databaseManager->getTrafficTime( - sqlMinTrafTime, m_appId); + m_minTrafTime = m_statManager->getTrafficTime(sqlMinTrafTime, m_appId); m_maxTrafTime = getMaxTrafTime(m_type); @@ -157,10 +156,9 @@ void TrafListModel::updateRowCache(int row) const const char *sqlSelectTraffic = getSqlSelectTraffic(m_type, m_appId); - m_databaseManager->getTraffic( - sqlSelectTraffic, m_rowCache.trafTime, - m_rowCache.inBytes, m_rowCache.outBytes, - m_appId); + m_statManager->getTraffic(sqlSelectTraffic, m_rowCache.trafTime, + m_rowCache.inBytes, m_rowCache.outBytes, + m_appId); } QString TrafListModel::formatTrafUnit(qint64 bytes) const @@ -178,7 +176,7 @@ QString TrafListModel::formatTrafUnit(qint64 bytes) const return QLatin1String("0"); } - const FirewallConf *conf = m_databaseManager->firewallConf(); + const FirewallConf *conf = m_statManager->firewallConf(); const int trafUnit = conf ? conf->trafUnit() : 0; const int trafPrec = (trafUnit == FirewallConf::UnitBytes) ? 0 : 2; @@ -255,14 +253,14 @@ qint32 TrafListModel::getMaxTrafTime(TrafType type) const char *TrafListModel::getSqlMinTrafTime(TrafType type, qint64 appId) { switch (type) { - case TrafHourly: return appId ? DatabaseSql::sqlSelectMinTrafAppHour - : DatabaseSql::sqlSelectMinTrafHour; - case TrafDaily: return appId ? DatabaseSql::sqlSelectMinTrafAppDay - : DatabaseSql::sqlSelectMinTrafDay; - case TrafMonthly: return appId ? DatabaseSql::sqlSelectMinTrafAppMonth - : DatabaseSql::sqlSelectMinTrafMonth; - case TrafTotal: return appId ? DatabaseSql::sqlSelectMinTrafAppTotal - : DatabaseSql::sqlSelectMinTrafTotal; + case TrafHourly: return appId ? StatSql::sqlSelectMinTrafAppHour + : StatSql::sqlSelectMinTrafHour; + case TrafDaily: return appId ? StatSql::sqlSelectMinTrafAppDay + : StatSql::sqlSelectMinTrafDay; + case TrafMonthly: return appId ? StatSql::sqlSelectMinTrafAppMonth + : StatSql::sqlSelectMinTrafMonth; + case TrafTotal: return appId ? StatSql::sqlSelectMinTrafAppTotal + : StatSql::sqlSelectMinTrafTotal; } Q_UNREACHABLE(); @@ -272,14 +270,14 @@ const char *TrafListModel::getSqlMinTrafTime(TrafType type, qint64 appId) const char *TrafListModel::getSqlSelectTraffic(TrafType type, qint64 appId) { switch (type) { - case TrafHourly: return appId ? DatabaseSql::sqlSelectTrafAppHour - : DatabaseSql::sqlSelectTrafHour; - case TrafDaily: return appId ? DatabaseSql::sqlSelectTrafAppDay - : DatabaseSql::sqlSelectTrafDay; - case TrafMonthly: return appId ? DatabaseSql::sqlSelectTrafAppMonth - : DatabaseSql::sqlSelectTrafMonth; - case TrafTotal: return appId ? DatabaseSql::sqlSelectTrafAppTotal - : DatabaseSql::sqlSelectTrafTotal; + case TrafHourly: return appId ? StatSql::sqlSelectTrafAppHour + : StatSql::sqlSelectTrafHour; + case TrafDaily: return appId ? StatSql::sqlSelectTrafAppDay + : StatSql::sqlSelectTrafDay; + case TrafMonthly: return appId ? StatSql::sqlSelectTrafAppMonth + : StatSql::sqlSelectTrafMonth; + case TrafTotal: return appId ? StatSql::sqlSelectTrafAppTotal + : StatSql::sqlSelectTrafTotal; } Q_UNREACHABLE(); diff --git a/src/ui/log/model/traflistmodel.h b/src/ui/log/model/traflistmodel.h index dfcd93db..25faa533 100644 --- a/src/ui/log/model/traflistmodel.h +++ b/src/ui/log/model/traflistmodel.h @@ -3,7 +3,7 @@ #include -QT_FORWARD_DECLARE_CLASS(DatabaseManager) +QT_FORWARD_DECLARE_CLASS(StatManager) struct TrafficRow { bool isValid(int row) const { return row == this->row; } @@ -28,7 +28,7 @@ public: }; Q_ENUM(TrafType) - explicit TrafListModel(DatabaseManager *databaseManager, + explicit TrafListModel(StatManager *statManager, QObject *parent = nullptr); TrafListModel::TrafType type() const { return m_type; } @@ -90,7 +90,7 @@ private: mutable TrafficRow m_rowCache; - DatabaseManager *m_databaseManager; + StatManager *m_statManager; }; #endif // TRAFLISTMODEL_H diff --git a/src/ui/db/migrations/1.sql b/src/ui/stat/migrations/1.sql similarity index 100% rename from src/ui/db/migrations/1.sql rename to src/ui/stat/migrations/1.sql diff --git a/src/ui/db/quotamanager.cpp b/src/ui/stat/quotamanager.cpp similarity index 100% rename from src/ui/db/quotamanager.cpp rename to src/ui/stat/quotamanager.cpp diff --git a/src/ui/db/quotamanager.h b/src/ui/stat/quotamanager.h similarity index 100% rename from src/ui/db/quotamanager.h rename to src/ui/stat/quotamanager.h diff --git a/src/ui/db/db-migrations.qrc b/src/ui/stat/stat-migrations.qrc similarity index 50% rename from src/ui/db/db-migrations.qrc rename to src/ui/stat/stat-migrations.qrc index 35bb7607..5a7fbf31 100644 --- a/src/ui/db/db-migrations.qrc +++ b/src/ui/stat/stat-migrations.qrc @@ -1,6 +1,5 @@ - + migrations/1.sql - migrations/2.sql diff --git a/src/ui/db/databasemanager.cpp b/src/ui/stat/statmanager.cpp similarity index 69% rename from src/ui/db/databasemanager.cpp rename to src/ui/stat/statmanager.cpp index e06a27a7..49739de8 100644 --- a/src/ui/db/databasemanager.cpp +++ b/src/ui/stat/statmanager.cpp @@ -1,19 +1,20 @@ -#include "databasemanager.h" +#include "statmanager.h" #include +#include +#include + #include "../conf/firewallconf.h" #include "../fortcommon.h" #include "../util/dateutil.h" #include "../util/fileutil.h" #include "../util/osutil.h" -#include "databasesql.h" #include "quotamanager.h" -#include -#include +#include "statsql.h" -Q_DECLARE_LOGGING_CATEGORY(CLOG_DATABASE_MANAGER) -Q_LOGGING_CATEGORY(CLOG_DATABASE_MANAGER, "fort.databaseManager") +Q_DECLARE_LOGGING_CATEGORY(CLOG_STAT_MANAGER) +Q_LOGGING_CATEGORY(CLOG_STAT_MANAGER, "fort.statManager") #define DATABASE_USER_VERSION 2 @@ -51,9 +52,9 @@ bool migrateFunc(SqliteDb *db, int version, void *ctx) } -DatabaseManager::DatabaseManager(const QString &filePath, - QuotaManager *quotaManager, - QObject *parent) : +StatManager::StatManager(const QString &filePath, + QuotaManager *quotaManager, + QObject *parent) : QObject(parent), m_isActivePeriodSet(false), m_isActivePeriod(false), @@ -73,14 +74,14 @@ DatabaseManager::DatabaseManager(const QString &filePath, { } -DatabaseManager::~DatabaseManager() +StatManager::~StatManager() { clearStmts(); delete m_sqliteDb; } -void DatabaseManager::setFirewallConf(const FirewallConf *conf) +void StatManager::setFirewallConf(const FirewallConf *conf) { m_conf = conf; @@ -92,29 +93,29 @@ void DatabaseManager::setFirewallConf(const FirewallConf *conf) initializeQuota(); } -bool DatabaseManager::initialize() +bool StatManager::initialize() { m_lastTrafHour = m_lastTrafDay = m_lastTrafMonth = 0; if (!m_sqliteDb->open(m_filePath)) { - qCritical(CLOG_DATABASE_MANAGER()) << "File open error:" - << m_filePath - << m_sqliteDb->errorMessage(); + qCritical(CLOG_STAT_MANAGER()) << "File open error:" + << m_filePath + << m_sqliteDb->errorMessage(); return false; } - m_sqliteDb->execute(DatabaseSql::sqlPragmas); + m_sqliteDb->execute(StatSql::sqlPragmas); - if (!m_sqliteDb->migrate(":/db/migrations", DATABASE_USER_VERSION, + if (!m_sqliteDb->migrate(":/stat/migrations", DATABASE_USER_VERSION, false, &migrateFunc)) { - qCritical(CLOG_DATABASE_MANAGER()) << "Migration error" << m_filePath; + qCritical(CLOG_STAT_MANAGER()) << "Migration error" << m_filePath; return false; } return true; } -void DatabaseManager::initializeActivePeriod() +void StatManager::initializeActivePeriod() { m_isActivePeriodSet = false; @@ -126,7 +127,7 @@ void DatabaseManager::initializeActivePeriod() activePeriodToHour, activePeriodToMinute); } -void DatabaseManager::initializeQuota() +void StatManager::initializeQuota() { if (!m_conf) return; @@ -140,14 +141,14 @@ void DatabaseManager::initializeQuota() qint64 inBytes, outBytes; - getTraffic(DatabaseSql::sqlSelectTrafDay, trafDay, inBytes, outBytes); + getTraffic(StatSql::sqlSelectTrafDay, trafDay, inBytes, outBytes); m_quotaManager->setTrafDayBytes(inBytes); - getTraffic(DatabaseSql::sqlSelectTrafMonth, trafMonth, inBytes, outBytes); + getTraffic(StatSql::sqlSelectTrafMonth, trafMonth, inBytes, outBytes); m_quotaManager->setTrafMonthBytes(inBytes); } -void DatabaseManager::clear() +void StatManager::clear() { clearAppIds(); clearStmts(); @@ -161,23 +162,23 @@ void DatabaseManager::clear() m_quotaManager->clear(); } -void DatabaseManager::clearStmts() +void StatManager::clearStmts() { qDeleteAll(m_sqliteStmts); m_sqliteStmts.clear(); } -void DatabaseManager::replaceAppPathAt(int index, const QString &appPath) +void StatManager::replaceAppPathAt(int index, const QString &appPath) { m_appPaths.replace(index, appPath); } -void DatabaseManager::replaceAppIdAt(int index, qint64 appId) +void StatManager::replaceAppIdAt(int index, qint64 appId) { m_appIds.replace(index, appId); } -void DatabaseManager::clearAppId(qint64 appId) +void StatManager::clearAppId(qint64 appId) { const int index = m_appIds.indexOf(appId); @@ -186,7 +187,7 @@ void DatabaseManager::clearAppId(qint64 appId) } } -void DatabaseManager::clearAppIds() +void StatManager::clearAppIds() { int index = m_appIds.size(); @@ -195,7 +196,7 @@ void DatabaseManager::clearAppIds() } } -void DatabaseManager::logClear() +void StatManager::logClear() { m_appFreeIndex = INVALID_APP_INDEX; m_appFreeIndexes.clear(); @@ -204,7 +205,7 @@ void DatabaseManager::logClear() m_appIds.clear(); } -void DatabaseManager::logClearApp(quint32 pid, int index) +void StatManager::logClearApp(quint32 pid, int index) { m_appIndexes.remove(pid); @@ -223,7 +224,7 @@ void DatabaseManager::logClearApp(quint32 pid, int index) } } -void DatabaseManager::logProcNew(quint32 pid, const QString &appPath) +void StatManager::logProcNew(quint32 pid, const QString &appPath) { Q_ASSERT(!m_appIndexes.contains(pid)); @@ -257,7 +258,7 @@ void DatabaseManager::logProcNew(quint32 pid, const QString &appPath) m_appIndexes.insert(pid, procIndex); } -void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafBytes) +void StatManager::logStatTraf(quint16 procCount, const quint32 *procTrafBytes) { if (!m_conf || !m_conf->logStat()) return; @@ -311,27 +312,27 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte // Insert Statements const QStmtList insertTrafAppStmts = QStmtList() - << getTrafficStmt(DatabaseSql::sqlInsertTrafAppHour, trafHour) - << getTrafficStmt(DatabaseSql::sqlInsertTrafAppDay, trafDay) - << getTrafficStmt(DatabaseSql::sqlInsertTrafAppMonth, trafMonth) - << getTrafficStmt(DatabaseSql::sqlUpdateTrafAppTotal, -1); + << getTrafficStmt(StatSql::sqlInsertTrafAppHour, trafHour) + << getTrafficStmt(StatSql::sqlInsertTrafAppDay, trafDay) + << getTrafficStmt(StatSql::sqlInsertTrafAppMonth, trafMonth) + << getTrafficStmt(StatSql::sqlUpdateTrafAppTotal, -1); const QStmtList insertTrafStmts = QStmtList() - << getTrafficStmt(DatabaseSql::sqlInsertTrafHour, trafHour) - << getTrafficStmt(DatabaseSql::sqlInsertTrafDay, trafDay) - << getTrafficStmt(DatabaseSql::sqlInsertTrafMonth, trafMonth); + << getTrafficStmt(StatSql::sqlInsertTrafHour, trafHour) + << getTrafficStmt(StatSql::sqlInsertTrafDay, trafDay) + << getTrafficStmt(StatSql::sqlInsertTrafMonth, trafMonth); // Update Statements const QStmtList updateTrafAppStmts = QStmtList() - << getTrafficStmt(DatabaseSql::sqlUpdateTrafAppHour, trafHour) - << getTrafficStmt(DatabaseSql::sqlUpdateTrafAppDay, trafDay) - << getTrafficStmt(DatabaseSql::sqlUpdateTrafAppMonth, trafMonth) - << getTrafficStmt(DatabaseSql::sqlUpdateTrafAppTotal, -1); + << getTrafficStmt(StatSql::sqlUpdateTrafAppHour, trafHour) + << getTrafficStmt(StatSql::sqlUpdateTrafAppDay, trafDay) + << getTrafficStmt(StatSql::sqlUpdateTrafAppMonth, trafMonth) + << getTrafficStmt(StatSql::sqlUpdateTrafAppTotal, -1); const QStmtList updateTrafStmts = QStmtList() - << getTrafficStmt(DatabaseSql::sqlUpdateTrafHour, trafHour) - << getTrafficStmt(DatabaseSql::sqlUpdateTrafDay, trafDay) - << getTrafficStmt(DatabaseSql::sqlUpdateTrafMonth, trafMonth); + << getTrafficStmt(StatSql::sqlUpdateTrafHour, trafHour) + << getTrafficStmt(StatSql::sqlUpdateTrafDay, trafDay) + << getTrafficStmt(StatSql::sqlUpdateTrafMonth, trafMonth); for (int i = 0; i < procCount; ++i) { quint32 pid = *procTrafBytes++; @@ -345,9 +346,9 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte const int procIndex = m_appIndexes.value(pid, INVALID_APP_INDEX); if (Q_UNLIKELY(procIndex == INVALID_APP_INDEX)) { - qCritical(CLOG_DATABASE_MANAGER()) << "UI & Driver's states mismatch! Expected processes:" - << m_appIndexes.keys() << "Got:" << procCount - << "(" << i << pid << inactive << ")"; + qCritical(CLOG_STAT_MANAGER()) << "UI & Driver's states mismatch! Expected processes:" + << m_appIndexes.keys() << "Got:" << procCount + << "(" << i << pid << inactive << ")"; abort(); } @@ -395,8 +396,8 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte const qint32 oldTrafHour = trafHour - 24 * trafHourKeepDays; deleteTrafStmts - << getTrafficStmt(DatabaseSql::sqlDeleteTrafAppHour, oldTrafHour) - << getTrafficStmt(DatabaseSql::sqlDeleteTrafHour, oldTrafHour); + << getTrafficStmt(StatSql::sqlDeleteTrafAppHour, oldTrafHour) + << getTrafficStmt(StatSql::sqlDeleteTrafHour, oldTrafHour); } // Traffic Day @@ -405,8 +406,8 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte const qint32 oldTrafDay = trafHour - 24 * trafDayKeepDays; deleteTrafStmts - << getTrafficStmt(DatabaseSql::sqlDeleteTrafAppDay, oldTrafDay) - << getTrafficStmt(DatabaseSql::sqlDeleteTrafDay, oldTrafDay); + << getTrafficStmt(StatSql::sqlDeleteTrafAppDay, oldTrafDay) + << getTrafficStmt(StatSql::sqlDeleteTrafDay, oldTrafDay); } // Traffic Month @@ -416,8 +417,8 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte trafHour, -trafMonthKeepMonths); deleteTrafStmts - << getTrafficStmt(DatabaseSql::sqlDeleteTrafAppMonth, oldTrafMonth) - << getTrafficStmt(DatabaseSql::sqlDeleteTrafMonth, oldTrafMonth); + << getTrafficStmt(StatSql::sqlDeleteTrafAppMonth, oldTrafMonth) + << getTrafficStmt(StatSql::sqlDeleteTrafMonth, oldTrafMonth); } stepStmtList(deleteTrafStmts); @@ -435,25 +436,25 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte emit trafficAdded(unixTime, sumInBytes, sumOutBytes); } -void DatabaseManager::deleteApp(qint64 appId) +void StatManager::deleteApp(qint64 appId) { clearAppId(appId); // Delete Statements const QStmtList deleteAppStmts = QStmtList() - << getAppStmt(DatabaseSql::sqlDeleteAppTrafHour, appId) - << getAppStmt(DatabaseSql::sqlDeleteAppTrafDay, appId) - << getAppStmt(DatabaseSql::sqlDeleteAppTrafMonth, appId) - << getAppStmt(DatabaseSql::sqlDeleteAppId, appId); + << getAppStmt(StatSql::sqlDeleteAppTrafHour, appId) + << getAppStmt(StatSql::sqlDeleteAppTrafDay, appId) + << getAppStmt(StatSql::sqlDeleteAppTrafMonth, appId) + << getAppStmt(StatSql::sqlDeleteAppId, appId); stepStmtList(deleteAppStmts); } -void DatabaseManager::resetAppTotals() +void StatManager::resetAppTotals() { m_sqliteDb->beginTransaction(); - SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlResetAppTrafTotals); + SqliteStmt *stmt = getSqliteStmt(StatSql::sqlResetAppTrafTotals); const qint64 unixTime = DateUtil::getUnixTime(); stmt->bindInt(1, DateUtil::getUnixHour(unixTime)); @@ -464,11 +465,11 @@ void DatabaseManager::resetAppTotals() m_sqliteDb->commitTransaction(); } -qint64 DatabaseManager::getAppId(const QString &appPath) +qint64 StatManager::getAppId(const QString &appPath) { qint64 appId = INVALID_APP_ID; - SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlSelectAppId); + SqliteStmt *stmt = getSqliteStmt(StatSql::sqlSelectAppId); stmt->bindText(1, appPath); if (stmt->step() == SqliteStmt::StepRow) { @@ -479,11 +480,11 @@ qint64 DatabaseManager::getAppId(const QString &appPath) return appId; } -qint64 DatabaseManager::createAppId(const QString &appPath, qint64 unixTime) +qint64 StatManager::createAppId(const QString &appPath, qint64 unixTime) { qint64 appId = INVALID_APP_ID; - SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlInsertAppId); + SqliteStmt *stmt = getSqliteStmt(StatSql::sqlInsertAppId); stmt->bindText(1, appPath); stmt->bindInt64(2, unixTime); @@ -499,9 +500,9 @@ qint64 DatabaseManager::createAppId(const QString &appPath, qint64 unixTime) return appId; } -void DatabaseManager::getAppList(QStringList &list, QVector &appIds) +void StatManager::getAppList(QStringList &list, QVector &appIds) { - SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlSelectAppPaths); + SqliteStmt *stmt = getSqliteStmt(StatSql::sqlSelectAppPaths); while (stmt->step() == SqliteStmt::StepRow) { appIds.append(stmt->columnInt64(0)); @@ -510,26 +511,26 @@ void DatabaseManager::getAppList(QStringList &list, QVector &appIds) stmt->reset(); } -void DatabaseManager::updateTrafficList(const QStmtList &insertStmtList, - const QStmtList &updateStmtList, - quint32 inBytes, quint32 outBytes, - qint64 appId) +void StatManager::updateTrafficList(const QStmtList &insertStmtList, + const QStmtList &updateStmtList, + quint32 inBytes, quint32 outBytes, + qint64 appId) { int i = 0; - foreach (SqliteStmt *stmtUpdate, updateStmtList) { + for (SqliteStmt *stmtUpdate : updateStmtList) { if (!updateTraffic(stmtUpdate, inBytes, outBytes, appId)) { SqliteStmt *stmtInsert = insertStmtList.at(i); if (!updateTraffic(stmtInsert, inBytes, outBytes, appId)) { - qCritical(CLOG_DATABASE_MANAGER()) << "Update traffic error:" - << m_sqliteDb->errorMessage(); + qCritical(CLOG_STAT_MANAGER()) << "Update traffic error:" + << m_sqliteDb->errorMessage(); } } ++i; } } -bool DatabaseManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes, - quint32 outBytes, qint64 appId) +bool StatManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes, + quint32 outBytes, qint64 appId) { stmt->bindInt64(2, inBytes); stmt->bindInt64(3, outBytes); @@ -546,15 +547,15 @@ bool DatabaseManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes, && m_sqliteDb->changes() != 0; } -void DatabaseManager::stepStmtList(const QStmtList &stmtList) +void StatManager::stepStmtList(const QStmtList &stmtList) { - foreach (SqliteStmt *stmtDelete, stmtList) { + for (SqliteStmt *stmtDelete : stmtList) { stmtDelete->step(); stmtDelete->reset(); } } -qint32 DatabaseManager::getTrafficTime(const char *sql, qint64 appId) +qint32 StatManager::getTrafficTime(const char *sql, qint64 appId) { qint32 trafTime = 0; @@ -572,9 +573,9 @@ qint32 DatabaseManager::getTrafficTime(const char *sql, qint64 appId) return trafTime; } -void DatabaseManager::getTraffic(const char *sql, qint32 trafTime, - qint64 &inBytes, qint64 &outBytes, - qint64 appId) +void StatManager::getTraffic(const char *sql, qint32 trafTime, + qint64 &inBytes, qint64 &outBytes, + qint64 appId) { SqliteStmt *stmt = getSqliteStmt(sql); @@ -594,7 +595,7 @@ void DatabaseManager::getTraffic(const char *sql, qint32 trafTime, stmt->reset(); } -SqliteStmt *DatabaseManager::getTrafficStmt(const char *sql, qint32 trafTime) +SqliteStmt *StatManager::getTrafficStmt(const char *sql, qint32 trafTime) { SqliteStmt *stmt = getSqliteStmt(sql); @@ -603,7 +604,7 @@ SqliteStmt *DatabaseManager::getTrafficStmt(const char *sql, qint32 trafTime) return stmt; } -SqliteStmt *DatabaseManager::getAppStmt(const char *sql, qint64 appId) +SqliteStmt *StatManager::getAppStmt(const char *sql, qint64 appId) { SqliteStmt *stmt = getSqliteStmt(sql); @@ -612,7 +613,7 @@ SqliteStmt *DatabaseManager::getAppStmt(const char *sql, qint64 appId) return stmt; } -SqliteStmt *DatabaseManager::getSqliteStmt(const char *sql) +SqliteStmt *StatManager::getSqliteStmt(const char *sql) { SqliteStmt *stmt = m_sqliteStmts.value(sql); diff --git a/src/ui/db/databasemanager.h b/src/ui/stat/statmanager.h similarity index 88% rename from src/ui/db/databasemanager.h rename to src/ui/stat/statmanager.h index 341b9d28..2977b985 100644 --- a/src/ui/db/databasemanager.h +++ b/src/ui/stat/statmanager.h @@ -1,5 +1,5 @@ -#ifndef DATABASEMANAGER_H -#define DATABASEMANAGER_H +#ifndef STATMANAGER_H +#define STATMANAGER_H #include #include @@ -13,16 +13,16 @@ QT_FORWARD_DECLARE_CLASS(QuotaManager) QT_FORWARD_DECLARE_CLASS(SqliteDb) QT_FORWARD_DECLARE_CLASS(SqliteStmt) -class DatabaseManager : public QObject +class StatManager : public QObject { Q_OBJECT public: - explicit DatabaseManager(const QString &filePath, - QuotaManager *quotaManager, - QObject *parent = nullptr); - ~DatabaseManager() override; - CLASS_DELETE_COPY_MOVE(DatabaseManager) + explicit StatManager(const QString &filePath, + QuotaManager *quotaManager, + QObject *parent = nullptr); + ~StatManager() override; + CLASS_DELETE_COPY_MOVE(StatManager) const FirewallConf *firewallConf() const { return m_conf; } void setFirewallConf(const FirewallConf *conf); @@ -120,4 +120,4 @@ private: QVector m_appIds; }; -#endif // DATABASEMANAGER_H +#endif // STATMANAGER_H diff --git a/src/ui/db/databasesql.cpp b/src/ui/stat/statsql.cpp similarity index 65% rename from src/ui/db/databasesql.cpp rename to src/ui/stat/statsql.cpp index b989feea..ad01ac27 100644 --- a/src/ui/db/databasesql.cpp +++ b/src/ui/stat/statsql.cpp @@ -1,230 +1,230 @@ -#include "databasesql.h" +#include "statsql.h" -const char * const DatabaseSql::sqlPragmas = - "PRAGMA locking_mode=EXCLUSIVE;" - "PRAGMA synchronous=NORMAL;" +const char * const StatSql::sqlPragmas = + "PRAGMA locking_mode = EXCLUSIVE;" + "PRAGMA synchronous = NORMAL;" ; -const char * const DatabaseSql::sqlSelectAppId = +const char * const StatSql::sqlSelectAppId = "SELECT app_id FROM app WHERE path = ?1;" ; -const char * const DatabaseSql::sqlInsertAppId = +const char * const StatSql::sqlInsertAppId = "INSERT INTO app(path, creat_time, traf_time, in_bytes, out_bytes)" " VALUES(?1, ?2, ?3, 0, 0);" ; -const char * const DatabaseSql::sqlDeleteAppId = +const char * const StatSql::sqlDeleteAppId = "DELETE FROM app WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlSelectAppPaths = +const char * const StatSql::sqlSelectAppPaths = "SELECT app_id, path FROM app ORDER BY creat_time;" ; -const char * const DatabaseSql::sqlInsertTrafAppHour = +const char * const StatSql::sqlInsertTrafAppHour = "INSERT INTO traffic_app_hour(app_id, traf_time, in_bytes, out_bytes)" " VALUES(?4, ?1, ?2, ?3);" ; -const char * const DatabaseSql::sqlInsertTrafAppDay = +const char * const StatSql::sqlInsertTrafAppDay = "INSERT INTO traffic_app_day(app_id, traf_time, in_bytes, out_bytes)" " VALUES(?4, ?1, ?2, ?3);" ; -const char * const DatabaseSql::sqlInsertTrafAppMonth = +const char * const StatSql::sqlInsertTrafAppMonth = "INSERT INTO traffic_app_month(app_id, traf_time, in_bytes, out_bytes)" " VALUES(?4, ?1, ?2, ?3);" ; -const char * const DatabaseSql::sqlInsertTrafHour = +const char * const StatSql::sqlInsertTrafHour = "INSERT INTO traffic_hour(traf_time, in_bytes, out_bytes)" " VALUES(?1, ?2, ?3);" ; -const char * const DatabaseSql::sqlInsertTrafDay = +const char * const StatSql::sqlInsertTrafDay = "INSERT INTO traffic_day(traf_time, in_bytes, out_bytes)" " VALUES(?1, ?2, ?3);" ; -const char * const DatabaseSql::sqlInsertTrafMonth = +const char * const StatSql::sqlInsertTrafMonth = "INSERT INTO traffic_month(traf_time, in_bytes, out_bytes)" " VALUES(?1, ?2, ?3);" ; -const char * const DatabaseSql::sqlUpdateTrafAppHour = +const char * const StatSql::sqlUpdateTrafAppHour = "UPDATE traffic_app_hour" " SET in_bytes = in_bytes + ?2," " out_bytes = out_bytes + ?3" " WHERE app_id = ?4 and traf_time = ?1;" ; -const char * const DatabaseSql::sqlUpdateTrafAppDay = +const char * const StatSql::sqlUpdateTrafAppDay = "UPDATE traffic_app_day" " SET in_bytes = in_bytes + ?2," " out_bytes = out_bytes + ?3" " WHERE app_id = ?4 and traf_time = ?1;" ; -const char * const DatabaseSql::sqlUpdateTrafAppMonth = +const char * const StatSql::sqlUpdateTrafAppMonth = "UPDATE traffic_app_month" " SET in_bytes = in_bytes + ?2," " out_bytes = out_bytes + ?3" " WHERE app_id = ?4 and traf_time = ?1;" ; -const char * const DatabaseSql::sqlUpdateTrafAppTotal = +const char * const StatSql::sqlUpdateTrafAppTotal = "UPDATE app" " SET in_bytes = in_bytes + ?2," " out_bytes = out_bytes + ?3" " WHERE app_id = ?4 and 0 != ?1;" ; -const char * const DatabaseSql::sqlUpdateTrafHour = +const char * const StatSql::sqlUpdateTrafHour = "UPDATE traffic_hour" " SET in_bytes = in_bytes + ?2," " out_bytes = out_bytes + ?3" " WHERE traf_time = ?1;" ; -const char * const DatabaseSql::sqlUpdateTrafDay = +const char * const StatSql::sqlUpdateTrafDay = "UPDATE traffic_day" " SET in_bytes = in_bytes + ?2," " out_bytes = out_bytes + ?3" " WHERE traf_time = ?1;" ; -const char * const DatabaseSql::sqlUpdateTrafMonth = +const char * const StatSql::sqlUpdateTrafMonth = "UPDATE traffic_month" " SET in_bytes = in_bytes + ?2," " out_bytes = out_bytes + ?3" " WHERE traf_time = ?1;" ; -const char * const DatabaseSql::sqlSelectMinTrafAppHour = +const char * const StatSql::sqlSelectMinTrafAppHour = "SELECT min(traf_time) FROM traffic_app_hour" " WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlSelectMinTrafAppDay = +const char * const StatSql::sqlSelectMinTrafAppDay = "SELECT min(traf_time) FROM traffic_app_day" " WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlSelectMinTrafAppMonth = +const char * const StatSql::sqlSelectMinTrafAppMonth = "SELECT min(traf_time) FROM traffic_app_month" " WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlSelectMinTrafAppTotal = +const char * const StatSql::sqlSelectMinTrafAppTotal = "SELECT traf_time FROM app WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlSelectMinTrafHour = +const char * const StatSql::sqlSelectMinTrafHour = "SELECT min(traf_time) FROM traffic_hour;" ; -const char * const DatabaseSql::sqlSelectMinTrafDay = +const char * const StatSql::sqlSelectMinTrafDay = "SELECT min(traf_time) FROM traffic_app_day;" ; -const char * const DatabaseSql::sqlSelectMinTrafMonth = +const char * const StatSql::sqlSelectMinTrafMonth = "SELECT min(traf_time) FROM traffic_app_month;" ; -const char * const DatabaseSql::sqlSelectMinTrafTotal = +const char * const StatSql::sqlSelectMinTrafTotal = "SELECT min(traf_time) FROM app;" ; -const char * const DatabaseSql::sqlSelectTrafAppHour = +const char * const StatSql::sqlSelectTrafAppHour = "SELECT in_bytes, out_bytes" " FROM traffic_app_hour" " WHERE app_id = ?2 and traf_time = ?1;" ; -const char * const DatabaseSql::sqlSelectTrafAppDay = +const char * const StatSql::sqlSelectTrafAppDay = "SELECT in_bytes, out_bytes" " FROM traffic_app_day" " WHERE app_id = ?2 and traf_time = ?1;" ; -const char * const DatabaseSql::sqlSelectTrafAppMonth = +const char * const StatSql::sqlSelectTrafAppMonth = "SELECT in_bytes, out_bytes" " FROM traffic_app_month" " WHERE app_id = ?2 and traf_time = ?1;" ; -const char * const DatabaseSql::sqlSelectTrafAppTotal = +const char * const StatSql::sqlSelectTrafAppTotal = "SELECT in_bytes, out_bytes" " FROM app" " WHERE app_id = ?2 and 0 != ?1;" ; -const char * const DatabaseSql::sqlSelectTrafHour = +const char * const StatSql::sqlSelectTrafHour = "SELECT in_bytes, out_bytes" " FROM traffic_hour WHERE traf_time = ?1;" ; -const char * const DatabaseSql::sqlSelectTrafDay = +const char * const StatSql::sqlSelectTrafDay = "SELECT in_bytes, out_bytes" " FROM traffic_day WHERE traf_time = ?1;" ; -const char * const DatabaseSql::sqlSelectTrafMonth = +const char * const StatSql::sqlSelectTrafMonth = "SELECT in_bytes, out_bytes" " FROM traffic_month WHERE traf_time = ?1;" ; -const char * const DatabaseSql::sqlSelectTrafTotal = +const char * const StatSql::sqlSelectTrafTotal = "SELECT sum(in_bytes), sum(out_bytes)" " FROM app WHERE 0 != ?1;" ; -const char * const DatabaseSql::sqlDeleteTrafAppHour = +const char * const StatSql::sqlDeleteTrafAppHour = "DELETE FROM traffic_app_hour" " WHERE traf_time < ?1" " and app_id in (SELECT app_id FROM app);" ; -const char * const DatabaseSql::sqlDeleteTrafAppDay = +const char * const StatSql::sqlDeleteTrafAppDay = "DELETE FROM traffic_app_day" " WHERE traf_time < ?1" " and app_id in (SELECT app_id FROM app);" ; -const char * const DatabaseSql::sqlDeleteTrafAppMonth = +const char * const StatSql::sqlDeleteTrafAppMonth = "DELETE FROM traffic_app_month" " WHERE traf_time < ?1" " and app_id in (SELECT app_id FROM app);" ; -const char * const DatabaseSql::sqlDeleteTrafHour = +const char * const StatSql::sqlDeleteTrafHour = "DELETE FROM traffic_hour WHERE traf_time < ?1;" ; -const char * const DatabaseSql::sqlDeleteTrafDay = +const char * const StatSql::sqlDeleteTrafDay = "DELETE FROM traffic_day WHERE traf_time < ?1;" ; -const char * const DatabaseSql::sqlDeleteTrafMonth = +const char * const StatSql::sqlDeleteTrafMonth = "DELETE FROM traffic_month WHERE traf_time < ?1;" ; -const char * const DatabaseSql::sqlDeleteAppTrafHour = +const char * const StatSql::sqlDeleteAppTrafHour = "DELETE FROM traffic_app_hour" " WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlDeleteAppTrafDay = +const char * const StatSql::sqlDeleteAppTrafDay = "DELETE FROM traffic_app_day" " WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlDeleteAppTrafMonth = +const char * const StatSql::sqlDeleteAppTrafMonth = "DELETE FROM traffic_app_month" " WHERE app_id = ?1;" ; -const char * const DatabaseSql::sqlResetAppTrafTotals = +const char * const StatSql::sqlResetAppTrafTotals = "UPDATE app SET traf_time = ?1, in_bytes = 0, out_bytes = 0;" ; diff --git a/src/ui/db/databasesql.h b/src/ui/stat/statsql.h similarity index 96% rename from src/ui/db/databasesql.h rename to src/ui/stat/statsql.h index f1445824..b440ab79 100644 --- a/src/ui/db/databasesql.h +++ b/src/ui/stat/statsql.h @@ -1,7 +1,7 @@ -#ifndef DATABASESQL_H -#define DATABASESQL_H +#ifndef STATSQL_H +#define STATSQL_H -class DatabaseSql +class StatSql { public: static const char * const sqlPragmas; @@ -65,4 +65,4 @@ public: static const char * const sqlResetAppTrafTotals; }; -#endif // DATABASESQL_H +#endif // STATSQL_H diff --git a/src/ui/util/app/appinfomanager.cpp b/src/ui/util/app/appinfomanager.cpp index 509b037d..2d233853 100644 --- a/src/ui/util/app/appinfomanager.cpp +++ b/src/ui/util/app/appinfomanager.cpp @@ -3,11 +3,12 @@ #include #include +#include +#include + #include "appinfojob.h" #include "appinfoworker.h" #include "apputil.h" -#include -#include Q_DECLARE_LOGGING_CATEGORY(CLOG_APPINFOCACHE) Q_LOGGING_CATEGORY(CLOG_APPINFOCACHE, "fort.appInfoWorker")