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

Go to the source code of this file.

Functions

void load_style ()

Variables

Glib::RefPtr< Gtk::CssProvider > global_css

Function Documentation

◆ load_style()

void load_style ( )

Definition at line 47 of file StyleProvider.cpp.

48{
49 global_css = Gtk::CssProvider::create();
50
51 const std::string theme = read_saved_theme();
52 const std::string cssName = (theme == "dark")
53 ? "BastionGuard-dark.css"
54 : "BastionGuard.css";
55
56 const std::string local = "data/" + cssName;
57 const std::string installed = std::string(DATA_DIR) + "/" + cssName;
58
59 std::string used;
60
61 try {
62 if (std::filesystem::exists(local)) {
63 global_css->load_from_path(local);
64 used = local;
65 } else if (std::filesystem::exists(installed)) {
66 global_css->load_from_path(installed);
67 used = installed;
68 } else {
69 const std::string fallback_local = "data/BastionGuard.css";
70 const std::string fallback_installed = std::string(DATA_DIR) + "/BastionGuard.css";
71 if (std::filesystem::exists(fallback_local)) {
72 global_css->load_from_path(fallback_local);
73 used = fallback_local;
74 } else if (std::filesystem::exists(fallback_installed)) {
75 global_css->load_from_path(fallback_installed);
76 used = fallback_installed;
77 } else {
78 std::cerr << "⚠ Nessun file CSS trovato:\n"
79 << " " << local << "\n " << installed
80 << std::endl;
81 return;
82 }
83 }
84
85 Gtk::StyleContext::add_provider_for_display(
86 Gdk::Display::get_default(),
88 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
89
90 std::cout << _("[CSS] Tema '") << theme
91 << _("' caricato da: ") << used << std::endl;
92
93 } catch (const Glib::Error& ex) {
94 std::cerr << _("❌ Errore CSS: ") << ex.what() << std::endl;
95 }
96}
#define _(s)
#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().

Variable Documentation

◆ global_css

Glib::RefPtr<Gtk::CssProvider> global_css
extern

Definition at line 34 of file StyleProvider.cpp.