MainWindow

1. Overview

The MainWindow module implements the primary BastionGuard Backup graphical interface.

Its principal responsibilities are:

  • Provides snapshot, settings, wizard, about, backup, restore, deletion, and log pages
  • Manages navigation and responsive window sizing
  • Coordinates snapshot actions with the central controller
  • Persists language and theme preferences
  • Displays repository and operation status

The file defines multiple cooperating classes:

  • MainWindow – derives from Gtk.Window
  • AboutWindow – derives from Gtk.Window

2. Class Structure and Dependencies

public class MainWindow : Gtk.Window
public class AboutWindow : Gtk.Window

The source imports:

  • Gtk
  • Gee
  • GLib
  • TeeJee.Logging
  • TeeJee.FileSystem
  • TeeJee.JsonHelper
  • TeeJee.ProcessHelper
  • TeeJee.GtkHelper
  • TeeJee.System
  • TeeJee.Misc

The GTK inheritance and imported modules allow the component to participate in the application event loop, share the central backup state, and construct native GTK4 controls.


3. Primary Runtime State

The principal fields declared by the module include:

  • Gtk.Box hbox_root – Box widget used by the interface
  • Gtk.Box vbox_sidebar – Box widget used by the interface
  • Gtk.Stack content_stack – main dynamic navigation stack
  • Gtk.Widget? settings_page_widget – Widget? widget used by the interface
  • Gtk.Widget? wizard_page_widget – Widget? widget used by the interface
  • Gtk.Widget? about_page_widget – Widget? widget used by the interface
  • Gtk.Widget? backup_page_widget – Widget? widget used by the interface
  • Gtk.Widget? restore_page_widget – Widget? widget used by the interface
  • Gtk.Widget? delete_page_widget – Widget? widget used by the interface
  • Gtk.Widget? rsync_log_page_widget – Widget? widget used by the interface
  • Gtk.Button btn_nav_snapshots – button used to trigger the corresponding nav snapshots action
  • Gtk.Button btn_nav_settings – button used to trigger the corresponding nav settings action
  • Gtk.Button btn_nav_wizard – button used to trigger the corresponding nav wizard action
  • Gtk.Button btn_nav_about – button used to trigger the corresponding nav about action
  • Gtk.Button? current_nav_btn – Button? widget used by the interface
  • Gtk.CssProvider? css_provider – CssProvider? widget used by the interface
  • bool dark_mode – mode flag controlling dark mode
  • Gtk.Button? btn_theme_light – button used to trigger the corresponding theme light action
  • Gtk.Button? btn_theme_dark – button used to trigger the corresponding theme dark action
  • string THEME_CONFIG_DIR – text value for THEME CONFIG DIR
  • string THEME_CONFIG_FILE – text value for THEME CONFIG FILE
  • string LANG_CONFIG_FILE – text value for LANG CONFIG FILE
  • Gtk.ComboBoxText? lang_combo – ComboBoxText? widget used by the interface
  • string current_lang – text value for current lang
  • string[] LANG_CODES – runtime reference for LANG CODES
  • string[] LANG_NAMES – runtime reference for LANG NAMES
  • Gtk.Button btn_backup – button used to trigger the corresponding backup action
  • Gtk.Button btn_restore – button used to trigger the corresponding restore action

The file also contains 20 additional supporting fields used for layout, navigation, or internal state.


4. User Interface Composition

The module directly constructs the following GTK widget types:

  • Gtk.Box – layout containers
  • Gtk.Button – action and navigation buttons
  • Gtk.ComboBoxText – text-based selection controls
  • Gtk.CssProvider – runtime theme stylesheets
  • Gtk.HeaderBar – window title and header actions
  • Gtk.Image – themed icons and state illustrations
  • Gtk.Label – headings, descriptions, and status text
  • Gtk.LinkButton – external or internal informational links
  • Gtk.MessageDialog – modal notices and confirmations
  • Gtk.Separator – visual section separators
  • Gtk.Stack – multi-page content navigation

Event-driven behavior is connected through signals such as:

activate_link
browse_selected
changed
clicked
close_request
delete_selected
mark_selected
request_close
view_snapshot_log

5. Initialization

MainWindow()

public MainWindow()

Initializes the class instance, creates its GTK controls, and prepares the initial state. It reads or updates central state through App.live_system. It creates Gtk.Box where required. It connects the close_request signal.

AboutWindow()

public AboutWindow(Gtk.Window parent)

Initializes the class instance, creates its GTK controls, and prepares the initial state. It creates Gtk.Box, Gtk.Image, Gtk.Label, Gtk.LinkButton where required. It connects the activate_link signal.


6. Central Controller Integration

