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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/*
* Copyright (C) 2014 Michal Ratajsky <michal.ratajsky@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the licence, 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <libmatemixer/matemixer.h>
#include <libmatemixer/matemixer-private.h>
#include "pulse-connection.h"
#include "pulse-port.h"
#include "pulse-port-switch.h"
#include "pulse-stream.h"
struct _PulsePortSwitchPrivate
{
GList *ports;
PulseStream *stream;
};
enum {
PROP_0,
PROP_STREAM,
N_PROPERTIES
};
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
static void pulse_port_switch_class_init (PulsePortSwitchClass *klass);
static void pulse_port_switch_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void pulse_port_switch_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void pulse_port_switch_init (PulsePortSwitch *swtch);
G_DEFINE_ABSTRACT_TYPE (PulsePortSwitch, pulse_port_switch, MATE_MIXER_TYPE_SWITCH)
static gboolean pulse_port_switch_set_active_option (MateMixerSwitch *mms,
MateMixerSwitchOption *mmso);
static const GList *pulse_port_switch_list_options (MateMixerSwitch *mms);
static gint compare_ports (gconstpointer a,
gconstpointer b);
static gint compare_port_name (gconstpointer a,
gconstpointer b);
static void
pulse_port_switch_class_init (PulsePortSwitchClass *klass)
{
GObjectClass *object_class;
MateMixerSwitchClass *switch_class;
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = pulse_port_switch_get_property;
object_class->set_property = pulse_port_switch_set_property;
switch_class = MATE_MIXER_SWITCH_CLASS (klass);
switch_class->set_active_option = pulse_port_switch_set_active_option;
switch_class->list_options = pulse_port_switch_list_options;
properties[PROP_STREAM] =
g_param_spec_object ("stream",
"Stream",
"PulseAudio stream",
PULSE_TYPE_STREAM,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
g_type_class_add_private (G_OBJECT_CLASS (klass), sizeof (PulsePortSwitchPrivate));
}
static void
pulse_port_switch_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
PulsePortSwitch *swtch;
swtch = PULSE_PORT_SWITCH (object);
switch (param_id) {
case PROP_STREAM:
g_value_set_object (value, swtch->priv->stream);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
pulse_port_switch_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
PulsePortSwitch *swtch;
swtch = PULSE_PORT_SWITCH (object);
switch (param_id) {
case PROP_STREAM:
/* Construct-only object */
swtch->priv->stream = g_value_get_object (value);
if (swtch->priv->stream != NULL)
g_object_add_weak_pointer (G_OBJECT (swtch->priv->stream),
(gpointer *) &swtch->priv->stream);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
pulse_port_switch_init (PulsePortSwitch *swtch)
{
swtch->priv = G_TYPE_INSTANCE_GET_PRIVATE (swtch,
PULSE_TYPE_PORT_SWITCH,
PulsePortSwitchPrivate);
}
PulseStream *
pulse_port_switch_get_stream (PulsePortSwitch *swtch)
{
g_return_val_if_fail (PULSE_IS_PORT_SWITCH (swtch), NULL);
return swtch->priv->stream;
}
void
pulse_port_switch_add_port (PulsePortSwitch *swtch, PulsePort *port)
{
g_return_if_fail (PULSE_IS_PORT_SWITCH (swtch));
g_return_if_fail (PULSE_IS_PORT (port));
swtch->priv->ports = g_list_insert_sorted (swtch->priv->ports,
port,
compare_ports);
}
void
pulse_port_switch_set_active_port (PulsePortSwitch *swtch, PulsePort *port)
{
g_return_if_fail (PULSE_IS_PORT_SWITCH (swtch));
g_return_if_fail (PULSE_IS_PORT (port));
_mate_mixer_switch_set_active_option (MATE_MIXER_SWITCH (swtch),
MATE_MIXER_SWITCH_OPTION (port));
}
void
pulse_port_switch_set_active_port_by_name (PulsePortSwitch *swtch, const gchar *name)
{
GList *item;
g_return_if_fail (PULSE_IS_PORT_SWITCH (swtch));
g_return_if_fail (name != NULL);
item = g_list_find_custom (swtch->priv->ports, name, compare_port_name);
if G_UNLIKELY (item == NULL) {
g_debug ("Invalid switch port name %s", name);
return;
}
pulse_port_switch_set_active_port (swtch, PULSE_PORT (item->data));
}
static gboolean
pulse_port_switch_set_active_option (MateMixerSwitch *mms, MateMixerSwitchOption *mmso)
{
PulsePortSwitchClass *klass;
g_return_val_if_fail (PULSE_IS_PORT_SWITCH (mms), FALSE);
g_return_val_if_fail (PULSE_IS_PORT (mmso), FALSE);
klass = PULSE_PORT_SWITCH_GET_CLASS (PULSE_PORT_SWITCH (mms));
return klass->set_active_port (PULSE_PORT_SWITCH (mms),
PULSE_PORT (mmso));
}
static const GList *
pulse_port_switch_list_options (MateMixerSwitch *swtch)
{
g_return_val_if_fail (PULSE_IS_PORT_SWITCH (swtch), NULL);
return PULSE_PORT_SWITCH (swtch)->priv->ports;
}
static gint
compare_ports (gconstpointer a, gconstpointer b)
{
return pulse_port_get_priority (PULSE_PORT (b)) -
pulse_port_get_priority (PULSE_PORT (a));
}
static gint
compare_port_name (gconstpointer a, gconstpointer b)
{
PulsePort *port = PULSE_PORT (a);
const gchar *name = (const gchar *) b;
return strcmp (pulse_port_get_name (port), name);
}
|