fractal/session/view/sidebar/
verification_row.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use adw::subclass::prelude::BinImpl;
use gtk::{glib, prelude::*, subclass::prelude::*, CompositeTemplate};

use crate::session::model::IdentityVerification;

mod imp {
    use std::cell::RefCell;

    use glib::subclass::InitializingObject;

    use super::*;

    #[derive(Debug, Default, CompositeTemplate, glib::Properties)]
    #[template(resource = "/org/gnome/Fractal/ui/session/view/sidebar/verification_row.ui")]
    #[properties(wrapper_type = super::VerificationRow)]
    pub struct VerificationRow {
        /// The identity verification represented by this row.
        #[property(get, set = Self::set_identity_verification, explicit_notify, nullable)]
        pub identity_verification: RefCell<Option<IdentityVerification>>,
    }

    #[glib::object_subclass]
    impl ObjectSubclass for VerificationRow {
        const NAME: &'static str = "SidebarVerificationRow";
        type Type = super::VerificationRow;
        type ParentType = adw::Bin;

        fn class_init(klass: &mut Self::Class) {
            Self::bind_template(klass);
        }

        fn instance_init(obj: &InitializingObject<Self>) {
            obj.init_template();
        }
    }

    #[glib::derived_properties]
    impl ObjectImpl for VerificationRow {}

    impl WidgetImpl for VerificationRow {}
    impl BinImpl for VerificationRow {}

    impl VerificationRow {
        /// Set the identity verification represented by this row.
        fn set_identity_verification(&self, verification: Option<IdentityVerification>) {
            if *self.identity_verification.borrow() == verification {
                return;
            }

            self.identity_verification.replace(verification);
            self.obj().notify_identity_verification();
        }
    }
}

glib::wrapper! {
    /// A sidebar row representing an identity verification.
    pub struct VerificationRow(ObjectSubclass<imp::VerificationRow>)
        @extends gtk::Widget, adw::Bin, @implements gtk::Accessible;
}

impl VerificationRow {
    pub fn new() -> Self {
        glib::Object::new()
    }
}