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-profile-combo-box.h" |
19 |
|
|
#include "cc-sound-resources.h" |
20 |
|
|
|
21 |
|
|
struct _CcProfileComboBox |
22 |
|
|
{ |
23 |
|
|
GtkComboBox parent_instance; |
24 |
|
|
|
25 |
|
|
GtkListStore *profile_model; |
26 |
|
|
|
27 |
|
|
GvcMixerControl *mixer_control; |
28 |
|
|
GvcMixerUIDevice *device; |
29 |
|
|
}; |
30 |
|
|
|
31 |
|
✗ |
G_DEFINE_TYPE (CcProfileComboBox, cc_profile_combo_box, GTK_TYPE_COMBO_BOX) |
32 |
|
|
|
33 |
|
|
static void |
34 |
|
✗ |
profile_changed_cb (CcProfileComboBox *self) |
35 |
|
|
{ |
36 |
|
|
GtkTreeIter iter; |
37 |
|
✗ |
g_autofree gchar *profile = NULL; |
38 |
|
|
|
39 |
|
✗ |
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter)) |
40 |
|
✗ |
return; |
41 |
|
|
|
42 |
|
✗ |
gtk_tree_model_get (GTK_TREE_MODEL (self->profile_model), &iter, |
43 |
|
|
1, &profile, |
44 |
|
|
-1); |
45 |
|
|
|
46 |
|
✗ |
if (!gvc_mixer_control_change_profile_on_selected_device (self->mixer_control, |
47 |
|
|
self->device, |
48 |
|
|
profile)) |
49 |
|
|
{ |
50 |
|
✗ |
g_warning ("Failed to change profile on %s", gvc_mixer_ui_device_get_description (self->device)); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
static void |
55 |
|
✗ |
cc_profile_combo_box_dispose (GObject *object) |
56 |
|
|
{ |
57 |
|
✗ |
CcProfileComboBox *self = CC_PROFILE_COMBO_BOX (object); |
58 |
|
|
|
59 |
|
✗ |
g_clear_object (&self->device); |
60 |
|
|
|
61 |
|
✗ |
G_OBJECT_CLASS (cc_profile_combo_box_parent_class)->dispose (object); |
62 |
|
✗ |
} |
63 |
|
|
|
64 |
|
|
void |
65 |
|
✗ |
cc_profile_combo_box_class_init (CcProfileComboBoxClass *klass) |
66 |
|
|
{ |
67 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
68 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
69 |
|
|
|
70 |
|
✗ |
object_class->dispose = cc_profile_combo_box_dispose; |
71 |
|
|
|
72 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/sound/cc-profile-combo-box.ui"); |
73 |
|
|
|
74 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcProfileComboBox, profile_model); |
75 |
|
|
|
76 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, profile_changed_cb); |
77 |
|
✗ |
} |
78 |
|
|
|
79 |
|
|
void |
80 |
|
✗ |
cc_profile_combo_box_init (CcProfileComboBox *self) |
81 |
|
|
{ |
82 |
|
✗ |
g_resources_register (cc_sound_get_resource ()); |
83 |
|
|
|
84 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
85 |
|
✗ |
} |
86 |
|
|
|
87 |
|
|
void |
88 |
|
✗ |
cc_profile_combo_box_set_device (CcProfileComboBox *self, |
89 |
|
|
GvcMixerControl *mixer_control, |
90 |
|
|
GvcMixerUIDevice *device) |
91 |
|
|
{ |
92 |
|
|
GList *profiles, *link; |
93 |
|
|
|
94 |
|
✗ |
g_return_if_fail (CC_IS_PROFILE_COMBO_BOX (self)); |
95 |
|
|
|
96 |
|
✗ |
if (device == self->device) |
97 |
|
✗ |
return; |
98 |
|
|
|
99 |
|
✗ |
g_clear_object (&self->mixer_control); |
100 |
|
✗ |
self->mixer_control = g_object_ref (mixer_control); |
101 |
|
✗ |
g_clear_object (&self->device); |
102 |
|
✗ |
gtk_list_store_clear (self->profile_model); |
103 |
|
|
|
104 |
|
✗ |
if (device == NULL) |
105 |
|
✗ |
return; |
106 |
|
|
|
107 |
|
✗ |
self->device = g_object_ref (device); |
108 |
|
✗ |
profiles = gvc_mixer_ui_device_get_profiles (device); |
109 |
|
✗ |
for (link = profiles; link; link = link->next) |
110 |
|
|
{ |
111 |
|
✗ |
GvcMixerCardProfile *profile = link->data; |
112 |
|
|
GtkTreeIter iter; |
113 |
|
|
|
114 |
|
✗ |
gtk_list_store_append (self->profile_model, &iter); |
115 |
|
✗ |
gtk_list_store_set (self->profile_model, &iter, |
116 |
|
|
0, profile->human_profile, |
117 |
|
|
1, profile->profile, |
118 |
|
|
-1); |
119 |
|
|
|
120 |
|
✗ |
if (g_strcmp0 (gvc_mixer_ui_device_get_active_profile (device), profile->profile) == 0) |
121 |
|
|
{ |
122 |
|
✗ |
g_signal_handlers_block_by_func(self, profile_changed_cb, self); |
123 |
|
✗ |
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter); |
124 |
|
✗ |
g_signal_handlers_unblock_by_func(self, profile_changed_cb, self); |
125 |
|
|
} |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
gint |
130 |
|
✗ |
cc_profile_combo_box_get_profile_count (CcProfileComboBox *self) |
131 |
|
|
{ |
132 |
|
✗ |
g_return_val_if_fail (CC_IS_PROFILE_COMBO_BOX (self), 0); |
133 |
|
✗ |
return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (self->profile_model), NULL); |
134 |
|
|
} |
135 |
|
|
|