The module reads or modifies the following Main controller members through the global App object:

  • App.backup_parent_uuid
  • App.btrfs_mode
  • App.check_btrfs_layout_system
  • App.delete_file_task
  • App.delete_list
  • App.dry_run
  • App.exit_app
  • App.first_run
  • App.init_mount_list
  • App.live_system
  • App.mirror_system
  • App.repo
  • App.save_app_config
  • App.snapshot_to_restore
  • App.sys_root
  • App.task
  • App.thread_delete_running

7. Operational Workflow

  1. Initialize the sidebar, header, dynamic content stack, and snapshot list
  2. Refresh repository and status information
  3. Launch backup, restore, deletion, settings, setup, and log subflows
  4. Apply language and theme changes
  5. Perform centralized cleanup when the window closes

8. Method Reference

build_headerbar()

private void build_headerbar()

Builds the headerbar portion of the interface. It creates Gtk.Box, Gtk.Button, Gtk.HeaderBar where required. It connects the clicked signal.

load_theme_preference()

private bool load_theme_preference()

Loads theme preference from persistent or runtime state.

save_theme_preference()

private void save_theme_preference(bool use_dark)

Saves theme preference into the application model or persistent configuration.

load_language_preference()

private string load_language_preference()

Loads language preference from persistent or runtime state.

save_language_preference()

private void save_language_preference(string lang_code)

Saves language preference into the application model or persistent configuration.

apply_language_env()

private void apply_language_env(string lang_code)

Applies language env to the active state.

on_language_changed()

private void on_language_changed()

Event handler for language changed. It creates Gtk.MessageDialog where required.

restart_application()

private void restart_application()

Implements the restart application operation. It reads or updates central state through App.exit_app.

load_css()

private void load_css(bool use_dark = false)

Loads css from persistent or runtime state. It creates Gtk.CssProvider where required.

apply_theme()

private void apply_theme(bool use_dark)

Applies theme to the active state.

update_theme_buttons()

private void update_theme_buttons()

Updates theme buttons to reflect the current state.

init_sidebar()

private void init_sidebar()

Initializes sidebar state and controls. It creates Gtk.Box, Gtk.ComboBoxText, Gtk.Label, Gtk.Separator where required. It connects the changed, clicked signals.

make_nav_btn()

private Gtk.Button make_nav_btn(string icon, string label, string page)

Factory helper that creates nav btn. It creates Gtk.Box, Gtk.Button, Gtk.Label where required. It connects the clicked signal.

make_theme_btn()

private Gtk.Button make_theme_btn(string icon, string label)

Factory helper that creates theme btn. It creates Gtk.Box, Gtk.Button, Gtk.Label where required.

activate_nav()

private void activate_nav(Gtk.Button btn, string page)

Implements the activate nav operation.

show_snapshots_page()

private void show_snapshots_page()

Displays snapshots page to the user.

page_requires_expanded_window()

private bool page_requires_expanded_window(string page)

Implements the page requires expanded window operation.

remember_compact_window_size()

private void remember_compact_window_size()

Implements the remember compact window size operation.

resize_main_window()

private void resize_main_window(int width, int height)

Implements the resize main window operation.

apply_window_mode_for_page()

private void apply_window_mode_for_page(string page)

Applies window mode for page to the active state.

set_dynamic_page()

private void set_dynamic_page(string name, ref Gtk.Widget? slot, Gtk.Widget widget)

Sets dynamic page and updates dependent UI state.

open_backup_flow()

private void open_backup_flow()

Opens backup flow and updates the active interface. It connects the request_close signal.

open_delete_flow()

private void open_delete_flow()

Opens delete flow and updates the active interface. It connects the request_close signal.

open_restore_flow()

private void open_restore_flow()

Opens restore flow and updates the active interface. It reads or updates central state through App.dry_run, App.repo. It connects the request_close signal.

open_rsync_log_page()

private void open_rsync_log_page(string log_file)

Opens rsync log page and updates the active interface. It connects the request_close signal.

init_settings_page()

private void init_settings_page()

Initializes settings page state and controls. It connects the request_close signal.

init_wizard_page()

private void init_wizard_page()

Initializes wizard page state and controls. It connects the request_close signal.

init_about_page()

private void init_about_page()

Initializes about page state and controls. It creates Gtk.Box, Gtk.Label, Gtk.LinkButton where required. It connects the activate_link signal.

init_content()

private void init_content()

Initializes content state and controls. It creates Gtk.Box, Gtk.Stack where required.

init_snapshots_page()

private void init_snapshots_page()

Initializes snapshots page state and controls. It creates Gtk.Box, Gtk.Image, Gtk.Label where required. It connects the browse_selected, clicked, delete_selected, mark_selected, view_snapshot_log signals.

make_card()

