room-creation: Port to glib::Properties macro
This commit is contained in:
parent
68af2ee00b
commit
47072ab2c2
|
@ -25,14 +25,17 @@ use crate::{
|
||||||
const MAX_BYTES: usize = 255;
|
const MAX_BYTES: usize = 255;
|
||||||
|
|
||||||
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/room_creation.ui")]
|
#[template(resource = "/org/gnome/Fractal/ui/session/view/room_creation.ui")]
|
||||||
|
#[properties(wrapper_type = super::RoomCreation)]
|
||||||
pub struct RoomCreation {
|
pub struct RoomCreation {
|
||||||
pub session: WeakRef<Session>,
|
/// The current session.
|
||||||
|
#[property(get, set = Self::set_session, explicit_notify, nullable)]
|
||||||
|
pub session: glib::WeakRef<Session>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub create_button: TemplateChild<SpinnerButton>,
|
pub create_button: TemplateChild<SpinnerButton>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
@ -78,41 +81,34 @@ mod imp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for RoomCreation {
|
#[glib::derived_properties]
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
impl ObjectImpl for RoomCreation {}
|
||||||
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 RoomCreation {}
|
impl WidgetImpl for RoomCreation {}
|
||||||
impl WindowImpl for RoomCreation {}
|
impl WindowImpl for RoomCreation {}
|
||||||
impl AdwWindowImpl for RoomCreation {}
|
impl AdwWindowImpl for RoomCreation {}
|
||||||
impl ToastableWindowImpl for RoomCreation {}
|
impl ToastableWindowImpl for RoomCreation {}
|
||||||
|
|
||||||
|
impl RoomCreation {
|
||||||
|
/// Set the current session.
|
||||||
|
fn set_session(&self, session: Option<Session>) {
|
||||||
|
if self.session.upgrade() == session {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(session) = &session {
|
||||||
|
self.server_name
|
||||||
|
.set_label(&format!(":{}", session.user_id().server_name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.session.set(session.as_ref());
|
||||||
|
self.obj().notify_session();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
/// Preference Window to display and update room details.
|
/// Dialog to create a new room.
|
||||||
pub struct RoomCreation(ObjectSubclass<imp::RoomCreation>)
|
pub struct RoomCreation(ObjectSubclass<imp::RoomCreation>)
|
||||||
@extends gtk::Widget, gtk::Window, adw::Window, ToastableWindow, @implements gtk::Accessible;
|
@extends gtk::Widget, gtk::Window, adw::Window, ToastableWindow, @implements gtk::Accessible;
|
||||||
}
|
}
|
||||||
|
@ -126,28 +122,6 @@ impl RoomCreation {
|
||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(session) = session {
|
|
||||||
imp.server_name
|
|
||||||
.set_label(&format!(":{}", session.user_id().server_name()));
|
|
||||||
}
|
|
||||||
|
|
||||||
imp.session.set(session);
|
|
||||||
self.notify("session");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create the room, if it is allowed.
|
/// Create the room, if it is allowed.
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn create_room(&self) {
|
fn create_room(&self) {
|
||||||
|
|
Loading…
Reference in New Issue