MainWindow.cpp

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: Implementation. The file contains 1071 lines and belongs to the MainWindow.cpp path.

The companion file is MainWindow.hpp.


2. Component Responsibilities

  • Implement the behavior declared by the corresponding header or entry-point contract.
  • 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:

  • MainWindow.hpp
  • Resource.hpp
  • util/AppResolver.hpp
  • glibmm/i18n.h
  • glibmm/miscutils.h
  • gdkmm/pixbuf.h
  • gio/gio.h
  • gtk/gtk.h
  • locale.h

System and library dependencies:

  • cstdlib
  • algorithm
  • filesystem
  • fstream
  • iostream
  • optional
  • sstream

4. Declared Types

Candidate

Declares a struct.


5. Constants and Fixed Configuration

The file declares or uses the following fixed values:

constexpr int kNotifDesktopActive = 15;
constexpr int kNotifDesktopIdle = 16;
constexpr const char* kUISocketPath = "unix:///tmp/bsd-daemon.sock";
constexpr const char* kSystemdServiceName = "bsc-daemon.service";
constexpr const char* kSystemAutostartDesktop = "/etc/xdg/autostart/bastionguard-sc-autostart.desktop";
constexpr const char* kFallbackSystemAutostartDesktop = "/etc/xdg/autostart/bastionguard-sc.desktop";
constexpr const char* kSystemAutostartBackupDesktop = "/etc/xdg/autostart/bastionguard-sc-autostart.desktop.bak";
constexpr int kWhatConnection = 3;
constexpr int kTypeWarning = 1;

6. Signals and Event Integration

