From 23aff232b03ac3f845a957c62229066fa50a09ff Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Sat, 10 Jul 2021 14:20:22 +0200 Subject: [PATCH] room_details: Add basic window --- data/resources/resources.gresource.xml | 2 +- data/resources/style.css | 37 +++++++ data/resources/ui/content-room-details.ui | 80 +++++++++++++++ data/resources/ui/content-room-history.ui | 6 +- po/POTFILES.in | 3 + src/meson.build | 2 + src/session/content/mod.rs | 2 + src/session/content/room_details/mod.rs | 3 + .../content/room_details/room_details.rs | 99 +++++++++++++++++++ src/session/content/room_history.rs | 16 +++ 10 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 data/resources/ui/content-room-details.ui create mode 100644 src/session/content/room_details/mod.rs create mode 100644 src/session/content/room_details/room_details.rs diff --git a/data/resources/resources.gresource.xml b/data/resources/resources.gresource.xml index 2a6d9825..58479c3c 100644 --- a/data/resources/resources.gresource.xml +++ b/data/resources/resources.gresource.xml @@ -11,6 +11,7 @@ ui/content-item-row-menu.ui ui/content-message-row.ui ui/content-divider-row.ui + ui/content-room-details.ui ui/content-state-row.ui ui/content-markdown-popover.ui ui/content-invite.ui @@ -36,4 +37,3 @@ icons/scalable/status/explore-symbolic.svg - diff --git a/data/resources/style.css b/data/resources/style.css index e5728086..4f865da4 100644 --- a/data/resources/style.css +++ b/data/resources/style.css @@ -1,3 +1,40 @@ +.room-details-group avatar { + margin-bottom: 6px; +} + +.room-details-group avatar * { + /* Undo non-sensitive style. */ + filter: none; +} + +.room-details-group entry:disabled { + border-color: transparent; + /* Undo non-sensitive style. */ + color: @theme_text_color; + background: none; +} + +.room-details-group entry textview { + /* Undo non-sensitive style. */ + color: @theme_text_color; + background: none; +} + +.room-details-group entry text { + /* Undo non-sensitive style. */ + color: @theme_text_color; + background: none; +} + +.room-details-name { + font-size: 2em; + margin-bottom: 6px; +} + +.room-details-topic { + margin-bottom: 6px; +} + .title-header { font-size: 36px; font-weight: bold; diff --git a/data/resources/ui/content-room-details.ui b/data/resources/ui/content-room-details.ui new file mode 100644 index 00000000..913f4f44 --- /dev/null +++ b/data/resources/ui/content-room-details.ui @@ -0,0 +1,80 @@ + + + + diff --git a/data/resources/ui/content-room-history.ui b/data/resources/ui/content-room-history.ui index a9cf96e7..25ab7148 100644 --- a/data/resources/ui/content-room-history.ui +++ b/data/resources/ui/content-room-history.ui @@ -2,6 +2,11 @@
+ + Room _Details + room-history.details + action-disabled + _Leave Room room-history.leave @@ -182,4 +187,3 @@ - diff --git a/po/POTFILES.in b/po/POTFILES.in index 76eec5fd..d4a8fc10 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -12,6 +12,7 @@ data/resources/ui/content-item.ui data/resources/ui/content-invite.ui data/resources/ui/content-markdown-popover.ui data/resources/ui/content-message-row.ui +data/resources/ui/content-room-details.ui data/resources/ui/content-room-history.ui data/resources/ui/content-state-row.ui data/resources/ui/content.ui @@ -55,6 +56,8 @@ src/session/content/invite.rs src/session/content/markdown_popover.rs src/session/content/message_row.rs src/session/content/mod.rs +src/session/content/room_details/room_details.rs +src/session/content/room_details/mod.rs src/session/content/room_history.rs src/session/content/state_row.rs src/session/mod.rs diff --git a/src/meson.build b/src/meson.build index 294b9139..5ce9765a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -53,6 +53,8 @@ sources = files( 'session/content/message_row.rs', 'session/content/mod.rs', 'session/content/room_history.rs', + 'session/content/room_details/mod.rs', + 'session/content/room_details/room_details.rs', 'session/content/state_row.rs', 'session/room/event.rs', 'session/room/highlight_flags.rs', diff --git a/src/session/content/mod.rs b/src/session/content/mod.rs index 1b59348d..de2b7b09 100644 --- a/src/session/content/mod.rs +++ b/src/session/content/mod.rs @@ -6,6 +6,7 @@ mod invite; mod item_row; mod markdown_popover; mod message_row; +mod room_details; mod room_history; mod state_row; @@ -17,5 +18,6 @@ use self::invite::Invite; use self::item_row::ItemRow; use self::markdown_popover::MarkdownPopover; use self::message_row::MessageRow; +use self::room_details::RoomDetails; use self::room_history::RoomHistory; use self::state_row::StateRow; diff --git a/src/session/content/room_details/mod.rs b/src/session/content/room_details/mod.rs new file mode 100644 index 00000000..ef27ee7e --- /dev/null +++ b/src/session/content/room_details/mod.rs @@ -0,0 +1,3 @@ +mod room_details; + +pub use self::room_details::RoomDetails; diff --git a/src/session/content/room_details/room_details.rs b/src/session/content/room_details/room_details.rs new file mode 100644 index 00000000..4da4a807 --- /dev/null +++ b/src/session/content/room_details/room_details.rs @@ -0,0 +1,99 @@ +use adw::subclass::prelude::*; +use gtk::{glib, prelude::*, subclass::prelude::*, CompositeTemplate}; + +use crate::components::CustomEntry; +use crate::session::Room; + +mod imp { + use super::*; + use glib::subclass::InitializingObject; + use once_cell::unsync::OnceCell; + + #[derive(Debug, Default, CompositeTemplate)] + #[template(resource = "/org/gnome/FractalNext/content-room-details.ui")] + pub struct RoomDetails { + pub room: OnceCell, + } + + #[glib::object_subclass] + impl ObjectSubclass for RoomDetails { + const NAME: &'static str = "RoomDetails"; + type Type = super::RoomDetails; + type ParentType = adw::PreferencesWindow; + + fn class_init(klass: &mut Self::Class) { + CustomEntry::static_type(); + Self::bind_template(klass); + } + + fn instance_init(obj: &InitializingObject) { + obj.init_template(); + } + } + + impl ObjectImpl for RoomDetails { + fn properties() -> &'static [glib::ParamSpec] { + use once_cell::sync::Lazy; + static PROPERTIES: Lazy> = Lazy::new(|| { + vec![glib::ParamSpec::new_object( + "room", + "Room", + "The room backing all details of the preference window", + Room::static_type(), + glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT_ONLY, + )] + }); + + PROPERTIES.as_ref() + } + + fn set_property( + &self, + obj: &Self::Type, + _id: usize, + value: &glib::Value, + pspec: &glib::ParamSpec, + ) { + match pspec.name() { + "room" => obj.set_room(value.get().unwrap()), + _ => unimplemented!(), + } + } + + fn property(&self, _obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { + match pspec.name() { + "room" => self.room.get().to_value(), + _ => unimplemented!(), + } + } + } + + impl WidgetImpl for RoomDetails {} + impl WindowImpl for RoomDetails {} + impl AdwWindowImpl for RoomDetails {} + impl PreferencesWindowImpl for RoomDetails {} +} + +glib::wrapper! { + /// Preference Window to display and update room details. + pub struct RoomDetails(ObjectSubclass) + @extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow, @implements gtk::Accessible; +} + +impl RoomDetails { + pub fn new(parent_window: &Option, room: &Room) -> Self { + glib::Object::new(&[("transient-for", parent_window), ("room", room)]) + .expect("Failed to create RoomDetails") + } + + pub fn room(&self) -> &Room { + let priv_ = imp::RoomDetails::from_instance(self); + // Use unwrap because room property is CONSTRUCT_ONLY. + priv_.room.get().unwrap() + } + + fn set_room(&self, room: Room) { + let priv_ = imp::RoomDetails::from_instance(self); + priv_.room.set(room).expect("Room already initialized"); + } +} diff --git a/src/session/content/room_history.rs b/src/session/content/room_history.rs index caa4f5e9..d25e3a07 100644 --- a/src/session/content/room_history.rs +++ b/src/session/content/room_history.rs @@ -1,4 +1,5 @@ use crate::components::RoomTitle; +use crate::session::content::RoomDetails; use crate::session::{content::ItemRow, content::MarkdownPopover, room::Room, room::RoomType}; use adw::subclass::prelude::*; use gtk::{ @@ -62,6 +63,9 @@ mod imp { klass.install_action("room-history.leave", None, move |widget, _, _| { widget.leave(); }); + klass.install_action("room-history.details", None, move |widget, _, _| { + widget.open_room_details(); + }); } fn instance_init(obj: &InitializingObject) { @@ -292,6 +296,13 @@ impl RoomHistory { } } + pub fn open_room_details(&self) { + if let Some(room) = self.room() { + let window = RoomDetails::new(&self.parent_window(), &room); + window.show(); + } + } + fn update_room_state(&self) { let priv_ = imp::RoomHistory::from_instance(self); @@ -327,6 +338,11 @@ impl RoomHistory { } } } + + /// Returns the parent GtkWindow containing this widget. + fn parent_window(&self) -> Option { + self.root()?.downcast().ok() + } } impl Default for RoomHistory {