File: loader_view.rs

package info (click to toggle)
papers 49.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,332 kB
  • sloc: ansic: 37,722; sh: 197; xml: 127; makefile: 112
file content (78 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
use crate::deps::*;

use std::cell::Cell;

mod imp {
    use super::*;

    #[derive(Debug, Default, CompositeTemplate, Properties)]
    #[properties(wrapper_type = super::PpsLoaderView)]
    #[template(resource = "/org/gnome/papers/ui/loader-view.ui")]
    pub struct PpsLoaderView {
        #[template_child]
        stack: TemplateChild<gtk::Stack>,
        #[template_child]
        progress_bar: TemplateChild<gtk::ProgressBar>,
        #[template_child]
        spinner: TemplateChild<adw::Spinner>,
        #[property(get, set = Self::set_fraction)]
        fraction: Cell<f64>,
        #[property(get, set)]
        uri: RefCell<String>,
    }

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

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

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

    impl BinImpl for PpsLoaderView {}

    impl WidgetImpl for PpsLoaderView {}

    #[glib::derived_properties]
    impl ObjectImpl for PpsLoaderView {
        fn signals() -> &'static [Signal] {
            static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();

            SIGNALS.get_or_init(|| vec![Signal::builder("cancel").run_last().build()])
        }
    }

    impl PpsLoaderView {
        fn set_fraction(&self, fraction: f64) {
            if fraction < 0.0 {
                self.stack.set_visible_child_name("spinner");
            } else {
                self.progress_bar.set_fraction(fraction);
                self.stack.set_visible_child_name("bar");
            }
            self.fraction.set(fraction);
        }
    }

    #[gtk::template_callbacks]
    impl PpsLoaderView {
        #[template_callback]
        fn cancel_clicked(&self) {
            self.obj().emit_by_name::<()>("cancel", &[]);
        }
    }
}

glib::wrapper! {
    pub struct PpsLoaderView(ObjectSubclass<imp::PpsLoaderView>)
        @extends gtk::Widget, adw::Bin,
        @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}