Skip to content
API Documentation
BastionGuard™
Utils.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 "Utils.hpp"
23#include <gio/gio.h>
24#include <glibmm/main.h>
25
26void Utils::notify(const std::string& title, const std::string& msg) {
27 GNotification* n = g_notification_new(title.c_str());
28 g_notification_set_body(n, msg.c_str());
29 GApplication* app = g_application_get_default();
30 if (app) g_application_send_notification(app, nullptr, n);
31}
32
34 Gtk::Window* parent,
35 const std::string& message,
36 Gtk::MessageType type,
37 const std::string& secondary)
38{
39 // Heap-allocato: vive finché l'utente non risponde. Si auto-distrugge
40 // nella callback di signal_response, evitando il classico bug GTK4 del
41 // dialog stack-local che sparisce subito.
42 Gtk::MessageDialog* dlg = parent
43 ? new Gtk::MessageDialog(*parent, message, /*use_markup*/false,
44 type, Gtk::ButtonsType::OK, /*modal*/true)
45 : new Gtk::MessageDialog(message, /*use_markup*/false,
46 type, Gtk::ButtonsType::OK, /*modal*/true);
47
48 if (!secondary.empty())
49 dlg->set_secondary_text(secondary);
50
51 dlg->signal_response().connect([dlg](int) {
52 dlg->hide();
53 delete dlg;
54 });
55
56 dlg->present();
57}
static void notify(const std::string &title, const std::string &msg)
Definition Utils.cpp:26
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