[fractal/get-widgets-from-ui-struct: 20/21] Make ui::AccountSettings build its own gtk::Builder




commit 7645af26b81d6176772821a72a671f2144a7f201
Author: Alejandro Domínguez <adomu net-c com>
Date:   Mon Dec 7 21:19:30 2020 +0100

    Make ui::AccountSettings build its own gtk::Builder

 fractal-gtk/src/ui/account.rs | 82 ++++++++++++++++++++++---------------------
 fractal-gtk/src/ui/mod.rs     |  5 +--
 2 files changed, 43 insertions(+), 44 deletions(-)
---
diff --git a/fractal-gtk/src/ui/account.rs b/fractal-gtk/src/ui/account.rs
index 9c5fa6dd..b9daf109 100644
--- a/fractal-gtk/src/ui/account.rs
+++ b/fractal-gtk/src/ui/account.rs
@@ -38,7 +38,9 @@ pub struct AccountSettings {
 }
 
 impl AccountSettings {
-    pub fn new(builder: &gtk::Builder) -> Self {
+    pub fn new() -> Self {
+        let builder = gtk::Builder::from_resource("/org/gnome/Fractal/ui/account_settings.ui");
+
         Self {
             root: builder
                 .get_object("account_settings_box")
@@ -180,45 +182,6 @@ impl AccountSettings {
                 app_runtime.update_state_with(|state| state.update_username_account_settings());
             }));
 
-        fn validate_password_input(builder: &gtk::Builder) {
-            let hint = builder
-                .get_object::<gtk::Label>("password-dialog-verify-hint")
-                .expect("Can't find password-dialog-verify-hint in ui file.");
-            let confirm_password = builder
-                .get_object::<gtk::Button>("password-dialog-apply")
-                .expect("Can't find password-dialog-apply in ui file.");
-            let old = builder
-                .get_object::<gtk::Entry>("password-dialog-old-entry")
-                .expect("Can't find password-dialog-old-entry in ui file.");
-            let new = builder
-                .get_object::<gtk::Entry>("password-dialog-entry")
-                .expect("Can't find password-dialog-entry in ui file.");
-            let verify = builder
-                .get_object::<gtk::Entry>("password-dialog-verify-entry")
-                .expect("Can't find password-dialog-verify-entry in ui file.");
-
-            let mut empty = true;
-            let mut matching = true;
-            let old_p = old.get_text();
-            let new_p = new.get_text();
-            let verify_p = verify.get_text();
-
-            if new_p != verify_p {
-                matching = false;
-            }
-            if !new_p.is_empty() && !verify_p.is_empty() && !old_p.is_empty() {
-                empty = false;
-            }
-
-            if matching {
-                hint.hide();
-            } else {
-                hint.show();
-            }
-
-            confirm_password.set_sensitive(matching && !empty);
-        }
-
         // Password dialog
         self.password
             .connect_clicked(clone!(@strong app_runtime => move |_| {
@@ -500,3 +463,42 @@ impl AccountSettings {
         dialog.hide();
     }
 }
+
+fn validate_password_input(builder: &gtk::Builder) {
+    let hint = builder
+        .get_object::<gtk::Label>("password-dialog-verify-hint")
+        .expect("Can't find password-dialog-verify-hint in ui file.");
+    let confirm_password = builder
+        .get_object::<gtk::Button>("password-dialog-apply")
+        .expect("Can't find password-dialog-apply in ui file.");
+    let old = builder
+        .get_object::<gtk::Entry>("password-dialog-old-entry")
+        .expect("Can't find password-dialog-old-entry in ui file.");
+    let new = builder
+        .get_object::<gtk::Entry>("password-dialog-entry")
+        .expect("Can't find password-dialog-entry in ui file.");
+    let verify = builder
+        .get_object::<gtk::Entry>("password-dialog-verify-entry")
+        .expect("Can't find password-dialog-verify-entry in ui file.");
+
+    let mut empty = true;
+    let mut matching = true;
+    let old_p = old.get_text();
+    let new_p = new.get_text();
+    let verify_p = verify.get_text();
+
+    if new_p != verify_p {
+        matching = false;
+    }
+    if !new_p.is_empty() && !verify_p.is_empty() && !old_p.is_empty() {
+        empty = false;
+    }
+
+    if matching {
+        hint.hide();
+    } else {
+        hint.show();
+    }
+
+    confirm_password.set_sensitive(matching && !empty);
+}
diff --git a/fractal-gtk/src/ui/mod.rs b/fractal-gtk/src/ui/mod.rs
index 7f5e678b..3a8d9219 100644
--- a/fractal-gtk/src/ui/mod.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -110,9 +110,7 @@ impl UI {
         builder
             .add_from_resource("/org/gnome/Fractal/ui/password_dialog.ui")
             .expect("Can't load ui file: password_dialog.ui");
-        builder
-            .add_from_resource("/org/gnome/Fractal/ui/account_settings.ui")
-            .expect("Can't load ui file: account_settings.ui");
+        let account_settings = account::AccountSettings::new();
 
         let main_window: libhandy::ApplicationWindow = builder
             .get_object("main_window")
@@ -126,7 +124,6 @@ impl UI {
         let deck = builder
             .get_object::<libhandy::Deck>("main_deck")
             .expect("Couldn't find main_deck in ui file");
-        let account_settings = account::AccountSettings::new(&builder);
 
         UI {
             builder,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]