ui: Add "About" window to display version, authors, license, etc.

This adds a new adw::AboutWindow containing information about version, authors, license, links etc.
It is opened via a new menu button in the toolbar, which opens a menu containing an "About Helvum" button.

The version and authors are pulled from the Cargo.toml file.
This commit is contained in:
Tom A. Wagner 2023-09-19 16:12:29 +02:00
parent e92c77f2b1
commit bc006fe393
4 changed files with 72 additions and 16 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "helvum"
version = "0.4.1"
authors = ["Tom A. Wagner <tom.a.wagner@protonmail.com>"]
authors = ["Tom Wagner <tom.a.wagner@protonmail.com>"]
edition = "2021"
rust-version = "1.70"
license = "GPL-3.0-only"
@ -15,7 +15,7 @@ categories = ["gui", "multimedia"]
[dependencies]
pipewire = "0.7.1"
adw = { version = "0.5", package = "libadwaita" }
adw = { version = "0.5", package = "libadwaita", features = ["v1_2"] }
glib = { version = "0.18", features = ["log"] }
log = "0.4.11"

View file

@ -12,7 +12,7 @@ base_id = 'org.pipewire.Helvum'
dependency('glib-2.0', version: '>= 2.66')
dependency('gtk4', version: '>= 4.4.0')
dependency('libadwaita-1')
dependency('libadwaita-1', version: '>= 1.2')
dependency('libpipewire-0.3')
desktop_file_validate = find_program('desktop-file-validate', required: false)

View file

@ -26,6 +26,9 @@ use pipewire::channel::Sender;
use crate::{graph_manager::GraphManager, ui, GtkMessage, PipewireMessage};
static STYLE: &str = include_str!("style.css");
static APP_ID: &str = "org.pipewire.Helvum";
static VERSION: &str = env!("CARGO_PKG_VERSION");
static AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
mod imp {
use super::*;
@ -81,10 +84,50 @@ mod imp {
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
self.setup_actions();
}
}
impl GtkApplicationImpl for Application {}
impl AdwApplicationImpl for Application {}
impl Application {
fn setup_actions(&self) {
let obj = &*self.obj();
// Add <Control-Q> shortcut for quitting the application.
let quit = gtk::gio::SimpleAction::new("quit", None);
quit.connect_activate(clone!(@weak obj => move |_, _| {
obj.quit();
}));
obj.set_accels_for_action("app.quit", &["<Control>Q"]);
obj.add_action(&quit);
let action_about = gio::ActionEntry::builder("about")
.activate(|obj: &super::Application, _, _| {
obj.imp().show_about_dialog();
})
.build();
obj.add_action_entries([action_about]);
}
fn show_about_dialog(&self) {
let authors: Vec<&str> = AUTHORS.split(':').collect();
let about_window = adw::AboutWindow::builder()
.application_icon(APP_ID)
.application_name("Helvum")
.developer_name("Tom Wagner")
.developers(authors)
.version(VERSION)
.website("https://gitlab.freedesktop.org/pipewire/helvum")
.issue_url("https://gitlab.freedesktop.org/pipewire/helvum/-/issues")
.license_type(gtk::License::Gpl30Only)
.build();
about_window.present();
}
}
}
glib::wrapper! {
@ -101,7 +144,7 @@ impl Application {
pw_sender: Sender<GtkMessage>,
) -> Self {
let app: Application = glib::Object::builder()
.property("application-id", "org.pipewire.Helvum")
.property("application-id", APP_ID)
.build();
let imp = app.imp();
@ -114,14 +157,6 @@ impl Application {
))
.expect("Should be able to set graph manager");
// Add <Control-Q> shortcut for quitting the application.
let quit = gtk::gio::SimpleAction::new("quit", None);
quit.connect_activate(clone!(@weak app => move |_, _| {
app.quit();
}));
app.set_accels_for_action("app.quit", &["<Control>Q"]);
app.add_action(&quit);
app
}
}

View file

@ -2,6 +2,14 @@
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<menu id="primary_menu">
<section>
<item>
<attribute name="label">_About Helvum</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>
</menu>
<template class="HelvumWindow" parent="AdwApplicationWindow">
<property name="default-width">1280</property>
<property name="default-height">720</property>
@ -12,10 +20,23 @@
<child>
<object class="AdwHeaderBar" id="header_bar">
<child type="end">
<object class="GtkBox">
<style>
<class name="toolbar"></class>
</style>
<child>
<object class="HelvumZoomEntry">
<property name="zoomed-widget">graph</property>
</object>
</child>
<child>
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="menu-model">primary_menu</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>