File: SettingsSidebarRow.vala

package info (click to toggle)
granite-7 7.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,876 kB
  • sloc: xml: 86; makefile: 9
file content (131 lines) | stat: -rw-r--r-- 3,823 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright 2017–2021 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

private class Granite.SettingsSidebarRow : Gtk.ListBoxRow {
    public SettingsPage.StatusType status_type {
        set {
            switch (value) {
                case SettingsPage.StatusType.ERROR:
                    status_icon.icon_name = "emblem-error";
                    break;
                case SettingsPage.StatusType.OFFLINE:
                    status_icon.icon_name = "emblem-disabled";
                    break;
                case SettingsPage.StatusType.SUCCESS:
                    status_icon.icon_name = "emblem-enabled";
                    break;
                case SettingsPage.StatusType.WARNING:
                    status_icon.icon_name = "emblem-warning";
                    break;
                case SettingsPage.StatusType.NONE:
                    status_icon.clear ();
                    break;
            }
        }
    }

    public Gtk.Widget display_widget { get; construct; }

    public string? header { get; set; }

    public unowned SettingsPage page { get; construct; }

    public string icon_name {
        get {
            return _icon_name;
        }
        set {
            _icon_name = value;
            if (display_widget is Gtk.Image) {
                ((Gtk.Image) display_widget).icon_name = value;
                ((Gtk.Image) display_widget).icon_size = Gtk.IconSize.LARGE;
            }
        }
    }

    public string status {
        set {
            status_label.label = value;
            status_label.visible = true;
        }
    }

    public string title {
        get {
            return _title;
        }
        set {
            _title = value;
            title_label.label = value;
        }
    }

    private Gtk.Image status_icon;
    private Gtk.Label status_label;
    private Gtk.Label title_label;
    private string _icon_name;
    private string _title;

    public SettingsSidebarRow (SettingsPage page) {
        Object (
            page: page
        );
    }

    construct {
        title_label = new Gtk.Label (page.title) {
            ellipsize = Pango.EllipsizeMode.END,
            vexpand = true,
            xalign = 0
        };
        title_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

        status_icon = new Gtk.Image () {
            halign = Gtk.Align.END,
            valign = Gtk.Align.END
        };

        status_label = new Gtk.Label (null) {
            use_markup = true,
            ellipsize = Pango.EllipsizeMode.END,
            vexpand = true,
            xalign = 0,
            visible = false
        };
        status_label.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);

        if (page.icon_name != null) {
            display_widget = new Gtk.Image ();
            icon_name = page.icon_name;
        } else {
            display_widget = page.display_widget;
        }

        var overlay = new Gtk.Overlay ();
        overlay.set_child (display_widget);
        overlay.add_overlay (status_icon);

        var grid = new Gtk.Grid ();
        grid.attach (overlay, 0, 0, 1, 2);
        grid.attach (title_label, 1, 0);
        grid.attach (status_label, 1, 1);

        child = grid;

        header = page.header;
        page.bind_property ("icon-name", this, "icon-name", BindingFlags.DEFAULT);
        page.bind_property ("status", this, "status", BindingFlags.DEFAULT);
        page.bind_property ("status-type", this, "status-type", BindingFlags.DEFAULT);
        page.bind_property ("title", this, "title", BindingFlags.DEFAULT);

        if (page.status != null) {
            status = page.status;
        }

        if (page.status_type != SettingsPage.StatusType.NONE) {
            status_type = page.status_type;
        }
    }
}