[fractal/get-widgets-from-ui-struct: 11/19] Move room_settings from AppOp and widgets to UI
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/get-widgets-from-ui-struct: 11/19] Move room_settings from AppOp and widgets to UI
- Date: Wed, 23 Dec 2020 22:45:11 +0000 (UTC)
commit ef69355178fd5b4233ed88185794fa338832f6e3
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 | 59 ++++--------------
fractal-gtk/src/meson.build | 2 +-
fractal-gtk/src/ui/mod.rs | 3 +-
fractal-gtk/src/{widgets => ui}/room_settings.rs | 76 ++++++++++++++++++++----
fractal-gtk/src/widgets/mod.rs | 2 -
5 files changed, 79 insertions(+), 63 deletions(-)
---
diff --git a/fractal-gtk/src/appop/room_settings.rs b/fractal-gtk/src/appop/room_settings.rs
index 6532a8ac..a07471ea 100644
--- a/fractal-gtk/src/appop/room_settings.rs
+++ b/fractal-gtk/src/appop/room_settings.rs
@@ -1,69 +1,32 @@
-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 94%
rename from fractal-gtk/src/widgets/room_settings.rs
rename to fractal-gtk/src/ui/room_settings.rs
index ba38e3c9..4ae321f3 100644
--- a/fractal-gtk/src/widgets/room_settings.rs
+++ b/fractal-gtk/src/ui/room_settings.rs
@@ -1,22 +1,76 @@
-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,
+ ) -> Option<()> {
+ 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);
+
+ None
+ }
+
+ 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 {
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]