Skip to content
API Documentation
BastionGuard™
ScanPromptWindow.cpp
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#include "ScanPromptWindow.hpp"
22#include "Resource.hpp"
23#include <filesystem>
24#include <fstream>
25#include <glibmm/i18n.h>
26#include <glibmm/miscutils.h>
27
28// Sceglie il CSS in base al tema salvato in ~/.config/BastionGuard/theme.conf.
29// Stessa logica di StyleProvider::load_style() e
30// AlertWindowRealtime::resolve_theme_css(), così il popup USB segue
31// il tema (dark/light) impostato dall'utente invece di rimanere
32// forzatamente in light mode.
33static std::string usb_prompt_resolve_theme_css() {
34 const std::string conf =
35 Glib::get_home_dir() + "/.config/BastionGuard/theme.conf";
36 std::ifstream tf(conf);
37 std::string theme;
38 if (tf >> theme && theme == "dark")
39 return "BastionGuard-dark.css";
40 return "BastionGuard.css";
41}
42
43ScanPromptWindow::ScanPromptWindow(const std::string& devnode)
44 : titleLabel(_("Unità USB rilevata")),
45 messageLabel(_("È stata collegata una nuova periferica USB:\n\n") + devnode +
46 _("\n\nVuoi eseguire una scansione antivirus?")),
47 scanButton(_("Scansiona")),
48 cancelButton(_("Annulla"))
49{
50 set_title("");
51 set_default_size(520, 220);
52 set_resizable(false);
53 set_modal(true);
54
55 add_css_class("app-dialog");
56 add_css_class("main-window");
57 add_css_class("app-window");
58
59 try {
60 auto css = Gtk::CssProvider::create();
61 css->load_from_path(resource(usb_prompt_resolve_theme_css()));
62 auto display = Gdk::Display::get_default();
63 Gtk::StyleContext::add_provider_for_display(display, css, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
64 } catch (...) {}
65
66 auto header = Gtk::make_managed<Gtk::HeaderBar>();
67 header->set_show_title_buttons(false);
68 header->set_decoration_layout("");
69 header->add_css_class("custom-headerbar");
70
71 auto close_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
72 close_box->set_margin_end(6);
73
74 try {
75 auto px = Gdk::Pixbuf::create_from_file(resource("icon-close.png"), 28, 28, true);
76 auto btn = Gtk::make_managed<Gtk::Button>();
77 btn->set_child(*Gtk::make_managed<Gtk::Image>(px));
78 btn->add_css_class("header-button");
79
80 btn->signal_clicked().connect([this]() { hide(); });
81
82 close_box->append(*btn);
83 } catch (...) {}
84
85 header->pack_end(*close_box);
86
87 auto header_wrapper = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
88 header_wrapper->append(*header);
89 set_titlebar(*header_wrapper);
90
91 titleLabel.get_style_context()->add_class("title");
92 titleLabel.set_halign(Gtk::Align::CENTER);
93
94 messageLabel.set_wrap(true);
95 messageLabel.set_justify(Gtk::Justification::CENTER);
96 messageLabel.set_halign(Gtk::Align::CENTER);
97
98 scanButton.add_css_class("btn-success");
99 cancelButton.add_css_class("btn-danger");
100
101 auto btn_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 20);
102 btn_box->set_halign(Gtk::Align::CENTER);
103 btn_box->append(scanButton);
104 btn_box->append(cancelButton);
105
106 scanButton.signal_clicked().connect([this]() {
107 sig_scan_.emit();
108 hide();
109 });
110
111 cancelButton.signal_clicked().connect([this]() {
112 sig_cancel_.emit();
113 hide();
114 });
115
116
117 set_child(vbox);
118 vbox.set_margin(25);
119 vbox.append(titleLabel);
120 vbox.append(messageLabel);
121 vbox.append(*btn_box);
122
123 present();
124}
#define _(s)
static std::string usb_prompt_resolve_theme_css()
sigc::signal< void()> sig_scan_
sigc::signal< void()> sig_cancel_
ScanPromptWindow(const std::string &devnode)
std::string resource(const std::string &rel)
Definition Resource.hpp:31