[fractal/split-async-state-ui-appop-mgmt: 11/13] Move room_settings from AppOp and widgets to UI




commit 7a595be3a2823cc1aa30060d31e59b7e1f412b55
Author: Alejandro Domínguez <adomu net-c com>
Date:   Sat Dec 5 13:01:36 2020 +0100

    Move room_settings from AppOp and widgets to UI

 fractal-gtk/src/appop/room_settings.rs           | 58 +++---------------
 fractal-gtk/src/meson.build                      |  2 +-
 fractal-gtk/src/ui/mod.rs                        |  3 +-
 fractal-gtk/src/{widgets => ui}/room_settings.rs | 78 ++++++++++++++++++++----
 fractal-gtk/src/widgets/mod.rs                   |  2 -
 5 files changed, 78 insertions(+), 65 deletions(-)
---
diff --git a/fractal-gtk/src/appop/room_settings.rs b/fractal-gtk/src/appop/room_settings.rs
index 6532a8ac..b1bf422d 100644
--- a/fractal-gtk/src/appop/room_settings.rs
+++ b/fractal-gtk/src/appop/room_settings.rs
@@ -1,69 +1,31 @@
-use gtk::prelude::*;
-
 use crate::actions::AppState;
 use crate::appop::AppOp;
 
-use crate::widgets;
-
 impl AppOp {
     pub fn create_room_settings(&mut self) -> Option<()> {
-        let login_data = self.login_data.clone()?;
-        let window = self
-            .ui
-            .builder
-            .get_object::<gtk::Window>("main_window")
-            .expect("Can't find main_window in ui file.");
-        let stack = self
-            .ui
-            .builder
-            .get_object::<gtk::Stack>("subview_stack")
-            .expect("Can't find subview_stack in ui file.");
-
-        {
-            let room = self.rooms.get(&self.active_room.clone()?)?;
-            let mut panel = widgets::RoomSettings::new(
-                login_data.session_client.clone(),
-                &window,
-                login_data.uid,
-                room.clone(),
-            );
-            let page = panel.create(login_data.session_client.clone())?;
-
-            /* remove old panel */
-            if let Some(widget) = stack.get_child_by_name("room-settings") {
-                stack.remove(&widget);
-            }
-
-            stack.add_named(&page, "room-settings");
-
-            self.ui.room_settings = Some(panel);
-        }
-
+        let (session_client, user_id) = self
+            .login_data
+            .as_ref()
+            .map(|ld| (ld.session_client.clone(), ld.uid.clone()))?;
+        let room = self.rooms.get(self.active_room.as_ref()?).cloned()?;
+        self.ui.create_room_settings(session_client, user_id, room);
         self.set_state(AppState::RoomSettings);
-
         None
     }
 
     pub fn show_new_room_avatar(&self) -> Option<()> {
-        self.ui.room_settings.as_ref()?.show_new_room_avatar();
-        None
+        self.ui.show_new_room_avatar()
     }
 
     pub fn show_new_room_name(&self) -> Option<()> {
-        self.ui.room_settings.as_ref()?.show_new_room_name();
-        None
+        self.ui.show_new_room_name()
     }
 
     pub fn show_new_room_topic(&self) -> Option<()> {
-        self.ui.room_settings.as_ref()?.show_new_room_topic();
-        None
+        self.ui.show_new_room_topic()
     }
 
     pub fn set_notifications_switch(&self, active: bool, sensitive: bool) -> Option<()> {
-        self.ui
-            .room_settings
-            .as_ref()?
-            .set_notifications_switch(active, sensitive);
-        None
+        self.ui.set_notifications_switch(active, sensitive)
     }
 }
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index ef80081b..9776a695 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -106,6 +106,7 @@ app_sources = files(
   'ui/member.rs',
   'ui/mod.rs',
   'ui/notify.rs',
+  'ui/room_settings.rs',
   'ui/start_chat.rs',
   'util/i18n.rs',
   'util/mod.rs',
@@ -128,7 +129,6 @@ app_sources = files(
   'widgets/room_history.rs',
   'widgets/roomlist.rs',
   'widgets/roomrow.rs',
-  'widgets/room_settings.rs',
   'widgets/scroll_widget.rs',
   'widgets/source_dialog.rs',
   'widgets/sourceview_entry.rs',
diff --git a/fractal-gtk/src/ui/mod.rs b/fractal-gtk/src/ui/mod.rs
index 9bd8e712..af19e39a 100644
--- a/fractal-gtk/src/ui/mod.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -15,6 +15,7 @@ pub mod directory;
 pub mod invite;
 pub mod member;
 pub mod notify;
+pub mod room_settings;
 pub mod start_chat;
 
 pub struct UI {
@@ -23,7 +24,7 @@ pub struct UI {
     pub main_window: libhandy::ApplicationWindow,
     pub sventry: SVEntry,
     pub sventry_box: Box<gtk::Stack>,
-    pub room_settings: Option<widgets::RoomSettings>,
+    pub room_settings: Option<room_settings::RoomSettings>,
     pub history: Option<widgets::RoomHistory>,
     pub roomlist: widgets::RoomList,
     pub media_viewer: Option<widgets::MediaViewer>,
diff --git a/fractal-gtk/src/widgets/room_settings.rs b/fractal-gtk/src/ui/room_settings.rs
similarity index 93%
rename from fractal-gtk/src/widgets/room_settings.rs
rename to fractal-gtk/src/ui/room_settings.rs
index ba38e3c9..81ae93e2 100644
--- a/fractal-gtk/src/widgets/room_settings.rs
+++ b/fractal-gtk/src/ui/room_settings.rs
@@ -1,22 +1,74 @@
-use crate::backend::{room, HandleError};
-use glib::clone;
-use matrix_sdk::identifiers::UserId;
-use matrix_sdk::Client as MatrixClient;
-use std::cell::RefCell;
-use std::rc::Rc;
-
-use crate::util::i18n::ni18n_f;
-use gio::prelude::*;
-use gtk::prelude::*;
-
+use super::UI;
 use crate::actions;
 use crate::actions::{ButtonState, StateExt};
 use crate::app::RUNTIME;
+use crate::backend::{room, HandleError};
 use crate::model::{member::Member, room::Room};
+use crate::util::i18n::ni18n_f;
 use crate::util::markup_text;
 use crate::widgets;
 use crate::widgets::avatar::AvatarExt;
 use crate::widgets::members_list::MembersList;
+use crate::APPOP;
+use gio::prelude::*;
+use glib::clone;
+use gtk::prelude::*;
+use matrix_sdk::identifiers::UserId;
+use matrix_sdk::Client as MatrixClient;
+use std::cell::RefCell;
+use std::rc::Rc;
+
+impl UI {
+    pub fn create_room_settings(
+        &mut self,
+        session_client: MatrixClient,
+        user_id: UserId,
+        room: Room,
+    ) {
+        let window = self
+            .builder
+            .get_object::<gtk::Window>("main_window")
+            .expect("Can't find main_window in ui file.");
+
+        let mut panel = RoomSettings::new(session_client.clone(), &window, user_id, room);
+        let page = panel.create(session_client);
+
+        let stack = self
+            .builder
+            .get_object::<gtk::Stack>("subview_stack")
+            .expect("Can't find subview_stack in ui file.");
+        // remove old panel
+        if let Some(widget) = stack.get_child_by_name("room-settings") {
+            stack.remove(&widget);
+        }
+
+        stack.add_named(&page, "room-settings");
+
+        self.room_settings = Some(panel);
+    }
+
+    pub fn show_new_room_avatar(&self) -> Option<()> {
+        self.room_settings.as_ref()?.show_new_room_avatar();
+        None
+    }
+
+    pub fn show_new_room_name(&self) -> Option<()> {
+        self.room_settings.as_ref()?.show_new_room_name();
+        None
+    }
+
+    pub fn show_new_room_topic(&self) -> Option<()> {
+        self.room_settings.as_ref()?.show_new_room_topic();
+        None
+    }
+
+    pub fn set_notifications_switch(&self, active: bool, sensitive: bool) -> Option<()> {
+        self.room_settings
+            .as_ref()?
+            .set_notifications_switch(active, sensitive);
+        None
+    }
+}
 
 #[derive(Debug, Clone)]
 pub struct RoomSettings {
@@ -60,7 +112,7 @@ impl RoomSettings {
 
     /* creates a empty list with members.len() rows, the content will be loaded when the row is
      * drawn */
-    pub fn create(&mut self, session_client: MatrixClient) -> Option<gtk::Box> {
+    pub fn create(&mut self, session_client: MatrixClient) -> gtk::Box {
         let page = self
             .builder
             .get_object::<gtk::Box>("room_settings_box")
@@ -82,7 +134,7 @@ impl RoomSettings {
         self.init_room_settings(session_client.clone());
         self.connect(session_client);
 
-        Some(page)
+        page
     }
 
     pub fn connect(&mut self, session_client: MatrixClient) {
diff --git a/fractal-gtk/src/widgets/mod.rs b/fractal-gtk/src/widgets/mod.rs
index e88a8dec..eeffa33e 100644
--- a/fractal-gtk/src/widgets/mod.rs
+++ b/fractal-gtk/src/widgets/mod.rs
@@ -16,7 +16,6 @@ pub mod members_list;
 mod message;
 pub mod message_menu;
 pub mod room_history;
-pub mod room_settings;
 mod roomlist;
 mod roomrow;
 mod scroll_widget;
@@ -44,7 +43,6 @@ pub use self::media_viewer::MediaViewer;
 pub use self::members_list::MembersList;
 pub use self::message::MessageBox;
 pub use self::room_history::RoomHistory;
-pub use self::room_settings::RoomSettings;
 pub use self::roomlist::RoomList;
 pub use self::roomrow::RoomRow;
 pub use self::scroll_widget::page_down;


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