The file exposes or connects the following signal-related elements:

  • m_settingsPage.signal_toggle_protection_requested().connect(
  • m_uiServer.signal_daemon_connected.connect(
  • m_uiServer.signal_daemon_disconnected.connect(
  • m_uiServer.signal_new_connection.connect(
  • m_uiServer.signal_alert.connect(
  • m_langDialog->signal_hide().connect([this]() {
  • btnLang->signal_clicked().connect(
  • m_btnLight->signal_clicked().connect([this]() { applyTheme(false); });
  • m_btnDark->signal_clicked().connect([this]() { applyTheme(true); });
  • btn->signal_clicked().connect(cb);
  • btn->signal_clicked().connect([this, btn, pageName]() {
  • g_signal_connect(
  • m_alertDialog->signal_verdict.connect(

GTK-facing callbacks must execute on the main UI context. Components with worker threads use dispatchers or idle callbacks to cross the thread boundary.


7. Functions and Methods

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

1. MainWindow

MainWindow::MainWindow()

Constructs the object, initializes its state, builds required resources, and connects the relevant callbacks.

2. ~MainWindow

MainWindow::~MainWindow()

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

3. saveConfig

void MainWindow::saveConfig()

Serializes or persists config.

4. loadConfig

void MainWindow::loadConfig()

Loads config from its persistent or runtime source.

5. applyLanguage

void MainWindow::applyLanguage(const std::string& lang)

Applies language to the active configuration or interface.

6. showLanguageDialog

void MainWindow::showLanguageDialog()

Displays language dialog.

7. loadTheme

void MainWindow::loadTheme(bool dark)

Loads theme from its persistent or runtime source.

8. applyTheme

void MainWindow::applyTheme(bool dark)

Applies theme to the active configuration or interface.

9. buildHeaderBar

void MainWindow::buildHeaderBar()

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

10. buildSidebar

void MainWindow::buildSidebar()

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

11. makeSidebarButton

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

Creates or derives sidebar button.

12. activateSidebarButton

void MainWindow::activateSidebarButton(Gtk::Button* btn)

Implements the activate sidebar button operation declared by this component.

13. startDesktopActivityMonitor

void MainWindow::startDesktopActivityMonitor()

Starts desktop activity monitor and activates the associated runtime resources.

14. pollDesktopActivity

bool MainWindow::pollDesktopActivity()

Polls desktop activity and returns the current condition.

15. noteDesktopActivity

void MainWindow::noteDesktopActivity()

Records desktop activity in the current in-memory model.

16. sendDesktopActivityState

void MainWindow::sendDesktopActivityState(bool active, bool force)

Sends desktop activity state to the connected peer or subsystem.

17. onDaemonConnected

void MainWindow::onDaemonConnected()

Handles the daemon connected callback or user event.

18. onDaemonDisconnected

void MainWindow::onDaemonDisconnected()

Handles the daemon disconnected callback or user event.

19. cacheKey

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

Implements the cache key operation declared by this component.

20. onNewConnection

void MainWindow::onNewConnection(const ConnectionInfo& info)

Handles the new connection callback or user event.

21. onDaemonAlert

void MainWindow::onDaemonAlert(const AlertInfo& alert)

Handles the daemon alert callback or user event.

22. onVerdict

void MainWindow::onVerdict(Verdict v, const ConnectionInfo& info)

Handles the verdict callback or user event.

23. setStatus

void MainWindow::setStatus(const std::string& msg)

Updates status and synchronizes dependent state.

24. applyProtectionEnabled

void MainWindow::applyProtectionEnabled(bool enabled)

Applies protection enabled to the active configuration or interface.

25. refreshSystemIntegrationStatus

void MainWindow::refreshSystemIntegrationStatus()

Refreshes system integration status from the authoritative system state.

26. on_close_request

bool MainWindow::on_close_request()

Handles the close request callback or user event.


8. Filesystem, IPC, Network, and Command Interfaces

Relevant literal paths, endpoints, or resource locations include:

  • /org/freedesktop/ScreenSaver
  • /org/gnome/ScreenSaver
  • /org/cinnamon/ScreenSaver
  • /org/mate/ScreenSaver
  • unix:///tmp/bsd-daemon.sock
  • /etc/xdg/autostart/bastionguard-sc-autostart.desktop
  • /etc/xdg/autostart/bastionguard-sc.desktop
  • /etc/xdg/autostart/bastionguard-sc-autostart.desktop.bak
  • /bastionguard-sc/settings.ini

Relevant command or protocol construction lines include:

<< "install -m 0644 " << shellQuote(kSystemAutostartDesktop) << " " << shellQuote(backupFile) << "; fi; ";
<< "install -m 0644 " << shellQuote(kFallbackSystemAutostartDesktop) << " " << shellQuote(backupFile) << "; fi; ";
script << "rm -f " << shellQuote(kSystemAutostartDesktop) << " " << shellQuote(kFallbackSystemAutostartDesktop) << "; ";
script << "if systemctl list-unit-files " << shellQuote(kSystemdServiceName) << " --no-legend 2>/dev/null | grep -q .; then "
<< "systemctl disable --now " << shellQuote(kSystemdServiceName) << "; "
<< "else systemctl stop " << shellQuote(kSystemdServiceName) << " 2>/dev/null || true; fi; ";
<< "install -D -m 0644 " << shellQuote(backupFile) << " " << shellQuote(kSystemAutostartDesktop) << "; "
<< "else install -D -m 0644 " << shellQuote(generatedAutostart.string()) << " " << shellQuote(kSystemAutostartDesktop) << "; fi; ";
script << "rm -f " << shellQuote(kFallbackSystemAutostartDesktop) << "; ";
script << "systemctl enable --now " << shellQuote(kSystemdServiceName) << "; ";
ok = runCommand("pkexec /bin/sh -c " + shellQuote(script.str()));
const bool serviceEnabled = runCommand("systemctl is-enabled --quiet " + std::string(kSystemdServiceName) + " >/dev/null 2>&1");

9. 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

10. 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.
  • Privileged file or service modifications are delegated through pkexec.
  • Temporary paths are used; file naming, permissions, and replacement behavior form part of the privilege boundary.

11. Error Handling and Operational Notes

  • Exceptions are caught locally in one or more operations to prevent application-wide termination.
  • Diagnostic failures are written to standard error or the GLib logging channel.
  • Boolean-returning operations use false to report recoverable failure.
  • Optional results distinguish unavailable data from valid empty values.

12. Source Integrity

Relative source path: MainWindow.cpp

SHA-256:

de46e6fda4a6eb64cfe564c750830c3c1ea10077b815c1cf9bd06387da8cefaf

13. 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.