Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright (C) 2018 Canonical Ltd. |
3 |
|
|
* |
4 |
|
|
* This program is free software; you can redistribute it and/or |
5 |
|
|
* modify it under the terms of the GNU General Public License as |
6 |
|
|
* published by the Free Software Foundation; either version 2 of the |
7 |
|
|
* License, or (at your option) any later version. |
8 |
|
|
* |
9 |
|
|
* This program is distributed in the hope that it will be useful, but |
10 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
|
|
* Lesser General Public License for more details. |
13 |
|
|
* |
14 |
|
|
* You should have received a copy of the GNU General Public License |
15 |
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 |
|
|
*/ |
17 |
|
|
|
18 |
|
|
#include "cc-device-combo-box.h" |
19 |
|
|
#include "cc-sound-resources.h" |
20 |
|
|
|
21 |
|
|
struct _CcDeviceComboBox |
22 |
|
|
{ |
23 |
|
|
GtkComboBox parent_instance; |
24 |
|
|
|
25 |
|
|
GtkListStore *device_model; |
26 |
|
|
|
27 |
|
|
GvcMixerControl *mixer_control; |
28 |
|
|
gboolean is_output; |
29 |
|
|
}; |
30 |
|
|
|
31 |
|
✗ |
G_DEFINE_TYPE (CcDeviceComboBox, cc_device_combo_box, GTK_TYPE_COMBO_BOX) |
32 |
|
|
|
33 |
|
|
static gboolean get_iter (CcDeviceComboBox *self, guint id, GtkTreeIter *iter); |
34 |
|
|
|
35 |
|
|
void |
36 |
|
✗ |
cc_device_combo_box_device_added (CcDeviceComboBox *self, |
37 |
|
|
guint id) |
38 |
|
|
{ |
39 |
|
✗ |
GvcMixerUIDevice *device = NULL; |
40 |
|
✗ |
g_autofree gchar *label = NULL; |
41 |
|
✗ |
g_autofree gchar *icon_name = NULL; |
42 |
|
|
const gchar *origin; |
43 |
|
|
GtkTreeIter iter; |
44 |
|
|
|
45 |
|
✗ |
if (self->is_output) |
46 |
|
✗ |
device = gvc_mixer_control_lookup_output_id (self->mixer_control, id); |
47 |
|
|
else |
48 |
|
✗ |
device = gvc_mixer_control_lookup_input_id (self->mixer_control, id); |
49 |
|
✗ |
if (device == NULL) |
50 |
|
✗ |
return; |
51 |
|
|
|
52 |
|
✗ |
origin = gvc_mixer_ui_device_get_origin (device); |
53 |
|
✗ |
if (origin && origin[0] != '\0') |
54 |
|
|
{ |
55 |
|
✗ |
label = g_strdup_printf ("%s - %s", |
56 |
|
|
gvc_mixer_ui_device_get_description (device), |
57 |
|
|
origin); |
58 |
|
|
} |
59 |
|
|
else |
60 |
|
|
{ |
61 |
|
✗ |
label = g_strdup (gvc_mixer_ui_device_get_description (device)); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
✗ |
if (gvc_mixer_ui_device_get_icon_name (device) != NULL) |
65 |
|
✗ |
icon_name = g_strdup_printf ("%s-symbolic", gvc_mixer_ui_device_get_icon_name (device)); |
66 |
|
|
|
67 |
|
✗ |
if (!get_iter (self, id, &iter)) |
68 |
|
✗ |
gtk_list_store_append (self->device_model, &iter); |
69 |
|
|
|
70 |
|
✗ |
gtk_list_store_set (self->device_model, &iter, |
71 |
|
|
0, label, |
72 |
|
|
1, icon_name, |
73 |
|
|
2, id, |
74 |
|
|
-1); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
static gboolean |
78 |
|
✗ |
get_iter (CcDeviceComboBox *self, |
79 |
|
|
guint id, |
80 |
|
|
GtkTreeIter *iter) |
81 |
|
|
{ |
82 |
|
✗ |
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->device_model), iter)) |
83 |
|
✗ |
return FALSE; |
84 |
|
|
|
85 |
|
|
do |
86 |
|
|
{ |
87 |
|
|
guint i; |
88 |
|
|
|
89 |
|
✗ |
gtk_tree_model_get (GTK_TREE_MODEL (self->device_model), iter, 2, &i, -1); |
90 |
|
✗ |
if (i == id) |
91 |
|
✗ |
return TRUE; |
92 |
|
✗ |
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->device_model), iter)); |
93 |
|
|
|
94 |
|
✗ |
return FALSE; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
void |
98 |
|
✗ |
cc_device_combo_box_device_removed (CcDeviceComboBox *self, |
99 |
|
|
guint id) |
100 |
|
|
{ |
101 |
|
|
GtkTreeIter iter; |
102 |
|
|
|
103 |
|
✗ |
if (get_iter (self, id, &iter)) |
104 |
|
✗ |
gtk_list_store_remove (self->device_model, &iter); |
105 |
|
✗ |
} |
106 |
|
|
|
107 |
|
|
void |
108 |
|
✗ |
cc_device_combo_box_active_device_changed (CcDeviceComboBox *self, |
109 |
|
|
guint id) |
110 |
|
|
{ |
111 |
|
|
GtkTreeIter iter; |
112 |
|
|
|
113 |
|
✗ |
if (get_iter (self, id, &iter)) |
114 |
|
✗ |
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter); |
115 |
|
|
else |
116 |
|
✗ |
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), NULL); |
117 |
|
✗ |
} |
118 |
|
|
|
119 |
|
|
static void |
120 |
|
✗ |
cc_device_combo_box_dispose (GObject *object) |
121 |
|
|
{ |
122 |
|
✗ |
CcDeviceComboBox *self = CC_DEVICE_COMBO_BOX (object); |
123 |
|
|
|
124 |
|
✗ |
g_clear_object (&self->mixer_control); |
125 |
|
|
|
126 |
|
✗ |
G_OBJECT_CLASS (cc_device_combo_box_parent_class)->dispose (object); |
127 |
|
✗ |
} |
128 |
|
|
|
129 |
|
|
void |
130 |
|
✗ |
cc_device_combo_box_class_init (CcDeviceComboBoxClass *klass) |
131 |
|
|
{ |
132 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
133 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
134 |
|
|
|
135 |
|
✗ |
object_class->dispose = cc_device_combo_box_dispose; |
136 |
|
|
|
137 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/sound/cc-device-combo-box.ui"); |
138 |
|
|
|
139 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDeviceComboBox, device_model); |
140 |
|
✗ |
} |
141 |
|
|
|
142 |
|
|
void |
143 |
|
✗ |
cc_device_combo_box_init (CcDeviceComboBox *self) |
144 |
|
|
{ |
145 |
|
✗ |
g_resources_register (cc_sound_get_resource ()); |
146 |
|
|
|
147 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
148 |
|
✗ |
} |
149 |
|
|
|
150 |
|
|
void |
151 |
|
✗ |
cc_device_combo_box_set_mixer_control (CcDeviceComboBox *self, |
152 |
|
|
GvcMixerControl *mixer_control, |
153 |
|
|
gboolean is_output) |
154 |
|
|
{ |
155 |
|
✗ |
g_return_if_fail (CC_IS_DEVICE_COMBO_BOX (self)); |
156 |
|
|
|
157 |
|
✗ |
g_clear_object (&self->mixer_control); |
158 |
|
|
|
159 |
|
✗ |
self->mixer_control = g_object_ref (mixer_control); |
160 |
|
✗ |
self->is_output = is_output; |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
GvcMixerUIDevice * |
164 |
|
✗ |
cc_device_combo_box_get_device (CcDeviceComboBox *self) |
165 |
|
|
{ |
166 |
|
|
GtkTreeIter iter; |
167 |
|
|
guint id; |
168 |
|
|
|
169 |
|
✗ |
g_return_val_if_fail (CC_IS_DEVICE_COMBO_BOX (self), NULL); |
170 |
|
|
|
171 |
|
✗ |
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter)) |
172 |
|
✗ |
return NULL; |
173 |
|
|
|
174 |
|
✗ |
gtk_tree_model_get (GTK_TREE_MODEL (self->device_model), &iter, 2, &id, -1); |
175 |
|
|
|
176 |
|
✗ |
if (self->is_output) |
177 |
|
✗ |
return gvc_mixer_control_lookup_output_id (self->mixer_control, id); |
178 |
|
|
else |
179 |
|
✗ |
return gvc_mixer_control_lookup_input_id (self->mixer_control, id); |
180 |
|
|
} |
181 |
|
|
|