join-room-dialog: Port to glib::Properties macro
This commit is contained in:
parent
cf0f9d6f78
commit
20882366b9
|
@ -9,14 +9,17 @@ use ruma::{
|
||||||
use crate::{session::model::Session, spawn, toast, Window};
|
use crate::{session::model::Session, spawn, toast, Window};
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
use glib::{object::WeakRef, subclass::InitializingObject};
|
use glib::subclass::InitializingObject;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug, Default, CompositeTemplate)]
|
#[derive(Debug, Default, CompositeTemplate, glib::Properties)]
|
||||||
#[template(resource = "/org/gnome/Fractal/ui/session/view/join_room_dialog.ui")]
|
#[template(resource = "/org/gnome/Fractal/ui/session/view/join_room_dialog.ui")]
|
||||||
|
#[properties(wrapper_type = super::JoinRoomDialog)]
|
||||||
pub struct JoinRoomDialog {
|
pub struct JoinRoomDialog {
|
||||||
pub session: WeakRef<Session>,
|
/// The current session.
|
||||||
|
#[property(get, set = Self::set_session, explicit_notify)]
|
||||||
|
pub session: glib::WeakRef<Session>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub entry: TemplateChild<gtk::Entry>,
|
pub entry: TemplateChild<gtk::Entry>,
|
||||||
}
|
}
|
||||||
|
@ -44,32 +47,8 @@ mod imp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for JoinRoomDialog {
|
#[glib::derived_properties]
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
impl ObjectImpl for JoinRoomDialog {}
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
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) {
|
|
||||||
match pspec.name() {
|
|
||||||
"session" => self.obj().set_session(value.get().unwrap()),
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
|
||||||
match pspec.name() {
|
|
||||||
"session" => self.obj().session().to_value(),
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WidgetImpl for JoinRoomDialog {}
|
impl WidgetImpl for JoinRoomDialog {}
|
||||||
impl WindowImpl for JoinRoomDialog {}
|
impl WindowImpl for JoinRoomDialog {}
|
||||||
|
@ -83,6 +62,18 @@ mod imp {
|
||||||
self.parent_response(response)
|
self.parent_response(response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl JoinRoomDialog {
|
||||||
|
/// 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! {
|
||||||
|
@ -100,23 +91,6 @@ impl JoinRoomDialog {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The current session.
|
|
||||||
pub fn session(&self) -> Option<Session> {
|
|
||||||
self.imp().session.upgrade()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the current session.
|
|
||||||
pub fn set_session(&self, session: Option<&Session>) {
|
|
||||||
let imp = self.imp();
|
|
||||||
|
|
||||||
if self.session().as_ref() == session {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
imp.session.set(session);
|
|
||||||
self.notify("session");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handle when the entry text changed.
|
/// Handle when the entry text changed.
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn entry_changed(&self, entry: >k::Entry) {
|
fn entry_changed(&self, entry: >k::Entry) {
|
||||||
|
|
Loading…
Reference in New Issue