fractal/session/view/content/room_details/invite_subpage/
item.rsuse gtk::{glib, prelude::*, subclass::prelude::*};
use crate::session::model::User;
mod imp {
use std::{
cell::{Cell, OnceCell, RefCell},
marker::PhantomData,
};
use super::*;
#[derive(Debug, Default, glib::Properties)]
#[properties(wrapper_type = super::InviteItem)]
pub struct InviteItem {
#[property(get, construct_only)]
pub user: OnceCell<User>,
#[property(get, set = Self::set_is_invitee, explicit_notify)]
pub is_invitee: Cell<bool>,
#[property(get = Self::can_invite)]
pub can_invite: PhantomData<bool>,
#[property(get, set = Self::set_invite_exception, explicit_notify, nullable)]
pub invite_exception: RefCell<Option<String>>,
}
#[glib::object_subclass]
impl ObjectSubclass for InviteItem {
const NAME: &'static str = "RoomDetailsInviteItem";
type Type = super::InviteItem;
}
#[glib::derived_properties]
impl ObjectImpl for InviteItem {}
impl InviteItem {
fn set_is_invitee(&self, is_invitee: bool) {
if self.is_invitee.get() == is_invitee {
return;
}
self.is_invitee.set(is_invitee);
self.obj().notify_is_invitee();
}
fn can_invite(&self) -> bool {
self.invite_exception.borrow().is_none()
}
fn set_invite_exception(&self, exception: Option<String>) {
if exception == *self.invite_exception.borrow() {
return;
}
let could_invite = self.can_invite();
self.invite_exception.replace(exception);
let obj = self.obj();
obj.notify_invite_exception();
if could_invite != self.can_invite() {
obj.notify_can_invite();
}
}
}
}
glib::wrapper! {
pub struct InviteItem(ObjectSubclass<imp::InviteItem>);
}
impl InviteItem {
pub fn new(user: &impl IsA<User>) -> Self {
glib::Object::builder().property("user", user).build()
}
}