Skip to content
API Documentation
BastionGuard™
main_window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <gtkmm.h>
4#include <giomm.h>
5
6#include <chrono>
7#include <cstdint>
8#include <string>
9#include <vector>
10
11#include "device_enumerator.hpp"
12#include "models.hpp"
13#include "recovery_worker.hpp"
14#include "scan_worker.hpp"
15
16class MainWindow : public Gtk::Window {
17public:
19 ~MainWindow() override;
20
21private:
22 enum class ThemeMode { Dark, Light };
23 enum class WizardStep { Source, Destination, Scan, Recover };
24
26 void build_sidebar();
27 void build_dashboard();
29 void build_wizard();
30 void build_about_page();
32
33 void apply_theme(ThemeMode mode);
36 void activate_sidebar_button(Gtk::Button* button);
37
38 void refresh_devices();
40 void select_source(const std::string& path, const std::string& label);
42 void update_wizard_step();
43 void append_log(const std::string& line);
44
47 void on_sidebar_about();
48 void on_refresh_devices();
50 void on_open_image();
53 void on_dashboard_device_activated(Gtk::ListBoxRow* row);
54 void on_recovery_device_activated(Gtk::ListBoxRow* row);
55 void on_theme_dark();
56 void on_theme_light();
57 void on_wizard_back();
58 void on_wizard_next();
59 void on_scan_now();
60 void on_recover_now();
61 void on_launch_elevated();
62 void on_scan_progress(const ScanProgress& progress);
63 void on_scan_completed(const ScanReport& report);
64 void on_recovery_completed(const RecoveryResult& result);
65 void populate_scan_results(const ScanReport& report);
67 std::vector<size_t> selected_result_indices() const;
68 void set_all_results_selected(bool selected);
69 static std::string result_group_label(const ScanResult& result);
70 static std::string result_subgroup_label(const ScanResult& result);
71 void minimize_window();
72 void hide_window();
73
74 static std::string human_size(uint64_t bytes);
75 static std::string read_language();
76 static void save_language(const std::string& lang_code);
77 static std::string read_theme();
78 static void save_theme(const std::string& theme_code);
79
80private:
83
84 Glib::RefPtr<Gtk::CssProvider> css_provider_;
85
86 Gtk::Box main_box_{Gtk::Orientation::HORIZONTAL, 0};
87 Gtk::Stack page_stack_;
88
89 Gtk::Box sidebar_{Gtk::Orientation::VERTICAL, 10};
90 Gtk::Box dashboard_page_{Gtk::Orientation::VERTICAL, 16};
91 Gtk::Box recovery_page_{Gtk::Orientation::VERTICAL, 16};
92 Gtk::Box about_page_{Gtk::Orientation::VERTICAL, 24};
93
94
95 Gtk::Grid cards_grid_;
96 Gtk::Frame card_status_;
97 Gtk::Frame card_source_;
98 Gtk::Frame card_update_;
102
103 Gtk::Frame devices_frame_;
104 Gtk::ScrolledWindow devices_scroller_;
105 Gtk::ListBox devices_list_;
106
107 Gtk::Label brand_label_;
108 Gtk::Button btn_dashboard_;
109 Gtk::Button btn_recovery_;
110 Gtk::Button btn_about_;
111 Gtk::Button btn_refresh_;
112 Gtk::Button btn_theme_dark_;
113 Gtk::Button btn_theme_light_;
114 Gtk::Button* dashboard_button_ = nullptr;
115 Gtk::Button* recovery_button_ = nullptr;
116 Gtk::Button* about_button_ = nullptr;
117 std::vector<Gtk::Button*> sidebar_buttons_;
118
119 Gtk::DropDown lang_combo_;
120 bool lang_changing_ = false;
121
122 Gtk::Box recovery_header_{Gtk::Orientation::VERTICAL, 8};
123 Gtk::Label recovery_title_;
125
126 Gtk::Frame wizard_frame_;
127 Gtk::Box wizard_root_{Gtk::Orientation::VERTICAL, 12};
128 Gtk::Stack wizard_stack_;
129 Gtk::Box wizard_nav_{Gtk::Orientation::HORIZONTAL, 8};
130 Gtk::Button btn_wizard_back_;
131 Gtk::Button btn_wizard_next_;
133
134 Gtk::Box source_step_box_{Gtk::Orientation::VERTICAL, 8};
136 Gtk::Box source_button_row_{Gtk::Orientation::HORIZONTAL, 8};
137 Gtk::Button btn_open_image_;
140 Gtk::ScrolledWindow recovery_devices_scroller_;
142
143 Gtk::Box destination_step_box_{Gtk::Orientation::VERTICAL, 8};
145 Gtk::Box destination_button_row_{Gtk::Orientation::HORIZONTAL, 8};
146 Gtk::Entry entry_output_;
148
149 Gtk::Box scan_step_box_{Gtk::Orientation::VERTICAL, 8};
151 Gtk::ProgressBar scan_progress_bar_;
154 Gtk::Button btn_scan_now_;
155
156 Gtk::Box recover_step_box_{Gtk::Orientation::VERTICAL, 8};
158 Gtk::Frame results_frame_;
159 Gtk::ScrolledWindow results_scroller_;
160 Gtk::Box results_tree_box_{Gtk::Orientation::VERTICAL, 8};
163 Gtk::Box results_actions_row_{Gtk::Orientation::HORIZONTAL, 8};
166 Gtk::Button btn_recover_now_;
167
168 Gtk::ScrolledWindow log_scroller_;
169 Gtk::TextView log_view_;
170 Glib::RefPtr<Gtk::TextBuffer> log_buffer_;
171
172 Glib::RefPtr<Gtk::FileDialog> file_dialog_;
173 Glib::RefPtr<Gtk::FileDialog> folder_dialog_;
174
175 std::vector<DeviceInfo> devices_;
178 std::string output_dir_;
180 std::vector<bool> result_selection_;
181 std::vector<Gtk::CheckButton*> result_check_buttons_;
182
185
187 sigc::connection scan_timer_connection_;
188 std::chrono::steady_clock::time_point scan_started_at_{};
189};
void hide_window()
void on_sidebar_recovery()
Gtk::Button btn_wizard_back_
void update_selected_results_state()
void on_recovery_device_activated(Gtk::ListBoxRow *row)
Gtk::DropDown lang_combo_
Gtk::Button btn_open_image_
void populate_device_lists()
static void save_theme(const std::string &theme_code)
Gtk::ScrolledWindow devices_scroller_
Gtk::Label wizard_notice_label_
Gtk::Button btn_choose_destination_
WizardStep current_step_
Gtk::Label results_selected_label_
std::string selected_source_label_
void activate_sidebar_button(Gtk::Button *button)
~MainWindow() override
void populate_scan_results(const ScanReport &report)
Gtk::ListBox devices_list_
void on_scan_completed(const ScanReport &report)
Gtk::Box sidebar_
Gtk::Button btn_recover_now_
Gtk::Entry entry_output_
Glib::RefPtr< Gtk::CssProvider > css_provider_
Gtk::Button btn_launch_elevated_
Gtk::Button btn_use_selected_device_
static std::string result_subgroup_label(const ScanResult &result)
Gtk::ScrolledWindow log_scroller_
Gtk::Grid cards_grid_
void on_sidebar_about()
Gtk::ListBox recovery_devices_list_
void append_log(const std::string &line)
AboutPage about_page_
void update_theme_buttons()
Gtk::Label source_card_label_
Glib::RefPtr< Gtk::FileDialog > folder_dialog_
Gtk::Box destination_step_box_
Gtk::Button * recovery_button_
void on_theme_dark()
Gtk::Button btn_scan_now_
Gtk::Frame card_source_
Gtk::Button * dashboard_button_
DashboardPage dashboard_page_
Gtk::Button * about_button_
std::vector< Gtk::CheckButton * > result_check_buttons_
void update_wizard_step()
ScanReport last_report_
void on_open_image()
Gtk::Stack page_stack_
sigc::connection scan_timer_connection_
RecoveryWorker recovery_worker_
static std::string human_size(uint64_t bytes)
Gtk::Frame devices_frame_
void apply_inline_css()
static std::string result_group_label(const ScanResult &result)
void on_recover_now()
Gtk::Button btn_dashboard_
Gtk::TextView log_view_
static void save_language(const std::string &lang_code)
void on_sidebar_dashboard()
void on_choose_destination()
Gtk::Box results_tree_box_
Gtk::Label brand_label_
Gtk::Label scan_timer_label_
void select_source(const std::string &path, const std::string &label)
Gtk::Frame card_update_
void on_language_changed()
Gtk::Button btn_results_clear_
std::string output_dir_
Gtk::Box recover_step_box_
void on_wizard_next()
Gtk::Button btn_theme_light_
std::vector< size_t > selected_result_indices() const
Gtk::Box wizard_nav_
void on_dashboard_device_activated(Gtk::ListBoxRow *row)
ScanWorker scan_worker_
Gtk::Button btn_about_
void on_scan_progress(const ScanProgress &progress)
Gtk::Button btn_recovery_
Gtk::Label status_card_label_
Gtk::ProgressBar scan_progress_bar_
void on_scan_now()
std::vector< DeviceInfo > devices_
std::vector< Gtk::Button * > sidebar_buttons_
Gtk::Stack wizard_stack_
void build_headerbar()
Gtk::Box results_actions_row_
void on_refresh_devices()
Gtk::Label results_count_label_
void on_theme_light()
Gtk::Frame results_frame_
Gtk::Frame wizard_frame_
void build_wizard()
Gtk::ScrolledWindow results_scroller_
bool lang_changing_
Gtk::Button btn_theme_dark_
ScanProgress last_scan_progress_
void apply_theme(bool use_dark)
void build_dashboard()
Gtk::Box source_step_box_
std::vector< bool > result_selection_
Gtk::Label recover_step_label_
void on_wizard_back()
Glib::RefPtr< Gtk::FileDialog > file_dialog_
Gtk::Label scan_status_label_
Gtk::Button btn_results_select_all_
Gtk::Label destination_step_label_
static std::string read_theme()
Glib::RefPtr< Gtk::TextBuffer > log_buffer_
std::chrono::steady_clock::time_point scan_started_at_
Gtk::Box main_box_
void build_about_page()
ThemeMode current_theme_
void build_sidebar(ClamdConfig &clamdConfig)
Gtk::Label update_card_label_
void on_recovery_completed(const RecoveryResult &result)
void refresh_devices()
Gtk::ScrolledWindow recovery_devices_scroller_
Gtk::Box destination_button_row_
void update_action_controls()
void on_launch_elevated()
Gtk::Label source_step_label_
void build_recovery_page()
Gtk::Box source_button_row_
Gtk::Button btn_wizard_next_
Gtk::Box recovery_page_
Gtk::Label recovery_title_
Gtk::Box scan_step_box_
std::string selected_source_path_
Gtk::Button btn_refresh_
Gtk::Box wizard_root_
Gtk::Frame card_status_
Gtk::Box recovery_header_
void update_source_state()
void minimize_window()
Gtk::Label recovery_subtitle_
static std::string read_language()
void on_use_selected_device()
Gtk::Label scan_step_label_
void set_all_results_selected(bool selected)