implement AboutDialog as trait

This commit is contained in:
yggverse 2025-02-05 15:02:41 +02:00
parent 6f52d198e2
commit 00877ee36f
2 changed files with 9 additions and 28 deletions

View file

@ -10,6 +10,7 @@ use widget::Widget;
use window::Window; use window::Window;
use crate::Profile; use crate::Profile;
use adw::{prelude::AdwDialogExt, AboutDialog};
use gtk::{ use gtk::{
gio::{Cancellable, File}, gio::{Cancellable, File},
prelude::{GtkWindowExt, IsA}, prelude::{GtkWindowExt, IsA},
@ -59,7 +60,7 @@ impl Browser {
// Connect events // Connect events
action.about.connect_activate({ action.about.connect_activate({
let window = window.clone(); let window = window.clone();
move || About::new().present(Some(&window.g_box)) move || AboutDialog::about().present(Some(&window.g_box))
}); });
action.close.connect_activate({ action.close.connect_activate({

View file

@ -1,20 +1,9 @@
use adw::{prelude::AdwDialogExt, AboutDialog}; pub trait About {
use gtk::{prelude::IsA, License}; fn about() -> Self;
pub struct About {
gobject: AboutDialog,
} }
impl Default for About { impl About for adw::AboutDialog {
fn default() -> Self { fn about() -> Self {
Self::new()
}
}
impl About {
// Construct
pub fn new() -> Self {
// Collect debug info
let debug = &[ let debug = &[
format!( format!(
"Adwaita {}.{}.{}", "Adwaita {}.{}.{}",
@ -38,22 +27,13 @@ impl About {
// @TODO // @TODO
]; ];
// Init gobject adw::AboutDialog::builder()
let gobject = AboutDialog::builder()
.application_name(env!("CARGO_PKG_NAME")) .application_name(env!("CARGO_PKG_NAME"))
.debug_info(debug.join("\n")) .debug_info(debug.join("\n"))
.developer_name(env!("CARGO_PKG_DESCRIPTION")) .developer_name(env!("CARGO_PKG_DESCRIPTION"))
.issue_url(env!("CARGO_PKG_REPOSITORY")) .issue_url(env!("CARGO_PKG_REPOSITORY"))
.license_type(License::MitX11) .license_type(gtk::License::MitX11)
.version(env!("CARGO_PKG_VERSION")) .version(env!("CARGO_PKG_VERSION"))
.build(); .build()
// Return new struct
Self { gobject }
}
// Actions
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
self.gobject.present(parent);
} }
} }