[fractal/fractal-next] room: Add error signal
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] room: Add error signal
- Date: Mon, 31 May 2021 14:24:37 +0000 (UTC)
commit 88b5c0c9845bad21cec09cc409132f5c4355b6e2
Author: Julian Sparber <julian sparber net>
Date: Wed May 26 18:49:06 2021 +0200
room: Add error signal
the "error" signal will be emited whenever an error has to be displayed
to the user.
data/resources/ui/session.ui | 5 +++++
src/session/mod.rs | 12 +++++++++++-
src/session/room/room.rs | 26 ++++++++++++++++++++++++++
src/session/room_list.rs | 38 +++++++++++++++++++++++++++++++++++---
4 files changed, 77 insertions(+), 4 deletions(-)
---
diff --git a/data/resources/ui/session.ui b/data/resources/ui/session.ui
index 6cd6e86d..f5688197 100644
--- a/data/resources/ui/session.ui
+++ b/data/resources/ui/session.ui
@@ -46,6 +46,11 @@
<object class="Content">
<property name="compact" bind-source="content" bind-property="folded"
bind-flags="sync-create"/>
<property name="room" bind-source="Session" bind-property="selected-room"
bind-flags="sync-create | bidirectional"/>
+ <property name="error-list">
+ <object class="GListStore" id="error_list">
+ <property name="item-type">Error</property>
+ </object>
+ </property>
</object>
</child>
</object>
diff --git a/src/session/mod.rs b/src/session/mod.rs
index a3285ad4..705a96e8 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -15,13 +15,14 @@ pub use self::user::User;
use crate::secret;
use crate::secret::StoredSession;
use crate::utils::do_async;
+use crate::Error;
use crate::RUNTIME;
use adw;
use adw::subclass::prelude::BinImpl;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
-use gtk::{glib, glib::clone, glib::SyncSender, CompositeTemplate};
+use gtk::{gio, glib, glib::clone, glib::SyncSender, CompositeTemplate};
use gtk_macros::send;
use log::error;
use matrix_sdk::api::r0::filter::{FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter};
@@ -43,6 +44,8 @@ mod imp {
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/FractalNext/session.ui")]
pub struct Session {
+ #[template_child]
+ pub error_list: TemplateChild<gio::ListStore>,
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
@@ -70,6 +73,7 @@ mod imp {
fn instance_init(obj: &InitializingObject<Self>) {
Sidebar::static_type();
Content::static_type();
+ Error::static_type();
obj.init_template();
}
}
@@ -133,6 +137,12 @@ mod imp {
self.parent_constructed(obj);
self.categories.set_room_list(&self.room_list);
+
+ self.room_list
+ .connect_error(clone!(@weak obj => move |_, error| {
+ let priv_ = imp::Session::from_instance(&obj);
+ priv_.error_list.append(&error);
+ }));
}
}
impl WidgetImpl for Session {}
diff --git a/src/session/room/room.rs b/src/session/room/room.rs
index 71c81094..b1ca1df6 100644
--- a/src/session/room/room.rs
+++ b/src/session/room/room.rs
@@ -29,10 +29,12 @@ use crate::session::{
User,
};
use crate::utils::do_async;
+use crate::Error;
use crate::RUNTIME;
mod imp {
use super::*;
+ use glib::subclass::Signal;
use once_cell::sync::{Lazy, OnceCell};
use std::cell::Cell;
use std::collections::HashMap;
@@ -189,6 +191,18 @@ mod imp {
_ => unimplemented!(),
}
}
+
+ fn signals() -> &'static [Signal] {
+ static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
+ vec![Signal::builder(
+ "error",
+ &[Error::static_type().into()],
+ <()>::static_type().into(),
+ )
+ .build()]
+ });
+ SIGNALS.as_ref()
+ }
}
}
@@ -664,4 +678,16 @@ impl Room {
.collect(),
)
}
+
+ pub fn connect_error<F: Fn(&Self, Error) + 'static>(&self, f: F) -> glib::SignalHandlerId {
+ self.connect_local("error", true, move |values| {
+ let obj = values[0].get::<Self>().unwrap();
+ let error = values[1].get::<Error>().unwrap();
+
+ f(&obj, error);
+
+ None
+ })
+ .unwrap()
+ }
}
diff --git a/src/session/room_list.rs b/src/session/room_list.rs
index 65430b1b..9171176a 100644
--- a/src/session/room_list.rs
+++ b/src/session/room_list.rs
@@ -2,10 +2,14 @@ use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*};
use indexmap::map::IndexMap;
use matrix_sdk::{deserialized_responses::Rooms as ResponseRooms, identifiers::RoomId, Client};
-use crate::session::{room::Room, user::User};
+use crate::{
+ session::{room::Room, user::User},
+ Error,
+};
mod imp {
- use once_cell::unsync::OnceCell;
+ use glib::subclass::Signal;
+ use once_cell::sync::{Lazy, OnceCell};
use std::cell::RefCell;
use super::*;
@@ -25,7 +29,19 @@ mod imp {
type Interfaces = (gio::ListModel,);
}
- impl ObjectImpl for RoomList {}
+ impl ObjectImpl for RoomList {
+ fn signals() -> &'static [Signal] {
+ static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
+ vec![Signal::builder(
+ "error",
+ &[Error::static_type().into()],
+ <()>::static_type().into(),
+ )
+ .build()]
+ });
+ SIGNALS.as_ref()
+ }
+ }
impl ListModelImpl for RoomList {
fn item_type(&self, _list_model: &Self::Type) -> glib::Type {
@@ -120,6 +136,10 @@ impl RoomList {
}
}),
);
+
+ room.connect_error(clone!(@weak self as obj => move |_, error| {
+ obj.emit_by_name("error", &[&error]).unwrap();
+ }));
}
self.items_changed(position as u32, 0, added as u32);
@@ -206,4 +226,16 @@ impl RoomList {
self.items_added(added);
}
}
+
+ pub fn connect_error<F: Fn(&Self, Error) + 'static>(&self, f: F) -> glib::SignalHandlerId {
+ self.connect_local("error", true, move |values| {
+ let obj = values[0].get::<Self>().unwrap();
+ let error = values[1].get::<Error>().unwrap();
+
+ f(&obj, error);
+
+ None
+ })
+ .unwrap()
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]