Skip to content
API Documentation
BastionGuard™
anonymous_namespace{main_window.cpp} Namespace Reference

Functions

std::string format_elapsed (std::chrono::steady_clock::duration elapsed)
void set_button_with_svg_icon (Gtk::Button &button, const std::string &svg_path, const Glib::ustring &text)
std::string read_text_file (const std::string &path)
std::string load_license_text ()

Function Documentation

◆ format_elapsed()

std::string anonymous_namespace{main_window.cpp}::format_elapsed ( std::chrono::steady_clock::duration elapsed)

Definition at line 21 of file main_window.cpp.

21 {
22 const auto total_seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed).count();
23 const auto hours = total_seconds / 3600;
24 const auto minutes = (total_seconds % 3600) / 60;
25 const auto seconds = total_seconds % 60;
26
27 std::ostringstream oss;
28 oss << std::setfill('0');
29 if (hours > 0) oss << std::setw(2) << hours << ':';
30 oss << std::setw(2) << minutes << ':' << std::setw(2) << seconds;
31 return oss.str();
32 }

References format_elapsed().

Referenced by format_elapsed().

◆ load_license_text()

std::string anonymous_namespace{main_window.cpp}::load_license_text ( )

Definition at line 78 of file main_window.cpp.

78 {
79 std::string text = read_text_file(resource("LICENSE.txt"));
80 if (text.empty()) text = read_text_file("data/LICENSE.txt");
81 if (text.empty()) text = read_text_file("../data/LICENSE.txt");
82 if (text.empty()) text = read_text_file("LICENSE");
83 if (text.empty()) text = read_text_file("../LICENSE");
84
85 if (text.empty()) {
86 text =
87 "BastionGuard™ Recovery Data\n"
88 "\n"
89 "Copyright (C) 2025–2026 Calogero Scarnà.\n"
90 "\n"
91 "This program is free software: you can redistribute it and/or modify "
92 "it under the terms of the GNU General Public License as published by "
93 "the Free Software Foundation, either version 3 of the License, or "
94 "(at your option) any later version.\n"
95 "\n"
96 "See the LICENSE file for the complete GNU GPLv3 text.\n"
97 "BastionGuard™ is a trademark of Calogero Scarnà.\n";
98 }
99
100 return text;
101 }
std::string read_text_file(const std::string &path)
std::string resource(const std::string &rel)
Definition Resource.hpp:31

References load_license_text(), read_text_file(), and resource().

Referenced by load_license_text().

◆ read_text_file()

std::string anonymous_namespace{main_window.cpp}::read_text_file ( const std::string & path)

Definition at line 69 of file main_window.cpp.

69 {
70 std::ifstream input(path, std::ios::binary);
71 if (!input.is_open()) return {};
72
73 std::ostringstream content;
74 content << input.rdbuf();
75 return content.str();
76 }

References read_text_file().

Referenced by load_license_text(), and read_text_file().

◆ set_button_with_svg_icon()

void anonymous_namespace{main_window.cpp}::set_button_with_svg_icon ( Gtk::Button & button,
const std::string & svg_path,
const Glib::ustring & text )

Definition at line 34 of file main_window.cpp.

36 {
37 auto* box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 10);
38 box->set_halign(Gtk::Align::START);
39
40 bool icon_loaded = false;
41 try {
42 auto texture = Gdk::Texture::create_from_filename(svg_path);
43 auto* image = Gtk::make_managed<Gtk::Image>();
44 image->set(texture);
45 image->set_pixel_size(20);
46 image->set_halign(Gtk::Align::START);
47 box->append(*image);
48 icon_loaded = true;
49 } catch (const Glib::Error&) {
50 } catch (...) {
51 }
52
53 if (!icon_loaded) {
54 auto* fallback = Gtk::make_managed<Gtk::Label>("•");
55 fallback->set_halign(Gtk::Align::START);
56 fallback->add_css_class("small-label");
57 box->append(*fallback);
58 }
59
60 auto* label = Gtk::make_managed<Gtk::Label>(text);
61 label->set_halign(Gtk::Align::START);
62 label->set_hexpand(true);
63 label->set_xalign(0.0f);
64 box->append(*label);
65
66 button.set_child(*box);
67 }

References set_button_with_svg_icon().

Referenced by set_button_with_svg_icon().