File: ApplicationView.vala

package info (click to toggle)
granite 6.2.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,768 kB
  • sloc: python: 10; makefile: 8
file content (77 lines) | stat: -rw-r--r-- 2,953 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright 2019 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

public class ApplicationView : Gtk.Grid {
    construct {
        var progress_visible_label = new Gtk.Label ("Show Progress:");

        var progress_visible_switch = new Gtk.Switch ();
        progress_visible_switch.valign = Gtk.Align.CENTER;

        var progress_scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0, 1, 0.05);

        var badge_visible_label = new Gtk.Label ("Show Badge:");

        var badge_visible_switch = new Gtk.Switch ();
        badge_visible_switch.valign = Gtk.Align.CENTER;

        var badge_spin = new Gtk.SpinButton.with_range (0, int64.MAX, 1);

        column_spacing = 12;
        row_spacing = 6;
        orientation = Gtk.Orientation.VERTICAL;
        halign = Gtk.Align.CENTER;
        valign = Gtk.Align.CENTER;
        attach (progress_visible_label, 0, 0);
        attach (progress_visible_switch, 1, 0);
        attach (progress_scale, 2, 0);
        attach (badge_visible_label, 0, 1);
        attach (badge_visible_switch, 1, 1);
        attach (badge_spin, 2, 1);

        progress_visible_switch.bind_property ("active", progress_scale, "sensitive", GLib.BindingFlags.SYNC_CREATE);
        badge_visible_switch.bind_property ("active", badge_spin, "sensitive", GLib.BindingFlags.SYNC_CREATE);

        progress_scale.value_changed.connect (() => {
            Granite.Services.Application.set_progress.begin (progress_scale.get_value (), (obj, res) => {
                try {
                    Granite.Services.Application.set_progress.end (res);
                } catch (GLib.Error e) {
                    critical (e.message);
                }
            });
        });

        progress_visible_switch.notify["active"].connect (() => {
            Granite.Services.Application.set_progress_visible.begin (progress_visible_switch.active, (obj, res) => {
                try {
                    Granite.Services.Application.set_progress_visible.end (res);
                } catch (GLib.Error e) {
                    critical (e.message);
                }
            });
        });

        badge_spin.value_changed.connect (() => {
            Granite.Services.Application.set_badge.begin ((int64)badge_spin.value, (obj, res) => {
                try {
                    Granite.Services.Application.set_badge.end (res);
                } catch (GLib.Error e) {
                    critical (e.message);
                }
            });
        });

        badge_visible_switch.notify["active"].connect (() => {
            Granite.Services.Application.set_badge_visible.begin (badge_visible_switch.active, (obj, res) => {
                try {
                    Granite.Services.Application.set_badge_visible.end (res);
                } catch (GLib.Error e) {
                    critical (e.message);
                }
            });
        });
    }
}