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-level-bar.h" |
19 |
|
|
#include "cc-sound-resources.h" |
20 |
|
|
#include "cc-stream-row.h" |
21 |
|
|
#include "cc-volume-slider.h" |
22 |
|
|
#include "cc-sound-enums.h" |
23 |
|
|
|
24 |
|
|
#define SPEECH_DISPATCHER_PREFIX "speech-dispatcher-" |
25 |
|
|
|
26 |
|
|
struct _CcStreamRow |
27 |
|
|
{ |
28 |
|
|
GtkListBoxRow parent_instance; |
29 |
|
|
|
30 |
|
|
GtkBox *label_box; |
31 |
|
|
GtkLabel *name_label; |
32 |
|
|
GtkImage *icon_image; |
33 |
|
|
CcVolumeSlider *volume_slider; |
34 |
|
|
CcLevelBar *level_bar; |
35 |
|
|
|
36 |
|
|
GvcMixerStream *stream; |
37 |
|
|
guint id; |
38 |
|
|
}; |
39 |
|
|
|
40 |
|
✗ |
G_DEFINE_TYPE (CcStreamRow, cc_stream_row, GTK_TYPE_LIST_BOX_ROW) |
41 |
|
|
|
42 |
|
|
static void |
43 |
|
✗ |
cc_stream_row_dispose (GObject *object) |
44 |
|
|
{ |
45 |
|
✗ |
CcStreamRow *self = CC_STREAM_ROW (object); |
46 |
|
|
|
47 |
|
✗ |
g_clear_object (&self->stream); |
48 |
|
|
|
49 |
|
✗ |
G_OBJECT_CLASS (cc_stream_row_parent_class)->dispose (object); |
50 |
|
✗ |
} |
51 |
|
|
|
52 |
|
|
void |
53 |
|
✗ |
cc_stream_row_class_init (CcStreamRowClass *klass) |
54 |
|
|
{ |
55 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
56 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
57 |
|
|
|
58 |
|
✗ |
object_class->dispose = cc_stream_row_dispose; |
59 |
|
|
|
60 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/sound/cc-stream-row.ui"); |
61 |
|
|
|
62 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcStreamRow, label_box); |
63 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcStreamRow, icon_image); |
64 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcStreamRow, name_label); |
65 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcStreamRow, volume_slider); |
66 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcStreamRow, level_bar); |
67 |
|
✗ |
} |
68 |
|
|
|
69 |
|
|
void |
70 |
|
✗ |
cc_stream_row_init (CcStreamRow *self) |
71 |
|
|
{ |
72 |
|
✗ |
g_resources_register (cc_sound_get_resource ()); |
73 |
|
|
|
74 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
75 |
|
✗ |
} |
76 |
|
|
|
77 |
|
|
CcStreamRow * |
78 |
|
✗ |
cc_stream_row_new (GtkSizeGroup *size_group, |
79 |
|
|
GvcMixerStream *stream, |
80 |
|
|
guint id, |
81 |
|
|
CcStreamType stream_type, |
82 |
|
|
GvcMixerControl *mixer_control) |
83 |
|
|
{ |
84 |
|
|
CcStreamRow *self; |
85 |
|
✗ |
g_autoptr(GIcon) gicon = NULL; |
86 |
|
|
const gchar *stream_name; |
87 |
|
|
const gchar *icon_name; |
88 |
|
|
|
89 |
|
✗ |
self = g_object_new (CC_TYPE_STREAM_ROW, NULL); |
90 |
|
✗ |
self->stream = g_object_ref (stream); |
91 |
|
✗ |
self->id = id; |
92 |
|
|
|
93 |
|
✗ |
icon_name = gvc_mixer_stream_get_icon_name (stream); |
94 |
|
✗ |
stream_name = gvc_mixer_stream_get_name (stream); |
95 |
|
|
|
96 |
|
✗ |
if (g_str_has_prefix (stream_name, SPEECH_DISPATCHER_PREFIX)) |
97 |
|
✗ |
gicon = g_themed_icon_new_with_default_fallbacks ("org.gnome.Settings-accessibility"); |
98 |
|
✗ |
else if (gtk_icon_theme_has_icon (gtk_icon_theme_get_for_display (gdk_display_get_default ()), icon_name)) |
99 |
|
✗ |
gicon = g_themed_icon_new_with_default_fallbacks (icon_name); |
100 |
|
|
else |
101 |
|
✗ |
gicon = g_themed_icon_new_with_default_fallbacks ("application-x-executable"); |
102 |
|
|
|
103 |
|
✗ |
gtk_image_set_from_gicon (self->icon_image, gicon); |
104 |
|
|
|
105 |
|
✗ |
gtk_label_set_label (self->name_label, gvc_mixer_stream_get_name (stream)); |
106 |
|
✗ |
cc_volume_slider_set_stream (self->volume_slider, stream, stream_type); |
107 |
|
✗ |
cc_volume_slider_set_mixer_control (self->volume_slider, mixer_control); |
108 |
|
✗ |
cc_level_bar_set_stream (self->level_bar, stream); |
109 |
|
|
|
110 |
|
✗ |
gtk_size_group_add_widget (size_group, GTK_WIDGET (self->label_box)); |
111 |
|
|
|
112 |
|
✗ |
return self; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
GvcMixerStream * |
116 |
|
✗ |
cc_stream_row_get_stream (CcStreamRow *self) |
117 |
|
|
{ |
118 |
|
✗ |
g_return_val_if_fail (CC_IS_STREAM_ROW (self), NULL); |
119 |
|
✗ |
return self->stream; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
guint |
123 |
|
✗ |
cc_stream_row_get_id (CcStreamRow *self) |
124 |
|
|
{ |
125 |
|
✗ |
g_return_val_if_fail (CC_IS_STREAM_ROW (self), 0); |
126 |
|
✗ |
return self->id; |
127 |
|
|
} |
128 |
|
|
|