From dac4eec3ec94ea9a312b1e4f6b123eb0a2e8b4a3 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 12 Feb 2021 14:10:39 +0500 Subject: [PATCH] UI: Prepare ConnectionsWindow. --- src/ui/3rdparty/sqlite/sqlitestmt.h | 2 +- src/ui/FortFirewallUI.pro | 4 + src/ui/form/conn/connectionscontroller.cpp | 37 ++++ src/ui/form/conn/connectionscontroller.h | 34 ++++ src/ui/form/conn/connectionswindow.cpp | 190 +++++++++++++++++++++ src/ui/form/conn/connectionswindow.h | 53 ++++++ src/ui/form/opt/pages/statisticspage.cpp | 3 +- src/ui/form/prog/programscontroller.cpp | 3 +- src/ui/form/prog/programswindow.cpp | 17 +- src/ui/form/prog/programswindow.h | 4 - src/ui/form/zone/zoneswindow.h | 2 - src/ui/fort-icons.qrc | 1 + src/ui/fortmanager.cpp | 62 +++++++ src/ui/fortmanager.h | 18 ++ src/ui/fortsettings.h | 13 ++ src/ui/icons/connect.png | Bin 0 -> 1094 bytes src/ui/log/logmanager.cpp | 8 +- src/ui/log/logmanager.h | 2 + src/ui/model/applistmodel.cpp | 6 - src/ui/model/connlistmodel.cpp | 23 ++- src/ui/model/connlistmodel.h | 9 +- src/ui/util/conf/confutil.h | 2 +- 22 files changed, 455 insertions(+), 38 deletions(-) create mode 100644 src/ui/form/conn/connectionscontroller.cpp create mode 100644 src/ui/form/conn/connectionscontroller.h create mode 100644 src/ui/form/conn/connectionswindow.cpp create mode 100644 src/ui/form/conn/connectionswindow.h create mode 100644 src/ui/icons/connect.png diff --git a/src/ui/3rdparty/sqlite/sqlitestmt.h b/src/ui/3rdparty/sqlite/sqlitestmt.h index 8bc787e4..dc7c02d6 100644 --- a/src/ui/3rdparty/sqlite/sqlitestmt.h +++ b/src/ui/3rdparty/sqlite/sqlitestmt.h @@ -7,7 +7,7 @@ #include "../../util/classhelpers.h" -QT_FORWARD_DECLARE_STRUCT(sqlite3_stmt) +struct sqlite3_stmt; class SqliteStmt { diff --git a/src/ui/FortFirewallUI.pro b/src/ui/FortFirewallUI.pro index 8a14f242..bfce28d3 100644 --- a/src/ui/FortFirewallUI.pro +++ b/src/ui/FortFirewallUI.pro @@ -18,6 +18,8 @@ SOURCES += \ control/controlworker.cpp \ driver/drivermanager.cpp \ driver/driverworker.cpp \ + form/conn/connectionscontroller.cpp \ + form/conn/connectionswindow.cpp \ form/controls/checkspincombo.cpp \ form/controls/checktimeperiod.cpp \ form/controls/controlutil.cpp \ @@ -133,6 +135,8 @@ HEADERS += \ control/controlworker.h \ driver/drivermanager.h \ driver/driverworker.h \ + form/conn/connectionscontroller.h \ + form/conn/connectionswindow.h \ form/controls/checkspincombo.h \ form/controls/checktimeperiod.h \ form/controls/controlutil.h \ diff --git a/src/ui/form/conn/connectionscontroller.cpp b/src/ui/form/conn/connectionscontroller.cpp new file mode 100644 index 00000000..25d597e9 --- /dev/null +++ b/src/ui/form/conn/connectionscontroller.cpp @@ -0,0 +1,37 @@ +#include "connectionscontroller.h" + +#include "../../conf/confmanager.h" +#include "../../fortmanager.h" +#include "../../translationmanager.h" + +ConnectionsController::ConnectionsController(FortManager *fortManager, QObject *parent) : + QObject(parent), m_fortManager(fortManager) +{ + connect(translationManager(), &TranslationManager::languageChanged, this, + &ConnectionsController::retranslateUi); +} + +FortSettings *ConnectionsController::settings() const +{ + return fortManager()->settings(); +} + +ConfManager *ConnectionsController::confManager() const +{ + return fortManager()->confManager(); +} + +FirewallConf *ConnectionsController::conf() const +{ + return confManager()->conf(); +} + +ConnListModel *ConnectionsController::connListModel() const +{ + return fortManager()->connListModel(); +} + +TranslationManager *ConnectionsController::translationManager() const +{ + return TranslationManager::instance(); +} diff --git a/src/ui/form/conn/connectionscontroller.h b/src/ui/form/conn/connectionscontroller.h new file mode 100644 index 00000000..f2be174d --- /dev/null +++ b/src/ui/form/conn/connectionscontroller.h @@ -0,0 +1,34 @@ +#ifndef CONNECTIONSCONTROLLER_H +#define CONNECTIONSCONTROLLER_H + +#include + +class ConfManager; +class ConnListModel; +class FirewallConf; +class FortManager; +class FortSettings; +class TranslationManager; + +class ConnectionsController : public QObject +{ + Q_OBJECT + +public: + explicit ConnectionsController(FortManager *fortManager, QObject *parent = nullptr); + + FortManager *fortManager() const { return m_fortManager; } + FortSettings *settings() const; + ConfManager *confManager() const; + FirewallConf *conf() const; + ConnListModel *connListModel() const; + TranslationManager *translationManager() const; + +signals: + void retranslateUi(); + +private: + FortManager *m_fortManager = nullptr; +}; + +#endif // CONNECTIONSCONTROLLER_H diff --git a/src/ui/form/conn/connectionswindow.cpp b/src/ui/form/conn/connectionswindow.cpp new file mode 100644 index 00000000..cae117a1 --- /dev/null +++ b/src/ui/form/conn/connectionswindow.cpp @@ -0,0 +1,190 @@ +#include "connectionswindow.h" + +#include +#include +#include +#include + +#include "../../conf/firewallconf.h" +#include "../../fortmanager.h" +#include "../../fortsettings.h" +#include "../../model/connlistmodel.h" +#include "../../util/guiutil.h" +#include "../../util/iconcache.h" +#include "../controls/controlutil.h" +#include "../controls/tableview.h" +#include "connectionscontroller.h" + +namespace { + +#define CONN_LIST_HEADER_VERSION 1 + +} + +ConnectionsWindow::ConnectionsWindow(FortManager *fortManager, QWidget *parent) : + WidgetWindow(parent), m_ctrl(new ConnectionsController(fortManager, this)) +{ + setupUi(); + setupController(); +} + +void ConnectionsWindow::setupController() +{ + connect(ctrl(), &ConnectionsController::retranslateUi, this, + &ConnectionsWindow::onRetranslateUi); + + connect(this, &ConnectionsWindow::aboutToClose, fortManager(), + &FortManager::closeConnectionsWindow); + + connect(fortManager(), &FortManager::afterSaveConnWindowState, this, + &ConnectionsWindow::onSaveWindowState); + connect(fortManager(), &FortManager::afterRestoreConnWindowState, this, + &ConnectionsWindow::onRestoreWindowState); + + emit ctrl()->retranslateUi(); +} + +void ConnectionsWindow::onSaveWindowState() +{ + auto header = m_connListView->horizontalHeader(); + settings()->setConnListHeader(header->saveState()); + settings()->setConnListHeaderVersion(CONN_LIST_HEADER_VERSION); +} + +void ConnectionsWindow::onRestoreWindowState() +{ + if (settings()->connListHeaderVersion() != CONN_LIST_HEADER_VERSION) + return; + + auto header = m_connListView->horizontalHeader(); + header->restoreState(settings()->connListHeader()); +} + +void ConnectionsWindow::onRetranslateUi() +{ + this->unsetLocale(); + + m_cbLogBlockedIp->setText(tr("Collect blocked connections")); + + connListModel()->refresh(); + + this->setWindowTitle(tr("Connections")); +} + +void ConnectionsWindow::setupUi() +{ + auto layout = new QVBoxLayout(); + layout->setContentsMargins(6, 6, 6, 6); + + // Header + auto header = setupHeader(); + layout->addLayout(header); + + // Table + setupTableConnList(); + setupTableConnListHeader(); + layout->addWidget(m_connListView, 1); + + this->setLayout(layout); + + // Font + this->setFont(QFont("Tahoma", 9)); + + // Icon + this->setWindowIcon(GuiUtil::overlayIcon(":/images/sheild-96.png", ":/icons/connect.png")); + + // Size + this->resize(1024, 768); + this->setMinimumSize(500, 400); +} + +QLayout *ConnectionsWindow::setupHeader() +{ + auto layout = new QHBoxLayout(); + + // Log Options + setupLogOptions(); + + layout->addStretch(); + layout->addWidget(m_btLogOptions); + + return layout; +} + +void ConnectionsWindow::setupLogOptions() +{ + setupLogBlockedIp(); + + // Menu + const QList menuWidgets = { /*m_cbLogBlocked,*/ ControlUtil::createSeparator(), + m_cbLogBlockedIp }; + auto layout = ControlUtil::createLayoutByWidgets(menuWidgets); + + auto menu = ControlUtil::createMenuByLayout(layout, this); + + m_btLogOptions = ControlUtil::createButton(":/icons/wrench.png"); + m_btLogOptions->setMenu(menu); +} + +void ConnectionsWindow::setupLogBlockedIp() +{ + m_cbLogBlockedIp = ControlUtil::createCheckBox(conf()->logBlockedIp(), [&](bool checked) { + if (conf()->logBlockedIp() == checked) + return; + + conf()->setLogBlockedIp(checked); + + fortManager()->applyConfImmediateFlags(); + }); +} + +void ConnectionsWindow::setupTableConnList() +{ + m_connListView = new TableView(); + m_connListView->setAlternatingRowColors(true); + m_connListView->setSelectionMode(QAbstractItemView::ExtendedSelection); + m_connListView->setSelectionBehavior(QAbstractItemView::SelectItems); + + m_connListView->setSortingEnabled(true); + m_connListView->setModel(connListModel()); +} + +void ConnectionsWindow::setupTableConnListHeader() +{ + auto header = m_connListView->horizontalHeader(); + + header->setSectionResizeMode(0, QHeaderView::Interactive); + header->setSectionResizeMode(1, QHeaderView::Interactive); + header->setSectionResizeMode(2, QHeaderView::Interactive); + header->setSectionResizeMode(3, QHeaderView::Fixed); + header->setSectionResizeMode(4, QHeaderView::Stretch); + + header->resizeSection(0, 600); + header->resizeSection(1, 120); + header->resizeSection(2, 100); + header->resizeSection(3, 30); + + header->setSectionsClickable(true); + header->setSortIndicatorShown(true); + header->setSortIndicator(4, Qt::DescendingOrder); +} + +FortManager *ConnectionsWindow::fortManager() const +{ + return ctrl()->fortManager(); +} + +FortSettings *ConnectionsWindow::settings() const +{ + return ctrl()->settings(); +} + +FirewallConf *ConnectionsWindow::conf() const +{ + return ctrl()->conf(); +} + +ConnListModel *ConnectionsWindow::connListModel() const +{ + return fortManager()->connListModel(); +} diff --git a/src/ui/form/conn/connectionswindow.h b/src/ui/form/conn/connectionswindow.h new file mode 100644 index 00000000..643a85c5 --- /dev/null +++ b/src/ui/form/conn/connectionswindow.h @@ -0,0 +1,53 @@ +#ifndef CONNECTIONSWINDOW_H +#define CONNECTIONSWINDOW_H + +#include "../../util/window/widgetwindow.h" + +QT_FORWARD_DECLARE_CLASS(QCheckBox) +QT_FORWARD_DECLARE_CLASS(QPushButton) + +class ConnListModel; +class ConnectionsController; +class FirewallConf; +class FortManager; +class FortSettings; +class TableView; + +class ConnectionsWindow : public WidgetWindow +{ + Q_OBJECT + +public: + explicit ConnectionsWindow(FortManager *fortManager, QWidget *parent = nullptr); + +protected slots: + void onSaveWindowState(); + void onRestoreWindowState(); + + void onRetranslateUi(); + +private: + void setupController(); + + void setupUi(); + QLayout *setupHeader(); + void setupLogOptions(); + void setupLogBlockedIp(); + void setupTableConnList(); + void setupTableConnListHeader(); + + ConnectionsController *ctrl() const { return m_ctrl; } + FortManager *fortManager() const; + FortSettings *settings() const; + FirewallConf *conf() const; + ConnListModel *connListModel() const; + +private: + ConnectionsController *m_ctrl = nullptr; + + QPushButton *m_btLogOptions = nullptr; + QCheckBox *m_cbLogBlockedIp = nullptr; + TableView *m_connListView = nullptr; +}; + +#endif // CONNECTIONSWINDOW_H diff --git a/src/ui/form/opt/pages/statisticspage.cpp b/src/ui/form/opt/pages/statisticspage.cpp index 1c7fce72..7ff2152c 100644 --- a/src/ui/form/opt/pages/statisticspage.cpp +++ b/src/ui/form/opt/pages/statisticspage.cpp @@ -19,7 +19,6 @@ #include "../../../conf/firewallconf.h" #include "../../../fortmanager.h" #include "../../../fortsettings.h" -#include "../../../log/logmanager.h" #include "../../../model/appstatmodel.h" #include "../../../model/traflistmodel.h" #include "../../../util/app/appinfocache.h" @@ -68,7 +67,7 @@ void StatisticsPage::setGraphEdited(bool v) AppStatModel *StatisticsPage::appStatModel() const { - return fortManager()->logManager()->appStatModel(); + return fortManager()->appStatModel(); } AppInfoCache *StatisticsPage::appInfoCache() const diff --git a/src/ui/form/prog/programscontroller.cpp b/src/ui/form/prog/programscontroller.cpp index 8cd7d845..6917f057 100644 --- a/src/ui/form/prog/programscontroller.cpp +++ b/src/ui/form/prog/programscontroller.cpp @@ -2,7 +2,6 @@ #include "../../conf/confmanager.h" #include "../../fortmanager.h" -#include "../../log/logmanager.h" #include "../../translationmanager.h" ProgramsController::ProgramsController(FortManager *fortManager, QObject *parent) : @@ -29,7 +28,7 @@ FirewallConf *ProgramsController::conf() const AppListModel *ProgramsController::appListModel() const { - return fortManager()->logManager()->appListModel(); + return fortManager()->appListModel(); } TranslationManager *ProgramsController::translationManager() const diff --git a/src/ui/form/prog/programswindow.cpp b/src/ui/form/prog/programswindow.cpp index 3211e527..bdf3d16f 100644 --- a/src/ui/form/prog/programswindow.cpp +++ b/src/ui/form/prog/programswindow.cpp @@ -111,7 +111,6 @@ void ProgramsWindow::onRetranslateUi() m_btLogOptions->setText(tr("Options")); m_cbLogBlocked->setText(tr("Collect New Blocked Programs")); - m_cbLogBlockedIp->setText(tr("Collect blocked connections")); appListModel()->refresh(); @@ -390,11 +389,9 @@ QLayout *ProgramsWindow::setupHeader() void ProgramsWindow::setupLogOptions() { setupLogBlocked(); - setupLogBlockedIp(); // Menu - const QList menuWidgets = { m_cbLogBlocked, ControlUtil::createSeparator(), - m_cbLogBlockedIp }; + const QList menuWidgets = { m_cbLogBlocked }; auto layout = ControlUtil::createLayoutByWidgets(menuWidgets); auto menu = ControlUtil::createMenuByLayout(layout, this); @@ -417,18 +414,6 @@ void ProgramsWindow::setupLogBlocked() m_cbLogBlocked->setFont(ControlUtil::fontDemiBold()); } -void ProgramsWindow::setupLogBlockedIp() -{ - m_cbLogBlockedIp = ControlUtil::createCheckBox(conf()->logBlockedIp(), [&](bool checked) { - if (conf()->logBlockedIp() == checked) - return; - - conf()->setLogBlockedIp(checked); - - fortManager()->applyConfImmediateFlags(); - }); -} - void ProgramsWindow::setupTableApps() { m_appListView = new TableView(); diff --git a/src/ui/form/prog/programswindow.h b/src/ui/form/prog/programswindow.h index 4f485f79..2512ddeb 100644 --- a/src/ui/form/prog/programswindow.h +++ b/src/ui/form/prog/programswindow.h @@ -22,8 +22,6 @@ class FortSettings; class ProgramsController; class TableView; -QT_FORWARD_DECLARE_STRUCT(AppRow) - class ProgramsWindow : public WidgetWindow { Q_OBJECT @@ -49,7 +47,6 @@ private: QLayout *setupHeader(); void setupLogOptions(); void setupLogBlocked(); - void setupLogBlockedIp(); void setupTableApps(); void setupTableAppsHeader(); void setupAppInfoRow(); @@ -109,7 +106,6 @@ private: QDialog *m_formAppEdit = nullptr; QPushButton *m_btLogOptions = nullptr; QCheckBox *m_cbLogBlocked = nullptr; - QCheckBox *m_cbLogBlockedIp = nullptr; TableView *m_appListView = nullptr; QWidget *m_appInfoRow = nullptr; QPushButton *m_btAppCopyPath = nullptr; diff --git a/src/ui/form/zone/zoneswindow.h b/src/ui/form/zone/zoneswindow.h index 43cfbbac..a82707dc 100644 --- a/src/ui/form/zone/zoneswindow.h +++ b/src/ui/form/zone/zoneswindow.h @@ -17,8 +17,6 @@ class TaskManager; class ZoneListModel; class ZonesController; -QT_FORWARD_DECLARE_STRUCT(ZoneRow) - class ZonesWindow : public WidgetWindow { Q_OBJECT diff --git a/src/ui/fort-icons.qrc b/src/ui/fort-icons.qrc index f7b96454..cd4545ba 100644 --- a/src/ui/fort-icons.qrc +++ b/src/ui/fort-icons.qrc @@ -7,6 +7,7 @@ icons/arrow-retweet.png icons/clock.png icons/cog.png + icons/connect.png icons/copy.png icons/database.png icons/download.png diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 82533588..0fe78c5e 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -15,6 +15,7 @@ #include "conf/confmanager.h" #include "conf/firewallconf.h" #include "driver/drivermanager.h" +#include "form/conn/connectionswindow.h" #include "form/graph/graphwindow.h" #include "form/opt/optionswindow.h" #include "form/prog/programswindow.h" @@ -56,6 +57,7 @@ FortManager::FortManager(FortSettings *fortSettings, QObject *parent) : m_optWindowState(new WidgetWindowStateWatcher(this)), m_zoneWindowState(new WidgetWindowStateWatcher(this)), m_graphWindowState(new WidgetWindowStateWatcher(this)), + m_connWindowState(new WidgetWindowStateWatcher(this)), m_settings(fortSettings), m_quotaManager(new QuotaManager(fortSettings, this)), m_statManager(new StatManager(fortSettings->statFilePath(), m_quotaManager, this)), @@ -69,6 +71,7 @@ FortManager::FortManager(FortSettings *fortSettings, QObject *parent) : m_appInfoCache(new AppInfoCache(this)), m_appListModel(new AppListModel(m_confManager, this)), m_appStatModel(new AppStatModel(m_statManager, this)), + m_connListModel(new ConnListModel(m_confManager, this)), m_zoneListModel(new ZoneListModel(m_confManager, this)) { setupTranslationManager(); @@ -320,12 +323,22 @@ bool FortManager::setupZonesWindow() return true; } +bool FortManager::setupConnectionsWindow() +{ + m_connWindow = new ConnectionsWindow(this); + + m_connWindowState->install(m_connWindow); + + return true; +} + void FortManager::closeUi() { closeGraphWindow(true); closeOptionsWindow(); closeProgramsWindow(); closeZonesWindow(); + closeConnectionsWindow(); } void FortManager::launch() @@ -504,6 +517,34 @@ void FortManager::updateGraphWindow() m_graphWindow->updateWindowFlags(); } +void FortManager::showConnectionsWindow() +{ + if (!(m_connWindow && m_connWindow->isVisible())) + return; + + if (!m_connWindow) { + setupConnectionsWindow(); + restoreConnWindowState(); + } + + m_connWindow->show(); + m_connWindow->raise(); + m_connWindow->activateWindow(); +} + +void FortManager::closeConnectionsWindow() +{ + if (!m_connWindow) + return; + + saveConnWindowState(); + + m_connWindow->hide(); + + m_connWindow->deleteLater(); + m_connWindow = nullptr; +} + void FortManager::exit(int retcode) { if (!checkPassword()) @@ -720,6 +761,22 @@ void FortManager::restoreGraphWindowState() settings()->graphWindowMaximized()); } +void FortManager::saveConnWindowState() +{ + settings()->setConnWindowGeometry(m_connWindowState->geometry()); + settings()->setConnWindowMaximized(m_connWindowState->maximized()); + + emit afterSaveConnWindowState(); +} + +void FortManager::restoreConnWindowState() +{ + m_connWindowState->restore(m_connWindow, QSize(1024, 768), settings()->connWindowGeometry(), + settings()->connWindowMaximized()); + + emit afterRestoreConnWindowState(); +} + void FortManager::updateTrayIcon(bool alerted) { const auto icon = alerted @@ -769,6 +826,10 @@ void FortManager::createTrayMenu() this, SLOT(switchGraphWindow()), true, (m_graphWindow != nullptr)); addHotKey(m_graphWindowAction, settings()->hotKeyGraph(), conf()->logStat()); + m_connectionsAction = addAction(menu, IconCache::icon(":/icons/connect.png"), QString(), this, + SLOT(showConnectionsWindow())); + addHotKey(m_connectionsAction, settings()->hotKeyConnections(), hotKeyEnabled); + menu->addSeparator(); m_filterEnabledAction = addAction(menu, QIcon(), QString(), this, SLOT(saveTrayFlags()), true); @@ -837,6 +898,7 @@ void FortManager::retranslateTrayMenu() m_optionsAction->setText(tr("Options")); m_zonesAction->setText(tr("Zones")); m_graphWindowAction->setText(tr("Traffic Graph")); + m_connectionsAction->setText(tr("Connections")); m_filterEnabledAction->setText(tr("Filter Enabled")); m_stopTrafficAction->setText(tr("Stop Traffic")); diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index 5f508353..22da9210 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -12,6 +12,8 @@ class AppInfoCache; class AppListModel; class AppStatModel; class ConfManager; +class ConnListModel; +class ConnectionsWindow; class DriverManager; class EnvManager; class FirewallConf; @@ -52,6 +54,7 @@ public: TaskManager *taskManager() const { return m_taskManager; } AppListModel *appListModel() const { return m_appListModel; } AppStatModel *appStatModel() const { return m_appStatModel; } + ConnListModel *connListModel() const { return m_connListModel; } ZoneListModel *zoneListModel() const { return m_zoneListModel; } signals: @@ -66,6 +69,9 @@ signals: void afterSaveZoneWindowState(); void afterRestoreZoneWindowState(); + void afterSaveConnWindowState(); + void afterRestoreConnWindowState(); + public slots: void installDriver(); void removeDriver(); @@ -91,6 +97,9 @@ public slots: void switchGraphWindow(); void updateGraphWindow(); + void showConnectionsWindow(); + void closeConnectionsWindow(); + void exit(int retcode = 0); bool checkPassword(); @@ -134,6 +143,7 @@ private: bool setupProgramsWindow(); bool setupOptionsWindow(); bool setupZonesWindow(); + bool setupConnectionsWindow(); void closeUi(); @@ -157,6 +167,9 @@ private: void saveGraphWindowState(bool visible); void restoreGraphWindowState(); + void saveConnWindowState(); + void restoreConnWindowState(); + void updateTrayIcon(bool alerted = false); void updateTrayMenu(bool onlyFlags = false); @@ -195,10 +208,14 @@ private: GraphWindow *m_graphWindow = nullptr; WidgetWindowStateWatcher *m_graphWindowState = nullptr; + ConnectionsWindow *m_connWindow = nullptr; + WidgetWindowStateWatcher *m_connWindowState = nullptr; + QAction *m_programsAction = nullptr; QAction *m_optionsAction = nullptr; QAction *m_zonesAction = nullptr; QAction *m_graphWindowAction = nullptr; + QAction *m_connectionsAction = nullptr; QAction *m_filterEnabledAction = nullptr; QAction *m_stopTrafficAction = nullptr; QAction *m_stopInetTrafficAction = nullptr; @@ -220,6 +237,7 @@ private: AppListModel *m_appListModel = nullptr; AppStatModel *m_appStatModel = nullptr; + ConnListModel *m_connListModel = nullptr; ZoneListModel *m_zoneListModel = nullptr; }; diff --git a/src/ui/fortsettings.h b/src/ui/fortsettings.h index 7de0ad3f..a2b63e05 100644 --- a/src/ui/fortsettings.h +++ b/src/ui/fortsettings.h @@ -208,6 +208,18 @@ public: } void setGraphWindowGridColor(const QColor &v) { setIniColor("graphWindow/gridColor", v); } + QRect connWindowGeometry() const { return iniValue("connWindow/geometry").toRect(); } + void setConnWindowGeometry(const QRect &v) { setIniValue("connWindow/geometry", v); } + + bool connWindowMaximized() const { return iniBool("connWindow/maximized"); } + void setConnWindowMaximized(bool on) { setIniValue("connWindow/maximized", on); } + + int connListHeaderVersion() const { return iniInt("connWindow/connListHeaderVersion"); } + void setConnListHeaderVersion(int v) { setIniValue("connWindow/connListHeaderVersion", v); } + + QByteArray connListHeader() const { return iniByteArray("connWindow/connListHeader"); } + void setConnListHeader(const QByteArray &v) { setIniValue("connWindow/connListHeader", v); } + qint32 quotaDayAlerted() const { return iniInt("quota/dayAlerted"); } void setQuotaDayAlerted(qint32 v) { setIniValue("quota/dayAlerted", v); } @@ -221,6 +233,7 @@ public: QString hotKeyOptions() const { return iniText("hotKey/options"); } QString hotKeyZones() const { return iniText("hotKey/zones"); } QString hotKeyGraph() const { return iniText("hotKey/graph"); } + QString hotKeyConnections() const { return iniText("hotKey/connections"); } QString hotKeyFilter() const { return iniText("hotKey/filter", "Ctrl+Alt+Shift+F"); } QString hotKeyStopTraffic() const { return iniText("hotKey/stopTraffic"); } QString hotKeyStopInetTraffic() const { return iniText("hotKey/stopInetTraffic"); } diff --git a/src/ui/icons/connect.png b/src/ui/icons/connect.png new file mode 100644 index 0000000000000000000000000000000000000000..786b1db6ea633eb6759930f632550044749fc03e GIT binary patch literal 1094 zcmV-M1iAZ(P)xLv&=v&L+K~7l@%6!vCTbN3YD3gg zON)m3LRK`OeW@u*OB;nEEiG+>>04@HmuTf$c@ zBRoJ*gDlINV*)6xI9-%tLkE^+Cn=SUgAj)iP>PF=Y+rt8)_|Sg49h`+ZsyF80T6@; z=bBD0O?pF1Qsbd!S$48@PtzdCSVEX`uO!QPO|KOU&I(XoKcaSx2KFsTvu?D>6myU` zp%Q3>l0=o^jO(qqqJDs@SOSG}oiJ%b^Y;7d%-E=am-cs|iAlw=W?{mH+cFbj)ER(@ zsSr3l8jQJu;1a8AS_4%Mi~Dto9zC*SMcqvNtTHG&IK(&Io5EXrop9jTD3T=1IY$UM zh}HZ6k|_-tOxpCr&Q)LkJ$6=r&6OYW+tUj8x7}l5j~N3lCNkAIivYMr+z2Z-{`lr9 zPgFp8!?4;p64;-g6<2(s-vu}1RKh_2J>c==g3fdR1`s*9m?nU7P=N(BigH@Y?Y~6@ zlvbauec%>rX>LX$KQ%N3j-$hOvzb;OP&39bb{7r0@NH7_g{DMk6+ut7!`+K`5|0p!3*5a65A#O^Tv1b*V^!MlMtYapv)(*6QM@Wq#QYTPnNPi{A3FqVTxm zXWgdrqEL7Q@Mp!Cc41vdM=RF;H-Oo4Qxni9cV;Kssu~ACG9Rn3gc266cZfV)urdR@ z=e?h+iIykYs*86-h!Wa6d(HCoGDR%7~E?^7$mDg&-Kv z8?Y5W+qUO&&#wq5*?neCyao5Iywx^Wh;vz-T;>oU6qSgscsQC!RKO#zlVNue%!YFyNsbCzB*Bed%#uT%DX~3o?$UC^fczSC(IYwc-)L+kI8R zsflL*i_@% M07*qoM6N<$g5JpuQvd(} literal 0 HcmV?d00001 diff --git a/src/ui/log/logmanager.cpp b/src/ui/log/logmanager.cpp index 8f803f53..fe03f58d 100644 --- a/src/ui/log/logmanager.cpp +++ b/src/ui/log/logmanager.cpp @@ -9,6 +9,7 @@ #include "../fortmanager.h" #include "../model/applistmodel.h" #include "../model/appstatmodel.h" +#include "../model/connlistmodel.h" #include "../util/dateutil.h" #include "../util/osutil.h" #include "logbuffer.h" @@ -33,6 +34,11 @@ AppStatModel *LogManager::appStatModel() const return fortManager()->appStatModel(); } +ConnListModel *LogManager::connListModel() const +{ + return fortManager()->connListModel(); +} + DriverWorker *LogManager::driverWorker() const { return fortManager()->driverManager()->driverWorker(); @@ -143,7 +149,7 @@ void LogManager::readLogEntries(LogBuffer *logBuffer) case LogEntry::AppBlockedIp: { LogEntryBlockedIp blockedIpEntry; logBuffer->readEntryBlockedIp(&blockedIpEntry); - // connListModel()->handleLogBlockedIp(blockedIpEntry); + connListModel()->handleLogBlockedIp(blockedIpEntry); break; } case LogEntry::ProcNew: { diff --git a/src/ui/log/logmanager.h b/src/ui/log/logmanager.h index 926827fd..a575d635 100644 --- a/src/ui/log/logmanager.h +++ b/src/ui/log/logmanager.h @@ -5,6 +5,7 @@ class AppListModel; class AppStatModel; +class ConnListModel; class FortManager; class DriverWorker; class LogBuffer; @@ -21,6 +22,7 @@ public: DriverWorker *driverWorker() const; AppListModel *appListModel() const; AppStatModel *appStatModel() const; + ConnListModel *connListModel() const; void setActive(bool active); diff --git a/src/ui/model/applistmodel.cpp b/src/ui/model/applistmodel.cpp index 45a9ef71..a203ae61 100644 --- a/src/ui/model/applistmodel.cpp +++ b/src/ui/model/applistmodel.cpp @@ -61,12 +61,6 @@ void AppListModel::handleLogBlocked(const LogEntryBlocked &logEntry) { const QString appPath = logEntry.path(); -#if 0 - const QString ipText = NetUtil::ip4ToText(logEntry.ip()) - + ", " + NetUtil::protocolName(logEntry.proto()) - + ':' + QString::number(logEntry.port()); -#endif - if (confManager()->appPathExists(appPath)) return; // already added by user diff --git a/src/ui/model/connlistmodel.cpp b/src/ui/model/connlistmodel.cpp index cabd24b9..eb947ca9 100644 --- a/src/ui/model/connlistmodel.cpp +++ b/src/ui/model/connlistmodel.cpp @@ -1,12 +1,33 @@ #include "connlistmodel.h" -ConnListModel::ConnListModel(QObject *parent) : StringListModel(parent) { } +#include "../log/logentryblockedip.h" + +ConnListModel::ConnListModel(ConfManager *confManager, QObject *parent) : + StringListModel(parent), m_confManager(confManager) +{ +} void ConnListModel::setAppPath(const QString &appPath) { m_appPath = appPath; } +void ConnListModel::handleLogBlockedIp(const LogEntryBlockedIp &logEntry) +{ + const QString appPath = logEntry.path(); + +#if 0 + const QString ipText = NetUtil::ip4ToText(logEntry.ip()) + + ", " + NetUtil::protocolName(logEntry.proto()) + + ':' + QString::number(logEntry.port()); + + if (confManager()->addApp( + appPath, QString(), QDateTime(), groupId, false, logEntry.blocked(), true)) { + reset(); + } +#endif +} + void ConnListModel::clear() { m_appPath = QString(); diff --git a/src/ui/model/connlistmodel.h b/src/ui/model/connlistmodel.h index 38d1fe39..7b5ccd90 100644 --- a/src/ui/model/connlistmodel.h +++ b/src/ui/model/connlistmodel.h @@ -3,22 +3,27 @@ #include "../util/model/stringlistmodel.h" +class ConfManager; +class LogEntryBlockedIp; + class ConnListModel : public StringListModel { Q_OBJECT public: - explicit ConnListModel(QObject *parent = nullptr); + explicit ConnListModel(ConfManager *confManager, QObject *parent = nullptr); QString appPath() const { return m_appPath; } void setAppPath(const QString &appPath); -signals: + void handleLogBlockedIp(const LogEntryBlockedIp &logEntry); public slots: void clear() override; private: + ConfManager *m_confManager = nullptr; + QString m_appPath; }; diff --git a/src/ui/util/conf/confutil.h b/src/ui/util/conf/confutil.h index aab4a46c..afcddbdb 100644 --- a/src/ui/util/conf/confutil.h +++ b/src/ui/util/conf/confutil.h @@ -15,7 +15,7 @@ class ConfAppsWalker; class EnvManager; class FirewallConf; -QT_FORWARD_DECLARE_STRUCT(fort_traf) +struct fort_traf; using longs_arr_t = QVector; using shorts_arr_t = QVector;