Skip to content
API Documentation
BastionGuard™
StyleProvider.cpp File Reference

Go to the source code of this file.

Macros

#define DATA_DIR   "/usr/share/bastionguard-recovery-data/data"

Functions

static std::string read_saved_theme ()
void load_style ()

Variables

Glib::RefPtr< Gtk::CssProvider > global_css

Macro Definition Documentation

◆ DATA_DIR

#define DATA_DIR   "/usr/share/bastionguard-recovery-data/data"

Definition at line 28 of file StyleProvider.cpp.

Function Documentation

◆ load_style()

void load_style ( )

Definition at line 44 of file StyleProvider.cpp.

45{
46 global_css = Gtk::CssProvider::create();
47
48 const std::string theme = read_saved_theme();
49 const std::string cssName = (theme == "dark")
50 ? "BastionGuard-dark.css"
51 : "BastionGuard.css";
52
53 const std::string local = "data/" + cssName;
54 const std::string installed = std::string(DATA_DIR) + "/" + cssName;
55
56 std::string used;
57
58 try {
59 if (std::filesystem::exists(local)) {
60 global_css->load_from_path(local);
61 used = local;
62 } else if (std::filesystem::exists(installed)) {
63 global_css->load_from_path(installed);
64 used = installed;
65 } else {
66 const std::string fallback_local = "data/BastionGuard.css";
67 const std::string fallback_installed = std::string(DATA_DIR) + "/BastionGuard.css";
68 if (std::filesystem::exists(fallback_local)) {
69 global_css->load_from_path(fallback_local);
70 used = fallback_local;
71 } else if (std::filesystem::exists(fallback_installed)) {
72 global_css->load_from_path(fallback_installed);
73 used = fallback_installed;
74 } else {
75 std::cerr << trs("⚠ No CSS file found:\n")
76 << " " << local << "\n " << installed
77 << std::endl;
78 return;
79 }
80 }
81
82 auto display = Gdk::Display::get_default();
83 if (display) {
84 gtk_style_context_add_provider_for_display(
85 display->gobj(),
86 GTK_STYLE_PROVIDER(global_css->gobj()),
87 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
88 );
89 }
90
91 std::cout << _("[CSS] Tema '") << theme
92 << _("' caricato da: ") << used << std::endl;
93
94 } catch (const Glib::Error& ex) {
95 std::cerr << _("❌ Errore CSS: ") << ex.what() << std::endl;
96 }
97}
#define _(s)
std::string trs(const char *msgid)
Definition i18n.cpp:22
#define DATA_DIR
Definition Resource.hpp:28
Glib::RefPtr< Gtk::CssProvider > global_css
static std::string read_saved_theme()

References _, DATA_DIR, global_css, load_style(), read_saved_theme(), and trs().

◆ read_saved_theme()

std::string read_saved_theme ( )
static

Definition at line 34 of file StyleProvider.cpp.

34 {
35 const std::string path =
36 Glib::get_home_dir() + "/.config/bastionguard-recovery-data/theme.conf";
37 std::ifstream f(path);
38 if (!f.is_open()) return "light";
39 std::string val;
40 f >> val;
41 return (val == "dark") ? "dark" : "light";
42}

References read_saved_theme().

Variable Documentation

◆ global_css

Glib::RefPtr<Gtk::CssProvider> global_css

Definition at line 31 of file StyleProvider.cpp.