summaryrefslogtreecommitdiff
path: root/libmatemixer/matemixer-client-stream.c
blob: 3ff3c54f86108eea4c0164a9135f0c12aadbb915 (plain)
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
 * 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 <glib.h>
#include <glib-object.h>

#include "matemixer-client-stream.h"
#include "matemixer-enums.h"
#include "matemixer-enum-types.h"
#include "matemixer-stream.h"

/**
 * SECTION:matemixer-client-stream
 * @short_description: Interface providing extra functionality for client streams
 * @see_also: #MateMixerStream
 * @include: libmatemixer/matemixer.h
 *
 * #MateMixerClientStream represents a special kind of stream, which belongs
 * to a parent input or output stream.
 *
 * A typical example of a client stream is a stream provided by an application.
 */

G_DEFINE_INTERFACE (MateMixerClientStream, mate_mixer_client_stream, G_TYPE_OBJECT)

static void
mate_mixer_client_stream_default_init (MateMixerClientStreamInterface *iface)
{
    g_object_interface_install_property (iface,
                                         g_param_spec_flags ("client-flags",
                                                             "Client flags",
                                                             "Capability flags of the client stream",
                                                             MATE_MIXER_TYPE_CLIENT_STREAM_FLAGS,
                                                             MATE_MIXER_CLIENT_STREAM_NO_FLAGS,
                                                             G_PARAM_READABLE |
                                                             G_PARAM_STATIC_STRINGS));

    g_object_interface_install_property (iface,
                                         g_param_spec_enum ("role",
                                                            "Role",
                                                            "Role of the client stream",
                                                            MATE_MIXER_TYPE_CLIENT_STREAM_ROLE,
                                                            MATE_MIXER_CLIENT_STREAM_ROLE_NONE,
                                                            G_PARAM_READABLE |
                                                            G_PARAM_STATIC_STRINGS));

    g_object_interface_install_property (iface,
                                         g_param_spec_object ("parent",
                                                              "Parent",
                                                              "Parent stream of the client stream",
                                                              MATE_MIXER_TYPE_STREAM,
                                                              G_PARAM_READABLE |
                                                              G_PARAM_STATIC_STRINGS));

    g_object_interface_install_property (iface,
                                         g_param_spec_string ("app-name",
                                                              "App name",
                                                              "Name of the client stream application",
                                                              NULL,
                                                              G_PARAM_READABLE |
                                                              G_PARAM_STATIC_STRINGS));

    g_object_interface_install_property (iface,
                                         g_param_spec_string ("app-id",
                                                              "App ID",
                                                              "Identifier of the client stream application",
                                                              NULL,
                                                              G_PARAM_READABLE |
                                                              G_PARAM_STATIC_STRINGS));

    g_object_interface_install_property (iface,
                                         g_param_spec_string ("app-version",
                                                              "App version",
                                                              "Version of the client stream application",
                                                              NULL,
                                                              G_PARAM_READABLE |
                                                              G_PARAM_STATIC_STRINGS));

    g_object_interface_install_property (iface,
                                         g_param_spec_string ("app-icon",
                                                              "App icon",
                                                              "Icon name of the client stream application",
                                                              NULL,
                                                              G_PARAM_READABLE |
                                                              G_PARAM_STATIC_STRINGS));
}

/**
 * mate_mixer_client_stream_get_flags:
 * @client: a #MateMixerClientStream
 *
 */
MateMixerClientStreamFlags
mate_mixer_client_stream_get_flags (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), MATE_MIXER_CLIENT_STREAM_NO_FLAGS);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->get_flags)
        return iface->get_flags (client);

    return MATE_MIXER_CLIENT_STREAM_NO_FLAGS;
}

/**
 * mate_mixer_client_stream_get_role:
 * @client: a #MateMixerClientStream
 *
 */
MateMixerClientStreamRole
mate_mixer_client_stream_get_role (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), MATE_MIXER_CLIENT_STREAM_ROLE_NONE);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->get_role)
        return iface->get_role (client);

    return MATE_MIXER_CLIENT_STREAM_ROLE_NONE;
}

/**
 * mate_mixer_client_stream_get_parent:
 * @client: a #MateMixerClientStream
 *
 * Gets the parent stream of the client stream.
 *
 * Returns: a #MateMixerStream or %NULL if the parent stream is not known.
 */
MateMixerStream *
mate_mixer_client_stream_get_parent (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), NULL);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->get_parent)
        return iface->get_parent (client);

    return NULL;
}

/**
 * mate_mixer_client_stream_set_parent:
 * @client: a #MateMixerClientStream
 * @parent: a #MateMixerStream
 *
 * Changes the parent stream of the client stream. The parent stream must be a
 * non-client input or output stream.
 *
 * Returns: %TRUE on success or %FALSE on failure.
 */
gboolean
mate_mixer_client_stream_set_parent (MateMixerClientStream *client, MateMixerStream *parent)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), FALSE);
    g_return_val_if_fail (MATE_MIXER_IS_STREAM (parent), FALSE);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->set_parent)
        return iface->set_parent (client, parent);

    return FALSE;
}

/**
 * mate_mixer_client_stream_remove:
 * @client: a #MateMixerClientStream
 *
 * Removes the client stream.
 *
 * Returns: %TRUE on success or %FALSE on failure.
 */
gboolean
mate_mixer_client_stream_remove (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), FALSE);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->remove)
        return iface->remove (client);

    return FALSE;
}

/**
 * mate_mixer_client_stream_get_app_name:
 * @client: a #MateMixerClientStream
 *
 * Gets the name of the application in case the stream is an application
 * stream.
 *
 * Returns: a string on success, or %NULL if the stream is not an application
 * stream or if the application does not provide a name.
 */
const gchar *
mate_mixer_client_stream_get_app_name (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), NULL);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->get_app_name)
        return iface->get_app_name (client);

    return NULL;
}

/**
 * mate_mixer_client_stream_get_app_id:
 * @client: a #MateMixerClientStream
 *
 * Gets the identifier (e.g. org.example.app) of the application in case the
 * stream is an application stream.
 *
 * Returns: a string on success, or %NULL if the stream is not an application
 * stream or if the application does not provide an identifier.
 */
const gchar *
mate_mixer_client_stream_get_app_id (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), NULL);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->get_app_id)
        return iface->get_app_id (client);

    return NULL;
}

/**
 * mate_mixer_client_stream_get_app_version:
 * @client: a #MateMixerClientStream
 *
 * Gets the version of the application in case the stream is an application
 * stream.
 *
 * Returns: a string on success, or %NULL if the stream is not an application
 * stream or if the application does not provide a version string.
 */
const gchar *
mate_mixer_client_stream_get_app_version (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), NULL);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->get_app_version)
        return iface->get_app_version (client);

    return NULL;
}

/**
 * mate_mixer_client_stream_get_app_icon:
 * @client: a #MateMixerClientStream
 *
 * Gets the XDG icon name of the application in case the stream is an
 * application stream.
 *
 * Returns: a string on success, or %NULL if the stream is not an application
 * stream or if the application does not provide an icon name.
 */
const gchar *
mate_mixer_client_stream_get_app_icon (MateMixerClientStream *client)
{
    MateMixerClientStreamInterface *iface;

    g_return_val_if_fail (MATE_MIXER_IS_CLIENT_STREAM (client), NULL);

    iface = MATE_MIXER_CLIENT_STREAM_GET_INTERFACE (client);

    if (iface->get_app_icon)
        return iface->get_app_icon (client);

    return NULL;
}