private Gtk.Box make_card(bool hexpand)

Factory helper that creates card. It creates Gtk.Box where required.

make_action_btn()

private Gtk.Button make_action_btn(string icon, string label, bool primary, bool danger, string css_class = "")

Factory helper that creates action btn. It creates Gtk.Box, Gtk.Button, Gtk.Label where required.

init_delayed()

private bool init_delayed()

Performs initialization scheduled after the window has been presented. It reads or updates central state through App.backup_parent_uuid, App.btrfs_mode, App.first_run, App.repo.

refresh_all()

private bool refresh_all()

Refreshes all from the current application state.

on_close_request()

private bool on_close_request()

Handles a request to close the window and coordinates cleanup or state persistence. It reads or updates central state through App.delete_file_task, App.delete_list, App.exit_app, App.live_system, App.repo, App.task, App.thread_delete_running. It connects the close_request signal.

create_snapshot()

public void create_snapshot()

Creates snapshot required by the workflow. It reads or updates central state through App.btrfs_mode, App.check_btrfs_layout_system, App.repo.

delete_selected()

public void delete_selected()

Implements the delete selected operation. It reads or updates central state through App.delete_list, App.repo, App.thread_delete_running. It creates Gtk.MessageDialog where required.

mark_selected()

public void mark_selected()

Implements the mark selected operation. It reads or updates central state through App.repo.

browse_selected()

public void browse_selected()

Opens a GTK chooser for selected. It reads or updates central state through App.btrfs_mode, App.repo.

view_snapshot_log()

public void view_snapshot_log(bool view_restore_log)

Implements the view snapshot log operation.

btn_restore_clicked()

private void btn_restore_clicked()

Implements the btn restore clicked operation. It reads or updates central state through App.mirror_system.

check_if_deletion_running()

private bool check_if_deletion_running()

Checks if deletion running and returns the validation result. It reads or updates central state through App.thread_delete_running.

restore()

private void restore()

Implements the restore operation. It reads or updates central state through App.init_mount_list, App.mirror_system, App.snapshot_to_restore.

show_settings()

public void show_settings()

Displays settings to the user.

btn_settings_clicked()

private void btn_settings_clicked()

Implements the btn settings clicked operation.

btn_wizard_clicked()

private void btn_wizard_clicked()

Implements the btn wizard clicked operation.

settings_changed()

private void settings_changed(bool btrfs_mode_prev)

Implements the settings changed operation. It reads or updates central state through App.btrfs_mode, App.repo, App.save_app_config, App.sys_root.

btn_about_clicked()

private void btn_about_clicked()

Implements the btn about clicked operation.

ui_sensitive()

private void ui_sensitive(bool enable)

Implements the ui sensitive operation.

update_statusbar()

private void update_statusbar()

Updates statusbar to reflect the current state. It reads or updates central state through App.repo.

themed_icon()

private Gtk.Image themed_icon(string icon_name, int size)

Creates a themed GTK image at the requested size.

reload_themed_icons()

private void reload_themed_icons()

Reloads icons after a theme change.


9. External Resources and Paths

The source references the following relevant paths, command fragments, or resource identifiers:

/etc/bastionguard-backup
/etc/bastionguard-backup/theme.json
/etc/bastionguard-backup/language.json
/proc/self/exe
restart: cannot read /proc/self/exe: 
/css/
/localhost

10. Data and Event Flow

  1. Construct the component and initialize its child controls
  2. Load the current model state into the interface
  3. React to GTK signals generated by navigation, selections, and action controls
  4. Read or update central backup and restore state through the global controller
  5. Persist the final selections when the workflow is accepted or closed

11. Runtime and Security Considerations

  • Shared controller state: the component reads and modifies the global App controller used by the surrounding workflow.
  • Device safety: device selections are validated before backup or restore operations continue.
  • Signal-driven behavior: GTK callbacks update the model and interface when controls are activated or changed.
  • Reusable presentation: the component can be hosted as a standalone window or embedded inside the main navigation stack.
  • Dry-run support: the interface can invoke validation or simulation paths without committing the final restore operation.

12. Implementation Considerations

  • Persistent writes: settings or metadata are written directly by the component or delegated helper methods.
  • External commands: command execution errors and return statuses must be surfaced to the user and log.
  • Global coupling: the class depends on the process-wide App object rather than receiving a controller through dependency injection.
  • Embedding contract: parent containers must use detach_root_widget() only after the window has initialized its root widget.

13. Licensing

The source header contains the following copyright notices:

Copyright 2012-2018 Tony George <teejeetech@gmail.com>
Copyright 2025-2026 Calogero Scarnà — BastionGuard Backup

The file is distributed under the GNU General Public License version 2 or later.