From eca93df1ebc02b8cf32c3970b4de5b92c914095e Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 3 Nov 2024 19:57:44 +0200 Subject: [PATCH] implement about dialog --- src/app.rs | 2 ++ src/app/browser.rs | 12 +++++++ src/app/browser/about.rs | 41 +++++++++++++++++++++++ src/app/browser/window.rs | 24 +++++++------ src/app/browser/window/header.rs | 2 ++ src/app/browser/window/header/bar.rs | 2 ++ src/app/browser/window/header/bar/menu.rs | 2 ++ 7 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 src/app/browser/about.rs diff --git a/src/app.rs b/src/app.rs index 7322b459..c4991d37 100644 --- a/src/app.rs +++ b/src/app.rs @@ -41,6 +41,7 @@ impl App { profile_path: PathBuf, ) -> Self { // Init actions + let action_about = Action::new("win", true, None); let action_debug = Action::new("win", true, None); let action_profile = Action::new("win", true, None); let action_quit = Action::new("win", true, None); @@ -80,6 +81,7 @@ impl App { // Init components let browser = Arc::new(Browser::new( profile_path, + action_about.simple(), action_debug.simple(), action_profile.simple(), action_quit.simple(), diff --git a/src/app/browser.rs b/src/app/browser.rs index 38f13230..c78594d9 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -1,7 +1,9 @@ +mod about; mod database; mod widget; mod window; +use about::About; use database::Database; use widget::Widget; use window::Window; @@ -28,6 +30,7 @@ impl Browser { // Extras profile_path: PathBuf, // Actions + action_about: SimpleAction, action_debug: SimpleAction, action_profile: SimpleAction, action_quit: SimpleAction, @@ -43,6 +46,7 @@ impl Browser { ) -> Browser { // Init components let window = Arc::new(Window::new( + action_about.clone(), action_debug.clone(), action_profile.clone(), action_quit.clone(), @@ -61,6 +65,7 @@ impl Browser { let widget = Arc::new(Widget::new( window.gobject(), &[ + action_about.clone(), action_debug.clone(), action_profile.clone(), action_quit.clone(), @@ -77,6 +82,13 @@ impl Browser { )); // Init events + action_about.connect_activate({ + let window = window.clone(); + move |_, _| { + About::new().present(Some(window.gobject())); + } + }); + action_debug.connect_activate({ let widget = widget.clone(); move |_, _| { diff --git a/src/app/browser/about.rs b/src/app/browser/about.rs new file mode 100644 index 00000000..631c8761 --- /dev/null +++ b/src/app/browser/about.rs @@ -0,0 +1,41 @@ +use adw::{prelude::AdwDialogExt, AboutDialog}; +use gtk::{prelude::IsA, License}; + +pub struct About { + gobject: AboutDialog, +} + +impl About { + // Construct + pub fn new() -> Self { + // Collect debug info + let debug = &[ + format!( + "GTK {}.{}.{}", + gtk::major_version(), + gtk::minor_version(), + gtk::micro_version() + ), + format!("SQLite {}", sqlite::version()), + // @TODO + ]; + + // Init gobject + let gobject = AboutDialog::builder() + .application_name(env!("CARGO_PKG_NAME")) + .debug_info(debug.join("\n")) + .developer_name(env!("CARGO_PKG_DESCRIPTION")) + .issue_url(env!("CARGO_PKG_REPOSITORY")) + .license_type(License::MitX11) + .version(env!("CARGO_PKG_VERSION")) + .build(); + + // Return new struct + Self { gobject } + } + + // Actions + pub fn present(&self, parent: Option<&impl IsA>) { + self.gobject.present(parent); + } +} diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 1fb68766..8e6012d0 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -23,6 +23,7 @@ impl Window { // Construct pub fn new( // Actions + action_about: SimpleAction, action_debug: SimpleAction, action_profile: SimpleAction, action_quit: SimpleAction, @@ -47,17 +48,18 @@ impl Window { let header = Header::new_arc( // Actions - action_debug.clone(), - action_profile.clone(), - action_quit.clone(), - action_page_new.clone(), - action_page_close.clone(), - action_page_close_all.clone(), - action_page_home.clone(), - action_page_history_back.clone(), - action_page_history_forward.clone(), - action_page_reload.clone(), - action_page_pin.clone(), + action_about, + action_debug, + action_profile, + action_quit, + action_page_new, + action_page_close, + action_page_close_all, + action_page_home, + action_page_history_back, + action_page_history_forward, + action_page_reload, + action_page_pin, // Widgets tab.gobject(), ); diff --git a/src/app/browser/window/header.rs b/src/app/browser/window/header.rs index 24a61a4b..4fbad526 100644 --- a/src/app/browser/window/header.rs +++ b/src/app/browser/window/header.rs @@ -16,6 +16,7 @@ impl Header { // Construct pub fn new_arc( // Actions + action_about: SimpleAction, action_debug: SimpleAction, action_profile: SimpleAction, action_quit: SimpleAction, @@ -32,6 +33,7 @@ impl Header { ) -> Arc { // Init components let bar = Bar::new_arc( + action_about, action_debug, action_profile, action_quit, diff --git a/src/app/browser/window/header/bar.rs b/src/app/browser/window/header/bar.rs index a8d33cf9..c2cc0c8b 100644 --- a/src/app/browser/window/header/bar.rs +++ b/src/app/browser/window/header/bar.rs @@ -19,6 +19,7 @@ pub struct Bar { impl Bar { // Construct pub fn new_arc( + action_about: SimpleAction, action_debug: SimpleAction, action_profile: SimpleAction, action_quit: SimpleAction, @@ -36,6 +37,7 @@ impl Bar { let control = Control::new_arc(); let tab = Tab::new_arc(action_page_new.clone(), view); let menu = Menu::new_arc( + action_about, action_debug, action_profile, action_quit, diff --git a/src/app/browser/window/header/bar/menu.rs b/src/app/browser/window/header/bar/menu.rs index be9a34a1..633aa697 100644 --- a/src/app/browser/window/header/bar/menu.rs +++ b/src/app/browser/window/header/bar/menu.rs @@ -17,6 +17,7 @@ pub struct Menu { #[rustfmt::skip] // @TODO template builder? impl Menu { pub fn new_arc( + action_about: SimpleAction, action_debug: SimpleAction, action_profile: SimpleAction, action_quit: SimpleAction, @@ -64,6 +65,7 @@ impl Menu { let main_tool = gio::Menu::new(); main_tool.append(Some("Debug"), Some(&detailed_action_name(action_debug))); main_tool.append(Some("Profile"), Some(&detailed_action_name(action_profile))); + main_tool.append(Some("About"), Some(&detailed_action_name(action_about))); main.append_submenu(Some("Tool"), &main_tool);