[fractal/fractal-next] room-details: Create object for MemberRow



commit b9f3143540e213d86fc9cf4d1140f9e6ba6911aa
Author: Julian Sparber <julian sparber net>
Date:   Thu Dec 9 17:26:49 2021 +0100

    room-details: Create object for MemberRow

 data/resources/resources.gresource.xml             |  1 +
 data/resources/ui/content-member-item.ui           | 14 +++
 data/resources/ui/content-member-page.ui           |  2 +-
 data/resources/ui/content-member-row.ui            | 23 +++--
 po/POTFILES.in                                     |  4 +-
 src/meson.build                                    |  3 +-
 .../content/room_details/member_page/member_row.rs | 99 ++++++++++++++++++++++
 .../{member_page.rs => member_page/mod.rs}         |  3 +
 8 files changed, 137 insertions(+), 12 deletions(-)
---
diff --git a/data/resources/resources.gresource.xml b/data/resources/resources.gresource.xml
index e9d7f1b8..94155cfb 100644
--- a/data/resources/resources.gresource.xml
+++ b/data/resources/resources.gresource.xml
@@ -12,6 +12,7 @@
     <file compressed="true" preprocess="xml-stripblanks" alias="content-item.ui">ui/content-item.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-message-file.ui">ui/content-message-file.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-member-page.ui">ui/content-member-page.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks" 
alias="content-member-item.ui">ui/content-member-item.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-member-row.ui">ui/content-member-row.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-invite-subpage.ui">ui/content-invite-subpage.ui</file>
     <file compressed="true" preprocess="xml-stripblanks" 
alias="content-invitee-item.ui">ui/content-invitee-item.ui</file>
diff --git a/data/resources/ui/content-member-item.ui b/data/resources/ui/content-member-item.ui
new file mode 100644
index 00000000..376d6af5
--- /dev/null
+++ b/data/resources/ui/content-member-item.ui
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="activatable">False</property>
+    <property name="selectable">False</property>
+    <property name="child">
+      <object class="ContentMemberRow">
+        <binding name="member">
+          <lookup name="item">GtkListItem</lookup>
+        </binding>
+      </object>
+    </property>
+  </template>
+</interface>
diff --git a/data/resources/ui/content-member-page.ui b/data/resources/ui/content-member-page.ui
index b7672eb0..cf9f4dcc 100644
--- a/data/resources/ui/content-member-page.ui
+++ b/data/resources/ui/content-member-page.ui
@@ -41,7 +41,7 @@
                 <property name="show-separators">True</property>
                 <property name="factory">
                   <object class="GtkBuilderListItemFactory">
-                    <property name="resource">/org/gnome/FractalNext/content-member-row.ui</property>
+                    <property name="resource">/org/gnome/FractalNext/content-member-item.ui</property>
                   </object>
                 </property>
                 <style>
diff --git a/data/resources/ui/content-member-row.ui b/data/resources/ui/content-member-row.ui
index fa1e34df..2e745ee5 100644
--- a/data/resources/ui/content-member-row.ui
+++ b/data/resources/ui/content-member-row.ui
@@ -1,18 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="GtkListItem">
+  <template class="ContentMemberRow" parent="AdwBin">
+    <property name="margin-top">12</property>
+    <property name="margin-bottom">12</property>
+    <property name="margin-start">12</property>
+    <property name="margin-end">12</property>
     <property name="child">
       <object class="GtkBox" id="header">
         <property name="spacing">12</property>
         <style>
-          <class name="header" />
+          <class name="header"/>
         </style>
         <child>
           <object class="ComponentsAvatar">
             <property name="size">32</property>
             <binding name="item">
               <lookup name="avatar" type="Member">
-                <lookup name="item">GtkListItem</lookup>
+                <lookup name="member">ContentMemberRow</lookup>
               </lookup>
             </binding>
           </object>
@@ -21,7 +25,7 @@
           <object class="GtkBox">
             <property name="orientation">vertical</property>
             <style>
-              <class name="title" />
+              <class name="title"/>
             </style>
             <child>
               <object class="GtkBox">
@@ -31,11 +35,11 @@
                     <property name="ellipsize">end</property>
                     <binding name="label">
                       <lookup name="display-name" type="Member">
-                        <lookup name="item">GtkListItem</lookup>
+                        <lookup name="member">ContentMemberRow</lookup>
                       </lookup>
                     </binding>
                     <style>
-                      <class name="title" />
+                      <class name="title"/>
                     </style>
                   </object>
                 </child>
@@ -43,7 +47,7 @@
                   <object class="Badge">
                     <binding name="power-level">
                       <lookup name="power-level" type="Member">
-                        <lookup name="item">GtkListItem</lookup>
+                        <lookup name="member">ContentMemberRow</lookup>
                       </lookup>
                     </binding>
                   </object>
@@ -57,11 +61,11 @@
                 <property name="ellipsize">end</property>
                 <binding name="label">
                   <lookup name="user-id" type="Member">
-                    <lookup name="item">GtkListItem</lookup>
+                    <lookup name="member">ContentMemberRow</lookup>
                   </lookup>
                 </binding>
                 <style>
-                  <class name="subtitle" />
+                  <class name="subtitle"/>
                 </style>
               </object>
             </child>
@@ -71,3 +75,4 @@
     </property>
   </template>
 </interface>
+
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 60ccf4bc..33fb20a3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -18,6 +18,7 @@ data/resources/ui/content-divider-row.ui
 data/resources/ui/content-item.ui
 data/resources/ui/content-invite.ui
 data/resources/ui/content-markdown-popover.ui
