session-view: Port to glib::Properties macro
This commit is contained in:
parent
47072ab2c2
commit
9d51d57fed
|
@ -17,12 +17,12 @@ mod imp {
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use glib::subclass::InitializingObject;
|
use glib::subclass::InitializingObject;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug, Default, CompositeTemplate)]
|
#[derive(Debug, Default, CompositeTemplate, glib::Properties)]
|
||||||
#[template(resource = "/org/gnome/Fractal/ui/session/view/session_view.ui")]
|
#[template(resource = "/org/gnome/Fractal/ui/session/view/session_view.ui")]
|
||||||
|
#[properties(wrapper_type = super::SessionView)]
|
||||||
pub struct SessionView {
|
pub struct SessionView {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub stack: TemplateChild<gtk::Stack>,
|
pub stack: TemplateChild<gtk::Stack>,
|
||||||
|
@ -36,6 +36,8 @@ mod imp {
|
||||||
pub content: TemplateChild<Content>,
|
pub content: TemplateChild<Content>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub media_viewer: TemplateChild<MediaViewer>,
|
pub media_viewer: TemplateChild<MediaViewer>,
|
||||||
|
/// The current session.
|
||||||
|
#[property(get, set = Self::set_session, explicit_notify, nullable)]
|
||||||
pub session: glib::WeakRef<Session>,
|
pub session: glib::WeakRef<Session>,
|
||||||
pub window_active_handler_id: RefCell<Option<SignalHandlerId>>,
|
pub window_active_handler_id: RefCell<Option<SignalHandlerId>>,
|
||||||
}
|
}
|
||||||
|
@ -115,35 +117,8 @@ mod imp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[glib::derived_properties]
|
||||||
impl ObjectImpl for SessionView {
|
impl ObjectImpl for SessionView {
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
|
||||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
|
||||||
vec![glib::ParamSpecObject::builder::<Session>("session")
|
|
||||||
.explicit_notify()
|
|
||||||
.build()]
|
|
||||||
});
|
|
||||||
|
|
||||||
PROPERTIES.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
|
||||||
let obj = self.obj();
|
|
||||||
|
|
||||||
match pspec.name() {
|
|
||||||
"session" => obj.set_session(value.get().unwrap()),
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
|
||||||
let obj = self.obj();
|
|
||||||
|
|
||||||
match pspec.name() {
|
|
||||||
"session" => obj.session().to_value(),
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
let obj = self.obj();
|
let obj = self.obj();
|
||||||
|
@ -206,6 +181,18 @@ mod imp {
|
||||||
|
|
||||||
impl WidgetImpl for SessionView {}
|
impl WidgetImpl for SessionView {}
|
||||||
impl BinImpl for SessionView {}
|
impl BinImpl for SessionView {}
|
||||||
|
|
||||||
|
impl SessionView {
|
||||||
|
/// Set the current session.
|
||||||
|
fn set_session(&self, session: Option<Session>) {
|
||||||
|
if self.session.upgrade() == session {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.session.set(session.as_ref());
|
||||||
|
self.obj().notify_session();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
|
@ -215,26 +202,11 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SessionView {
|
impl SessionView {
|
||||||
/// Create a new session.
|
/// Create a new session view.
|
||||||
pub async fn new() -> Self {
|
pub async fn new() -> Self {
|
||||||
glib::Object::new()
|
glib::Object::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The Matrix user session.
|
|
||||||
pub fn session(&self) -> Option<Session> {
|
|
||||||
self.imp().session.upgrade()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the Matrix user session.
|
|
||||||
pub fn set_session(&self, session: Option<&Session>) {
|
|
||||||
if self.session().as_ref() == session {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.imp().session.set(session);
|
|
||||||
self.notify("session");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The currently selected room, if any.
|
/// The currently selected room, if any.
|
||||||
pub fn selected_room(&self) -> Option<Room> {
|
pub fn selected_room(&self) -> Option<Room> {
|
||||||
self.imp().content.item().and_downcast()
|
self.imp().content.item().and_downcast()
|
||||||
|
|
|
@ -343,7 +343,7 @@ impl Window {
|
||||||
self.switch_to_loading_page();
|
self.switch_to_loading_page();
|
||||||
}
|
}
|
||||||
|
|
||||||
imp.session.set_session(None);
|
imp.session.set_session(None::<Session>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_window_size(&self) -> Result<(), glib::BoolError> {
|
pub fn save_window_size(&self) -> Result<(), glib::BoolError> {
|
||||||
|
|
Loading…
Reference in New Issue