Skip to content
API Documentation
BastionGuard™
RulesPage.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™ Secure Connection
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 * GPL-3.0 — BastionGuard™ is a trademark of Calogero Scarnà.
5 */
6
7#pragma once
8#include <gtkmm.h>
9#include <string>
10
11class RulesPage : public Gtk::Box
12{
13public:
14 RulesPage();
15
16private:
17 // ── Colonne del modello dati ─────────────────────────────────────────
18 struct Columns : public Gtk::TreeModel::ColumnRecord {
20 add(col_name);
21 add(col_action);
22 add(col_duration);
23 add(col_operand);
24 add(col_data);
25 add(col_enabled);
26 add(col_filepath); // path file JSON — non visibile
27 }
28 Gtk::TreeModelColumn<Glib::ustring> col_name;
29 Gtk::TreeModelColumn<Glib::ustring> col_action;
30 Gtk::TreeModelColumn<Glib::ustring> col_duration;
31 Gtk::TreeModelColumn<Glib::ustring> col_operand;
32 Gtk::TreeModelColumn<Glib::ustring> col_data;
33 Gtk::TreeModelColumn<bool> col_enabled;
34 Gtk::TreeModelColumn<Glib::ustring> col_filepath;
35 };
36
37 // ── Modelli ausiliari per i CellRendererCombo ────────────────────────
38 struct ComboColumns : public Gtk::TreeModel::ColumnRecord {
40 Gtk::TreeModelColumn<Glib::ustring> col_value;
41 };
42
45
46 // Modelli per i combo "Azione" e "Durata"
47 Glib::RefPtr<Gtk::ListStore> m_actionModel;
48 Glib::RefPtr<Gtk::ListStore> m_durationModel;
49
50 Glib::RefPtr<Gtk::ListStore> m_store;
51 Gtk::TreeView m_treeView;
52 Gtk::ScrolledWindow m_scroll;
53 Gtk::Box m_toolbar { Gtk::Orientation::HORIZONTAL, 6 };
54 Gtk::Button m_createBtn;
55 Gtk::Button m_reloadBtn;
56 Gtk::Button m_deleteBtn;
57 Gtk::Label m_countLabel;
58
59 // ── Struttura dati regola ────────────────────────────────────────────
60 struct Rule {
61 std::string name;
62 std::string action;
63 std::string duration;
64 std::string operand;
65 std::string data;
66 bool enabled = true;
67 std::string filepath;
68 };
69
70 // ── Helpers JSON ─────────────────────────────────────────────────────
71 bool replaceJsonStringField(const std::string& filepath,
72 const std::string& key,
73 const std::string& value);
74 bool replaceJsonBoolField(const std::string& filepath,
75 const std::string& key,
76 bool value);
77 bool writeFileAsRoot(const std::string& filepath,
78 const std::string& content);
79 bool createRuleFileAsRoot(const Rule& rule);
80 std::string escapeJson(const std::string& input);
81 std::string makeSafeFilename(const std::string& input);
82
83 // ── Signal handler editing ───────────────────────────────────────────
84 void onActionEdited(const Glib::ustring& path, const Glib::ustring& new_text);
85 void onDurationEdited(const Glib::ustring& path, const Glib::ustring& new_text);
86 void onDataEdited(const Glib::ustring& path, const Glib::ustring& new_text);
87 void onEnabledToggled(const Glib::ustring& path);
88
89 // ── Builder / loader ─────────────────────────────────────────────────
90 void buildComboModels();
91 void buildToolbar();
92 void buildTreeView();
93 void loadRules();
94 Rule parseRule(const std::string& filepath);
95 std::string jsonField(const std::string& json, const std::string& key);
96 void onCreateRule();
97 void onDelete();
98 void updateCount();
99};
nlohmann::json json
Definition Backend.cpp:2908
Gtk::Button m_deleteBtn
Definition RulesPage.hpp:56
bool writeFileAsRoot(const std::string &filepath, const std::string &content)
void onDelete()
void loadRules()
Gtk::ScrolledWindow m_scroll
Definition RulesPage.hpp:52
std::string escapeJson(const std::string &input)
std::string makeSafeFilename(const std::string &input)
std::string jsonField(const std::string &json, const std::string &key)
void buildToolbar()
Definition RulesPage.cpp:71
void onCreateRule()
void onDataEdited(const Glib::ustring &path, const Glib::ustring &new_text)
Gtk::Label m_countLabel
Definition RulesPage.hpp:57
void buildTreeView()
Gtk::Button m_createBtn
Definition RulesPage.hpp:54
bool createRuleFileAsRoot(const Rule &rule)
Glib::RefPtr< Gtk::ListStore > m_store
Definition RulesPage.hpp:50
Glib::RefPtr< Gtk::ListStore > m_actionModel
Definition RulesPage.hpp:47
Glib::RefPtr< Gtk::ListStore > m_durationModel
Definition RulesPage.hpp:48
ComboColumns m_comboColumns
Definition RulesPage.hpp:44
void updateCount()
Rule parseRule(const std::string &filepath)
void onActionEdited(const Glib::ustring &path, const Glib::ustring &new_text)
void buildComboModels()
Definition RulesPage.cpp:50
bool replaceJsonBoolField(const std::string &filepath, const std::string &key, bool value)
Gtk::Button m_reloadBtn
Definition RulesPage.hpp:55
Gtk::Box m_toolbar
Definition RulesPage.hpp:53
void onDurationEdited(const Glib::ustring &path, const Glib::ustring &new_text)
Gtk::TreeView m_treeView
Definition RulesPage.hpp:51
bool replaceJsonStringField(const std::string &filepath, const std::string &key, const std::string &value)
void onEnabledToggled(const Glib::ustring &path)
Columns m_columns
Definition RulesPage.hpp:43
Gtk::TreeModelColumn< Glib::ustring > col_data
Definition RulesPage.hpp:32
Gtk::TreeModelColumn< Glib::ustring > col_action
Definition RulesPage.hpp:29
Gtk::TreeModelColumn< Glib::ustring > col_operand
Definition RulesPage.hpp:31
Gtk::TreeModelColumn< Glib::ustring > col_duration
Definition RulesPage.hpp:30
Gtk::TreeModelColumn< bool > col_enabled
Definition RulesPage.hpp:33
Gtk::TreeModelColumn< Glib::ustring > col_filepath
Definition RulesPage.hpp:34
Gtk::TreeModelColumn< Glib::ustring > col_name
Definition RulesPage.hpp:28
Gtk::TreeModelColumn< Glib::ustring > col_value
Definition RulesPage.hpp:40
std::string duration
Definition RulesPage.hpp:63
std::string filepath
Definition RulesPage.hpp:67
std::string operand
Definition RulesPage.hpp:64
std::string data
Definition RulesPage.hpp:65
std::string action
Definition RulesPage.hpp:62
std::string name
Definition RulesPage.hpp:61