From fe3c153efa98fe445124a4cf3a92fcade078a700 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Tue, 20 Jun 2023 21:51:30 +0200 Subject: [PATCH] account_add_dialog: Use newer widgets We use AdwToolbarView and AdwNavigationView. Notes: - We replace the back button with a Cancel button to close the dialog - Set minimum size of 360x294 - Stop camera only once the camera page is hidden - Set hscrollbar policy to never --- data/resources/ui/account_add.ui | 70 ++++++++++++++++---------------- src/widgets/accounts/add.rs | 27 ++++++------ 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/data/resources/ui/account_add.ui b/data/resources/ui/account_add.ui index aaa611d..298ec38 100644 --- a/data/resources/ui/account_add.ui +++ b/data/resources/ui/account_add.ui @@ -26,28 +26,37 @@ True 820 760 + 360 + 294 + True Add a New Account - - False - True - + - - main + + managed + + + Escape + action(add.previous) + + + + + + + main + Add a New Account - - vertical - True - - - False - - - True - add.previous - go-previous-symbolic - Back + + + + False + False + + + Cancel + window.close @@ -73,8 +82,7 @@ - 340 - 400 + never 36 @@ -230,8 +238,10 @@ - - camera + + Camera + camera + @@ -241,8 +251,9 @@ - - create-provider + + Create Provider + create-provider @@ -252,17 +263,6 @@ - - - local - - - Escape - action(add.previous) - - - - 1 diff --git a/src/widgets/accounts/add.rs b/src/widgets/accounts/add.rs index a582d85..15c5757 100644 --- a/src/widgets/accounts/add.rs +++ b/src/widgets/accounts/add.rs @@ -1,10 +1,10 @@ +use adw::prelude::*; use adw::subclass::prelude::*; use anyhow::Result; use gettextrs::gettext; use gtk::{ gio, glib::{self, clone}, - prelude::*, Inhibit, }; @@ -32,7 +32,7 @@ mod imp { #[template_child] pub camera: TemplateChild, #[template_child] - pub deck: TemplateChild, + pub navigation_view: TemplateChild, #[template_child] pub image: TemplateChild, #[template_child] @@ -79,8 +79,13 @@ mod imp { klass.install_action("add.previous", None, |dialog, _, _| { let imp = dialog.imp(); - if imp.deck.visible_child_name().unwrap() != "main" { - imp.deck.set_visible_child_name("main"); + if imp + .navigation_view + .visible_page() + .and_then(|page| page.tag()) + .is_some_and(|tag| tag != "main") + { + imp.navigation_view.pop(); } else { dialog.close(); } @@ -196,7 +201,7 @@ impl AccountAddDialog { let imp = self.imp(); let entry = completion.entry().unwrap(); - imp.deck.set_visible_child_name("create-provider"); + imp.navigation_view.push_by_tag("create-provider"); imp.provider_page.set_provider(None); let name_entry = imp.provider_page.name_entry(); @@ -205,10 +210,8 @@ impl AccountAddDialog { } #[template_callback] - fn deck_visible_child_name_notify(&self, _pspec: glib::ParamSpec, deck: adw::Leaflet) { - if deck.visible_child_name().as_deref() != Some("camera") { - self.imp().camera.stop(); - } + fn camera_page_hidden(&self, _page: &adw::NavigationPage) { + self.imp().camera.stop(); } #[template_callback] @@ -237,7 +240,7 @@ impl AccountAddDialog { imp.provider_completion .set_model(Some(&model.completion_model())); self.set_provider(Some(provider)); - imp.deck.set_visible_child_name("main"); + imp.navigation_view.pop(); } async fn scan_from_screenshot(&self) { @@ -249,12 +252,12 @@ impl AccountAddDialog { async fn scan_from_camera(&self) { let imp = self.imp(); imp.camera.scan_from_camera().await; - imp.deck.set_visible_child_name("camera"); + imp.navigation_view.push_by_tag("camera"); } pub fn set_from_otp_uri(&self, otp_uri: &OTPUri) { let imp = self.imp(); - imp.deck.set_visible_child_name("main"); // Switch back the form view + imp.navigation_view.pop(); // Switch back the form view imp.token_entry.set_text(&otp_uri.secret()); imp.username_entry.set_text(&otp_uri.account());