1. Overview
The main_window.cpp file implements the primary GTK workflow for source selection, scanning, recovery and reporting.
This is an implementation file. It contains executable logic for the subsystem, including parsing, I/O, validation, recovery flow, or graphical behavior declared by the corresponding interface.
Its paired source or interface file is main_window.hpp.
Primary responsibilities:
- Build dashboard, recovery wizard and about views
- Enumerate devices and select sources
- Start background scan and recovery workers
- Display progress, logs and results
- Persist language and theme preferences
2. File Identity and Scope
- Source path:
src/main_window.cpp - Language: C++
- File role: implementation file
- Physical lines: 1573
- Non-empty lines: 1298
- SHA-256:
5d08b6455564c0b00ff4dfff43aeb5a0332b2dcb79c3ed5296117869e61ba7e1
The declarations in this file use the global namespace.
3. Dependencies
3.1 Project Headers
main_window.hppi18n.hppunistd.hpangomm.hResource.hppprivilege_utils.hpp
3.2 Standard and External Headers
gtk/gtk.halgorithmmapunordered_setiomanipfstreamfilesystemiostreamsstreamglibmm/ustring.h
These dependencies define the file’s compile-time integration with the recovery engine, GTK interface, on-disk format decoders, operating-system services, or C++ standard library.
4. Declared Types
No class, structure, or enumeration definition is declared directly in this file.
5. Constants and Configuration Values
No preprocessor or compile-time constants were detected as top-level declarations in this file.
5.1 Operational Strings, Paths, Formats, or Commands
The following code literals are operationally relevant and may identify filesystem paths, helper commands, formats, signatures, or subsystem labels:
Select a physical disk or image file. Physical disks require read access; use the pkexec button when needed.Relaunch with pkexecChoose a destination folder on a different disk or mount point than the source.BastionGuard-dark.cssBastionGuard.cssSource access denied. Relaunch with pkexec or adjust permissions.Failed to launch pkexec:Requested pkexec relaunch.NTFSext4EXT4BtrfsBTRFS/Supported filesystems: ext4 ⢠Btrfs ⢠NTFS ⢠FAT32 ⢠exFAT ⢠XFS ⢠HFS+/.config/bastionguard-recovery-data/lang.conf/.config/bastionguard-recovery-data/lang.conf/.config/bastionguard-recovery-data/theme.conf/theme.conf/proc/self/exe
6. Data Members and Persistent State
No class data members are declared directly in this file, or the file primarily implements methods declared elsewhere.
7. API and Function Inventory
The following callable interfaces or definitions were detected:
std::string format_elapsed(std::chrono::steady_clock::duration elapsed)– Implements the operation identified by this API and updates or returns the associated state.void set_button_with_svg_icon(Gtk::Button&button,const std::string&svg_path,const Glib::ustring&text)– Persists or exports the supplied state to the relevant destination.std::string read_text_file(const std::string&path)– Reads or derives the requested information and returns or stores the decoded result.std::string load_license_text()– Reads or derives the requested information and returns or stores the decoded result.void MainWindow::build_headerbar()– Constructs the requested object, data structure or user-interface component.} catch(const Glib::Error&ex)– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::build_sidebar()– Constructs the requested object, data structure or user-interface component.} catch(...)– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::build_dashboard()– Constructs the requested object, data structure or user-interface component.void MainWindow::build_wizard()– Constructs the requested object, data structure or user-interface component.void MainWindow::build_recovery_page()– Constructs the requested object, data structure or user-interface component.void MainWindow::apply_theme(ThemeMode mode)– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::update_theme_buttons()– Refreshes the related state or presentation from current data.void MainWindow::activate_sidebar_button(Gtk::Button*button)– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::refresh_devices()– Refreshes the related state or presentation from current data.void MainWindow::populate_device_lists()– Refreshes the related state or presentation from current data.void MainWindow::select_source(const std::string&path,const std::string&label)– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::update_source_state()– Refreshes the related state or presentation from current data.void MainWindow::update_wizard_step()– Refreshes the related state or presentation from current data.void MainWindow::append_log(const std::string&line)– Updates the relevant collection or range state.void MainWindow::on_sidebar_dashboard()– Handles the related event, callback or user action.void MainWindow::on_sidebar_recovery()– Handles the related event, callback or user action.void MainWindow::on_refresh_devices()– Handles the related event, callback or user action.void MainWindow::on_open_image()– Handles the related event, callback or user action.void MainWindow::on_choose_destination()– Handles the related event, callback or user action.void MainWindow::on_use_selected_device()– Handles the related event, callback or user action.void MainWindow::on_dashboard_device_activated(Gtk::ListBoxRow*row)– Handles the related event, callback or user action.void MainWindow::on_recovery_device_activated(Gtk::ListBoxRow*row)– Handles the related event, callback or user action.void MainWindow::on_theme_dark()– Handles the related event, callback or user action.void MainWindow::on_theme_light()– Handles the related event, callback or user action.void MainWindow::on_wizard_back()– Handles the related event, callback or user action.void MainWindow::on_wizard_next()– Handles the related event, callback or user action.void MainWindow::on_scan_now()– Handles the related event, callback or user action.void MainWindow::on_recover_now()– Handles the related event, callback or user action.void MainWindow::on_launch_elevated()– Handles the related event, callback or user action.void MainWindow::on_scan_progress(const ScanProgress&progress)– Handles the related event, callback or user action.void MainWindow::on_scan_completed(const ScanReport&report)– Handles the related event, callback or user action.std::string MainWindow::result_group_label(const ScanResult&result)– Implements the operation identified by this API and updates or returns the associated state.std::string MainWindow::result_subgroup_label(const ScanResult&result)– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::populate_scan_results(const ScanReport&report)– Refreshes the related state or presentation from current data.} else if(count==1)– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::update_selected_results_state()– Refreshes the related state or presentation from current data.std::vector<size_t> MainWindow::selected_result_indices()const– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::set_all_results_selected(bool selected)– Persists or exports the supplied state to the relevant destination.void MainWindow::on_recovery_completed(const RecoveryResult&result)– Handles the related event, callback or user action.void MainWindow::minimize_window()– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::hide_window()– Implements the operation identified by this API and updates or returns the associated state.void MainWindow::build_about_page()– Constructs the requested object, data structure or user-interface component.void MainWindow::update_action_controls()– Refreshes the related state or presentation from current data.void MainWindow::on_sidebar_about()– Handles the related event, callback or user action.std::string MainWindow::read_language()– Reads or derives the requested information and returns or stores the decoded result.void MainWindow::save_language(const std::string&lang_code)– Persists or exports the supplied state to the relevant destination.std::string MainWindow::read_theme()– Reads or derives the requested information and returns or stores the decoded result.void MainWindow::save_theme(const std::string&theme_code)– Persists or exports the supplied state to the relevant destination.void MainWindow::on_language_changed()– Handles the related event, callback or user action.std::string MainWindow::human_size(uint64_t bytes)– Implements the operation identified by this API and updates or returns the associated state.
8. Operational Flow
The subsystem represented by this file normally participates in the following flow:
- Build dashboard, recovery wizard and about views.
- Enumerate devices and select sources.
- Start background scan and recovery workers.
- Display progress, logs and results.
- Persist language and theme preferences.
- Expose or execute the detected APIs:
format_elapsed, set_button_with_svg_icon, read_text_file, load_license_text, build_headerbar, catch, build_sidebar, build_dashboard, build_wizard, build_recovery_page, apply_theme, update_theme_buttons, activate_sidebar_button, refresh_devices, populate_device_lists, select_source, update_source_state, update_wizard_stepand additional helpers. - Return explicit results, progress data, recovered records, or diagnostics to the calling layer.
9. Validation and Error Handling
- Errors are propagated through Boolean results, error strings, logs, exceptions, or status records depending on the API.
- Byte offsets, sizes and lengths must be validated before arithmetic and before every read to avoid overflow and out-of-bounds access.
- Input and output paths require existence checks, permission handling and safe destination construction.
- The implementation contains explicit failure-catching paths and should retain the original diagnostic context.
10. Runtime, Concurrency, and Resource Management
- I/O: filesystem and raw-source operations can fail partially and must preserve exact byte counts and diagnostic context.
- Privileges: some paths involve raw devices, mappings or mounts and therefore require carefully bounded elevated execution.
- Error handling: explicit error, exception or optional-result paths are present and form part of the file contract.
- GTK lifecycle: widget ownership, signal connections and main-thread affinity must be preserved.
- File descriptors and streams must be closed on success, cancellation and error paths.
- Temporary loop devices, mappings and mounts require deterministic reverse-order cleanup.
- GTK objects and callbacks must obey main-thread affinity and signal lifetime rules.
11. Security and Data-Recovery Considerations
- Recovery code should prefer read-only source access and avoid writing to the original damaged medium.
- Raw devices and image files are treated as untrusted binary input; every offset and length must remain bounded by the source size.
- Recovered names and destination paths must be sanitized to prevent directory traversal and accidental overwrite outside the selected export directory.
- Operations that open block devices, create mappings or mount filesystems require elevated privileges and should expose the smallest possible privileged surface.
12. Implementation Considerations
- The implementation should remain aligned with declarations in the paired header and preserve documented return-value semantics.
- The file is large and combines multiple parsing or recovery stages; refactoring should preserve byte-level behavior and regression coverage.
- Large-device arithmetic uses 64-bit values; additions and multiplications should be checked before use as offsets or allocation sizes.
- Filesystem operations can cross trust boundaries and should use normalized, contained destination paths.
13. Integration with the Recovery Pipeline
- The file belongs to the application startup or presentation layer.
- It receives or presents data produced by scan and recovery services.
- Long-running operations should remain delegated to worker classes rather than blocking the GTK main loop.
14. Licensing and Provenance
No explicit copyright or software-license statement was detected in the opening section of this individual file. Distribution terms should therefore be verified against the project-level license and repository metadata.
The SHA-256 value in this document can be used to associate the generated documentation with the exact source version analyzed.
