accounts/details: Drop Editable widgets

They are basically useless, so switch to Adw equivalents where possible
Note our provider selection widget is still very bad :(
This commit is contained in:
Bilal Elmoussaoui 2023-04-10 04:51:19 +02:00
parent 157e014fc9
commit b31c342fba
8 changed files with 38 additions and 350 deletions

View file

@ -21,8 +21,6 @@
<file compressed="true" preprocess="xml-stripblanks" alias="preferences_password_page.ui">resources/ui/preferences_password_page.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="camera.ui">resources/ui/camera.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="editable_label.ui">resources/ui/editable_label.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="editable_spin.ui">resources/ui/editable_spin.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="error_revealer.ui">resources/ui/error_revealer.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">resources/ui/shortcuts.ui</file>

View file

@ -17,7 +17,8 @@
</section>
</menu>
<object class="GtkAdjustment" id="counter_adjustment">
<property name="upper">60</property>
<property name="upper">4294967295</property>
<property name="lower">0</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>

View file

@ -12,6 +12,12 @@
</attributes>
</child>
</object>
<object class="GtkAdjustment" id="counter_adjustment">
<property name="lower">0</property>
<property name="upper">4294967295</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<template parent="GtkBox" class="AccountDetailsPage">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
@ -51,27 +57,6 @@
<property name="margin-bottom">36</property>
<property name="spacing">12</property>
<child>
<object class="GtkStack" id="edit_stack">
<property name="transition-type">crossfade</property>
<child>
<object class="GtkStackPage">
<property name="name">edit</property>
<property name="child">
<object class="GtkButton">
<property name="label" translatable="yes">_Edit</property>
<property name="use-underline">True</property>
<property name="action-name">account.edit</property>
<style>
<class name="pill" />
</style>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">save</property>
<property name="child">
<object class="GtkButton">
<property name="label" translatable="yes">_Save</property>
<property name="use-underline">True</property>
@ -81,10 +66,6 @@
<class name="suggested-action" />
</style>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
@ -112,34 +93,14 @@
<object class="GtkListBox" id="list">
<property name="selection-mode">none</property>
<child>
<object class="AdwActionRow">
<object class="AdwEntryRow" id="account_label">
<property name="title" translatable="yes">Account</property>
<child>
<object class="EditableLabel" id="account_label">
<property name="halign">end</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Provider</property>
<child>
<object class="GtkStack" id="provider_stack">
<child>
<object class="GtkStackPage">
<property name="name">display</property>
<property name="child">
<object class="GtkLabel" id="provider_label">
<property name="halign">end</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">edit</property>
<property name="child">
<object class="GtkEntry" id="provider_entry">
<property name="halign">end</property>
<property name="valign">center</property>
@ -147,10 +108,6 @@
<property name="completion">provider_completion</property>
<property name="enable-emoji-completion">True</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
@ -185,10 +142,17 @@
</child>
<child>
<object class="AdwActionRow" id="counter_row">
<property name="activatable-widget">counter_spinbutton</property>
<property name="title" translatable="yes">Counter</property>
<property name="visible">False</property>
<child>
<object class="EditableSpin" id="counter_label">
<object class="GtkSpinButton" id="counter_spinbutton">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="text">0</property>
<property name="adjustment">counter_adjustment</property>
<property name="numeric">True</property>
</object>
</child>
</object>

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template parent="AdwBin" class="EditableLabel">
<child>
<object class="GtkStack" id="stack">
<property name="transition-type">crossfade</property>
<property name="hhomogeneous">False</property>
<child>
<object class="GtkStackPage">
<property name="name">label</property>
<property name="child">
<object class="GtkLabel" id="label">
<property name="halign">end</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">entry</property>
<property name="child">
<object class="GtkEntry" id="entry">
<property name="valign">center</property>
</object>
</property>
</object>
</child>
</object>
</child>
</template>
</interface>

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template parent="AdwBin" class="EditableSpin">
<child>
<object class="GtkStack" id="stack">
<property name="transition-type">crossfade</property>
<property name="hhomogeneous">False</property>
<child>
<object class="GtkStackPage">
<property name="name">label</property>
<property name="child">
<object class="GtkLabel" id="label">
<property name="halign">end</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">spin</property>
<property name="child">
<object class="GtkSpinButton" id="spin">
<property name="valign">center</property>
</object>
</property>
</object>
</child>
</object>
</child>
</template>
</interface>

View file

@ -18,10 +18,6 @@ mod imp {
use once_cell::sync::{Lazy, OnceCell};
use super::*;
use crate::{
models::Provider,
widgets::{editable_label::EditableSpin, EditableLabel},
};
#[derive(Default, gtk::CompositeTemplate)]
#[template(resource = "/com/belmoussaoui/Authenticator/account_details_page.ui")]
@ -31,9 +27,7 @@ mod imp {
#[template_child]
pub qrcode_picture: TemplateChild<gtk::Picture>,
#[template_child]
pub provider_label: TemplateChild<gtk::Label>,
#[template_child]
pub account_label: TemplateChild<EditableLabel>,
pub account_label: TemplateChild<adw::EntryRow>,
#[template_child(id = "list")]
pub listbox: TemplateChild<gtk::ListBox>,
#[template_child]
@ -41,7 +35,7 @@ mod imp {
#[template_child]
pub method_label: TemplateChild<gtk::Label>,
#[template_child]
pub counter_label: TemplateChild<EditableSpin>,
pub counter_spinbutton: TemplateChild<gtk::SpinButton>,
#[template_child]
pub period_label: TemplateChild<gtk::Label>,
#[template_child]
@ -52,13 +46,9 @@ mod imp {
pub period_row: TemplateChild<adw::ActionRow>,
#[template_child]
pub help_row: TemplateChild<UrlRow>,
#[template_child]
pub edit_stack: TemplateChild<gtk::Stack>,
pub qrcode_paintable: QRCodePaintable,
pub account: RefCell<Option<Account>>,
#[template_child]
pub provider_stack: TemplateChild<gtk::Stack>,
#[template_child]
pub provider_completion: TemplateChild<gtk::EntryCompletion>,
#[template_child]
pub provider_entry: TemplateChild<gtk::Entry>,
@ -75,15 +65,10 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.bind_template_instance_callbacks();
EditableLabel::static_type();
EditableSpin::static_type();
klass.install_action("account.delete", None, move |page, _, _| {
page.delete_account();
});
klass.install_action("account.edit", None, move |page, _, _| {
page.set_edit_mode();
});
klass.install_action("account.save", None, move |page, _, _| {
if let Err(err) = page.save() {
tracing::error!("Failed to save account details {}", err);
@ -91,16 +76,7 @@ mod imp {
});
klass.install_action("account.back", None, move |page, _, _| {
let imp = page.imp();
if imp.edit_stack.visible_child_name().as_deref() == Some("save") {
imp.edit_stack.set_visible_child_name("edit");
imp.account_label.stop_editing(false);
imp.counter_label.stop_editing(false);
imp.provider_stack.set_visible_child_name("display");
imp.edit_stack.grab_focus();
} else {
page.activate_action("win.back", None).unwrap();
}
});
klass.add_binding_action(
@ -134,19 +110,9 @@ mod imp {
self.parent_constructed();
self.qrcode_picture
.set_paintable(Some(&self.qrcode_paintable));
self.counter_label.set_adjustment(1, u32::MAX);
}
}
impl WidgetImpl for AccountDetailsPage {
fn unmap(&self) {
self.parent_unmap();
self.edit_stack.set_visible_child_name("edit");
self.account_label.stop_editing(false);
self.counter_label.stop_editing(false);
self.provider_stack.set_visible_child_name("display");
self.provider_entry.set_text("");
}
}
impl WidgetImpl for AccountDetailsPage {}
impl BoxImpl for AccountDetailsPage {}
}
@ -188,7 +154,7 @@ impl AccountDetailsPage {
imp.qrcode_paintable.set_qrcode(qr_code);
if account.provider().method().is_event_based() {
imp.counter_label.set_text(account.counter());
imp.counter_spinbutton.set_value(account.counter() as f64);
}
self.set_provider(account.provider());
imp.account_label.set_text(&account.name());
@ -204,7 +170,7 @@ impl AccountDetailsPage {
fn set_provider(&self, provider: Provider) {
let imp = self.imp();
imp.provider_label.set_text(&provider.name());
imp.provider_entry.set_text(&provider.name());
imp.algorithm_label
.set_text(&provider.algorithm().to_locale_string());
imp.method_label
@ -233,24 +199,8 @@ impl AccountDetailsPage {
imp.selected_provider.replace(Some(provider));
}
fn set_edit_mode(&self) {
let imp = self.imp();
imp.edit_stack.set_visible_child_name("save");
imp.account_label.start_editing();
imp.counter_label.start_editing();
imp.provider_stack.set_visible_child_name("edit");
if let Some(account) = imp.account.borrow().as_ref() {
imp.provider_entry.set_text(&account.provider().name());
}
imp.account_label.grab_focus();
}
fn save(&self) -> anyhow::Result<()> {
let imp = self.imp();
imp.edit_stack.set_visible_child_name("edit");
imp.account_label.stop_editing(true);
imp.counter_label.stop_editing(true);
imp.provider_stack.set_visible_child_name("display");
if let Some(account) = imp.account.borrow().as_ref() {
account.set_name(imp.account_label.text());
@ -267,7 +217,7 @@ impl AccountDetailsPage {
}
let old_counter = account.counter();
account.set_counter(imp.counter_label.value());
account.set_counter(imp.counter_spinbutton.value() as u32);
// regenerate the otp value if the counter value was changed
if old_counter != account.counter() && account.provider().method().is_event_based() {
account.generate_otp();

View file

@ -1,161 +0,0 @@
use gtk::{glib, prelude::*, subclass::prelude::*};
mod imp {
use adw::subclass::prelude::*;
use super::*;
#[derive(Default, gtk::CompositeTemplate)]
#[template(resource = "/com/belmoussaoui/Authenticator/editable_label.ui")]
pub struct EditableLabel {
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
pub entry: TemplateChild<gtk::Entry>,
#[template_child]
pub label: TemplateChild<gtk::Label>,
}
#[glib::object_subclass]
impl ObjectSubclass for EditableLabel {
const NAME: &'static str = "EditableLabel";
type Type = super::EditableLabel;
type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for EditableLabel {
fn constructed(&self) {
self.parent_constructed();
self.stack.set_visible_child_name("label");
}
}
impl WidgetImpl for EditableLabel {
fn grab_focus(&self) -> bool {
self.parent_grab_focus();
if self.stack.visible_child_name().as_deref() == Some("entry") {
self.entry.grab_focus();
true
} else {
false
}
}
}
impl BinImpl for EditableLabel {}
#[derive(Default, gtk::CompositeTemplate)]
#[template(resource = "/com/belmoussaoui/Authenticator/editable_spin.ui")]
pub struct EditableSpin {
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
pub spin: TemplateChild<gtk::SpinButton>,
#[template_child]
pub label: TemplateChild<gtk::Label>,
}
#[glib::object_subclass]
impl ObjectSubclass for EditableSpin {
const NAME: &'static str = "EditableSpin";
type Type = super::EditableSpin;
type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for EditableSpin {
fn constructed(&self) {
self.parent_constructed();
self.stack.set_visible_child_name("label");
}
}
impl WidgetImpl for EditableSpin {
fn grab_focus(&self) -> bool {
self.parent_grab_focus();
if self.stack.visible_child_name().as_deref() == Some("spin") {
self.spin.grab_focus();
true
} else {
false
}
}
}
impl BinImpl for EditableSpin {}
}
glib::wrapper! {
pub struct EditableLabel(ObjectSubclass<imp::EditableLabel>)
@extends gtk::Widget, adw::Bin;
}
impl EditableLabel {
pub fn set_text(&self, text: &str) {
let imp = self.imp();
imp.label.set_text(text);
imp.entry.set_text(text);
}
pub fn text(&self) -> glib::GString {
self.imp().entry.text()
}
pub fn start_editing(&self) {
self.imp().stack.set_visible_child_name("entry");
}
pub fn stop_editing(&self, commit: bool) {
let imp = self.imp();
imp.stack.set_visible_child_name("label");
if commit {
imp.label.set_text(&imp.entry.text());
}
}
}
glib::wrapper! {
pub struct EditableSpin(ObjectSubclass<imp::EditableSpin>)
@extends gtk::Widget, adw::Bin;
}
impl EditableSpin {
pub fn set_adjustment(&self, min: u32, max: u32) {
self.imp().spin.set_adjustment(&gtk::Adjustment::new(
0.0, min as f64, max as f64, 1.0, 1.0, 1.0,
));
}
pub fn set_text(&self, value: u32) {
let imp = self.imp();
imp.label.set_text(&value.to_string());
imp.spin.set_value(value as f64);
}
pub fn start_editing(&self) {
self.imp().stack.set_visible_child_name("spin");
}
pub fn stop_editing(&self, commit: bool) {
let imp = self.imp();
imp.stack.set_visible_child_name("label");
if commit {
imp.label.set_text(&(imp.spin.value() as u32).to_string());
}
}
pub fn value(&self) -> u32 {
self.imp().spin.value() as u32
}
}

View file

@ -2,7 +2,6 @@ mod accounts;
mod camera;
mod camera_paintable;
mod camera_row;
mod editable_label;
mod error_revealer;
mod preferences;
mod progress_icon;
@ -15,7 +14,6 @@ pub use self::{
camera::{screenshot, Camera, CameraEvent},
camera_paintable::CameraPaintable,
camera_row::{CameraItem, CameraRow},
editable_label::EditableLabel,
error_revealer::ErrorRevealer,
preferences::PreferencesWindow,
progress_icon::ProgressIcon,