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

Public Member Functions

 BankGuiWindow ()

Protected Member Functions

bool on_close_request () override

Private Member Functions

void build_headerbar ()
void minimize ()
void on_cancel_clicked ()
void on_open_clicked ()
void show_warning (const Glib::ustring &msg, const Glib::ustring &secondary={})
void on_sandbox_finished (const Glib::RefPtr< Gio::AsyncResult > &)
void terminate_sandbox ()

Private Attributes

Gtk::Entry entry_
Gtk::Button btn_open_
Gtk::Button btn_cancel_
Glib::RefPtr< Gio::Subprocess > sandbox_proc_
std::string sandbox_cmd_

Detailed Description

Definition at line 40 of file bankgui-main.cpp.

Constructor & Destructor Documentation

◆ BankGuiWindow()

BankGuiWindow::BankGuiWindow ( )
inline

Definition at line 42 of file bankgui-main.cpp.

42 {
43 set_title("");
44 set_resizable(false);
45 set_default_size(640, 300);
47
48
49 auto main_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 0);
50 set_child(*main_box);
51
52
53 auto sidebar = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 10);
54 sidebar->set_size_request(240, -1);
55 sidebar->get_style_context()->add_class("sidebar");
56
57
58 {
59 auto header = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 8);
60 header->get_style_context()->add_class("sidebar-header");
61
62 try {
63 auto pixbuf = Gdk::Pixbuf::create_from_file(resource("logo-sidebar.png"), 96, 96, true);
64 auto logo = Gtk::make_managed<Gtk::Image>(pixbuf);
65 header->append(*logo);
66 } catch (...) {
67 std::cerr << _("⚠ Impossibile caricare data/logo-sidebar.png") << "\n";
68 }
69
70 auto lbl = Gtk::make_managed<Gtk::Label>("BastionGuard");
71 lbl->set_halign(Gtk::Align::START);
72 lbl->get_style_context()->add_class("sidebar-title");
73 header->append(*lbl);
74
75 sidebar->append(*header);
76 }
77
78
79 auto spacer = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
80 spacer->set_vexpand(true);
81 sidebar->append(*spacer);
82
83 main_box->append(*sidebar);
84
85
86 auto content_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 10);
87 content_box->set_margin(24);
88 content_box->set_hexpand(true);
89 content_box->get_style_context()->add_class("content");
90 main_box->append(*content_box);
91
92 auto label = Gtk::make_managed<Gtk::Label>(
93 _("Inserisci l'URL della banca o un identificatore:")
94 );
95 label->set_wrap(true);
96 label->set_halign(Gtk::Align::START);
97 content_box->append(*label);
98
99 entry_.set_placeholder_text("https://www.miabanca.it");
100 entry_.set_activates_default(true);
101 content_box->append(entry_);
102
103 auto buttons = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 8);
104 buttons->set_halign(Gtk::Align::END);
105
106 btn_cancel_.set_label(_("Annulla"));
107 btn_cancel_.signal_clicked().connect(sigc::mem_fun(*this, &BankGuiWindow::on_cancel_clicked));
108 buttons->append(btn_cancel_);
109
110 btn_open_.set_label(_("Apri in Secure Browser"));
111 btn_open_.signal_clicked().connect(sigc::mem_fun(*this, &BankGuiWindow::on_open_clicked));
112 buttons->append(btn_open_);
113
114 content_box->append(*buttons);
115}
#define _(s)
Gtk::Button btn_cancel_
void on_cancel_clicked()
Gtk::Entry entry_
Gtk::Button btn_open_
std::string resource(const std::string &rel)
Definition Resource.hpp:31

References _, btn_cancel_, btn_open_, build_headerbar(), entry_, on_cancel_clicked(), on_open_clicked(), and resource().

Member Function Documentation

◆ build_headerbar()

void BankGuiWindow::build_headerbar ( )
inlineprivate

Definition at line 132 of file bankgui-main.cpp.

132 {
133 auto header = Gtk::make_managed<Gtk::HeaderBar>();
134 header->set_show_title_buttons(false);
135 header->set_decoration_layout("");
136 header->get_style_context()->add_class("custom-headerbar");
137
138 // Titolo centrato
139 auto title_label = Gtk::make_managed<Gtk::Label>("BastionGuard Secure Browser");
140 title_label->get_style_context()->add_class("header-title");
141 title_label->set_halign(Gtk::Align::CENTER);
142 title_label->set_valign(Gtk::Align::CENTER);
143 header->set_title_widget(*title_label);
144
145 // ---- Destra (pulsanti finestra) ----
146 auto header_right = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
147 header_right->get_style_context()->add_class("header-right");
148
149 try {
150 auto pix_min = Gdk::Pixbuf::create_from_file(resource("icon-minimize.png"), 32, 32, true);
151 auto btn_min = Gtk::make_managed<Gtk::Button>();
152 btn_min->set_child(*Gtk::make_managed<Gtk::Image>(pix_min));
153 btn_min->get_style_context()->add_class("header-button");
154 header_right->append(*btn_min);
155 btn_min->signal_clicked().connect([this]() { minimize(); });
156 } catch (...) {
157 std::cerr << _("⚠ Errore caricamento icona minimize") << "\n";
158 }
159
160 try {
161 auto pix_close = Gdk::Pixbuf::create_from_file(resource("icon-close.png"), 32, 32, true);
162 auto btn_close = Gtk::make_managed<Gtk::Button>();
163 btn_close->set_child(*Gtk::make_managed<Gtk::Image>(pix_close));
164 btn_close->get_style_context()->add_class("header-button");
165 header_right->append(*btn_close);
166 btn_close->signal_clicked().connect([this]() {
168 this->hide();
169 });
170 } catch (...) {
171 std::cerr << _("⚠ Errore caricamento icona close") << "\n";
172 }
173
174 header->pack_end(*header_right);
175 set_titlebar(*header);
176 }
void terminate_sandbox()

