Skip to content
API Documentation
BastionGuard™
StyleProvider.cpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21
22#include "StyleProvider.hpp"
23#include <gtkmm/cssprovider.h>
24#include <gtkmm/stylecontext.h>
25#include <gdkmm/display.h>
26#include <iostream>
27#include <filesystem>
28#include <glib/gi18n.h>
29#ifndef DATA_DIR
30#define DATA_DIR "/usr/share/BastionGuard/data"
31#endif
32
33void load_style() {
34 auto css = Gtk::CssProvider::create();
35
36 std::string local = "data/BastionGuard.css";
37 std::string installed = std::string(DATA_DIR) + "/BastionGuard.css";
38
39 try {
40 if (std::filesystem::exists(local)) {
41 css->load_from_path(local);
42 std::cout << _("✔ CSS caricato da ") << local << std::endl;
43 } else if (std::filesystem::exists(installed)) {
44 css->load_from_path(installed);
45 std::cout << _("✔ CSS caricato da ") << installed << std::endl;
46 } else {
47 std::cerr << _("⚠ Nessun file CSS trovato:\n")
48 << " " << local << "\n " << installed << std::endl;
49 }
50
51 Gtk::StyleContext::add_provider_for_display(
52 Gdk::Display::get_default(),
53 css,
54 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
55 );
56 } catch (const Glib::Error& ex) {
57 std::cerr << _("❌ Errore CSS: ") << ex.what() << std::endl;
58 }
59}
#define _(s)
#define DATA_DIR
Definition Resource.hpp:28
void load_style()