[fractal/fractal-next] room_details: Add basic window



commit 23aff232b03ac3f845a957c62229066fa50a09ff
Author: Kai A. Hiller <V02460 gmail com>
Date:   Sat Jul 10 14:20:22 2021 +0200

    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 +
 src/session/content/room_details/room_details.rs | 99 ++++++++++++++++++++++++
 src/session/content/room_history.rs              | 16 ++++
 10 files changed, 248 insertions(+), 2 deletions(-)
---
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 @@
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-item-row-menu.ui">ui/content-item-row-menu.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-message-row.ui">ui/content-message-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-divider-row.ui">ui/content-divider-row.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks" 
alias="content-room-details.ui">ui/content-room-details.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-state-row.ui">ui/content-state-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-markdown-popover.ui">ui/content-markdown-popover.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-invite.ui">ui/content-invite.ui</file>
@@ -36,4 +37,3 @@
     <file preprocess="xml-stripblanks">icons/scalable/status/explore-symbolic.svg</file>
   </gresource>
 </gresources>
-
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="RoomDetails" parent="AdwPreferencesWindow">
+    <property name="title" translatable="yes">Room Details</property>
+    <property name="search-enabled">False</property>
+    <child>
+      <object class="AdwPreferencesPage">
+        <property name="icon-name">applications-system-symbolic</property>
+        <property name="title" translatable="yes">General</property>
+        <property name="name">general</property>
+        <child>
+          <object class="AdwPreferencesGroup">
+            <style>
+              <class name="room-details-group" />
+            </style>
+            <child>
+              <object class="ComponentsAvatar">
+                <property name="size">128</property>
+                <binding name="item">
+                  <lookup name="avatar">
+                    <lookup name="room">RoomDetails</lookup>
+                  </lookup>
+                </binding>
+              </object>
+            </child>
+            <child>
+              <object class="GtkEntry" id="room_name_entry">
+                <property name="has-frame">True</property>
+                <property name="sensitive" bind-source="edit_toggle" bind-property="active" 
bind-flags="sync-create" />
+                <property name="xalign">0.5</property>
+                <property name="buffer">
+                  <object class="GtkEntryBuffer" id="room_name_buffer">
+                    <binding name="text">
+                      <lookup name="display-name">
+                        <lookup name="room">RoomDetails</lookup>
+                      </lookup>
+                    </binding>
+                  </object>
+                </property>
+                <style>
+                  <class name="room-details-name" />
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="CustomEntry">
+                <property name="sensitive" bind-source="edit_toggle" bind-property="active" 
bind-flags="sync-create" />
+                <child>
+                  <object class="GtkTextView" id="room_topic_text_view">
+                    <property name="justification">center</property>
+                    <property name="wrap-mode">word-char</property>
+                    <property name="accepts-tab">False</property>
+                    <property name="buffer">
+                      <object class="GtkTextBuffer" id="room_topic_buffer">
+                        <binding name="text">
+                          <lookup name="topic">
+                            <lookup name="room">RoomDetails</lookup>
+                          </lookup>
+                        </binding>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+                <style>
+                  <class name="room-details-topic" />
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkToggleButton" id="edit_toggle">
+                <property name="halign">center</property>
+                <property name="label" translatable="yes">Edit Details</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
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 @@
 <interface>
   <menu id="room-menu-model">
     <section>
+      <item>
+        <attribute name="label" translatable="yes">Room _Details</attribute>
+        <attribute name="action">room-history.details</attribute>
+        <attribute name="hidden-when">action-disabled</attribute>
+      </item>
       <item>
         <attribute name="label" translatable="yes">_Leave Room</attribute>
         <attribute name="action">room-history.leave</attribute>
@@ -182,4 +187,3 @@
     </child>
   </template>
 </interface>
-
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<Room>,
+    }
+
+    #[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<Self>) {
+            obj.init_template();
+        }
+    }
+
+    impl ObjectImpl for RoomDetails {
+        fn properties() -> &'static [glib::ParamSpec] {
+            use once_cell::sync::Lazy;
+            static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = 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<imp::RoomDetails>)
+        @extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow, @implements gtk::Accessible;
+}
+
+impl RoomDetails {
+    pub fn new(parent_window: &Option<gtk::Window>, 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<Self>) {
@@ -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<gtk::Window> {
+        self.root()?.downcast().ok()
+    }
 }
 
 impl Default for RoomHistory {


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