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

Go to the source code of this file.

Functions

static int compare_semver (const std::string &a, const std::string &b)
static bool check_service_active (const std::string &service_name)
static Gtk::Picture * load_picture_fixed (const std::string &path, int size)
Gtk::Picture * make_small_icon (const std::string &path)
Gtk::Picture * make_large_icon (const std::string &path)

Function Documentation

◆ check_service_active()

bool check_service_active ( const std::string & service_name)
static

Definition at line 76 of file DashboardPage.cpp.

76 {
77 return bg_process::run({"/usr/libexec/bastionguard/bastionguard-service",
78 "--system", "is-active", service_name}).ok();
79}
Result run(const std::vector< std::string > &args, bool merge_stderr=false, std::size_t limit=8U *1024U *1024U, const std::map< std::string, std::string > &environment={}, const std::function< bool(const std::string &)> &on_line={})

References check_service_active(), and bg_process::run().

Referenced by check_service_active(), and DashboardPage::update_from_logs().

◆ compare_semver()

int compare_semver ( const std::string & a,
const std::string & b )
static

Definition at line 42 of file DashboardPage.cpp.

43{
44 auto parse = [](const std::string& v) {
45 std::vector<int> parts;
46 std::stringstream ss(v);
47 std::string item;
48
49 while (std::getline(ss, item, '.')) {
50 try {
51 parts.push_back(std::stoi(item));
52 } catch (...) {
53 parts.push_back(0);
54 }
55 }
56
57 while (parts.size() < 3)
58 parts.push_back(0);
59
60 return parts;
61 };
62
63 auto pa = parse(a);
64 auto pb = parse(b);
65
66 for (size_t i = 0; i < 3; ++i) {
67 if (pa[i] != pb[i])
68 return pa[i] < pb[i] ? -1 : 1;
69 }
70
71 return 0;
72}

References compare_semver().

Referenced by DashboardPage::check_updates_async(), and compare_semver().

◆ load_picture_fixed()

Gtk::Picture * load_picture_fixed ( const std::string & path,
int size )
static

Definition at line 419 of file DashboardPage.cpp.

419 {
420 auto pic = Gtk::make_managed<Gtk::Picture>();
421 try {
422 auto pb = Gdk::Pixbuf::create_from_file(path);
423 auto scaled = pb->scale_simple(size, size, Gdk::InterpType::BILINEAR);
424 auto tex = Gdk::Texture::create_for_pixbuf(scaled);
425
426
427 pic->set_paintable(tex);
428 pic->set_content_fit(Gtk::ContentFit::CONTAIN);
429 pic->set_keep_aspect_ratio(true);
430 } catch (...) {
431 std::cerr << _("⚠ Impossibile caricare immagine: ") << path << "\n";
432 }
433
434
435 pic->set_hexpand(false);
436 pic->set_vexpand(false);
437 pic->set_halign(Gtk::Align::START);
438 pic->set_valign(Gtk::Align::START);
439
440 return pic;
441}
#define _(s)

References _, and load_picture_fixed().

Referenced by load_picture_fixed(), make_large_icon(), and make_small_icon().

◆ make_large_icon()

Gtk::Picture * make_large_icon ( const std::string & path)
inline

Definition at line 447 of file DashboardPage.cpp.

447 {
448 return load_picture_fixed(path, 128);
449}
static Gtk::Picture * load_picture_fixed(const std::string &path, int size)

References load_picture_fixed(), and make_large_icon().

Referenced by make_large_icon().

◆ make_small_icon()

Gtk::Picture * make_small_icon ( const std::string & path)
inline

Definition at line 443 of file DashboardPage.cpp.

443 {
444 return load_picture_fixed(path, 32);
445}

References load_picture_fixed(), and make_small_icon().

Referenced by make_small_icon().