Skip to content
API Documentation
BastionGuard™
USBScanPage.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#pragma once
22
23#include <gtkmm.h>
24#include <set>
25#include <queue>
26#include <thread>
27#include <atomic>
28#include <filesystem>
29#include <unordered_map>
30#include <mutex>
31
32#include "../LifetimeGuard.hpp"
33
34
36 std::string name;
37 std::string devnode;
38 std::string serial;
39 std::string uid;
40 uint64_t size_bytes = 0;
41};
42
43
49
50
51class USBScanPage : public Gtk::Box {
52public:
54 virtual ~USBScanPage();
55
56private:
57 std::vector<USBDeviceInfo> detect_usb_devices();
58 void update_cards();
59 Gtk::Widget* build_usb_card(const USBDeviceInfo& dev);
60
61 std::string find_mountpoint(const std::string& devnode);
62 std::string mount_partition(const std::string& devnode, bool& auto_mounted);
63
64 void run_clamdscan_async(const std::string& devnode);
65 bool try_start_scan(const std::string& uid);
66 void show_scan_result(const std::string& text);
67 void show_infected_dialog(const std::string& text);
68 std::string build_scan_report(const std::string& raw);
69
70 void write_log(const std::string& msg);
71 void update_log_view();
72 std::string get_log_path();
73
75
76 void append_live_output(const std::string& line);
77
78 void send_dbus_alert(const std::string& file, const std::string& family);
79
80 Gtk::FlowBox flowbox_devices_;
81 Gtk::Button btn_refresh_;
82 Gtk::CheckButton chk_auto_refresh_;
83 Gtk::Label lbl_title_;
84 Gtk::Label lbl_status_;
85 Gtk::TextView txt_log_;
86 Gtk::ScrolledWindow scroller_log_;
87
88 std::thread monitor_thread_;
89 std::atomic<bool> monitor_running_{false};
90 bool initial_scan_done_{false};
92
93 std::mutex scan_mtx_;
94 std::unordered_map<std::string, ScanState> device_state_;
95
96 std::mutex log_mtx_;
97 std::mutex pending_log_mtx_;
98 std::vector<std::string> pending_log_lines_;
99 sigc::connection log_idle_connection_;
100 sigc::connection auto_refresh_conn_;
101
103 Gtk::TextView* live_scan_textview_ = nullptr;
104
105 static std::string human_readable_size(uint64_t bytes);
106
108};
ScanState
std::string find_mountpoint(const std::string &devnode)
void update_cards()
Gtk::TextView * live_scan_textview_
std::atomic< bool > monitor_running_
Gtk::ScrolledWindow scroller_log_
void append_live_output(const std::string &line)
void send_dbus_alert(const std::string &file, const std::string &family)
std::mutex scan_mtx_
void show_scan_result(const std::string &text)
Gtk::Widget * build_usb_card(const USBDeviceInfo &dev)
Gtk::FlowBox flowbox_devices_
bool try_start_scan(const std::string &uid)
Gtk::Label lbl_title_
void update_log_view()
Gtk::TextView txt_log_
std::string get_log_path()
void start_monitor_thread()
std::mutex log_mtx_
Gtk::Label lbl_status_
sigc::connection auto_refresh_conn_
Gtk::CheckButton chk_auto_refresh_
std::mutex pending_log_mtx_
std::vector< std::string > pending_log_lines_
std::string mount_partition(const std::string &devnode, bool &auto_mounted)
bool initial_scan_done_
class LiveScanDialog * live_scan_dialog_
void run_clamdscan_async(const std::string &devnode)
void show_infected_dialog(const std::string &text)
std::string build_scan_report(const std::string &raw)
BastionGuard::AliveFlag alive_
std::unordered_map< std::string, ScanState > device_state_
std::thread monitor_thread_
sigc::connection log_idle_connection_
std::vector< USBDeviceInfo > detect_usb_devices()
bool ignore_existing_devices_
static std::string human_readable_size(uint64_t bytes)
void write_log(const std::string &msg)
Gtk::Button btn_refresh_
std::shared_ptr< std::atomic< bool > > AliveFlag
AliveFlag make_alive_flag()
uint64_t size_bytes
std::string uid
std::string name
std::string devnode
std::string serial