fractal/session_list/
new_session.rs1use gtk::{glib, subclass::prelude::*};
2
3use super::{SessionInfo, SessionInfoImpl};
4use crate::{components::AvatarData, prelude::*, secret::StoredSession};
5
6mod imp {
7 use std::cell::OnceCell;
8
9 use super::*;
10
11 #[derive(Debug, Default)]
12 pub struct NewSession {
13 avatar_data: OnceCell<AvatarData>,
15 }
16
17 #[glib::object_subclass]
18 impl ObjectSubclass for NewSession {
19 const NAME: &'static str = "NewSession";
20 type Type = super::NewSession;
21 type ParentType = SessionInfo;
22 }
23
24 impl ObjectImpl for NewSession {}
25
26 impl SessionInfoImpl for NewSession {
27 fn avatar_data(&self) -> AvatarData {
28 self.avatar_data
29 .get_or_init(|| {
30 let avatar_data = AvatarData::new();
31 avatar_data.set_display_name(self.obj().user_id().to_string());
32 avatar_data
33 })
34 .clone()
35 }
36 }
37}
38
39glib::wrapper! {
40 pub struct NewSession(ObjectSubclass<imp::NewSession>)
44 @extends SessionInfo;
45}
46
47impl NewSession {
48 pub fn new(stored_session: &StoredSession) -> Self {
50 glib::Object::builder()
51 .property("info", stored_session)
52 .build()
53 }
54}