[fractal/split-appop-ui] Move stuff in media_viewer from AppOp to UI
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/split-appop-ui] Move stuff in media_viewer from AppOp to UI
- Date: Sat, 2 Jan 2021 17:51:39 +0000 (UTC)
commit 9be9a5dcd26a792ec29b2864b428282af6e8da08
Author: Alejandro Domínguez <adomu net-c com>
Date: Sat Jan 2 17:57:55 2021 +0100
Move stuff in media_viewer from AppOp to UI
fractal-gtk/po/POTFILES.in | 1 +
fractal-gtk/src/app/mod.rs | 11 +++-----
fractal-gtk/src/appop/media_viewer.rs | 52 ++++++++---------------------------
fractal-gtk/src/meson.build | 1 +
fractal-gtk/src/ui/media_viewer.rs | 39 ++++++++++++++++++++++++++
fractal-gtk/src/ui/mod.rs | 7 +++++
fractal-gtk/src/ui/room_settings.rs | 10 ++-----
fractal-gtk/src/ui/state.rs | 6 +---
8 files changed, 68 insertions(+), 59 deletions(-)
---
diff --git a/fractal-gtk/po/POTFILES.in b/fractal-gtk/po/POTFILES.in
index 19345a78..f8a03ceb 100644
--- a/fractal-gtk/po/POTFILES.in
+++ b/fractal-gtk/po/POTFILES.in
@@ -112,6 +112,7 @@ fractal-gtk/src/ui/connect/send.rs
fractal-gtk/src/ui/connect/swipeable_widgets.rs
fractal-gtk/src/ui/directory.rs
fractal-gtk/src/ui/invite.rs
+fractal-gtk/src/ui/media_viewer.rs
fractal-gtk/src/ui/member.rs
fractal-gtk/src/ui/mod.rs
fractal-gtk/src/ui/notify.rs
diff --git a/fractal-gtk/src/app/mod.rs b/fractal-gtk/src/app/mod.rs
index 2b8469ae..352c9f76 100644
--- a/fractal-gtk/src/app/mod.rs
+++ b/fractal-gtk/src/app/mod.rs
@@ -139,14 +139,11 @@ fn new(gtk_app: gtk::Application) -> AppRuntime {
}
}));
- let view_stack = state
- .ui
- .builder
- .get_object::<gtk::Stack>("subview_stack")
- .expect("Can't find subview_stack in ui file.");
-
// Add account settings view to the view stack
- view_stack.add_named(&state.ui.account_settings.root, "account-settings");
+ state
+ .ui
+ .subview_stack
+ .add_named(&state.ui.account_settings.root, "account-settings");
let main_stack = state
.ui
diff --git a/fractal-gtk/src/appop/media_viewer.rs b/fractal-gtk/src/appop/media_viewer.rs
index 1e8df794..84943894 100644
--- a/fractal-gtk/src/appop/media_viewer.rs
+++ b/fractal-gtk/src/appop/media_viewer.rs
@@ -1,51 +1,23 @@
-use gtk::prelude::*;
-
-use crate::actions;
-
use crate::appop::AppOp;
use crate::appop::AppState;
-
-use crate::widgets;
-
use crate::model::message::Message;
impl AppOp {
- /* FIXME: take msg by reference and maybe create an action for this */
+ // FIXME: take msg by reference and maybe create an action for this
pub fn create_media_viewer(&mut self, msg: Message) -> Option<()> {
- let login_data = self.login_data.clone()?;
- let stack = self
- .ui
- .builder
- .get_object::<gtk::Stack>("subview_stack")
- .expect("Can't find subview_stack in ui file.");
-
- {
- let room_id = self.active_room.as_ref()?;
- let room = self.rooms.get(room_id)?;
- let mut panel = widgets::MediaViewer::new(
- self.ui.main_window.clone().upcast(),
- room,
- &msg,
- login_data.uid,
- );
- panel.display_media_viewer(login_data.session_client.clone(), msg);
- let (body, header) = panel.create(login_data.session_client.clone())?;
- self.ui.media_viewer = Some(panel);
-
- let actions = actions::Message::new(self.app_runtime.clone());
- header.insert_action_group("message", Some(&actions));
- body.insert_action_group("message", Some(&actions));
-
- /* remove old panel */
- if let Some(widget) = stack.get_child_by_name("media-viewer") {
- stack.remove(&widget);
- }
-
- stack.add_named(&body, "media-viewer");
- }
+ let login_data = self.login_data.as_ref()?;
+ let active_room = self.active_room.as_ref()?;
+ let room = self.rooms.get(active_room)?;
+
+ self.ui.create_media_viewer(
+ self.app_runtime.clone(),
+ login_data.session_client.clone(),
+ room,
+ login_data.uid.clone(),
+ msg,
+ )?;
self.set_state(AppState::MediaViewer);
-
None
}
}
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index 5b36427b..36cc8fc8 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -102,6 +102,7 @@ app_sources = files(
'ui/attach.rs',
'ui/directory.rs',
'ui/invite.rs',
+ 'ui/media_viewer.rs',
'ui/member.rs',
'ui/mod.rs',
'ui/notify.rs',
diff --git a/fractal-gtk/src/ui/media_viewer.rs b/fractal-gtk/src/ui/media_viewer.rs
new file mode 100644
index 00000000..263a67db
--- /dev/null
+++ b/fractal-gtk/src/ui/media_viewer.rs
@@ -0,0 +1,39 @@
+use super::UI;
+use crate::actions;
+use crate::app::AppRuntime;
+use crate::model::message::Message;
+use crate::model::room::Room;
+use crate::widgets;
+use gtk::prelude::*;
+use matrix_sdk::{identifiers::UserId, Client as MatrixClient};
+
+impl UI {
+ // FIXME: take msg by reference and maybe create an action for this
+ pub fn create_media_viewer(
+ &mut self,
+ app_runtime: AppRuntime,
+ session_client: MatrixClient,
+ room: &Room,
+ user_id: UserId,
+ msg: Message,
+ ) -> Option<()> {
+ let mut panel =
+ widgets::MediaViewer::new(self.main_window.clone().upcast(), room, &msg, user_id);
+ panel.display_media_viewer(session_client.clone(), msg);
+ let (body, header) = panel.create(session_client)?;
+ self.media_viewer = Some(panel);
+
+ let actions = actions::Message::new(app_runtime);
+ header.insert_action_group("message", Some(&actions));
+ body.insert_action_group("message", Some(&actions));
+
+ // remove old panel
+ if let Some(widget) = self.subview_stack.get_child_by_name("media-viewer") {
+ self.subview_stack.remove(&widget);
+ }
+
+ self.subview_stack.add_named(&body, "media-viewer");
+
+ Some(())
+ }
+}
diff --git a/fractal-gtk/src/ui/mod.rs b/fractal-gtk/src/ui/mod.rs
index 04d464e0..ae34796f 100644
--- a/fractal-gtk/src/ui/mod.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -14,6 +14,7 @@ pub mod attach;
pub mod connect;
pub mod directory;
pub mod invite;
+pub mod media_viewer;
pub mod member;
pub mod notify;
pub mod room_settings;
@@ -27,6 +28,7 @@ pub struct UI {
pub main_window: libhandy::ApplicationWindow,
pub sventry: SVEntry,
pub sventry_box: Box<gtk::Stack>,
+ pub subview_stack: gtk::Stack,
pub room_settings: Option<room_settings::RoomSettings>,
pub history: Option<widgets::RoomHistory>,
pub roomlist: widgets::RoomList,
@@ -88,6 +90,10 @@ impl UI {
let parent: gtk::Box = builder.get_object("room_parent").unwrap();
parent.add(&sventry_stack);
+ let subview_stack = builder
+ .get_object("subview_stack")
+ .expect("Can't find subview_stack in ui file.");
+
// Depends on main_window
// These are all dialogs transient for main_window
builder
@@ -131,6 +137,7 @@ impl UI {
main_window,
sventry,
sventry_box,
+ subview_stack,
room_settings: None,
history: None,
roomlist: widgets::RoomList::new(None, None),
diff --git a/fractal-gtk/src/ui/room_settings.rs b/fractal-gtk/src/ui/room_settings.rs
index 81ae93e2..0df1dab5 100644
--- a/fractal-gtk/src/ui/room_settings.rs
+++ b/fractal-gtk/src/ui/room_settings.rs
@@ -33,16 +33,12 @@ impl UI {
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);
+ if let Some(widget) = self.subview_stack.get_child_by_name("room-settings") {
+ self.subview_stack.remove(&widget);
}
- stack.add_named(&page, "room-settings");
+ self.subview_stack.add_named(&page, "room-settings");
self.room_settings = Some(panel);
}
diff --git a/fractal-gtk/src/ui/state.rs b/fractal-gtk/src/ui/state.rs
index a03da58b..05c83dc7 100644
--- a/fractal-gtk/src/ui/state.rs
+++ b/fractal-gtk/src/ui/state.rs
@@ -10,10 +10,6 @@ impl UI {
.builder
.get_object::<libhandy::Deck>("main_deck")
.expect("Could not find main_deck in ui file");
- let stack = self
- .builder
- .get_object::<gtk::Stack>("subview_stack")
- .expect("Could not find subview_stack in ui file");
let app = gio::Application::get_default().unwrap();
let global_back = app.lookup_action("back");
@@ -24,7 +20,7 @@ impl UI {
};
if let Some(v) = view {
- stack.set_visible_child_name(v);
+ self.subview_stack.set_visible_child_name(v);
}
if deck.get_adjacent_child(direction).is_some() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]