Skip to content
API Documentation
BastionGuard™
MainWindow.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™ Secure Connection
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 * GPL-3.0 — BastionGuard™ is a trademark of Calogero Scarnà.
5 */
6
7#pragma once
8
9#include <gtkmm.h>
10#include <chrono>
11#include <map>
12#include <memory>
13#include <string>
14#include <vector>
15
18#include "ipc/UIServer.hpp"
20#include "pages/AppsPage.hpp"
21#include "pages/NetworkPage.hpp"
22#include "pages/RulesPage.hpp"
23#include "pages/StatsPage.hpp"
24#include "pages/AboutPage.hpp"
26#include "TrayIcon.hpp"
27
28class MainWindow : public Gtk::ApplicationWindow
29{
30public:
32 ~MainWindow() override;
33
34private:
35 // ── Layout
36 Gtk::Box m_mainBox { Gtk::Orientation::HORIZONTAL, 0 };
37 Gtk::Stack m_stack;
38
39 // ── gRPC (deve essere dichiarato PRIMA delle Pages che lo referenziano)
41
42 // ── Pages
50
51 // ── Systray
53
54 // ── AlertDialog attivo (al massimo uno alla volta)
55 std::unique_ptr<AlertDialog> m_alertDialog;
56
57 // ── Dialogo lingua (creato on-demand)
58 std::unique_ptr<LanguageDialog> m_langDialog;
59
60 // ── Cache verdetti "always"
61 // Chiave: "app|host|ip" — solo ALLOW_ALWAYS e DENY_ALWAYS memorizzati
62 std::map<std::string, ReplyAction> m_verdictCache;
63 static std::string cacheKey(const std::string& app,
64 const std::string& host,
65 const std::string& ip);
66
67 // ── Sidebar
68 std::vector<Gtk::Button*> m_sidebarButtons;
69 Gtk::Button* m_activeButton = nullptr;
70 Gtk::Label* m_daemonLabel = nullptr;
71
72 // ── Tema
73 Glib::RefPtr<Gtk::CssProvider> m_cssProvider;
74 bool m_darkMode = false;
75 Gtk::Button* m_btnLight = nullptr;
76 Gtk::Button* m_btnDark = nullptr;
77
78 // ── Statusbar
79 Gtk::Statusbar m_statusbar;
80 guint m_statusCtx = 0;
81
82 // ── Statistiche sessione
83 uint64_t m_statAllowed = 0;
84 uint64_t m_statDenied = 0;
85
86 // ── Config
87 std::string m_configFile;
88 std::string m_language;
91
92 // ── Stato attività desktop
93 // La UI comunica al daemon se il desktop è attivo o idle/bloccato.
94 // Quando è idle il daemon non scansiona e non apre popup.
97 std::chrono::steady_clock::time_point m_lastUiActivity{};
98
99 // ── Builder
100 void buildHeaderBar();
101 void buildSidebar();
102 Gtk::Button* makeSidebarButton(const std::string& iconPath,
103 const std::string& label,
104 const std::string& pageName);
105 void activateSidebarButton(Gtk::Button* btn);
106
107 // ── Tema
108 void loadTheme(bool dark);
109 void applyTheme(bool dark);
110 void saveConfig();
111 void loadConfig();
112
113 // ── Lingua
114 void applyLanguage(const std::string& lang);
115 void showLanguageDialog();
116
117 // ── Daemon & Alert
118 void onDaemonConnected();
120 void onNewConnection(const ConnectionInfo& info);
121 void onDaemonAlert(const AlertInfo& alert);
122 void onVerdict(Verdict v, const ConnectionInfo& info);
123
124 void setStatus(const std::string& msg);
125 void applyProtectionEnabled(bool enabled);
127
129 bool pollDesktopActivity();
130 void noteDesktopActivity();
131 void sendDesktopActivityState(bool active, bool force = false);
132
133 bool on_close_request() override;
134};
Verdict
Gtk::Stack m_stack
ConnectionsPage m_connectionsPage
Gtk::Box m_mainBox
~MainWindow() override
bool m_darkMode
UIServer m_uiServer
static std::string cacheKey(const std::string &app, const std::string &host, const std::string &ip)
void loadConfig()
Gtk::Button * makeSidebarButton(const std::string &iconPath, const std::string &label, const std::string &pageName)
void onVerdict(Verdict v, const ConnectionInfo &info)
void buildHeaderBar()
bool on_close_request() override
void refreshSystemIntegrationStatus()
RulesPage m_rulesPage
std::map< std::string, ReplyAction > m_verdictCache
void onDaemonDisconnected()
void applyProtectionEnabled(bool enabled)
void applyTheme(bool dark)
bool m_protectionEnabled
void activateSidebarButton(Gtk::Button *btn)
void saveConfig()
void showLanguageDialog()
bool m_desktopActiveSent
std::unique_ptr< LanguageDialog > m_langDialog
SettingsPage m_settingsPage
TrayIcon m_tray
uint64_t m_statAllowed
uint64_t m_statDenied
std::unique_ptr< AlertDialog > m_alertDialog
Gtk::Button * m_btnLight
void buildSidebar()
Gtk::Label * m_daemonLabel
void setStatus(const std::string &msg)
guint m_statusCtx
void noteDesktopActivity()
void onDaemonAlert(const AlertInfo &alert)
Gtk::Statusbar m_statusbar
std::chrono::steady_clock::time_point m_lastUiActivity
bool pollDesktopActivity()
AboutPage m_aboutPage
std::string m_language
guint m_desktopActivityTimer
Gtk::Button * m_btnDark
Gtk::Button * m_activeButton
void loadTheme(bool dark)
std::string m_autostartBackupFile
void sendDesktopActivityState(bool active, bool force=false)
AppsPage m_appsPage
NetworkPage m_networkPage
std::string m_configFile
void onDaemonConnected()
void startDesktopActivityMonitor()
Glib::RefPtr< Gtk::CssProvider > m_cssProvider
StatsPage m_statsPage
void onNewConnection(const ConnectionInfo &info)
std::vector< Gtk::Button * > m_sidebarButtons
static void applyLanguage(const std::string &lang)
Definition main.cpp:79