Skip to content
API Documentation
BastionGuard™
FirewallChoiceDialog Class Reference

#include <FirewallChoiceDialog.hpp>

Inheritance diagram for FirewallChoiceDialog:

Public Member Functions

 FirewallChoiceDialog ()
virtual ~FirewallChoiceDialog ()=default

Public Attributes

sigc::signal< void(FirewallType)> signal_firewall_selected

Private Attributes

Gtk::Box vbox {Gtk::Orientation::VERTICAL}
Gtk::Label titleLabel
Gtk::Label descriptionLabel
Gtk::Button firewalldButton
Gtk::Button ufwButton
Gtk::Button installButton
Gtk::Button cancelButton
FirewallType detected
std::string distro

Detailed Description

Definition at line 31 of file FirewallChoiceDialog.hpp.

Constructor & Destructor Documentation

◆ FirewallChoiceDialog()

FirewallChoiceDialog::FirewallChoiceDialog ( )

Definition at line 43 of file FirewallChoiceDialog.cpp.

44 : vbox(Gtk::Orientation::VERTICAL, 15),
45 titleLabel(_("Protezione Firewall")),
46 descriptionLabel(_("Scegli quale firewall usare per bloccare gli IP malevoli:")),
47 firewalldButton(_("Usa firewalld")),
48 ufwButton(_("Usa UFW")),
49 installButton(_("Installa firewall")),
50 cancelButton(_("Annulla"))
51{
54
55
56 set_title("");
57 set_default_size(520, 260);
58 set_resizable(false);
59 set_modal(true);
60
61 auto ctx = get_style_context();
62 ctx->add_class("app-dialog");
63 ctx->add_class("main-window");
64 ctx->add_class("app-window");
65
66
67 try {
68 auto css = Gtk::CssProvider::create();
69 css->load_from_path(resource(firewall_choice_resolve_theme_css()));
70 Gtk::StyleContext::add_provider_for_display(
71 Gdk::Display::get_default(), css,
72 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
73 );
74 } catch (...) {
75 std::cerr << _("Errore caricamento CSS\n");
76 }
77
78 auto *header = Gtk::make_managed<Gtk::HeaderBar>();
79 header->set_show_title_buttons(false);
80 header->add_css_class("custom-headerbar");
81
82 auto *close_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
83 close_box->set_margin_end(6);
84
85 try {
86 auto px = Gdk::Pixbuf::create_from_file(resource("icon-close.png"), 28, 28, true);
87 auto *btn = Gtk::make_managed<Gtk::Button>();
88 btn->set_child(*Gtk::make_managed<Gtk::Image>(px));
89 btn->add_css_class("header-button");
90 btn->signal_clicked().connect([this]() { hide(); });
91 close_box->append(*btn);
92 } catch (...) {
93 std::cerr << _("Icona X non trovata\n");
94 }
95
96 header->pack_end(*close_box);
97
98 auto *header_wrapper = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
99 header_wrapper->append(*header);
100 set_titlebar(*header_wrapper);
101
102 titleLabel.set_halign(Gtk::Align::CENTER);
103 titleLabel.add_css_class("title");
104
105 descriptionLabel.set_wrap(true);
106 descriptionLabel.set_halign(Gtk::Align::CENTER);
107 descriptionLabel.set_margin_bottom(10);
108
109 firewalldButton.add_css_class("btn-success");
110 ufwButton.add_css_class("btn-success");
111 installButton.add_css_class("btn-warning");
112 cancelButton.add_css_class("btn-danger");
113
114 auto *buttonBox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 10);
115 buttonBox->set_halign(Gtk::Align::CENTER);
116
118 buttonBox->append(firewalldButton);
119
121 buttonBox->append(ufwButton);
122
125
126 if (!cmd.empty()) {
127 installButton.set_label(
128 Glib::ustring::compose(
129 _("Installa firewall (%1)"),
130 cmd
131 )
132 );
133 buttonBox->append(installButton);
134 }
135 }
136
137 buttonBox->append(cancelButton);
138
139 set_child(vbox);
140 vbox.set_margin(25);
141 vbox.set_halign(Gtk::Align::CENTER);
142
143 vbox.append(titleLabel);
144 vbox.append(descriptionLabel);
145 vbox.append(*buttonBox);
146
147
148 firewalldButton.signal_clicked().connect([this]() {
150 hide();
151 });
152
153 ufwButton.signal_clicked().connect([this]() {
155 hide();
156 });
157
158 installButton.signal_clicked().connect([this]() {
160 this,
161 _("Per installare il firewall esegui il comando:\n\n") +
163 Gtk::MessageType::INFO
164 );
165 });
166
167 cancelButton.signal_clicked().connect([this]() {
168 hide();
169 });
170
171}
#define _(s)
static std::string firewall_choice_resolve_theme_css()
sigc::signal< void(FirewallType)> signal_firewall_selected
static bool isUfwPresent()
static bool isFirewalldPresent()
static FirewallType detectFirewall()
static std::string detectDistro()
static std::string getInstallCommand(const std::string &distro, bool preferFirewalld=true)
static void show_message(Gtk::Window *parent, const std::string &message, Gtk::MessageType type=Gtk::MessageType::INFO, const std::string &secondary=std::string())
Definition Utils.cpp:33
std::string resource(const std::string &rel)
Definition Resource.hpp:31

References _, cancelButton, descriptionLabel, FirewallDetector::detectDistro(), detected, FirewallDetector::detectFirewall(), distro, firewall_choice_resolve_theme_css(), FIREWALLD, firewalldButton, FirewallInstaller::getInstallCommand(), installButton, FirewallDetector::isFirewalldPresent(), FirewallDetector::isUfwPresent(), NONE, resource(), Utils::show_message(), signal_firewall_selected, titleLabel, UFW, ufwButton, and vbox.

◆ ~FirewallChoiceDialog()

virtual FirewallChoiceDialog::~FirewallChoiceDialog ( )
virtualdefault

Member Data Documentation

◆ cancelButton

Gtk::Button FirewallChoiceDialog::cancelButton
private

Definition at line 45 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ descriptionLabel

Gtk::Label FirewallChoiceDialog::descriptionLabel
private

Definition at line 40 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ detected

FirewallType FirewallChoiceDialog::detected
private

Definition at line 47 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ distro

std::string FirewallChoiceDialog::distro
private

Definition at line 48 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ firewalldButton

Gtk::Button FirewallChoiceDialog::firewalldButton
private

Definition at line 42 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ installButton

Gtk::Button FirewallChoiceDialog::installButton
private

Definition at line 44 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ signal_firewall_selected

sigc::signal<void(FirewallType)> FirewallChoiceDialog::signal_firewall_selected

Definition at line 35 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ titleLabel

Gtk::Label FirewallChoiceDialog::titleLabel
private

Definition at line 39 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ ufwButton

Gtk::Button FirewallChoiceDialog::ufwButton
private

Definition at line 43 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().

◆ vbox

Gtk::Box FirewallChoiceDialog::vbox {Gtk::Orientation::VERTICAL}
private

Definition at line 38 of file FirewallChoiceDialog.hpp.

Referenced by FirewallChoiceDialog().


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