summaryrefslogtreecommitdiffstats
path: root/lan-mouse-gtk/src/fingerprint_window/imp.rs
blob: 943b68a2e83fbf3854e1b49c2eeb3bf78fc972aa (plain) (blame)
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
67
use std::sync::OnceLock;

use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::subclass::InitializingObject;
use gtk::{
    Button, CompositeTemplate, Text,
    glib::{self, subclass::Signal},
    template_callbacks,
};

#[derive(CompositeTemplate, Default)]
#[template(resource = "/de/feschber/LanMouse/fingerprint_window.ui")]
pub struct FingerprintWindow {
    #[template_child]
    pub description: TemplateChild<Text>,
    #[template_child]
    pub fingerprint: TemplateChild<Text>,
    #[template_child]
    pub confirm_button: TemplateChild<Button>,
}

#[glib::object_subclass]
impl ObjectSubclass for FingerprintWindow {
    const NAME: &'static str = "FingerprintWindow";
    const ABSTRACT: bool = false;

    type Type = super::FingerprintWindow;
    type ParentType = adw::Window;

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

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

#[template_callbacks]
impl FingerprintWindow {
    #[template_callback]
    fn handle_confirm(&self, _button: Button) {
        let desc = self.description.text().as_str().trim().to_owned();
        let fp = self.fingerprint.text().as_str().trim().to_owned();
        self.obj().emit_by_name("confirm-clicked", &[&desc, &fp])
    }
}

impl ObjectImpl for FingerprintWindow {
    fn signals() -> &'static [Signal] {
        static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
        SIGNALS.get_or_init(|| {
            vec![
                Signal::builder("confirm-clicked")
                    .param_types([String::static_type(), String::static_type()])
                    .build(),
            ]
        })
    }
}

impl WidgetImpl for FingerprintWindow {}
impl WindowImpl for FingerprintWindow {}
impl ApplicationWindowImpl for FingerprintWindow {}
impl AdwWindowImpl for FingerprintWindow {}