forked from elementary/wingpanel-indicator-sound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeviceItem.vala
95 lines (80 loc) · 2.89 KB
/
DeviceItem.vala
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
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
/*-
* Copyright 2021 elementary, Inc. (https://elementary.io)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Authored by: Sean Davis <sean@bluesabre.org>
*/
public class DeviceItem : Gtk.ListBoxRow {
public signal void activated ();
private Gtk.Image img_type;
private Gtk.RadioButton radio_button;
public Gtk.ListBoxRow row { get; construct; }
public string display_name { get; construct; }
public string icon_name { get; construct; }
public bool is_priority { get; set construct; }
public bool is_default { get; construct; }
public DeviceItem (string display_name, bool is_default, bool is_priority, string icon_name, Gtk.ListBoxRow? row) {
Object (display_name: display_name, is_default: is_default, is_priority: is_priority, icon_name: icon_name, row: row);
}
class construct {
set_css_name (Gtk.STYLE_CLASS_MENUITEM);
}
construct {
selectable = false;
var label = new Gtk.Label (display_name) {
ellipsize = Pango.EllipsizeMode.MIDDLE
};
radio_button = new Gtk.RadioButton (null) {
active = is_default,
hexpand = true,
xalign = 0
};
radio_button.add (label);
if (row != null) {
var item = (DeviceItem) row;
radio_button.set_group (item.radio_button.get_group ());
}
img_type = new Gtk.Image () {
icon_name = icon_name,
icon_size = Gtk.IconSize.MENU
};
var grid = new Gtk.Grid () {
column_spacing = 8
};
grid.add (radio_button);
grid.add (img_type);
add (grid);
show_all ();
no_show_all = true;
radio_button.toggled.connect (() => {
if (radio_button.active) {
activated ();
}
update_visible (radio_button.active);
});
update_visible (is_default);
}
public void set_default () {
radio_button.active = true;
is_priority = true;
update_visible (true);
}
public void update_visible (bool is_default) {
visible = is_priority || is_default;
}
}