References _, minimize(), resource(), and terminate_sandbox().

Referenced by BankGuiWindow().

◆ minimize()

void BankGuiWindow::minimize ( )
inlineprivate

Definition at line 179 of file bankgui-main.cpp.

179 {
180#if GTKMM_CHECK_VERSION(4,10,0)
181 this->hide();
182#endif
183 }

Referenced by build_headerbar().

◆ on_cancel_clicked()

void BankGuiWindow::on_cancel_clicked ( )
inlineprivate

Definition at line 185 of file bankgui-main.cpp.

185 {
187 hide();
188 }

References terminate_sandbox().

Referenced by BankGuiWindow().

◆ on_close_request()

bool BankGuiWindow::on_close_request ( )
inlineoverrideprotected

Definition at line 119 of file bankgui-main.cpp.

119 {
121 return false;
122 }

References terminate_sandbox().

◆ on_open_clicked()

void BankGuiWindow::on_open_clicked ( )
inlineprivate

Definition at line 190 of file bankgui-main.cpp.

190 {
191 auto url = entry_.get_text();
192 if (url.empty()) {
193 show_warning(_("Inserisci un URL valido."), _("Il campo non può essere vuoto."));
194 return;
195 }
196
197 set_sensitive(false);
198 try {
199 sandbox_cmd_ = "BastionGuard-bankopener \"" + url + "\"";
200 sandbox_proc_ = Gio::Subprocess::create(
201 {"BastionGuard-bankopener", url},
202 Gio::Subprocess::Flags::NONE
203 );
204 sandbox_proc_->wait_check_async(
205 sigc::mem_fun(*this, &BankGuiWindow::on_sandbox_finished)
206 );
207 } catch (const Glib::Error& ex) {
208 show_warning(_("Errore avvio subprocess."), ex.what());
209 set_sensitive(true);
210 }
211 }
Glib::RefPtr< Gio::Subprocess > sandbox_proc_
std::string sandbox_cmd_
void on_sandbox_finished(const Glib::RefPtr< Gio::AsyncResult > &)
void show_warning(const Glib::ustring &msg, const Glib::ustring &secondary={})

References _, entry_, on_sandbox_finished(), sandbox_cmd_, sandbox_proc_, and show_warning().

Referenced by BankGuiWindow().

◆ on_sandbox_finished()

void BankGuiWindow::on_sandbox_finished ( const Glib::RefPtr< Gio::AsyncResult > & )
inlineprivate

Definition at line 222 of file bankgui-main.cpp.

222 {
223 hide();
224 }

Referenced by on_open_clicked().

◆ show_warning()

void BankGuiWindow::show_warning ( const Glib::ustring & msg,
const Glib::ustring & secondary = {} )
inlineprivate

Definition at line 213 of file bankgui-main.cpp.

213 {}) {
214 auto* dialog = new Gtk::MessageDialog(
215 *this, msg, false, Gtk::MessageType::WARNING, Gtk::ButtonsType::OK, true);
216 if (!secondary.empty()) dialog->set_secondary_text(secondary);
217 dialog->set_modal(true);
218 dialog->signal_response().connect([dialog](int){ dialog->hide(); delete dialog; });
219 dialog->present();
220 }

Referenced by on_open_clicked().

◆ terminate_sandbox()

void BankGuiWindow::terminate_sandbox ( )
inlineprivate

Definition at line 226 of file bankgui-main.cpp.

226 {
227 if (!sandbox_proc_) return;
228 // Only terminate the subprocess started by this window. Never search
229 // the entire process table with an untrusted URL in a shell command.
230 sandbox_proc_->force_exit();
231 sandbox_proc_.reset();
232 }

References sandbox_proc_.

Referenced by build_headerbar(), on_cancel_clicked(), and on_close_request().

Member Data Documentation

◆ btn_cancel_

Gtk::Button BankGuiWindow::btn_cancel_
private

Definition at line 127 of file bankgui-main.cpp.

Referenced by BankGuiWindow().

◆ btn_open_

Gtk::Button BankGuiWindow::btn_open_
private

Definition at line 126 of file bankgui-main.cpp.

Referenced by BankGuiWindow().

◆ entry_

Gtk::Entry BankGuiWindow::entry_
private

Definition at line 125 of file bankgui-main.cpp.

Referenced by BankGuiWindow(), and on_open_clicked().

◆ sandbox_cmd_

std::string BankGuiWindow::sandbox_cmd_
private

Definition at line 129 of file bankgui-main.cpp.

Referenced by on_open_clicked().

◆ sandbox_proc_

Glib::RefPtr<Gio::Subprocess> BankGuiWindow::sandbox_proc_
private

Definition at line 128 of file bankgui-main.cpp.

Referenced by on_open_clicked(), and terminate_sandbox().


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