MainWindow.hpp

1. Overview

Primary GTKmm application window that composes all pages, connects to the security daemon, displays connection alerts, manages persistent UI settings, controls protection state, integrates the system tray, and reports desktop activity.

File role: Header Interface. The file contains 135 lines and belongs to the MainWindow.hpp path.

The companion file is MainWindow.cpp.


2. Component Responsibilities

  • Declare the component API, owned state, callbacks, and data structures.
  • Load persistent configuration and language preferences
  • Build the header bar, sidebar, page stack, status bar, and tray integration
  • Start the Unix-socket UI server
  • Route daemon connections and alerts to the appropriate pages and dialog
  • Cache persistent allow/deny verdicts and update session statistics
  • Monitor screen-lock and user-activity state
  • Perform service and autostart integration checks during shutdown or preference changes

3. Dependencies and Integration

Project-level dependencies:

  • gtkmm.h
  • dialogs/AlertDialog.hpp
  • dialogs/LanguageDialog.hpp
  • ipc/UIServer.hpp
  • pages/ConnectionsPage.hpp
  • pages/AppsPage.hpp
  • pages/NetworkPage.hpp
  • pages/RulesPage.hpp
  • pages/StatsPage.hpp
  • pages/AboutPage.hpp
  • pages/SettingsPage.hpp
  • TrayIcon.hpp

System and library dependencies:

  • chrono
  • map
  • memory
  • string
  • vector

4. Declared Types

MainWindow

Declares a class derived from or associated with public Gtk::ApplicationWindow.


5. Owned State and UI Members

User-interface members

  • Gtk::Box m_mainBox { Gtk::Orientation::HORIZONTAL, 0 };
  • Gtk::Stack m_stack;
  • std::vector<Gtk::Button*> m_sidebarButtons;
  • Gtk::Button* m_activeButton = nullptr;
  • Gtk::Label* m_daemonLabel = nullptr;
  • Glib::RefPtr<Gtk::CssProvider> m_cssProvider;
  • Gtk::Button* m_btnLight = nullptr;
  • Gtk::Button* m_btnDark = nullptr;
  • Gtk::Statusbar m_statusbar;

Data and configuration state

  • UIServer m_uiServer;
  • ConnectionsPage m_connectionsPage { m_uiServer };
  • AppsPage m_appsPage;
  • NetworkPage m_networkPage;
  • RulesPage m_rulesPage;
  • StatsPage m_statsPage;
  • AboutPage m_aboutPage;
  • SettingsPage m_settingsPage;
  • TrayIcon m_tray;
  • std::unique_ptr<AlertDialog> m_alertDialog;
  • std::unique_ptr<LanguageDialog> m_langDialog;
  • std::map<std::string, ReplyAction> m_verdictCache;
  • bool m_darkMode = false;
  • guint m_statusCtx = 0;
  • uint64_t m_statAllowed = 0;
  • uint64_t m_statDenied = 0;
  • std::string m_configFile;
  • std::string m_language;
  • bool m_protectionEnabled = true;
  • std::string m_autostartBackupFile;
  • guint m_desktopActivityTimer = 0;
  • bool m_desktopActiveSent = true;
  • std::chrono::steady_clock::time_point m_lastUiActivity{};

6. Functions and Methods

The file exposes or implements 26 detected function or method signatures.

1. MainWindow

MainWindow()

Implements the main window operation declared by this component.

2. ~MainWindow

~MainWindow() override

Releases resources owned by the object and stops any active background integration.

3. cacheKey

static std::string cacheKey(const std::string& app, const std::string& host, const std::string& ip)

Implements the cache key operation declared by this component.

4. buildHeaderBar

void buildHeaderBar()

Builds and configures the header bar user-interface or internal structure.

5. buildSidebar

void buildSidebar()

Builds and configures the sidebar user-interface or internal structure.

6. makeSidebarButton

Gtk::Button* makeSidebarButton(const std::string& iconPath, const std::string& label, const std::string& pageName)

Creates or derives sidebar button.

7. activateSidebarButton

void activateSidebarButton(Gtk::Button* btn)

Implements the activate sidebar button operation declared by this component.

8. loadTheme

void loadTheme(bool dark)

Loads theme from its persistent or runtime source.

9. applyTheme

void applyTheme(bool dark)

Applies theme to the active configuration or interface.

10. saveConfig

void saveConfig()

Serializes or persists config.

11. loadConfig

void loadConfig()

Loads config from its persistent or runtime source.

12. applyLanguage

void applyLanguage(const std::string& lang)

Applies language to the active configuration or interface.

13. showLanguageDialog

void showLanguageDialog()

Displays language dialog.

14. onDaemonConnected

void onDaemonConnected()

Handles the daemon connected callback or user event.

15. onDaemonDisconnected

void onDaemonDisconnected()

Handles the daemon disconnected callback or user event.

16. onNewConnection

void onNewConnection(const ConnectionInfo& info)

Handles the new connection callback or user event.

17. onDaemonAlert

void onDaemonAlert(const AlertInfo& alert)

Handles the daemon alert callback or user event.

18. onVerdict

void onVerdict(Verdict v, const ConnectionInfo& info)

Handles the verdict callback or user event.

19. setStatus

void setStatus(const std::string& msg)

Updates status and synchronizes dependent state.

20. applyProtectionEnabled

void applyProtectionEnabled(bool enabled)

Applies protection enabled to the active configuration or interface.

21. refreshSystemIntegrationStatus

void refreshSystemIntegrationStatus()

Refreshes system integration status from the authoritative system state.

22. startDesktopActivityMonitor

void startDesktopActivityMonitor()

Starts desktop activity monitor and activates the associated runtime resources.

23. pollDesktopActivity

bool pollDesktopActivity()

Polls desktop activity and returns the current condition.

24. noteDesktopActivity

void noteDesktopActivity()

Records desktop activity in the current in-memory model.

25. sendDesktopActivityState

void sendDesktopActivityState(bool active, bool force = false)

Sends desktop activity state to the connected peer or subsystem.

26. on_close_request

bool on_close_request() override

Handles the close request callback or user event.


7. Runtime Flow

  1. Load persistent configuration and language preferences
  2. Build the header bar, sidebar, page stack, status bar, and tray integration
  3. Start the Unix-socket UI server
  4. Route daemon connections and alerts to the appropriate pages and dialog
  5. Cache persistent allow/deny verdicts and update session statistics
  6. Monitor screen-lock and user-activity state
  7. Perform service and autostart integration checks during shutdown or preference changes

8. Runtime and Security Considerations

  • Communicates with the daemon through a local Unix socket.
  • Uses explicit verdict types for one-time and persistent connection decisions.
  • Tracks desktop idle/locked state so the daemon can suppress scans and popups when the desktop is inactive.
  • Uses pkexec/systemd integration for protected system configuration where required.

9. Error Handling and Operational Notes

  • Errors are propagated through the return type, callbacks, or the owning controller.

10. Source Integrity

Relative source path: MainWindow.hpp

SHA-256:

0439f5f993e315429d553a6b50eba8eddecaa25e5dddf999f8e34abafe5ab2f7

11. Licensing

The source header identifies this component as distributed under the GNU General Public License version 3. BastionGuard branding and trademarks remain subject to the notices stated in the source file.