+data/resources/ui/content-member-row.ui
 data/resources/ui/content-message-file.ui
 data/resources/ui/content-message-row.ui
 data/resources/ui/content-room-details.ui
@@ -82,7 +83,8 @@ src/session/content/room_details/invite_subpage/invitee.rs
 src/session/content/room_details/invite_subpage/mod.rs
 src/session/content/room_details/invite_subpage/invitee_list.rs
 src/session/content/room_details/invite_subpage/invitee_row.rs
-src/session/content/room_details/member_page.rs
+src/session/content/room_details/member_page/mod.rs
+src/session/content/room_details/member_page/member_row.rs
 src/session/content/room_details/mod.rs
 src/session/content/room_history/divider_row.rs
 src/session/content/room_history/item_row.rs
diff --git a/src/meson.build b/src/meson.build
index c12f114d..704cb34b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -77,7 +77,8 @@ sources = files(
   'session/content/room_details/invite_subpage/mod.rs',
   'session/content/room_details/invite_subpage/invitee_list.rs',
   'session/content/room_details/invite_subpage/invitee_row.rs',
-  'session/content/room_details/member_page.rs',
+  'session/content/room_details/member_page/mod.rs',
+  'session/content/room_details/member_page/member_row.rs',
   'session/content/room_details/mod.rs',
   'session/media_viewer.rs',
   'session/room/event.rs',
diff --git a/src/session/content/room_details/member_page/member_row.rs 
b/src/session/content/room_details/member_page/member_row.rs
new file mode 100644
index 00000000..b87e871c
--- /dev/null
+++ b/src/session/content/room_details/member_page/member_row.rs
@@ -0,0 +1,99 @@
+use gtk::{glib, prelude::*, subclass::prelude::*, CompositeTemplate};
+
+use crate::session::room::Member;
+use adw::subclass::prelude::BinImpl;
+
+mod imp {
+    use super::*;
+    use glib::subclass::InitializingObject;
+    use once_cell::sync::Lazy;
+    use std::cell::RefCell;
+
+    #[derive(Debug, Default, CompositeTemplate)]
+    #[template(resource = "/org/gnome/FractalNext/content-member-row.ui")]
+    pub struct MemberRow {
+        pub member: RefCell<Option<Member>>,
+    }
+
+    #[glib::object_subclass]
+    impl ObjectSubclass for MemberRow {
+        const NAME: &'static str = "ContentMemberRow";
+        type Type = super::MemberRow;
+        type ParentType = adw::Bin;
+
+        fn class_init(klass: &mut Self::Class) {
+            Self::bind_template(klass);
+        }
+
+        fn instance_init(obj: &InitializingObject<Self>) {
+            obj.init_template();
+        }
+    }
+
+    impl ObjectImpl for MemberRow {
+        fn properties() -> &'static [glib::ParamSpec] {
+            static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
+                vec![glib::ParamSpec::new_object(
+                    "member",
+                    "Member",
+                    "The member this row is showing",
+                    Member::static_type(),
+                    glib::ParamFlags::READWRITE | glib::ParamFlags::EXPLICIT_NOTIFY,
+                )]
+            });
+
+            PROPERTIES.as_ref()
+        }
+
+        fn set_property(
+            &self,
+            obj: &Self::Type,
+            _id: usize,
+            value: &glib::Value,
+            pspec: &glib::ParamSpec,
+        ) {
+            match pspec.name() {
+                "member" => {
+                    obj.set_member(value.get().unwrap());
+                }
+                _ => unimplemented!(),
+            }
+        }
+
+        fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
+            match pspec.name() {
+                "member" => obj.member().to_value(),
+                _ => unimplemented!(),
+            }
+        }
+    }
+    impl WidgetImpl for MemberRow {}
+    impl BinImpl for MemberRow {}
+}
+
+glib::wrapper! {
+    pub struct MemberRow(ObjectSubclass<imp::MemberRow>)
+        @extends gtk::Widget, adw::Bin, @implements gtk::Accessible;
+}
+
+impl MemberRow {
+    pub fn new(member: &Member) -> Self {
+        glib::Object::new(&[("member", member)]).expect("Failed to create MemberRow")
+    }
+
+    pub fn member(&self) -> Option<Member> {
+        let priv_ = imp::MemberRow::from_instance(self);
+        priv_.member.borrow().clone()
+    }
+
+    pub fn set_member(&self, member: Option<Member>) {
+        let priv_ = imp::MemberRow::from_instance(self);
+
+        if self.member() == member {
+            return;
+        }
+
+        priv_.member.replace(member);
+        self.notify("member");
+    }
+}
diff --git a/src/session/content/room_details/member_page.rs 
b/src/session/content/room_details/member_page/mod.rs
similarity index 98%
rename from src/session/content/room_details/member_page.rs
rename to src/session/content/room_details/member_page/mod.rs
index 155d9fda..f84f79f3 100644
--- a/src/session/content/room_details/member_page.rs
+++ b/src/session/content/room_details/member_page/mod.rs
@@ -5,6 +5,8 @@ use gtk::glib::{self, clone};
 use gtk::subclass::prelude::*;
 use gtk::CompositeTemplate;
 
+mod member_row;
+use self::member_row::MemberRow;
 use crate::components::{Avatar, Badge};
 use crate::prelude::*;
 use crate::session::content::RoomDetails;
@@ -40,6 +42,7 @@ mod imp {
         fn class_init(klass: &mut Self::Class) {
             Avatar::static_type();
             Badge::static_type();
+            MemberRow::static_type();
             Self::bind_template(klass);
         }
 


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