[fractal/split-async-state-ui-appop-mgmt: 12/13] Move stuff in user from AppOp to UI




commit 8c37b639c643c496cedc87df729575f8de0d8fb1
Author: Alejandro Domínguez <adomu net-c com>
Date:   Sat Dec 5 13:55:41 2020 +0100

    Move stuff in user from AppOp to UI

 fractal-gtk/src/appop/user.rs | 106 ++++--------------------------------------
 fractal-gtk/src/meson.build   |   1 +
 fractal-gtk/src/ui/mod.rs     |   1 +
 fractal-gtk/src/ui/user.rs    |  84 +++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 96 deletions(-)
---
diff --git a/fractal-gtk/src/appop/user.rs b/fractal-gtk/src/appop/user.rs
index e2cd0cd3..a6aee177 100644
--- a/fractal-gtk/src/appop/user.rs
+++ b/fractal-gtk/src/appop/user.rs
@@ -1,18 +1,8 @@
-use gtk::prelude::*;
-
-use crate::backend::{user, HandleError};
-
-use std::path::PathBuf;
-
+use super::LoginData;
 use crate::app::RUNTIME;
 use crate::appop::AppOp;
-
-use crate::cache::download_to_cache;
-
-use crate::widgets;
-use crate::widgets::AvatarExt;
-
-use super::LoginData;
+use crate::backend::{user, HandleError};
+use std::path::PathBuf;
 
 impl AppOp {
     pub fn get_username(&self) {
@@ -48,90 +38,14 @@ impl AppOp {
 
     pub fn show_user_info(&self) {
         let login_data = unwrap_or_unit_return!(self.login_data.clone());
-        let stack = self
-            .ui
-            .builder
-            .get_object::<gtk::Stack>("user_info")
-            .expect("Can't find user_info_avatar in ui file.");
-
-        /* Show user infos inside the popover but wait for all data to arrive */
-        if login_data.avatar.is_some() && login_data.username.is_some() {
-            let avatar = self
-                .ui
-                .builder
-                .get_object::<gtk::Container>("user_info_avatar")
-                .expect("Can't find user_info_avatar in ui file.");
-
-            let name = self
-                .ui
-                .builder
-                .get_object::<gtk::Label>("user_info_username")
-                .expect("Can't find user_info_avatar in ui file.");
-
-            let uid = self
-                .ui
-                .builder
-                .get_object::<gtk::Label>("user_info_uid")
-                .expect("Can't find user_info_avatar in ui file.");
-
-            uid.set_text(&login_data.uid.to_string());
-            name.set_text(&login_data.username.clone().unwrap_or_default());
-
-            /* remove all old avatar from the popover */
-            for w in avatar.get_children().iter() {
-                avatar.remove(w);
-            }
-
-            let w = widgets::Avatar::avatar_new(Some(40));
-            let data = w.circle(
-                login_data.uid.to_string(),
-                login_data.username.clone(),
-                40,
-                None,
-                None,
-            );
-            download_to_cache(
-                login_data.session_client.clone(),
-                self.user_info_cache.clone(),
-                login_data.uid.clone(),
-                data,
-            );
-
-            avatar.add(&w);
-            stack.set_visible_child_name("info");
-        } else {
-            stack.set_visible_child_name("spinner");
-        }
-
-        let eb = gtk::EventBox::new();
-        match login_data.avatar {
-            Some(_) => {
-                let w = widgets::Avatar::avatar_new(Some(24));
-                let data = w.circle(
-                    login_data.uid.to_string(),
-                    login_data.username,
-                    24,
-                    None,
-                    None,
-                );
-                download_to_cache(
-                    login_data.session_client,
-                    self.user_info_cache.clone(),
-                    login_data.uid,
-                    data,
-                );
-
-                eb.add(&w);
-            }
-            None => {
-                let w = gtk::Spinner::new();
-                w.show();
-                w.start();
-                eb.add(&w);
-            }
-        };
 
-        eb.connect_button_press_event(move |_, _| Inhibit(false));
+        self.ui.show_user_info(
+            login_data.session_client.clone(),
+            self.user_info_cache.clone(),
+            login_data.avatar.clone(),
+            login_data.username.clone(),
+            login_data.uid.clone(),
+        );
     }
 
     pub fn set_login_data(&mut self, login_data: LoginData) {
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index 9776a695..5f1d687b 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -108,6 +108,7 @@ app_sources = files(
   'ui/notify.rs',
   'ui/room_settings.rs',
   'ui/start_chat.rs',
+  'ui/user.rs',
   'util/i18n.rs',
   'util/mod.rs',
   'widgets/address.rs',
diff --git a/fractal-gtk/src/ui/mod.rs b/fractal-gtk/src/ui/mod.rs
index af19e39a..d4599e32 100644
--- a/fractal-gtk/src/ui/mod.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -17,6 +17,7 @@ pub mod member;
 pub mod notify;
 pub mod room_settings;
 pub mod start_chat;
+pub mod user;
 
 pub struct UI {
     pub builder: gtk::Builder,
diff --git a/fractal-gtk/src/ui/user.rs b/fractal-gtk/src/ui/user.rs
new file mode 100644
index 00000000..819647f9
--- /dev/null
+++ b/fractal-gtk/src/ui/user.rs
@@ -0,0 +1,84 @@
+use super::UI;
+use crate::appop::UserInfoCache;
+use crate::cache::download_to_cache;
+use crate::widgets;
+use crate::widgets::AvatarExt;
+use gtk::prelude::*;
+use matrix_sdk::identifiers::UserId;
+use matrix_sdk::Client as MatrixClient;
+use std::path::PathBuf;
+
+impl UI {
+    pub fn show_user_info(
+        &self,
+        session_client: MatrixClient,
+        user_info_cache: UserInfoCache,
+        avatar_path: Option<PathBuf>,
+        username: Option<String>,
+        user_id: UserId,
+    ) {
+        let stack = self
+            .builder
+            .get_object::<gtk::Stack>("user_info")
+            .expect("Can't find user_info_avatar in ui file.");
+
+        /* Show user infos inside the popover but wait for all data to arrive */
+        if let (Some(username), Some(_)) = (username.clone(), avatar_path.as_ref()) {
+            let avatar = self
+                .builder
+                .get_object::<gtk::Container>("user_info_avatar")
+                .expect("Can't find user_info_avatar in ui file.");
+
+            let name = self
+                .builder
+                .get_object::<gtk::Label>("user_info_username")
+                .expect("Can't find user_info_avatar in ui file.");
+
+            let uid = self
+                .builder
+                .get_object::<gtk::Label>("user_info_uid")
+                .expect("Can't find user_info_avatar in ui file.");
+
+            uid.set_text(user_id.as_ref());
+            name.set_text(&username);
+
+            /* remove all old avatar from the popover */
+            for w in avatar.get_children().iter() {
+                avatar.remove(w);
+            }
+
+            let w = widgets::Avatar::avatar_new(Some(40));
+            let data = w.circle(user_id.to_string(), Some(username), 40, None, None);
+            download_to_cache(
+                session_client.clone(),
+                user_info_cache.clone(),
+                user_id.clone(),
+                data,
+            );
+
+            avatar.add(&w);
+            stack.set_visible_child_name("info");
+        } else {
+            stack.set_visible_child_name("spinner");
+        }
+
+        let eb = gtk::EventBox::new();
+        match avatar_path {
+            Some(_) => {
+                let w = widgets::Avatar::avatar_new(Some(24));
+                let data = w.circle(user_id.to_string(), username, 24, None, None);
+                download_to_cache(session_client, user_info_cache, user_id, data);
+
+                eb.add(&w);
+            }
+            None => {
+                let w = gtk::Spinner::new();
+                w.show();
+                w.start();
+                eb.add(&w);
+            }
+        };
+
+        eb.connect_button_press_event(move |_, _| Inhibit(false));
+    }
+}


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