Skip to content
API Documentation
BastionGuard™
AlertWindow Class Reference
Inheritance diagram for AlertWindow:

Public Member Functions

 AlertWindow (const std::string &file, const std::string &family, size_t pending=0)

Public Attributes

sigc::signal< void()> signal_ignore_all

Private Member Functions

void move_to_quarantine ()

Private Attributes

std::string filePath
Gtk::Box vbox
Gtk::Label titleLabel
Gtk::Label messageLabel
Gtk::Label pendingLabel
Gtk::Button quarantineButton
Gtk::Button ignoreButton
Gtk::Button ignoreAllButton

Detailed Description

Definition at line 50 of file BastionGuard-ransomware-alert.cpp.

Constructor & Destructor Documentation

◆ AlertWindow()

AlertWindow::AlertWindow ( const std::string & file,
const std::string & family,
size_t pending = 0 )
inline

Definition at line 52 of file BastionGuard-ransomware-alert.cpp.

55 : filePath(file),
56 vbox(Gtk::Orientation::VERTICAL, 15),
57 titleLabel(_("⚠️ Attenzione: BastionGuard ha rilevato un'infezione")),
58 messageLabel(_("Famiglia: ") + family + "\n" + _("File: ") + file),
59 quarantineButton(_("Metti in quarantena")),
60 ignoreButton(_("Ignora")),
61 ignoreAllButton(_("Ignora tutti"))
62 {
63 set_title("");
64 set_default_size(620, 240);
65 set_resizable(false);
66 set_modal(true);
67
68 auto ctx = get_style_context();
69 ctx->add_class("app-dialog");
70 ctx->add_class("main-window");
71 ctx->add_class("app-window");
72
73 // CSS
74 try {
75 auto css = Gtk::CssProvider::create();
76 css->load_from_path(resource(resolve_theme_css()));
77 Gtk::StyleContext::add_provider_for_display(
78 Gdk::Display::get_default(),
79 css,
80 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
81 );
82 } catch (...) {}
83 auto header = Gtk::make_managed<Gtk::HeaderBar>();
84 header->set_show_title_buttons(false);
85 header->set_decoration_layout("");
86 header->add_css_class("custom-headerbar");
87
88 auto close_btn = Gtk::make_managed<Gtk::Button>();
89 try {
90 auto px = Gdk::Pixbuf::create_from_file(
91 resource("icon-close.png"), 28, 28, true
92 );
93 close_btn->set_child(*Gtk::make_managed<Gtk::Image>(px));
94 } catch (...) {}
95
96 close_btn->add_css_class("header-button");
97 close_btn->signal_clicked().connect([this]() {
98 close();
99 });
100
101 header->pack_end(*close_btn);
102 set_titlebar(*header);
103 titleLabel.set_halign(Gtk::Align::CENTER);
104 titleLabel.get_style_context()->add_class("title");
105
106 std::string iconPath =
107 (family == "OK" || family == "Clean" || family == "None")
108 ? "/usr/share/BastionGuard/data/icons/true.png"
109 : "/usr/share/BastionGuard/data/icons/false.png";
110
111 auto icon = Gtk::make_managed<Gtk::Picture>();
112 icon->set_halign(Gtk::Align::CENTER);
113
114 if (fs::exists(iconPath)) {
115 try {
116 auto pb = Gdk::Pixbuf::create_from_file(iconPath);
117 auto scaled = pb->scale_simple(68, 68, Gdk::InterpType::BILINEAR);
118 icon->set_paintable(Gdk::Texture::create_for_pixbuf(scaled));
119 } catch (...) {}
120 }
121
122 messageLabel.set_wrap(true);
123 messageLabel.set_justify(Gtk::Justification::CENTER);
124 messageLabel.set_halign(Gtk::Align::CENTER);
125
126 if (pending > 0) {
127 pendingLabel.set_text(
128 Glib::ustring::compose(_("🕒 %1 altri in attesa..."), pending)
129 );
130 pendingLabel.set_halign(Gtk::Align::CENTER);
131 }
132
133 quarantineButton.add_css_class("btn-danger");
134 ignoreButton.add_css_class("btn-success");
135 ignoreAllButton.add_css_class("btn-warning");
136
137 auto buttons = Gtk::make_managed<Gtk::Box>(
138 Gtk::Orientation::HORIZONTAL, 20
139 );
140 buttons->set_halign(Gtk::Align::CENTER);
141 buttons->append(quarantineButton);
142 buttons->append(ignoreButton);
143 buttons->append(ignoreAllButton);
144
145 set_child(vbox);
146 vbox.set_margin(25);
147 vbox.set_halign(Gtk::Align::CENTER);
148 vbox.append(titleLabel);
149 vbox.append(*icon);
150 vbox.append(messageLabel);
151 if (pending > 0) vbox.append(pendingLabel);
152 vbox.append(*buttons);
153
154 quarantineButton.signal_clicked().connect([this]() {
156 close();
157 });
158
159 ignoreButton.signal_clicked().connect([this]() {
160 close();
161 });
162
163 ignoreAllButton.signal_clicked().connect([this]() {
164 signal_ignore_all.emit();
165 close();
166 });
167 }
#define _(s)
static std::string resolve_theme_css()
sigc::signal< void()> signal_ignore_all
std::string resource(const std::string &rel)
Definition Resource.hpp:31

References _, filePath, ignoreAllButton, ignoreButton, messageLabel, move_to_quarantine(), pendingLabel, quarantineButton, resolve_theme_css(), resource(), signal_ignore_all, titleLabel, and vbox.

Referenced by AlertApp::show_next().

Member Function Documentation

◆ move_to_quarantine()

void AlertWindow::move_to_quarantine ( )
inlineprivate

Definition at line 183 of file BastionGuard-ransomware-alert.cpp.

183 {
185 std::cout << _("[✔] File in quarantena: ") << filePath << "\n";
186 else
187 std::cerr << _("❌ Errore quarantena: ") << filePath << "\n";
188 }
static bool move(const std::string &file)

References _, filePath, and Quarantine::move().

Referenced by AlertWindow().

Member Data Documentation

◆ filePath

std::string AlertWindow::filePath
private

Definition at line 172 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow(), and move_to_quarantine().

◆ ignoreAllButton

Gtk::Button AlertWindow::ignoreAllButton
private

Definition at line 181 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow().

◆ ignoreButton

Gtk::Button AlertWindow::ignoreButton
private

Definition at line 180 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow().

◆ messageLabel

Gtk::Label AlertWindow::messageLabel
private

Definition at line 176 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow().

◆ pendingLabel

Gtk::Label AlertWindow::pendingLabel
private

Definition at line 177 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow().

◆ quarantineButton

Gtk::Button AlertWindow::quarantineButton
private

Definition at line 179 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow().

◆ signal_ignore_all

sigc::signal<void()> AlertWindow::signal_ignore_all

Definition at line 169 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow(), and AlertApp::show_next().

◆ titleLabel

Gtk::Label AlertWindow::titleLabel
private

Definition at line 175 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow().

◆ vbox

Gtk::Box AlertWindow::vbox
private

Definition at line 174 of file BastionGuard-ransomware-alert.cpp.

Referenced by AlertWindow().


The documentation for this class was generated from the following file: