fractal/session_list/
new_session.rsuse gtk::{glib, subclass::prelude::*};
use super::{SessionInfo, SessionInfoImpl};
use crate::{components::AvatarData, prelude::*, secret::StoredSession};
mod imp {
use std::cell::OnceCell;
use super::*;
#[derive(Debug, Default)]
pub struct NewSession {
avatar_data: OnceCell<AvatarData>,
}
#[glib::object_subclass]
impl ObjectSubclass for NewSession {
const NAME: &'static str = "NewSession";
type Type = super::NewSession;
type ParentType = SessionInfo;
}
impl ObjectImpl for NewSession {}
impl SessionInfoImpl for NewSession {
fn avatar_data(&self) -> AvatarData {
self.avatar_data
.get_or_init(|| {
let avatar_data = AvatarData::new();
avatar_data.set_display_name(self.obj().user_id().to_string());
avatar_data
})
.clone()
}
}
}
glib::wrapper! {
pub struct NewSession(ObjectSubclass<imp::NewSession>)
@extends SessionInfo;
}
impl NewSession {
pub fn new(stored_session: &StoredSession) -> Self {
glib::Object::builder()
.property("info", stored_session)
.build()
}
}