mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 00:34:40 +01:00
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
This commit is contained in:
parent
f483735bce
commit
fe3c153efa
2 changed files with 50 additions and 47 deletions
|
@ -26,28 +26,37 @@
|
|||
<property name="modal">True</property>
|
||||
<property name="default-width">820</property>
|
||||
<property name="default-height">760</property>
|
||||
<property name="width-request">360</property>
|
||||
<property name="height-request">294</property>
|
||||
<property name="destroy-with-parent">True</property>
|
||||
<property name="title" translatable="yes">Add a New Account</property>
|
||||
<child>
|
||||
<object class="AdwLeaflet" id="deck">
|
||||
<property name="can-unfold">False</property>
|
||||
<property name="can-navigate-back">True</property>
|
||||
<signal name="notify::visible-child-name" handler="deck_visible_child_name_notify" swapped="true" />
|
||||
<object class="AdwNavigationView" id="navigation_view">
|
||||
<child>
|
||||
<object class="AdwLeafletPage">
|
||||
<property name="name">main</property>
|
||||
<object class='GtkShortcutController'>
|
||||
<property name='scope'>managed</property>
|
||||
<child>
|
||||
<object class='GtkShortcut'>
|
||||
<property name='trigger'>Escape</property>
|
||||
<property name='action'>action(add.previous)</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwNavigationPage">
|
||||
<property name="tag">main</property>
|
||||
<property name="title" translatable="yes">Add a New Account</property>
|
||||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="hexpand">True</property>
|
||||
<child>
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="show-title-buttons">False</property>
|
||||
<child type="start">
|
||||
<object class="GtkButton" id="back_btn">
|
||||
<property name="receives-default">True</property>
|
||||
<property name="action-name">add.previous</property>
|
||||
<property name="icon-name">go-previous-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Back</property>
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar">
|
||||
<property name="show-end-title-buttons">False</property>
|
||||
<property name="show-start-title-buttons">False</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="action-name">window.close</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
|
@ -73,8 +82,7 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="min-content-width">340</property>
|
||||
<property name="min-content-height">400</property>
|
||||
<property name="hscrollbar-policy">never</property>
|
||||
<child>
|
||||
<object class="AdwClamp">
|
||||
<property name="margin-top">36</property>
|
||||
|
@ -230,8 +238,10 @@
|
|||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwLeafletPage">
|
||||
<property name="name">camera</property>
|
||||
<object class="AdwNavigationPage">
|
||||
<property name="title" translatable="yes">Camera</property>
|
||||
<property name="tag">camera</property>
|
||||
<signal name="hidden" handler="camera_page_hidden" swapped="true" />
|
||||
<property name="child">
|
||||
<object class="Camera" id="camera">
|
||||
<signal name="close" handler="camera_closed" swapped="true" />
|
||||
|
@ -241,8 +251,9 @@
|
|||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwLeafletPage">
|
||||
<property name="name">create-provider</property>
|
||||
<object class="AdwNavigationPage">
|
||||
<property name="title" translatable="yes">Create Provider</property>
|
||||
<property name="tag">create-provider</property>
|
||||
<property name="child">
|
||||
<object class="ProviderPage" id="provider_page">
|
||||
<signal name="created" handler="provider_created" swapped="true" />
|
||||
|
@ -252,17 +263,6 @@
|
|||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class='GtkShortcutController'>
|
||||
<property name='scope'>local</property>
|
||||
<child>
|
||||
<object class='GtkShortcut'>
|
||||
<property name='trigger'>Escape</property>
|
||||
<property name='action'>action(add.previous)</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
<object class="GtkEntryCompletion" id="provider_completion">
|
||||
<property name="minimum-key-length">1</property>
|
||||
|
|
|
@ -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<Camera>,
|
||||
#[template_child]
|
||||
pub deck: TemplateChild<adw::Leaflet>,
|
||||
pub navigation_view: TemplateChild<adw::NavigationView>,
|
||||
#[template_child]
|
||||
pub image: TemplateChild<ProviderImage>,
|
||||
#[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());
|
||||
|
|
Loading…
Add table
Reference in a new issue