~cjcurran/+junk/sound-nua-ui-tweaks-fri-16

« back to all changes in this revision

Viewing changes to soundnua/gvc-mixer-dialog.c

  • Committer: Sebastien Bacher
  • Date: 2012-03-16 10:09:38 UTC
  • Revision ID: seb128@ubuntu.com-20120316100938-nt63xa0x58zfsen3
initialĀ sourceĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 
2
 *
 
3
 * Copyright (C) 2008 William Jon McCann
 
4
 * Copyright (C) 2012 Conor Curran
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 *
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <stdlib.h>
 
25
#include <stdio.h>
 
26
#include <unistd.h>
 
27
#include <math.h>
 
28
 
 
29
#include <glib.h>
 
30
#include <glib/gi18n-lib.h>
 
31
#include <gdk/gdkkeysyms.h>
 
32
#include <gtk/gtk.h>
 
33
#include <pulse/pulseaudio.h>
 
34
 
 
35
 
 
36
#include "gvc-channel-bar.h"
 
37
#include "gvc-balance-bar.h"
 
38
#include "gvc-combo-box.h"
 
39
#include "gvc-mixer-control.h"
 
40
#include "gvc-mixer-card.h"
 
41
#include "gvc-mixer-ui-device.h"
 
42
#include "gvc-mixer-sink.h"
 
43
#include "gvc-mixer-source.h"
 
44
#include "gvc-mixer-source-output.h"
 
45
#include "gvc-mixer-dialog.h"
 
46
#include "gvc-sound-theme-chooser.h"
 
47
#include "gvc-level-bar.h"
 
48
#include "gvc-speaker-test.h"
 
49
#include "gvc-mixer-control-private.h"
 
50
 
 
51
#define SCALE_SIZE 128
 
52
 
 
53
#define GVC_MIXER_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_DIALOG, GvcMixerDialogPrivate))
 
54
 
 
55
struct GvcMixerDialogPrivate
 
56
{
 
57
        GvcMixerControl *mixer_control;
 
58
        GHashTable      *bars;        
 
59
        GtkWidget       *notebook;
 
60
        GtkWidget       *output_bar;
 
61
        GtkWidget       *input_bar;
 
62
        GtkWidget       *input_level_bar;
 
63
        GtkWidget       *effects_bar;
 
64
        GtkWidget       *output_stream_box;
 
65
        GtkWidget       *sound_effects_box;
 
66
        GtkWidget       *hw_box;
 
67
        GtkWidget       *hw_treeview;
 
68
        GtkWidget       *hw_settings_box;
 
69
        GtkWidget       *hw_profile_combo;
 
70
        GtkWidget       *input_box;
 
71
        GtkWidget       *output_box;
 
72
        GtkWidget       *applications_box;
 
73
        GtkWidget       *no_apps_label;
 
74
        GtkWidget       *output_treeview;
 
75
        GtkWidget       *output_settings_box;
 
76
        GtkWidget       *output_balance_bar;
 
77
        GtkWidget       *output_fade_bar;
 
78
        GtkWidget       *output_lfe_bar;
 
79
        GtkWidget       *output_profile_combo;
 
80
        GtkWidget       *input_profile_combo;
 
81
        GtkWidget       *input_treeview;
 
82
        GtkWidget       *input_settings_box;
 
83
        GtkWidget       *sound_theme_chooser;
 
84
        GtkWidget       *click_feedback_button;
 
85
        GtkWidget       *audible_bell_button;
 
86
        GtkSizeGroup    *size_group;
 
87
        GtkWidget       *selected_output_label;
 
88
        GtkWidget       *selected_input_label;
 
89
        GtkWidget       *test_output_button;
 
90
        GSettings       *indicator_settings;
 
91
 
 
92
        gdouble          last_input_peak;
 
93
        guint            num_apps;
 
94
};
 
95
 
 
96
enum {
 
97
        NAME_COLUMN,
 
98
        DEVICE_COLUMN,
 
99
        ACTIVE_COLUMN,
 
100
        ID_COLUMN,
 
101
        SPEAKERS_COLUMN,
 
102
        ICON_COLUMN,
 
103
        NUM_COLUMNS
 
104
};
 
105
 
 
106
enum {
 
107
        HW_ID_COLUMN,
 
108
        HW_ICON_COLUMN,
 
109
        HW_NAME_COLUMN,
 
110
        HW_STATUS_COLUMN,
 
111
        HW_PROFILE_COLUMN,
 
112
        HW_PROFILE_HUMAN_COLUMN,
 
113
        HW_SENSITIVE_COLUMN,
 
114
        HW_NUM_COLUMNS
 
115
};
 
116
 
 
117
enum
 
118
{
 
119
        PROP_0,
 
120
        PROP_MIXER_CONTROL
 
121
};
 
122
 
 
123
static void     gvc_mixer_dialog_class_init (GvcMixerDialogClass *klass);
 
124
static void     gvc_mixer_dialog_init       (GvcMixerDialog      *mixer_dialog);
 
125
static void     gvc_mixer_dialog_finalize   (GObject             *object);
 
126
 
 
127
static void     bar_set_stream              (GvcMixerDialog      *dialog,
 
128
                                             GtkWidget           *bar,
 
129
                                             GvcMixerStream      *stream);
 
130
 
 
131
static void     on_adjustment_value_changed (GtkAdjustment  *adjustment,
 
132
                                             GvcMixerDialog *dialog);
 
133
static void     on_control_output_added (GvcMixerControl *control,
 
134
                                       guint            id,
 
135
                                       GvcMixerDialog  *dialog);
 
136
static void   on_control_active_output_update (GvcMixerControl *control,
 
137
                                               guint            id,
 
138
                                               GvcMixerDialog  *dialog);
 
139
                                       
 
140
static void   on_control_active_input_update (GvcMixerControl *control,
 
141
                                              guint            id,
 
142
                                              GvcMixerDialog  *dialog);
 
143
 
 
144
G_DEFINE_TYPE (GvcMixerDialog, gvc_mixer_dialog, GTK_TYPE_VBOX)
 
145
 
 
146
 
 
147
static void
 
148
update_description (GvcMixerDialog *dialog,
 
149
                    guint column,
 
150
                    const char *value,
 
151
                    GvcMixerStream *stream)
 
152
{
 
153
        GtkTreeModel *model;
 
154
        GtkTreeIter   iter;
 
155
        guint         id;
 
156
 
 
157
        if (GVC_IS_MIXER_SOURCE (stream))
 
158
                model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->input_treeview));
 
159
        else if (GVC_IS_MIXER_SINK (stream))
 
160
                model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->output_treeview));
 
161
        else
 
162
                g_assert_not_reached ();
 
163
 
 
164
        if (gtk_tree_model_get_iter_first (model, &iter) == FALSE){
 
165
                g_warning ("The tree is empty => Cannot update the description");
 
166
                return;        
 
167
        }
 
168
 
 
169
        id = gvc_mixer_stream_get_id (stream);
 
170
        do {
 
171
                guint       current_id;
 
172
 
 
173
                gtk_tree_model_get (model, &iter,
 
174
                                    ID_COLUMN, &current_id,
 
175
                                    -1);
 
176
                if (id != current_id)
 
177
                        continue;
 
178
 
 
179
                gtk_list_store_set (GTK_LIST_STORE (model),
 
180
                                    &iter,
 
181
                                    column, value,
 
182
                                    -1);
 
183
                break;
 
184
        } while (gtk_tree_model_iter_next (model, &iter));
 
185
}
 
186
 
 
187
static void
 
188
profile_selection_changed (GvcComboBox *combo_box,
 
189
                           const char  *profile,
 
190
                           GvcMixerDialog *dialog)
 
191
{       
 
192
        g_print ("profile_selection_changed - %s", profile);
 
193
        GvcMixerUIDevice *out;
 
194
        out = g_object_get_data (G_OBJECT (combo_box), "uidevice");
 
195
        
 
196
        if (out == NULL) {
 
197
                g_warning ("Could not find Output for profile combo box");
 
198
                return;
 
199
        }
 
200
 
 
201
        g_print (" \n on profile selection changed on output with \n description %s \n origin %s \n id %i \n \n",
 
202
                gvc_mixer_ui_device_get_description (out),
 
203
                gvc_mixer_ui_device_get_origin (out),
 
204
                gvc_mixer_ui_device_get_id (out));
 
205
 
 
206
        if (gvc_mixer_control_change_profile_on_selected_device (dialog->priv->mixer_control, out, profile) == FALSE) {
 
207
                g_warning ("Could not change profile on device %s",
 
208
                           gvc_mixer_ui_device_get_description (out));
 
209
        }
 
210
}
 
211
 
 
212
#define DECAY_STEP .15
 
213
 
 
214
static void
 
215
update_input_peak (GvcMixerDialog *dialog,
 
216
                   gdouble         v)
 
217
{
 
218
        GtkAdjustment *adj;
 
219
 
 
220
        if (dialog->priv->last_input_peak >= DECAY_STEP) {
 
221
                if (v < dialog->priv->last_input_peak - DECAY_STEP) {
 
222
                        v = dialog->priv->last_input_peak - DECAY_STEP;
 
223
                }
 
224
        }
 
225
 
 
226
        dialog->priv->last_input_peak = v;
 
227
 
 
228
        adj = gvc_level_bar_get_peak_adjustment (GVC_LEVEL_BAR (dialog->priv->input_level_bar));
 
229
        if (v >= 0) {
 
230
                gtk_adjustment_set_value (adj, v);
 
231
        } else {
 
232
                gtk_adjustment_set_value (adj, 0.0);
 
233
        }
 
234
}
 
235
 
 
236
static void
 
237
update_input_meter (GvcMixerDialog *dialog,
 
238
                    uint32_t        source_index,
 
239
                    uint32_t        sink_input_idx,
 
240
                    double          v)
 
241
{
 
242
        update_input_peak (dialog, v);
 
243
}
 
244
 
 
245
static void
 
246
on_monitor_suspended_callback (pa_stream *s,
 
247
                               void      *userdata)
 
248
{
 
249
        GvcMixerDialog *dialog;
 
250
 
 
251
        dialog = userdata;
 
252
 
 
253
        if (pa_stream_is_suspended (s)) {
 
254
                g_debug ("Stream suspended");
 
255
                update_input_meter (dialog,
 
256
                                    pa_stream_get_device_index (s),
 
257
                                    PA_INVALID_INDEX,
 
258
                                    -1);
 
259
        }
 
260
}
 
261
 
 
262
static void
 
263
on_monitor_read_callback (pa_stream *s,
 
264
                          size_t     length,
 
265
                          void      *userdata)
 
266
{
 
267
        GvcMixerDialog *dialog;
 
268
        const void     *data;
 
269
        double          v;
 
270
 
 
271
        dialog = userdata;
 
272
 
 
273
        if (pa_stream_peek (s, &data, &length) < 0) {
 
274
                g_warning ("Failed to read data from stream");
 
275
                return;
 
276
        }
 
277
 
 
278
        assert (length > 0);
 
279
        assert (length % sizeof (float) == 0);
 
280
 
 
281
        v = ((const float *) data)[length / sizeof (float) -1];
 
282
 
 
283
        pa_stream_drop (s);
 
284
 
 
285
        if (v < 0) {
 
286
                v = 0;
 
287
        }
 
288
        if (v > 1) {
 
289
                v = 1;
 
290
        }
 
291
 
 
292
        update_input_meter (dialog,
 
293
                            pa_stream_get_device_index (s),
 
294
                            pa_stream_get_monitor_stream (s),
 
295
                            v);
 
296
}
 
297
 
 
298
static void
 
299
create_monitor_stream_for_source (GvcMixerDialog *dialog,
 
300
                                  GvcMixerStream *stream)
 
301
{
 
302
        pa_stream     *s;
 
303
        char           t[16];
 
304
        pa_buffer_attr attr;
 
305
        pa_sample_spec ss;
 
306
        pa_context    *context;
 
307
        int            res;
 
308
        pa_proplist   *proplist;
 
309
        gboolean       has_monitor;
 
310
 
 
311
        if (stream == NULL) {
 
312
                return;
 
313
        }
 
314
        has_monitor = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (stream), "has-monitor"));
 
315
        if (has_monitor != FALSE) {
 
316
                return;
 
317
        }
 
318
 
 
319
        g_debug ("Create monitor for %u",
 
320
                 gvc_mixer_stream_get_index (stream));
 
321
 
 
322
        context = gvc_mixer_control_get_pa_context (dialog->priv->mixer_control);
 
323
 
 
324
        if (pa_context_get_server_protocol_version (context) < 13) {
 
325
                return;
 
326
        }
 
327
 
 
328
        ss.channels = 1;
 
329
        ss.format = PA_SAMPLE_FLOAT32;
 
330
        ss.rate = 25;
 
331
 
 
332
        memset (&attr, 0, sizeof (attr));
 
333
        attr.fragsize = sizeof (float);
 
334
        attr.maxlength = (uint32_t) -1;
 
335
 
 
336
        snprintf (t, sizeof (t), "%u", gvc_mixer_stream_get_index (stream));
 
337
 
 
338
        proplist = pa_proplist_new ();
 
339
        pa_proplist_sets (proplist, PA_PROP_APPLICATION_ID, "org.gnome.VolumeControl");
 
340
        s = pa_stream_new_with_proplist (context, _("Peak detect"), &ss, NULL, proplist);
 
341
        pa_proplist_free (proplist);
 
342
        if (s == NULL) {
 
343
                g_warning ("Failed to create monitoring stream");
 
344
                return;
 
345
        }
 
346
 
 
347
        pa_stream_set_read_callback (s, on_monitor_read_callback, dialog);
 
348
        pa_stream_set_suspended_callback (s, on_monitor_suspended_callback, dialog);
 
349
 
 
350
        res = pa_stream_connect_record (s,
 
351
                                        t,
 
352
                                        &attr,
 
353
                                        (pa_stream_flags_t) (PA_STREAM_DONT_MOVE
 
354
                                                             |PA_STREAM_PEAK_DETECT
 
355
                                                             |PA_STREAM_ADJUST_LATENCY));
 
356
        if (res < 0) {
 
357
                g_warning ("Failed to connect monitoring stream");
 
358
                pa_stream_unref (s);
 
359
        } else {
 
360
                g_object_set_data (G_OBJECT (stream), "has-monitor", GINT_TO_POINTER (TRUE));
 
361
                g_object_set_data (G_OBJECT (dialog->priv->input_level_bar), "pa_stream", s);
 
362
                g_object_set_data (G_OBJECT (dialog->priv->input_level_bar), "stream", stream);
 
363
        }
 
364
}
 
365
 
 
366
static void
 
367
stop_monitor_stream_for_source (GvcMixerDialog *dialog)
 
368
{
 
369
        pa_stream      *s;
 
370
        pa_context     *context;
 
371
        int             res;
 
372
        GvcMixerStream *stream;
 
373
 
 
374
        s = g_object_get_data (G_OBJECT (dialog->priv->input_level_bar), "pa_stream");
 
375
        if (s == NULL)
 
376
                return;
 
377
        stream = g_object_get_data (G_OBJECT (dialog->priv->input_level_bar), "stream");
 
378
        g_assert (stream != NULL);
 
379
 
 
380
        g_debug ("Stopping monitor for %u", pa_stream_get_index (s));
 
381
 
 
382
        context = gvc_mixer_control_get_pa_context (dialog->priv->mixer_control);
 
383
 
 
384
        if (pa_context_get_server_protocol_version (context) < 13) {
 
385
                return;
 
386
        }
 
387
 
 
388
        res = pa_stream_disconnect (s);
 
389
        if (res == 0)
 
390
                g_object_set_data (G_OBJECT (stream), "has-monitor", GINT_TO_POINTER (FALSE));
 
391
        g_object_set_data (G_OBJECT (dialog->priv->input_level_bar), "pa_stream", NULL);
 
392
        g_object_set_data (G_OBJECT (dialog->priv->input_level_bar), "stream", NULL);
 
393
}
 
394
 
 
395
static void
 
396
gvc_mixer_dialog_set_mixer_control (GvcMixerDialog  *dialog,
 
397
                                    GvcMixerControl *control)
 
398
{
 
399
        g_return_if_fail (GVC_MIXER_DIALOG (dialog));
 
400
        g_return_if_fail (GVC_IS_MIXER_CONTROL (control));
 
401
 
 
402
        g_object_ref (control);
 
403
 
 
404
        if (dialog->priv->mixer_control != NULL) {
 
405
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
406
                                                      G_CALLBACK (on_control_active_output_update),
 
407
                                                      dialog);
 
408
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
409
                                                      G_CALLBACK (on_control_active_input_update),
 
410
                                                      dialog);
 
411
                g_object_unref (dialog->priv->mixer_control);
 
412
        }
 
413
 
 
414
        dialog->priv->mixer_control = control;
 
415
 
 
416
        g_signal_connect (dialog->priv->mixer_control,
 
417
                          "active-output-update",
 
418
                          G_CALLBACK (on_control_active_output_update),
 
419
                          dialog);
 
420
        g_signal_connect (dialog->priv->mixer_control,
 
421
                          "active-input-update",
 
422
                          G_CALLBACK (on_control_active_input_update),
 
423
                          dialog);
 
424
 
 
425
        g_object_notify (G_OBJECT (dialog), "mixer-control");
 
426
}
 
427
 
 
428
static GvcMixerControl *
 
429
gvc_mixer_dialog_get_mixer_control (GvcMixerDialog *dialog)
 
430
{
 
431
        g_return_val_if_fail (GVC_IS_MIXER_DIALOG (dialog), NULL);
 
432
 
 
433
        return dialog->priv->mixer_control;
 
434
}
 
435
 
 
436
static void
 
437
gvc_mixer_dialog_set_property (GObject       *object,
 
438
                               guint          prop_id,
 
439
                               const GValue  *value,
 
440
                               GParamSpec    *pspec)
 
441
{
 
442
        GvcMixerDialog *self = GVC_MIXER_DIALOG (object);
 
443
 
 
444
        switch (prop_id) {
 
445
        case PROP_MIXER_CONTROL:
 
446
                gvc_mixer_dialog_set_mixer_control (self, g_value_get_object (value));
 
447
                break;
 
448
        default:
 
449
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
450
                break;
 
451
        }
 
452
}
 
453
 
 
454
static void
 
455
gvc_mixer_dialog_get_property (GObject     *object,
 
456
                               guint        prop_id,
 
457
                               GValue      *value,
 
458
                               GParamSpec  *pspec)
 
459
{
 
460
        GvcMixerDialog *self = GVC_MIXER_DIALOG (object);
 
461
 
 
462
        switch (prop_id) {
 
463
        case PROP_MIXER_CONTROL:
 
464
                g_value_set_object (value, gvc_mixer_dialog_get_mixer_control (self));
 
465
                break;
 
466
        default:
 
467
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
468
                break;
 
469
        }
 
470
}
 
471
 
 
472
static void
 
473
on_adjustment_value_changed (GtkAdjustment  *adjustment,
 
474
                             GvcMixerDialog *dialog)
 
475
{
 
476
        GvcMixerStream *stream;
 
477
 
 
478
        stream = g_object_get_data (G_OBJECT (adjustment), "gvc-mixer-dialog-stream");
 
479
        if (stream != NULL) {
 
480
                GObject *bar;
 
481
                gdouble volume, rounded;
 
482
                char *name;
 
483
 
 
484
                volume = gtk_adjustment_get_value (adjustment);
 
485
                rounded = round (volume);
 
486
 
 
487
                bar = g_object_get_data (G_OBJECT (adjustment), "gvc-mixer-dialog-bar");
 
488
                g_object_get (bar, "name", &name, NULL);
 
489
                g_debug ("Setting stream volume %lf (rounded: %lf) for bar '%s'", volume, rounded, name);
 
490
                g_free (name);
 
491
 
 
492
                /* FIXME would need to do that in the balance bar really... */
 
493
                /* Make sure we do not unmute muted streams, there's a button for that */
 
494
                if (volume == 0.0)
 
495
                        gvc_mixer_stream_set_is_muted (stream, TRUE);
 
496
                /* Only push the volume if it's actually changed */
 
497
                if (gvc_mixer_stream_set_volume(stream, (pa_volume_t) rounded) != FALSE)
 
498
                        gvc_mixer_stream_push_volume (stream);
 
499
        }
 
500
}
 
501
 
 
502
static void
 
503
on_bar_is_muted_notify (GObject        *object,
 
504
                        GParamSpec     *pspec,
 
505
                        GvcMixerDialog *dialog)
 
506
{
 
507
        gboolean        is_muted;
 
508
        GvcMixerStream *stream;
 
509
 
 
510
        is_muted = gvc_channel_bar_get_is_muted (GVC_CHANNEL_BAR (object));
 
511
 
 
512
        stream = g_object_get_data (object, "gvc-mixer-dialog-stream");
 
513
        if (stream != NULL) {
 
514
                gvc_mixer_stream_change_is_muted (stream, is_muted);
 
515
        } else {
 
516
                char *name;
 
517
                g_object_get (object, "name", &name, NULL);
 
518
                g_warning ("Unable to find stream for bar '%s'", name);
 
519
                g_free (name);
 
520
        }
 
521
}
 
522
 
 
523
static GtkWidget *
 
524
lookup_bar_for_stream (GvcMixerDialog *dialog,
 
525
                       GvcMixerStream *stream)
 
526
{
 
527
        GtkWidget *bar;
 
528
 
 
529
        bar = g_hash_table_lookup (dialog->priv->bars, GUINT_TO_POINTER (gvc_mixer_stream_get_id (stream)));
 
530
 
 
531
        return bar;
 
532
}
 
533
 
 
534
// TODO
 
535
// Do we need this ?
 
536
// UI devices now pull description material mainly for the card ports.
 
537
// Therefore the need for stream description dynamic changes more than ever seems unneccessary. 
 
538
static void
 
539
on_stream_description_notify (GvcMixerStream *stream,
 
540
                              GParamSpec     *pspec,
 
541
                              GvcMixerDialog *dialog)
 
542
{
 
543
        update_description (dialog, NAME_COLUMN,
 
544
                            gvc_mixer_stream_get_description (stream),
 
545
                            stream);
 
546
}
 
547
 
 
548
static void
 
549
on_stream_volume_notify (GObject        *object,
 
550
                         GParamSpec     *pspec,
 
551
                         GvcMixerDialog *dialog)
 
552
{
 
553
        GvcMixerStream *stream;
 
554
        GtkWidget      *bar;
 
555
        GtkAdjustment  *adj;
 
556
        stream = GVC_MIXER_STREAM (object);
 
557
 
 
558
        bar = lookup_bar_for_stream (dialog, stream);
 
559
 
 
560
        if (bar == NULL) {
 
561
                if (stream == gvc_mixer_control_get_default_sink(dialog->priv->mixer_control)) {
 
562
                        bar = dialog->priv->output_bar;
 
563
                }
 
564
                else if(stream == gvc_mixer_control_get_default_source(dialog->priv->mixer_control)) {
 
565
                        bar = dialog->priv->input_bar;
 
566
                }
 
567
                else{
 
568
                        g_warning ("Unable to find bar for stream %s in on_stream_volume_notify()",
 
569
                                   gvc_mixer_stream_get_name (stream));
 
570
                        return;
 
571
                }
 
572
        }
 
573
 
 
574
        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (bar)));
 
575
 
 
576
        g_signal_handlers_block_by_func (adj,
 
577
                                         on_adjustment_value_changed,
 
578
                                         dialog);
 
579
 
 
580
        gtk_adjustment_set_value (adj,
 
581
                                  gvc_mixer_stream_get_volume (stream));
 
582
 
 
583
        g_signal_handlers_unblock_by_func (adj,
 
584
                                           on_adjustment_value_changed,
 
585
                                           dialog);
 
586
}
 
587
 
 
588
static void
 
589
on_stream_is_muted_notify (GObject        *object,
 
590
                           GParamSpec     *pspec,
 
591
                           GvcMixerDialog *dialog)
 
592
{
 
593
        GvcMixerStream *stream;
 
594
        GtkWidget      *bar;
 
595
        gboolean        is_muted;
 
596
 
 
597
        stream = GVC_MIXER_STREAM (object);
 
598
 
 
599
        bar = lookup_bar_for_stream (dialog, stream);
 
600
 
 
601
        if (bar == NULL) {
 
602
                if (stream == gvc_mixer_control_get_default_sink(dialog->priv->mixer_control)) {
 
603
                        bar = dialog->priv->output_bar;
 
604
                }
 
605
                else if(stream == gvc_mixer_control_get_default_source(dialog->priv->mixer_control)) {
 
606
                        bar = dialog->priv->input_bar;
 
607
                }                
 
608
                else{
 
609
                        g_warning ("Unable to find bar for stream %s in on_stream_muted_notify()",
 
610
                                   gvc_mixer_stream_get_name (stream));
 
611
                        return;
 
612
                }
 
613
        }
 
614
 
 
615
 
 
616
        is_muted = gvc_mixer_stream_get_is_muted (stream);
 
617
        gvc_channel_bar_set_is_muted (GVC_CHANNEL_BAR (bar),
 
618
                                      is_muted);
 
619
 
 
620
        if (stream == gvc_mixer_control_get_default_sink (dialog->priv->mixer_control)) {
 
621
                gtk_widget_set_sensitive (dialog->priv->applications_box,
 
622
                                          !is_muted);
 
623
        }
 
624
 
 
625
}
 
626
 
 
627
static void
 
628
save_bar_for_stream (GvcMixerDialog *dialog,
 
629
                     GvcMixerStream *stream,
 
630
                     GtkWidget      *bar)
 
631
{
 
632
        g_print ("\n saving bar for stream %s",
 
633
                 gvc_mixer_stream_get_name (stream));
 
634
        g_hash_table_insert (dialog->priv->bars,
 
635
                             GUINT_TO_POINTER (gvc_mixer_stream_get_id (stream)),
 
636
                             bar);
 
637
}
 
638
 
 
639
static GtkWidget *
 
640
create_bar (GvcMixerDialog *dialog,
 
641
            gboolean        add_to_size_group,
 
642
            gboolean        symmetric)
 
643
{
 
644
        GtkWidget *bar;
 
645
 
 
646
        bar = gvc_channel_bar_new ();
 
647
        gtk_widget_set_sensitive (bar, FALSE);
 
648
        if (add_to_size_group && dialog->priv->size_group != NULL) {
 
649
                gvc_channel_bar_set_size_group (GVC_CHANNEL_BAR (bar),
 
650
                                                dialog->priv->size_group,
 
651
                                                symmetric);
 
652
        }
 
653
        gvc_channel_bar_set_orientation (GVC_CHANNEL_BAR (bar),
 
654
                                         GTK_ORIENTATION_HORIZONTAL);
 
655
        gvc_channel_bar_set_show_mute (GVC_CHANNEL_BAR (bar),
 
656
                                       TRUE);
 
657
        g_signal_connect (bar,
 
658
                          "notify::is-muted",
 
659
                          G_CALLBACK (on_bar_is_muted_notify),
 
660
                          dialog);
 
661
        return bar;
 
662
}
 
663
 
 
664
static GtkWidget *
 
665
create_app_bar (GvcMixerDialog *dialog,
 
666
                const char     *name,
 
667
                const char     *icon_name)
 
668
{
 
669
        GtkWidget *bar;
 
670
 
 
671
        bar = create_bar (dialog, FALSE, FALSE);
 
672
        gvc_channel_bar_set_ellipsize (GVC_CHANNEL_BAR (bar), TRUE);
 
673
        gvc_channel_bar_set_icon_name (GVC_CHANNEL_BAR (bar), icon_name);
 
674
        if (name == NULL || strchr (name, '_') == NULL) {
 
675
                gvc_channel_bar_set_name (GVC_CHANNEL_BAR (bar), name);
 
676
        } else {
 
677
                char **tokens, *escaped;
 
678
 
 
679
                tokens = g_strsplit (name, "_", -1);
 
680
                escaped = g_strjoinv ("__", tokens);
 
681
                g_strfreev (tokens);
 
682
                gvc_channel_bar_set_name (GVC_CHANNEL_BAR (bar), escaped);
 
683
                g_free (escaped);
 
684
        }
 
685
 
 
686
        return bar;
 
687
}
 
688
 
 
689
/* active_input_update
 
690
 * Handle input update change from the backend (control). 
 
691
 * Trust the backend whole-heartedly to deliver the correct input
 
692
 * i.e. keep it MVC.
 
693
 */
 
694
static void
 
695
active_input_update (GvcMixerDialog *dialog,
 
696
                     GvcMixerUIDevice *active_input)
 
697
{         
 
698
        g_print ("\n active_input_update %s \n", gvc_mixer_ui_device_get_description (active_input));
 
699
        // First make sure the correct UI device is selected.
 
700
        GtkTreeModel *model;
 
701
        GtkTreeIter   iter;
 
702
 
 
703
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->input_treeview));
 
704
 
 
705
        if (gtk_tree_model_get_iter_first (model, &iter) == FALSE){
 
706
                g_warning ("The tree is empty => we have no devices so cannot set the active input");
 
707
                return;        
 
708
        }
 
709
        
 
710
        do {
 
711
                gboolean         is_selected = FALSE;
 
712
                gint             id;
 
713
                        
 
714
                gtk_tree_model_get (model, &iter,
 
715
                                    ID_COLUMN, &id,
 
716
                                    -1);
 
717
 
 
718
                is_selected = id == gvc_mixer_ui_device_get_id (active_input);
 
719
                
 
720
                gtk_list_store_set (GTK_LIST_STORE (model),
 
721
                                    &iter,
 
722
                                    ACTIVE_COLUMN, is_selected,
 
723
                                    -1);
 
724
 
 
725
                if (is_selected) {
 
726
                        GtkTreeSelection *selection;
 
727
                        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->input_treeview));
 
728
                        gtk_tree_selection_select_iter (selection, &iter);
 
729
                }
 
730
                
 
731
        }while (gtk_tree_model_iter_next (model, &iter));
 
732
 
 
733
        stop_monitor_stream_for_source (dialog);
 
734
 
 
735
          // Not ideal but for now destroy the combo and recreate below.
 
736
        if (dialog->priv->input_profile_combo != NULL) {
 
737
                gtk_container_remove (GTK_CONTAINER (dialog->priv->input_settings_box),
 
738
                                      dialog->priv->input_profile_combo);
 
739
                dialog->priv->input_profile_combo = NULL;
 
740
        }
 
741
 
 
742
        GvcMixerStream       *stream;  
 
743
        const GvcChannelMap  *map;
 
744
        GtkAdjustment        *adj;
 
745
  
 
746
        stream = gvc_mixer_control_get_stream_from_device (dialog->priv->mixer_control, 
 
747
                                                           active_input); 
 
748
        if (stream == NULL) {
 
749
                g_warning ("active_input_update - couldn't find a stream from the supposed active input");
 
750
                gtk_widget_set_sensitive (dialog->priv->input_bar, 
 
751
                                          FALSE);                
 
752
                return;
 
753
        }
 
754
 
 
755
        // Set the label accordingly
 
756
        gtk_label_set_label (GTK_LABEL(dialog->priv->selected_input_label),
 
757
                             g_strdup_printf("Settings for %s",
 
758
                                             gvc_mixer_ui_device_get_description (active_input)));  
 
759
 
 
760
        gvc_channel_bar_set_base_volume (GVC_CHANNEL_BAR (dialog->priv->input_bar),
 
761
                                         gvc_mixer_stream_get_base_volume (stream));
 
762
        gvc_channel_bar_set_is_amplified (GVC_CHANNEL_BAR (dialog->priv->input_bar),
 
763
                                          gvc_mixer_stream_get_can_decibel (stream));
 
764
        /* Update the adjustment in case the previous bar wasn't decibel
 
765
         * capable, and we clipped it */
 
766
        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (dialog->priv->input_bar)));
 
767
        gtk_adjustment_set_value (adj,
 
768
                                  gvc_mixer_stream_get_volume (stream));        
 
769
        
 
770
        create_monitor_stream_for_source (dialog, stream);
 
771
        // remove any previous stream that might have been pointed at 
 
772
        // the static input bar and connect new signals from new stream.
 
773
        bar_set_stream (dialog, dialog->priv->input_bar, stream);   
 
774
 
 
775
        const GHashTable *profs_entries;
 
776
        profs_entries = gvc_mixer_ui_device_get_profiles (active_input);
 
777
 
 
778
        const GList* profiles = NULL;
 
779
        profiles = g_hash_table_get_values (profs_entries);
 
780
 
 
781
        if (profiles != NULL){
 
782
                dialog->priv->input_profile_combo = gvc_combo_box_new (_("Mode:"));                
 
783
                gvc_combo_box_set_profiles (GVC_COMBO_BOX (dialog->priv->input_profile_combo),
 
784
                                            profs_entries);
 
785
                                
 
786
                gboolean disabled;
 
787
                disabled = gvc_mixer_ui_device_determine_profile_sensitivity (active_input);
 
788
 
 
789
                if (disabled){
 
790
                        GvcMixerCardProfile *p;
 
791
                        // We can be sure that its just one profile in the list when it's disabled
 
792
                        p = g_list_last (profiles)->data;
 
793
                        gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->input_profile_combo), 
 
794
                                                                 p->profile);                        
 
795
                }
 
796
                else{
 
797
                        gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->input_profile_combo), 
 
798
                                                  gvc_mixer_control_get_active_profile_from_ui_device (dialog->priv->mixer_control,
 
799
                                                                                               active_input));
 
800
                }
 
801
                g_object_set_data (G_OBJECT (dialog->priv->input_profile_combo),
 
802
                                   "uidevice",
 
803
                                   active_input);
 
804
 
 
805
                g_signal_connect (G_OBJECT (dialog->priv->input_profile_combo), "changed",
 
806
                                  G_CALLBACK (profile_selection_changed), dialog);
 
807
 
 
808
                gtk_box_pack_start (GTK_BOX (dialog->priv->input_settings_box),
 
809
                                    dialog->priv->input_profile_combo,
 
810
                                    TRUE, FALSE, 0);
 
811
 
 
812
                if (dialog->priv->size_group != NULL) {
 
813
                        gvc_combo_box_set_size_group (GVC_COMBO_BOX (dialog->priv->input_profile_combo),
 
814
                                                      dialog->priv->size_group, FALSE);
 
815
                }
 
816
                gtk_widget_show (dialog->priv->input_profile_combo);                
 
817
                gtk_widget_set_sensitive (dialog->priv->input_profile_combo, 
 
818
                                           !disabled);
 
819
        }
 
820
}
 
821
 
 
822
/* active_output_update
 
823
 * Handle output update change from the backend (control). 
 
824
 * Trust the backend whole heartedly to deliver the correct output
 
825
 * i.e. keep it MVC.
 
826
 */
 
827
static void
 
828
active_output_update (GvcMixerDialog *dialog,
 
829
                      GvcMixerUIDevice *active_output)
 
830
{                 
 
831
        // First make sure the correct UI device is selected.
 
832
        GtkTreeModel *model;
 
833
        GtkTreeIter   iter;
 
834
        g_print ("\n\n active output update - device id = %i \n\n",
 
835
                 gvc_mixer_ui_device_get_id (active_output));
 
836
 
 
837
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->output_treeview));
 
838
 
 
839
        if (gtk_tree_model_get_iter_first (model, &iter) == FALSE){
 
840
                g_warning ("The tree is empty => we have no devices in the tree => cannot set the active output");
 
841
                return;        
 
842
        }
 
843
        
 
844
        do {
 
845
                gboolean         is_selected;
 
846
                gint             id;
 
847
                        
 
848
                gtk_tree_model_get (model, &iter,
 
849
                                    ID_COLUMN, &id,
 
850
                                    ACTIVE_COLUMN, &is_selected,                  
 
851
                                    -1);
 
852
 
 
853
                if (is_selected && id == gvc_mixer_ui_device_get_id (active_output)) {
 
854
                        g_print ("\n\n unneccessary active output update unless it was a profile change on the same device ? \n\n");
 
855
                }
 
856
 
 
857
                is_selected = id == gvc_mixer_ui_device_get_id (active_output);
 
858
                
 
859
                gtk_list_store_set (GTK_LIST_STORE (model),
 
860
                                    &iter,
 
861
                                    ACTIVE_COLUMN, is_selected,
 
862
                                    -1);
 
863
 
 
864
                if (is_selected) {
 
865
                        GtkTreeSelection *selection;
 
866
                        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->output_treeview));
 
867
                        gtk_tree_selection_select_iter (selection, &iter);
 
868
                }
 
869
                
 
870
        }while (gtk_tree_model_iter_next (model, &iter));
 
871
        
 
872
          // Not ideal but for now destroy the combo and recreate below.
 
873
        if (dialog->priv->output_profile_combo != NULL) {
 
874
                gtk_container_remove (GTK_CONTAINER (dialog->priv->output_settings_box),
 
875
                                      dialog->priv->output_profile_combo);
 
876
                dialog->priv->output_profile_combo = NULL;
 
877
        }
 
878
 
 
879
        GvcMixerStream       *stream;  
 
880
        const GvcChannelMap  *map;
 
881
        GtkAdjustment        *adj;
 
882
  
 
883
        stream = gvc_mixer_control_get_stream_from_device (dialog->priv->mixer_control, 
 
884
                                                           active_output); 
 
885
 
 
886
        if (stream == NULL) {
 
887
                g_warning ("active_output_update - couldn't find a stream from the supposed active output");
 
888
                return;
 
889
        }
 
890
 
 
891
        gboolean is_muted = gvc_mixer_stream_get_is_muted (stream);
 
892
        gtk_widget_set_sensitive (dialog->priv->applications_box,
 
893
                                  !is_muted);
 
894
        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (dialog->priv->output_bar)));
 
895
        g_signal_handlers_disconnect_by_func(adj, on_adjustment_value_changed, dialog);
 
896
 
 
897
        bar_set_stream (dialog, dialog->priv->output_bar, stream);
 
898
        gvc_channel_bar_set_base_volume (GVC_CHANNEL_BAR (dialog->priv->output_bar),
 
899
                                         gvc_mixer_stream_get_base_volume (stream));
 
900
        gvc_channel_bar_set_is_amplified (GVC_CHANNEL_BAR (dialog->priv->output_bar),
 
901
                                          gvc_mixer_stream_get_can_decibel (stream));
 
902
        /* Update the adjustment in case the previous bar wasn't decibel
 
903
         * capable, and we clipped it */
 
904
        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (dialog->priv->output_bar)));
 
905
        gtk_adjustment_set_value (adj,
 
906
                                  gvc_mixer_stream_get_volume (stream));
 
907
 
 
908
        map = gvc_mixer_stream_get_channel_map (stream);
 
909
 
 
910
        if (map == NULL) {
 
911
                g_warning ("Active output stream has no channel map");
 
912
                gtk_widget_set_sensitive (dialog->priv->output_bar, FALSE);
 
913
                gtk_widget_set_sensitive (dialog->priv->output_balance_bar, FALSE);
 
914
                gtk_widget_set_sensitive (dialog->priv->output_lfe_bar, FALSE);
 
915
                gtk_widget_set_sensitive (dialog->priv->output_fade_bar, FALSE);                
 
916
                return;
 
917
        }
 
918
 
 
919
 
 
920
        // Swap bars to the active map
 
921
        gvc_balance_bar_set_map (GVC_BALANCE_BAR (dialog->priv->output_balance_bar), 
 
922
                                 map);  
 
923
        gvc_balance_bar_set_map (GVC_BALANCE_BAR (dialog->priv->output_fade_bar), 
 
924
                                 map);
 
925
        gvc_balance_bar_set_map (GVC_BALANCE_BAR (dialog->priv->output_lfe_bar), 
 
926
                                 map);
 
927
                           
 
928
        // Set sensitivities accordingly.
 
929
        gtk_widget_set_sensitive (dialog->priv->output_balance_bar,
 
930
                                  gvc_channel_map_can_balance (map));                                    
 
931
        gtk_widget_set_sensitive (dialog->priv->output_fade_bar, 
 
932
                                  gvc_channel_map_can_fade (map));
 
933
        gtk_widget_set_sensitive (dialog->priv->output_lfe_bar, 
 
934
                                  gvc_channel_map_has_lfe (map));
 
935
        gtk_widget_set_sensitive (dialog->priv->output_bar, 
 
936
                                  TRUE);
 
937
        // Set the label accordingly
 
938
        gtk_label_set_label (GTK_LABEL(dialog->priv->selected_output_label),
 
939
                             g_strdup_printf("Settings for %s",
 
940
                                             gvc_mixer_ui_device_get_description (active_output)));
 
941
        g_print ("\n active_output_update %s \n", gvc_mixer_ui_device_get_description (active_output));
 
942
 
 
943
        const GHashTable *profs_entries;
 
944
        profs_entries = gvc_mixer_ui_device_get_profiles (active_output);
 
945
 
 
946
        GList* profiles = NULL;
 
947
        profiles = g_hash_table_get_values (profs_entries);
 
948
 
 
949
        if (profiles != NULL || gvc_mixer_ui_device_determine_profile_sensitivity (active_output)) {
 
950
 
 
951
                dialog->priv->output_profile_combo = gvc_combo_box_new (_("Mode:"));                
 
952
                gvc_combo_box_set_profiles (GVC_COMBO_BOX (dialog->priv->output_profile_combo),
 
953
                                            profs_entries);
 
954
                                
 
955
                gboolean disabled;
 
956
                disabled = gvc_mixer_ui_device_determine_profile_sensitivity (active_output);
 
957
 
 
958
                gtk_box_pack_start (GTK_BOX (dialog->priv->output_settings_box),
 
959
                                    dialog->priv->output_profile_combo,
 
960
                                    FALSE, FALSE, 3);
 
961
 
 
962
                if (dialog->priv->size_group != NULL) {
 
963
                        gvc_combo_box_set_size_group (GVC_COMBO_BOX (dialog->priv->output_profile_combo),
 
964
                                                      dialog->priv->size_group, FALSE);
 
965
                }
 
966
 
 
967
                if (disabled){
 
968
                        GvcMixerCardProfile *p;
 
969
                        // We can be sure that its just one profile in the list when it's disabled
 
970
                        p = g_list_last (profiles)->data;
 
971
                        gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->output_profile_combo), 
 
972
                                                                 p->profile);                        
 
973
                }
 
974
                else{
 
975
                        gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->output_profile_combo), 
 
976
                                                  gvc_mixer_control_get_active_profile_from_ui_device (dialog->priv->mixer_control,
 
977
                                                                                               active_output));
 
978
                }
 
979
                g_object_set_data (G_OBJECT (dialog->priv->output_profile_combo),
 
980
                                   "uidevice",
 
981
                                   active_output);
 
982
                g_signal_connect (G_OBJECT (dialog->priv->output_profile_combo), "changed",
 
983
                                  G_CALLBACK (profile_selection_changed), dialog);
 
984
 
 
985
                gtk_widget_show (dialog->priv->output_profile_combo);                
 
986
                gtk_widget_set_sensitive (dialog->priv->output_profile_combo, 
 
987
                                           !disabled);
 
988
        }
 
989
 
 
990
}
 
991
 
 
992
static void
 
993
bar_set_stream (GvcMixerDialog *dialog,
 
994
                GtkWidget      *bar,
 
995
                GvcMixerStream *stream)
 
996
{
 
997
        GtkAdjustment  *adj;
 
998
        GvcMixerStream *old_stream;
 
999
 
 
1000
        g_assert (bar != NULL);
 
1001
 
 
1002
        gtk_widget_set_sensitive (bar, (stream != NULL));
 
1003
 
 
1004
        adj = GTK_ADJUSTMENT (gvc_channel_bar_get_adjustment (GVC_CHANNEL_BAR (bar)));
 
1005
 
 
1006
        g_signal_handlers_disconnect_by_func (adj, on_adjustment_value_changed, dialog);
 
1007
 
 
1008
        g_object_set_data (G_OBJECT (bar), "gvc-mixer-dialog-stream", stream);
 
1009
        g_object_set_data (G_OBJECT (adj), "gvc-mixer-dialog-stream", stream);
 
1010
        g_object_set_data (G_OBJECT (adj), "gvc-mixer-dialog-bar", bar);
 
1011
 
 
1012
        if (stream != NULL) {
 
1013
                gboolean is_muted;
 
1014
 
 
1015
                is_muted = gvc_mixer_stream_get_is_muted (stream);
 
1016
                gvc_channel_bar_set_is_muted (GVC_CHANNEL_BAR (bar), is_muted);
 
1017
 
 
1018
                gtk_adjustment_set_value (adj,
 
1019
                                          gvc_mixer_stream_get_volume (stream));
 
1020
                g_signal_connect (stream,
 
1021
                                  "notify::is-muted",
 
1022
                                  G_CALLBACK (on_stream_is_muted_notify),
 
1023
                                  dialog);
 
1024
                g_signal_connect (stream,
 
1025
                                  "notify::volume",
 
1026
                                  G_CALLBACK (on_stream_volume_notify),
 
1027
                                  dialog);
 
1028
                g_signal_connect (adj,
 
1029
                                  "value-changed",
 
1030
                                  G_CALLBACK (on_adjustment_value_changed),
 
1031
                                  dialog);
 
1032
        }
 
1033
}
 
1034
 
 
1035
/**
 
1036
* This method handles all streams that are not an input or output
 
1037
* i.e. effects streams and application streams
 
1038
* TODO rename to truly reflect its usage. 
 
1039
**/
 
1040
static void
 
1041
add_stream (GvcMixerDialog *dialog,
 
1042
            GvcMixerStream *stream)
 
1043
{
 
1044
  
 
1045
        GtkWidget     *bar;
 
1046
        bar = NULL;
 
1047
 
 
1048
        if (stream == gvc_mixer_control_get_event_sink_input (dialog->priv->mixer_control)) {
 
1049
                bar = dialog->priv->effects_bar;
 
1050
                g_debug ("Adding effects stream");
 
1051
        } else {
 
1052
                // Must be a sink/source input/output
 
1053
                const char *name;
 
1054
                name = gvc_mixer_stream_get_name (stream);
 
1055
                g_print ("\n Add bar for application stream : %s",
 
1056
                             name);
 
1057
 
 
1058
                bar = create_app_bar (dialog, name,
 
1059
                                      gvc_mixer_stream_get_icon_name (stream));
 
1060
 
 
1061
                gtk_box_pack_start (GTK_BOX (dialog->priv->applications_box), bar, FALSE, FALSE, 12);
 
1062
                dialog->priv->num_apps++;
 
1063
                gtk_widget_hide (dialog->priv->no_apps_label);
 
1064
        }
 
1065
        // We should have a bar by now.
 
1066
        g_assert (bar != NULL);
 
1067
        GvcMixerStream *old_stream;
 
1068
 
 
1069
        if (bar != NULL) {
 
1070
                old_stream = g_object_get_data (G_OBJECT (bar), "gvc-mixer-dialog-stream");
 
1071
                if (old_stream != NULL) {
 
1072
                        char *name;
 
1073
                        g_object_get (bar, "name", &name, NULL);
 
1074
                        g_debug ("Disconnecting old stream '%s' from bar '%s'",
 
1075
                                 gvc_mixer_stream_get_name (old_stream), name);
 
1076
                        g_free (name);
 
1077
 
 
1078
                        g_signal_handlers_disconnect_by_func (old_stream, on_stream_is_muted_notify, dialog);
 
1079
                        g_signal_handlers_disconnect_by_func (old_stream, on_stream_volume_notify, dialog);
 
1080
                        g_hash_table_remove (dialog->priv->bars, GUINT_TO_POINTER (gvc_mixer_stream_get_id (old_stream)));
 
1081
                }
 
1082
                save_bar_for_stream (dialog, stream, bar);
 
1083
                bar_set_stream (dialog, bar, stream);
 
1084
                gtk_widget_show (bar);
 
1085
        }
 
1086
}
 
1087
 
 
1088
static void
 
1089
remove_stream (GvcMixerDialog  *dialog,
 
1090
               guint            id)
 
1091
{        
 
1092
        GtkWidget *bar;
 
1093
        bar = g_hash_table_lookup (dialog->priv->bars, GUINT_TO_POINTER (id));
 
1094
        if (bar != NULL) {
 
1095
                g_hash_table_remove (dialog->priv->bars, GUINT_TO_POINTER (id));
 
1096
                gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (bar)),
 
1097
                                      bar);
 
1098
                dialog->priv->num_apps--;
 
1099
                if (dialog->priv->num_apps == 0) {
 
1100
                        gtk_widget_show (dialog->priv->no_apps_label);
 
1101
                }
 
1102
        }
 
1103
 
 
1104
}
 
1105
 
 
1106
static void
 
1107
on_control_stream_added (GvcMixerControl *control,
 
1108
                         guint            id,
 
1109
                         GvcMixerDialog  *dialog)
 
1110
{
 
1111
        GvcMixerStream *stream;
 
1112
        stream = gvc_mixer_control_lookup_stream_id (control, id);
 
1113
        
 
1114
        if (stream == NULL) 
 
1115
                return;
 
1116
        
 
1117
        const char    *app_id;
 
1118
        app_id = gvc_mixer_stream_get_application_id (stream);
 
1119
 
 
1120
        if (stream == gvc_mixer_control_get_event_sink_input (dialog->priv->mixer_control) || (!GVC_IS_MIXER_SOURCE (stream) &&
 
1121
                !GVC_IS_MIXER_SINK (stream)
 
1122
                && !gvc_mixer_stream_is_virtual (stream)
 
1123
                && g_strcmp0 (app_id, "org.gnome.VolumeControl") != 0
 
1124
                && g_strcmp0 (app_id, "org.PulseAudio.pavucontrol") != 0)) {
 
1125
 
 
1126
                GtkWidget      *bar;
 
1127
 
 
1128
                bar = g_hash_table_lookup (dialog->priv->bars, GUINT_TO_POINTER (id));
 
1129
                if (bar != NULL) {
 
1130
                        g_debug ("GvcMixerDialog: Stream %u already added", id);
 
1131
                        return;
 
1132
                }
 
1133
                add_stream (dialog, stream);
 
1134
        } 
 
1135
}
 
1136
 
 
1137
static void
 
1138
on_control_stream_removed (GvcMixerControl *control,
 
1139
                           guint            id,
 
1140
                           GvcMixerDialog  *dialog)
 
1141
{
 
1142
        remove_stream (dialog, id);
 
1143
}
 
1144
 
 
1145
static gboolean
 
1146
find_item_by_id (GtkTreeModel *model,
 
1147
                 guint         id,
 
1148
                 guint         column,
 
1149
                 GtkTreeIter  *iter)
 
1150
{
 
1151
        gboolean found_item;
 
1152
 
 
1153
        found_item = FALSE;
 
1154
 
 
1155
        if (!gtk_tree_model_get_iter_first (model, iter)) {
 
1156
                return FALSE;
 
1157
        }
 
1158
 
 
1159
        do {
 
1160
                guint t_id;
 
1161
 
 
1162
                gtk_tree_model_get (model, iter,
 
1163
                                    column, &t_id, -1);
 
1164
 
 
1165
                if (id == t_id) {
 
1166
                        found_item = TRUE;
 
1167
                }
 
1168
        } while (!found_item && gtk_tree_model_iter_next (model, iter));
 
1169
 
 
1170
        return found_item;
 
1171
}
 
1172
 
 
1173
static void
 
1174
add_input_ui_entry (GvcMixerDialog *dialog,
 
1175
                    GvcMixerUIDevice *input)
 
1176
{
 
1177
        g_print ("\n Add input ui entry with id : %u \n",
 
1178
                  gvc_mixer_ui_device_get_id (input));
 
1179
 
 
1180
        gchar    *port_name;
 
1181
        gchar    *origin;
 
1182
        gchar    *description;
 
1183
        gboolean active;
 
1184
        gboolean available;
 
1185
        gint     card_id;
 
1186
        gint     stream_id;
 
1187
 
 
1188
        g_object_get (G_OBJECT (input),
 
1189
                     "stream-id", &stream_id,
 
1190
                     "card-id", &card_id,
 
1191
                     "origin", &origin,
 
1192
                     "description", &description,
 
1193
                     "port-name", &port_name,
 
1194
                     "port-available", &available,
 
1195
                      NULL);
 
1196
        
 
1197
        GtkTreeModel        *model;
 
1198
        GtkTreeIter          iter;
 
1199
        const GvcChannelMap *map;
 
1200
        GIcon               *icon;
 
1201
 
 
1202
        if (card_id == GVC_MIXER_UI_DEVICE_INVALID) {
 
1203
                GvcMixerStream *stream;
 
1204
                g_print ("just detected a network source");
 
1205
                stream = gvc_mixer_control_get_stream_from_device (dialog->priv->mixer_control, input);
 
1206
                if (stream == NULL) {
 
1207
                        g_warning ("tried to add the network source but the stream was null - fail ?!");
 
1208
                        g_free (port_name);                                     
 
1209
                        g_free (origin);                                                        
 
1210
                        g_free (description);                                           
 
1211
                        return;
 
1212
                }
 
1213
                icon = gvc_mixer_stream_get_gicon (stream);                     
 
1214
        }
 
1215
        else{
 
1216
                GvcMixerCard        *card;
 
1217
                card = gvc_mixer_control_lookup_card_id (dialog->priv->mixer_control, card_id);
 
1218
                icon = gvc_mixer_card_get_gicon (card);                 
 
1219
        }
 
1220
 
 
1221
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->input_treeview));
 
1222
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
1223
 
 
1224
        gtk_list_store_set (GTK_LIST_STORE (model),
 
1225
                            &iter,
 
1226
                            NAME_COLUMN, description,
 
1227
                            DEVICE_COLUMN, origin,
 
1228
                            ACTIVE_COLUMN, FALSE,
 
1229
                            ICON_COLUMN, icon,
 
1230
                            ID_COLUMN, gvc_mixer_ui_device_get_id (input),
 
1231
                            SPEAKERS_COLUMN,origin,
 
1232
                            -1);
 
1233
 
 
1234
        if (icon != NULL)
 
1235
                g_object_unref (icon);
 
1236
 
 
1237
        // TODO check this.
 
1238
        /*g_signal_connect (output,
 
1239
                          "notify::description",
 
1240
                          G_CALLBACK (on_output_description_notify),
 
1241
                          dialog);*/
 
1242
              
 
1243
        g_free (port_name);                                        
 
1244
        g_free (origin);                                                        
 
1245
        g_free (description);                   
 
1246
}                                   
 
1247
 
 
1248
static void
 
1249
add_output_ui_entry (GvcMixerDialog *dialog,
 
1250
                     GvcMixerUIDevice *output)
 
1251
{
 
1252
        g_print ("\n Add output ui entry with id : %u \n",
 
1253
                  gvc_mixer_ui_device_get_id (output));
 
1254
 
 
1255
        gchar    *sink_port_name;
 
1256
        gchar    *origin;
 
1257
        gchar    *description;
 
1258
        gboolean active;
 
1259
        gboolean available;
 
1260
        gint     card_id;
 
1261
        gint     sink_stream_id;
 
1262
 
 
1263
        g_object_get (G_OBJECT (output),
 
1264
                     "stream-id", &sink_stream_id,
 
1265
                     "card-id", &card_id,
 
1266
                     "origin", &origin,
 
1267
                     "description", &description,
 
1268
                     "port-name", &sink_port_name,
 
1269
                     "port-available", &available,
 
1270
                      NULL);
 
1271
        
 
1272
        GtkTreeModel        *model;
 
1273
        GtkTreeIter          iter;
 
1274
        const GvcChannelMap *map;
 
1275
        GIcon               *icon;
 
1276
 
 
1277
        if (card_id == GVC_MIXER_UI_DEVICE_INVALID) {
 
1278
                g_print ("just detected a network sink");
 
1279
                
 
1280
                GvcMixerStream *stream;
 
1281
                stream = gvc_mixer_control_get_stream_from_device (dialog->priv->mixer_control, output);
 
1282
                if (stream == NULL) {
 
1283
                        g_warning ("tried to add the network sink but the stream was null - fail ?!");
 
1284
                        g_free (sink_port_name);                                        
 
1285
                        g_free (origin);                                                        
 
1286
                        g_free (description);                                           
 
1287
                        return;
 
1288
                }
 
1289
                icon = gvc_mixer_stream_get_gicon (stream);                     
 
1290
        }
 
1291
        else{
 
1292
                GvcMixerCard        *card;
 
1293
                card = gvc_mixer_control_lookup_card_id (dialog->priv->mixer_control, card_id);
 
1294
                icon = gvc_mixer_card_get_gicon (card);                 
 
1295
        }
 
1296
 
 
1297
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->output_treeview));
 
1298
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
1299
 
 
1300
        gtk_list_store_set (GTK_LIST_STORE (model),
 
1301
                            &iter,
 
1302
                            NAME_COLUMN, description,
 
1303
                            DEVICE_COLUMN, origin,
 
1304
                            ACTIVE_COLUMN, FALSE,
 
1305
                            ICON_COLUMN, icon,
 
1306
                            ID_COLUMN, gvc_mixer_ui_device_get_id (output),
 
1307
                            SPEAKERS_COLUMN,origin,
 
1308
                            -1);
 
1309
 
 
1310
        if (icon != NULL)
 
1311
                g_object_unref (icon);
 
1312
 
 
1313
        // TODO check this.
 
1314
        /*g_signal_connect (output,
 
1315
                          "notify::description",
 
1316
                          G_CALLBACK (on_output_description_notify),
 
1317
                          dialog);*/
 
1318
              
 
1319
        g_free (sink_port_name);                                        
 
1320
        g_free (origin);                                                        
 
1321
        g_free (description);                   
 
1322
}                                   
 
1323
 
 
1324
static void
 
1325
on_control_output_added (GvcMixerControl *control,
 
1326
                         guint            id,
 
1327
                         GvcMixerDialog  *dialog)
 
1328
{
 
1329
        GvcMixerUIDevice* out = NULL;
 
1330
        out = gvc_mixer_control_lookup_output_id (control, id);
 
1331
 
 
1332
        if (out == NULL) {
 
1333
                g_warning ("on_control_output_added - tried to fetch an output of id %u but got nothing", id);
 
1334
                return;
 
1335
        }
 
1336
 
 
1337
        add_output_ui_entry (dialog, out);
 
1338
}
 
1339
 
 
1340
static void
 
1341
on_control_active_output_update (GvcMixerControl *control,
 
1342
                                 guint            id,
 
1343
                                 GvcMixerDialog  *dialog)
 
1344
{
 
1345
        GvcMixerUIDevice* out = NULL;
 
1346
        out = gvc_mixer_control_lookup_output_id (control, id);
 
1347
 
 
1348
        if (out == NULL) {
 
1349
                g_warning ("\n on_control_active_output_update - tried to fetch an output of id %u but got nothing", id);
 
1350
                return;
 
1351
        }
 
1352
        active_output_update (dialog, out);
 
1353
}
 
1354
 
 
1355
static void
 
1356
on_control_active_input_update (GvcMixerControl *control,
 
1357
                                 guint            id,
 
1358
                                 GvcMixerDialog  *dialog)
 
1359
{
 
1360
        GvcMixerUIDevice* in = NULL;
 
1361
        in = gvc_mixer_control_lookup_input_id (control, id);
 
1362
 
 
1363
        if (in == NULL) {
 
1364
                g_warning ("on_control_active_input_update - tried to fetch an input of id %u but got nothing", id);
 
1365
                return;
 
1366
        }
 
1367
        active_input_update (dialog, in);
 
1368
}
 
1369
 
 
1370
static void
 
1371
on_control_input_added (GvcMixerControl *control,
 
1372
                        guint            id,
 
1373
                        GvcMixerDialog  *dialog)
 
1374
{
 
1375
        GvcMixerUIDevice* in = NULL;
 
1376
        in = gvc_mixer_control_lookup_input_id (control, id);
 
1377
 
 
1378
        if (in == NULL) {
 
1379
                g_warning ("on_control_input_added - tried to fetch an input of id %u but got nothing", id);
 
1380
                return;
 
1381
        }
 
1382
        add_input_ui_entry (dialog, in);
 
1383
}
 
1384
 
 
1385
static void
 
1386
on_control_output_removed (GvcMixerControl *control,
 
1387
                           guint            id,
 
1388
                           GvcMixerDialog  *dialog)
 
1389
{
 
1390
        GtkWidget    *bar;
 
1391
        gboolean      found;
 
1392
        GtkTreeIter   iter;
 
1393
        GtkTreeModel *model;
 
1394
 
 
1395
        GvcMixerUIDevice* out = NULL;
 
1396
        out = gvc_mixer_control_lookup_output_id (control, id);
 
1397
        
 
1398
        gint sink_stream_id;
 
1399
        
 
1400
        g_object_get (G_OBJECT (out),
 
1401
                     "stream-id", &sink_stream_id,
 
1402
                      NULL);
 
1403
                      
 
1404
        g_print ("Remove output from dialog \n id : %u \n sink stream id : %i \n",
 
1405
                  id,
 
1406
                  sink_stream_id);
 
1407
 
 
1408
        /* remove from any models */
 
1409
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->output_treeview));
 
1410
        found = find_item_by_id (GTK_TREE_MODEL (model), id, ID_COLUMN, &iter);
 
1411
        if (found) {
 
1412
                gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
1413
        }
 
1414
}     
 
1415
 
 
1416
 
 
1417
                 
 
1418
static void
 
1419
on_control_input_removed (GvcMixerControl *control,
 
1420
                           guint            id,
 
1421
                           GvcMixerDialog  *dialog)
 
1422
{
 
1423
        GtkWidget    *bar;
 
1424
        gboolean      found;
 
1425
        GtkTreeIter   iter;
 
1426
        GtkTreeModel *model;
 
1427
 
 
1428
        GvcMixerUIDevice* in = NULL;
 
1429
        in = gvc_mixer_control_lookup_input_id (control, id);
 
1430
        
 
1431
        gint stream_id;
 
1432
        
 
1433
        g_object_get (G_OBJECT (in),
 
1434
                     "stream-id", &stream_id,
 
1435
                      NULL);
 
1436
                      
 
1437
        g_print ("Remove input from dialog \n id : %u \n stream id : %i \n",
 
1438
                  id,
 
1439
                  stream_id);
 
1440
 
 
1441
        /* remove from any models */
 
1442
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->input_treeview));
 
1443
        found = find_item_by_id (GTK_TREE_MODEL (model), id, ID_COLUMN, &iter);
 
1444
        if (found) {
 
1445
                gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
1446
        }        
 
1447
}
 
1448
 
 
1449
static void
 
1450
_gtk_label_make_bold (GtkLabel *label)
 
1451
{
 
1452
        PangoFontDescription *font_desc;
 
1453
 
 
1454
        font_desc = pango_font_description_new ();
 
1455
 
 
1456
        pango_font_description_set_weight (font_desc,
 
1457
                                           PANGO_WEIGHT_BOLD);
 
1458
 
 
1459
        /* This will only affect the weight of the font, the rest is
 
1460
         * from the current state of the widget, which comes from the
 
1461
         * theme or user prefs, since the font desc only has the
 
1462
         * weight flag turned on.
 
1463
         */
 
1464
        gtk_widget_modify_font (GTK_WIDGET (label), font_desc);
 
1465
 
 
1466
        pango_font_description_free (font_desc);
 
1467
}
 
1468
 
 
1469
 
 
1470
static void
 
1471
on_input_selection_changed (GtkTreeSelection *selection,
 
1472
                             GvcMixerDialog   *dialog)
 
1473
{
 
1474
        GtkTreeModel *model;
 
1475
        GtkTreeIter   iter;
 
1476
        gboolean      toggled;
 
1477
        guint         id;
 
1478
 
 
1479
        if (gtk_tree_selection_get_selected (selection, &model, &iter) == FALSE) {
 
1480
                g_debug ("Could not get default input from selection");
 
1481
                return;
 
1482
        }
 
1483
 
 
1484
        gtk_tree_model_get (model, &iter,
 
1485
                            ID_COLUMN, &id,
 
1486
                            ACTIVE_COLUMN, &toggled,
 
1487
                            -1);
 
1488
 
 
1489
        toggled ^= 1;
 
1490
        GvcMixerUIDevice *input;
 
1491
        //g_print ("on_input_selection_changed - try swap to input with id %u", id); 
 
1492
        input = gvc_mixer_control_lookup_input_id (dialog->priv->mixer_control, id);
 
1493
        
 
1494
        if (input == NULL) {
 
1495
                g_warning ("on_input_selection_changed - Unable to find input with id: %u", id);
 
1496
                return;
 
1497
        }
 
1498
 
 
1499
        gvc_mixer_control_change_input (dialog->priv->mixer_control, input);
 
1500
}
 
1501
 
 
1502
static void
 
1503
on_output_selection_changed (GtkTreeSelection *selection,
 
1504
                             GvcMixerDialog   *dialog)
 
1505
{
 
1506
        GtkTreeModel *model;
 
1507
        GtkTreeIter   iter;
 
1508
        gboolean      active;
 
1509
        guint         id;
 
1510
 
 
1511
        if (gtk_tree_selection_get_selected (selection, &model, &iter) == FALSE) {
 
1512
                g_debug ("Could not get default output from selection");
 
1513
                return;
 
1514
        }
 
1515
 
 
1516
        gtk_tree_model_get (model, &iter,
 
1517
                            ID_COLUMN, &id,
 
1518
                            ACTIVE_COLUMN, &active,
 
1519
                            -1);
 
1520
        
 
1521
        g_print ("\n\n on_output_selection_changed - active %i \n\n", active); 
 
1522
        if (active){
 
1523
                return;
 
1524
        }
 
1525
 
 
1526
        GvcMixerUIDevice *output;
 
1527
        g_print ("\n on_output_selection_changed - try swap to output with id %u", id); 
 
1528
        output = gvc_mixer_control_lookup_output_id (dialog->priv->mixer_control, id);
 
1529
        
 
1530
        if (output == NULL) {
 
1531
                g_warning ("on_output_selection_changed - Unable to find output with id: %u", id);
 
1532
                return;
 
1533
        }
 
1534
 
 
1535
        gvc_mixer_control_change_output (dialog->priv->mixer_control, output);
 
1536
}
 
1537
 
 
1538
static void
 
1539
name_to_text (GtkTreeViewColumn *column,
 
1540
              GtkCellRenderer *cell,
 
1541
              GtkTreeModel *model,
 
1542
              GtkTreeIter *iter,
 
1543
              gpointer user_data)
 
1544
{
 
1545
        char *name, *mapping;
 
1546
 
 
1547
        gtk_tree_model_get(model, iter,
 
1548
                           NAME_COLUMN, &name,
 
1549
                           SPEAKERS_COLUMN, &mapping,
 
1550
                           -1);
 
1551
 
 
1552
        if (mapping == NULL) {
 
1553
                g_object_set (cell, "text", name, NULL);
 
1554
        } else {
 
1555
                char *str;
 
1556
 
 
1557
                str = g_strdup_printf ("%s\n<i>%s</i>",
 
1558
                                       name, mapping);
 
1559
                g_object_set (cell, "markup", str, NULL);
 
1560
                g_free (str);
 
1561
        }
 
1562
 
 
1563
        g_free (name);
 
1564
        g_free (mapping);
 
1565
}
 
1566
 
 
1567
static GtkWidget *
 
1568
create_stream_treeview (GvcMixerDialog *dialog,
 
1569
                        GCallback       on_selection_changed)
 
1570
{
 
1571
        GtkWidget         *treeview;
 
1572
        GtkListStore      *store;
 
1573
        GtkCellRenderer   *renderer;
 
1574
        GtkTreeViewColumn *column;
 
1575
        GtkTreeSelection  *selection;
 
1576
 
 
1577
        treeview = gtk_tree_view_new ();
 
1578
        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
 
1579
 
 
1580
        store = gtk_list_store_new (NUM_COLUMNS,
 
1581
                                    G_TYPE_STRING,
 
1582
                                    G_TYPE_STRING,
 
1583
                                    G_TYPE_BOOLEAN,
 
1584
                                    G_TYPE_UINT,
 
1585
                                    G_TYPE_STRING,
 
1586
                                    G_TYPE_ICON);
 
1587
        gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
 
1588
                                 GTK_TREE_MODEL (store));
 
1589
 
 
1590
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
 
1591
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
 
1592
 
 
1593
        column = gtk_tree_view_column_new ();
 
1594
        gtk_tree_view_column_set_title (column, _("Name"));
 
1595
        renderer = gtk_cell_renderer_pixbuf_new ();
 
1596
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
1597
        g_object_set (G_OBJECT (renderer), "stock-size", GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
 
1598
        gtk_tree_view_column_set_attributes (column, renderer,
 
1599
                                             "gicon", ICON_COLUMN,
 
1600
                                             NULL);
 
1601
 
 
1602
        renderer = gtk_cell_renderer_text_new ();
 
1603
        gtk_tree_view_column_pack_start (column, renderer, TRUE);
 
1604
        gtk_tree_view_column_set_cell_data_func (column, renderer,
 
1605
                                                 name_to_text, NULL, NULL);
 
1606
        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
1607
 
 
1608
        g_signal_connect ( selection, "changed",
 
1609
                          on_selection_changed, dialog);
 
1610
#if 0
 
1611
        renderer = gtk_cell_renderer_text_new ();
 
1612
        column = gtk_tree_view_column_new_with_attributes (_("Device"),
 
1613
                                                           renderer,
 
1614
                                                           "text", DEVICE_COLUMN,
 
1615
                                                           NULL);
 
1616
        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
1617
#endif
 
1618
        return treeview;
 
1619
}
 
1620
 
 
1621
static void
 
1622
on_profile_changed (GvcComboBox *widget,
 
1623
                    const char  *profile,
 
1624
                    gpointer     user_data)
 
1625
{
 
1626
        GvcMixerCard        *card;
 
1627
 
 
1628
        card = g_object_get_data (G_OBJECT (widget), "card");
 
1629
        if (card == NULL) {
 
1630
                g_warning ("Could not find card for combobox");
 
1631
                return;
 
1632
        }
 
1633
 
 
1634
        g_debug ("Profile changed to %s for card %s", profile,
 
1635
                 gvc_mixer_card_get_name (card));
 
1636
 
 
1637
        gvc_mixer_card_change_profile (card, profile);
 
1638
}
 
1639
 
 
1640
static void
 
1641
on_test_speakers_clicked (GtkButton *widget,
 
1642
                          gpointer  user_data)
 
1643
{
 
1644
        GvcMixerDialog      *dialog = GVC_MIXER_DIALOG (user_data);
 
1645
        GtkTreeModel        *model;
 
1646
        GtkTreeIter         iter;
 
1647
        gint                active_output = GVC_MIXER_UI_DEVICE_INVALID;
 
1648
 
 
1649
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->output_treeview));
 
1650
        
 
1651
        if (gtk_tree_model_get_iter_first (model, &iter) == FALSE){
 
1652
                g_warning ("The tree is empty => we have no device to test speakers with return");
 
1653
                return;        
 
1654
        }
 
1655
                
 
1656
        do {
 
1657
                gboolean         is_selected = FALSE ;
 
1658
                gint             id;
 
1659
                        
 
1660
                gtk_tree_model_get (model, &iter,
 
1661
                                    ID_COLUMN, &id,
 
1662
                                    ACTIVE_COLUMN, &is_selected,
 
1663
                                    -1);
 
1664
                
 
1665
                if (is_selected) {
 
1666
                        active_output = id;
 
1667
                        break;
 
1668
                }
 
1669
                
 
1670
        }while (gtk_tree_model_iter_next (model, &iter));
 
1671
        
 
1672
        if (active_output == GVC_MIXER_UI_DEVICE_INVALID) {
 
1673
                g_warning ("Cant find the active output from the UI");
 
1674
                return;
 
1675
        }        
 
1676
 
 
1677
        GvcMixerUIDevice *output;
 
1678
        output = gvc_mixer_control_lookup_output_id (dialog->priv->mixer_control, (guint)active_output);
 
1679
        gint stream_id = gvc_mixer_ui_device_get_stream_id(output);
 
1680
 
 
1681
        if (stream_id == GVC_MIXER_UI_DEVICE_INVALID)
 
1682
                return;
 
1683
 
 
1684
        g_print ("Test the speakers on the %s", gvc_mixer_ui_device_get_description (output));
 
1685
        
 
1686
        GvcMixerStream        *stream;
 
1687
        GvcMixerCardProfile *profile;
 
1688
        GtkWidget           *d, *speaker_test, *container;
 
1689
        char                *title;
 
1690
 
 
1691
        stream = gvc_mixer_control_lookup_stream_id (dialog->priv->mixer_control, stream_id);
 
1692
        if (stream == NULL) {
 
1693
                g_print ("Stream/sink not found");
 
1694
                return;
 
1695
        }
 
1696
        title = g_strdup_printf (_("Speaker Testing for %s"), gvc_mixer_ui_device_get_description (output));
 
1697
        d = gtk_dialog_new_with_buttons (title,
 
1698
                                         GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget))),
 
1699
                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
1700
                                         GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 
1701
                                         NULL);
 
1702
        gtk_window_set_has_resize_grip (GTK_WINDOW (d), FALSE);
 
1703
 
 
1704
        g_free (title);
 
1705
        speaker_test = gvc_speaker_test_new (dialog->priv->mixer_control,
 
1706
                                             stream);
 
1707
        gtk_widget_show (speaker_test);
 
1708
        container = gtk_dialog_get_content_area (GTK_DIALOG (d));
 
1709
        gtk_container_add (GTK_CONTAINER (container), speaker_test);
 
1710
 
 
1711
        gtk_dialog_run (GTK_DIALOG (d));
 
1712
        gtk_widget_destroy (d);
 
1713
}
 
1714
 
 
1715
static GObject *
 
1716
gvc_mixer_dialog_constructor (GType                  type,
 
1717
                              guint                  n_construct_properties,
 
1718
                              GObjectConstructParam *construct_params)
 
1719
{
 
1720
        GObject          *object;
 
1721
        GvcMixerDialog   *self;
 
1722
        GtkWidget        *main_vbox;
 
1723
        GtkWidget        *label;
 
1724
        GtkWidget        *alignment;
 
1725
        GtkWidget        *box;
 
1726
        GtkWidget        *sbox;
 
1727
        GtkWidget        *ebox;
 
1728
        GtkWidget        *test_sound_box;
 
1729
        GSList           *streams;
 
1730
        GSList           *cards;
 
1731
        GSList           *l;
 
1732
        GvcMixerStream   *stream;
 
1733
        GvcMixerCard     *card;
 
1734
        GtkTreeSelection *selection;
 
1735
 
 
1736
        object = G_OBJECT_CLASS (gvc_mixer_dialog_parent_class)->constructor (type, n_construct_properties, construct_params);
 
1737
 
 
1738
        self = GVC_MIXER_DIALOG (object);
 
1739
 
 
1740
        main_vbox = GTK_WIDGET (self);
 
1741
        gtk_box_set_spacing (GTK_BOX (main_vbox), 2);
 
1742
 
 
1743
        gtk_container_set_border_width (GTK_CONTAINER (self), 3);
 
1744
 
 
1745
        self->priv->output_stream_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
 
1746
        alignment = gtk_alignment_new (0, 0, 1, 1);
 
1747
        gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 0, 0);
 
1748
        gtk_container_add (GTK_CONTAINER (alignment), self->priv->output_stream_box);
 
1749
        gtk_box_pack_start (GTK_BOX (main_vbox),
 
1750
                            alignment,
 
1751
                            FALSE, FALSE, 0);
 
1752
 
 
1753
        self->priv->notebook = gtk_notebook_new ();
 
1754
        gtk_box_pack_start (GTK_BOX (main_vbox),
 
1755
                            self->priv->notebook,
 
1756
                            TRUE, TRUE, 0);
 
1757
        gtk_container_set_border_width (GTK_CONTAINER (self->priv->notebook), 5);
 
1758
 
 
1759
        /* Output page */
 
1760
        self->priv->output_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);        
 
1761
        gtk_container_set_border_width (GTK_CONTAINER (self->priv->output_box), 12);
 
1762
        label = gtk_label_new (_("Output"));
 
1763
        gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
 
1764
                                  self->priv->output_box,
 
1765
                                  label);
 
1766
 
 
1767
        box = gtk_frame_new (_("Play sound through:"));
 
1768
        gtk_widget_set_size_request (GTK_WIDGET (box), 310, -1);        
 
1769
        label = gtk_frame_get_label_widget (GTK_FRAME (box));
 
1770
        _gtk_label_make_bold (GTK_LABEL (label));
 
1771
        gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
 
1772
        gtk_frame_set_shadow_type (GTK_FRAME (box), GTK_SHADOW_NONE);
 
1773
        gtk_box_pack_start (GTK_BOX (self->priv->output_box), box, FALSE, TRUE, 0);
 
1774
 
 
1775
        alignment = gtk_alignment_new (0, 0, 1, 1);
 
1776
        gtk_container_add (GTK_CONTAINER (box), alignment);
 
1777
        gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 10, 5, 0, 15);
 
1778
 
 
1779
        self->priv->output_treeview = create_stream_treeview (self,
 
1780
                                                              G_CALLBACK (on_output_selection_changed));
 
1781
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), self->priv->output_treeview);
 
1782
 
 
1783
        box = gtk_scrolled_window_new (NULL, NULL);
 
1784
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (box),
 
1785
                                        GTK_POLICY_NEVER,
 
1786
                                        GTK_POLICY_AUTOMATIC);
 
1787
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (box),
 
1788
                                             GTK_SHADOW_IN);
 
1789
        gtk_container_add (GTK_CONTAINER (box), self->priv->output_treeview);
 
1790
        gtk_container_add (GTK_CONTAINER (alignment), box);
 
1791
        
 
1792
        self->priv->selected_output_label = gtk_label_new (_("Settings for the selected device:"));
 
1793
        gtk_widget_set_halign (self->priv->selected_output_label, GTK_ALIGN_START);
 
1794
        _gtk_label_make_bold (GTK_LABEL (self->priv->selected_output_label));
 
1795
        self->priv->output_settings_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
1796
 
 
1797
        gtk_box_pack_start (GTK_BOX (self->priv->output_box),
 
1798
                            self->priv->output_settings_box,
 
1799
                            FALSE,
 
1800
                            FALSE,
 
1801
                            0);
 
1802
        gtk_box_pack_start (GTK_BOX (self->priv->output_settings_box),
 
1803
                            self->priv->selected_output_label,
 
1804
                            FALSE,
 
1805
                            FALSE,
 
1806
                            0);
 
1807
 
 
1808
        self->priv->output_balance_bar = gvc_balance_bar_new (BALANCE_TYPE_RL);
 
1809
        if (self->priv->size_group != NULL) {
 
1810
                gvc_balance_bar_set_size_group (GVC_BALANCE_BAR (self->priv->output_balance_bar),
 
1811
                                                self->priv->size_group,
 
1812
                                                FALSE);
 
1813
        }
 
1814
        gtk_box_pack_start (GTK_BOX (self->priv->output_settings_box),
 
1815
                            self->priv->output_balance_bar,
 
1816
                            FALSE, FALSE, 3);
 
1817
        gtk_widget_show (self->priv->output_balance_bar);
 
1818
 
 
1819
        self->priv->output_fade_bar = gvc_balance_bar_new (BALANCE_TYPE_FR);
 
1820
        if (self->priv->size_group != NULL) {
 
1821
                gvc_balance_bar_set_size_group (GVC_BALANCE_BAR (self->priv->output_fade_bar),
 
1822
                                                self->priv->size_group,
 
1823
                                                FALSE);
 
1824
        }
 
1825
        gtk_box_pack_start (GTK_BOX (self->priv->output_settings_box),
 
1826
                            self->priv->output_fade_bar,
 
1827
                            FALSE, FALSE, 3);
 
1828
        gtk_widget_show (self->priv->output_fade_bar);
 
1829
 
 
1830
        self->priv->output_lfe_bar = gvc_balance_bar_new (BALANCE_TYPE_LFE);
 
1831
        if (self->priv->size_group != NULL) {
 
1832
                gvc_balance_bar_set_size_group (GVC_BALANCE_BAR (self->priv->output_lfe_bar),
 
1833
                                                self->priv->size_group,
 
1834
                                                FALSE);
 
1835
        }
 
1836
        gtk_box_pack_start (GTK_BOX (self->priv->output_settings_box),
 
1837
                            self->priv->output_lfe_bar,
 
1838
                            FALSE, FALSE, 3);
 
1839
        gtk_widget_show (self->priv->output_lfe_bar);
 
1840
                
 
1841
        /* Creating a box and try to deal using the same size group. */
 
1842
        test_sound_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
1843
        gtk_box_pack_end (GTK_BOX (self->priv->output_settings_box),
 
1844
                          test_sound_box,
 
1845
                          FALSE, 
 
1846
                          FALSE,
 
1847
                          5);
 
1848
 
 
1849
        sbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
1850
        gtk_box_pack_start (GTK_BOX (test_sound_box),
 
1851
                            sbox,
 
1852
                            FALSE, FALSE, 0);
 
1853
 
 
1854
        label = gtk_label_new (_("Test:"));
 
1855
        gtk_box_pack_start (GTK_BOX (sbox),
 
1856
                            label,
 
1857
                            FALSE, FALSE, 0);
 
1858
        if (self->priv->size_group != NULL)
 
1859
                gtk_size_group_add_widget (self->priv->size_group, sbox);
 
1860
 
 
1861
        self->priv->test_output_button = gtk_button_new_with_label (_("Test Sound"));
 
1862
        
 
1863
        /* FIXME: I am getting mental with all these hardcoded padding values,
 
1864
         * Here 8 works fine, not sure why. */
 
1865
        gtk_box_pack_start (GTK_BOX (test_sound_box),
 
1866
                            self->priv->test_output_button,
 
1867
                            TRUE, TRUE, 8);
 
1868
 
 
1869
        /* Is this needed */
 
1870
        if (self->priv->size_group != NULL)
 
1871
                gtk_size_group_add_widget (self->priv->size_group, self->priv->test_output_button);
 
1872
 
 
1873
        gtk_widget_show (test_sound_box);
 
1874
 
 
1875
        gtk_container_add (GTK_CONTAINER (box), self->priv->output_settings_box);
 
1876
        g_signal_connect (self->priv->test_output_button,
 
1877
                          "released",
 
1878
                           G_CALLBACK (on_test_speakers_clicked),
 
1879
                           self);
 
1880
 
 
1881
        /* Input page */
 
1882
        self->priv->input_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
 
1883
        gtk_container_set_border_width (GTK_CONTAINER (self->priv->input_box), 12);
 
1884
        label = gtk_label_new (_("Input"));
 
1885
        gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
 
1886
                                  self->priv->input_box,
 
1887
                                  label);
 
1888
        box = gtk_frame_new (_("Record sound from:"));
 
1889
        gtk_widget_set_size_request (GTK_WIDGET (box), 310, -1);        
 
1890
        label = gtk_frame_get_label_widget (GTK_FRAME (box));
 
1891
        _gtk_label_make_bold (GTK_LABEL (label));
 
1892
        gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
 
1893
        gtk_frame_set_shadow_type (GTK_FRAME (box), GTK_SHADOW_NONE);
 
1894
        gtk_box_pack_start (GTK_BOX (self->priv->input_box), box, FALSE, TRUE, 0);
 
1895
 
 
1896
        alignment = gtk_alignment_new (0, 0, 1, 1);
 
1897
        gtk_container_add (GTK_CONTAINER (box), alignment);
 
1898
        gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 10, 5, 0, 15);
 
1899
 
 
1900
        self->priv->input_treeview = create_stream_treeview (self,
 
1901
                                                             G_CALLBACK (on_input_selection_changed));
 
1902
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), self->priv->input_treeview);
 
1903
 
 
1904
        box = gtk_scrolled_window_new (NULL, NULL);
 
1905
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (box),
 
1906
                                        GTK_POLICY_NEVER,
 
1907
                                        GTK_POLICY_AUTOMATIC);
 
1908
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (box),
 
1909
                                             GTK_SHADOW_IN);
 
1910
        gtk_container_add (GTK_CONTAINER (box), self->priv->input_treeview);
 
1911
        gtk_container_add (GTK_CONTAINER (alignment), box);
 
1912
 
 
1913
        self->priv->selected_input_label = gtk_label_new (_("Settings for the selected device:"));
 
1914
        gtk_widget_set_halign (self->priv->selected_input_label, GTK_ALIGN_START);
 
1915
        _gtk_label_make_bold (GTK_LABEL (self->priv->selected_input_label));
 
1916
        
 
1917
        self->priv->input_settings_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
1918
        gtk_box_pack_start (GTK_BOX (self->priv->input_box),
 
1919
                            self->priv->input_settings_box,
 
1920
                            FALSE,
 
1921
                            FALSE,
 
1922
                            0);
 
1923
        gtk_box_pack_start (GTK_BOX (self->priv->input_settings_box),
 
1924
                            self->priv->selected_input_label,
 
1925
                            FALSE,
 
1926
                            FALSE,
 
1927
                            0);     
 
1928
 
 
1929
        self->priv->input_bar = create_bar (self, FALSE, TRUE);
 
1930
        gvc_channel_bar_set_name (GVC_CHANNEL_BAR (self->priv->input_bar),
 
1931
                                  _("_Input volume:"));
 
1932
        gvc_channel_bar_set_low_icon_name (GVC_CHANNEL_BAR (self->priv->input_bar),
 
1933
                                           "audio-input-microphone-low-symbolic");
 
1934
        gvc_channel_bar_set_high_icon_name (GVC_CHANNEL_BAR (self->priv->input_bar),
 
1935
                                            "audio-input-microphone-high-symbolic");
 
1936
        gtk_widget_set_sensitive (self->priv->input_bar, FALSE);
 
1937
 
 
1938
        if (self->priv->size_group != NULL) {
 
1939
                gvc_channel_bar_set_size_group (GVC_CHANNEL_BAR (self->priv->input_bar),
 
1940
                                                self->priv->size_group,
 
1941
                                                FALSE);                
 
1942
        }
 
1943
 
 
1944
        gtk_box_pack_start (GTK_BOX (self->priv->input_settings_box),
 
1945
                            self->priv->input_bar,
 
1946
                            FALSE, FALSE, 15);
 
1947
        gtk_widget_show (self->priv->input_bar);
 
1948
        
 
1949
 
 
1950
        /* Creating a box and try to deal using the same size group. */
 
1951
        GtkWidget *input_level_box;
 
1952
        input_level_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
1953
        gtk_box_pack_start (GTK_BOX (self->priv->input_settings_box),
 
1954
                            input_level_box,
 
1955
                            FALSE,
 
1956
                            FALSE,
 
1957
                            5);
 
1958
 
 
1959
        sbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
1960
        gtk_box_pack_start (GTK_BOX (input_level_box),
 
1961
                            sbox,
 
1962
                            FALSE, FALSE, 0);
 
1963
        
 
1964
        label = gtk_label_new (_("Input level:"));
 
1965
        gtk_box_pack_start (GTK_BOX (sbox),
 
1966
                            label,
 
1967
                            FALSE, FALSE, 0);
 
1968
        if (self->priv->size_group != NULL)
 
1969
                gtk_size_group_add_widget (self->priv->size_group, sbox);
 
1970
 
 
1971
 
 
1972
        self->priv->input_level_bar = gvc_level_bar_new ();
 
1973
        gvc_level_bar_set_orientation (GVC_LEVEL_BAR (self->priv->input_level_bar),
 
1974
                                       GTK_ORIENTATION_HORIZONTAL);
 
1975
        gvc_level_bar_set_scale (GVC_LEVEL_BAR (self->priv->input_level_bar),
 
1976
                                 GVC_LEVEL_SCALE_LINEAR);
 
1977
 
 
1978
        gtk_box_pack_start (GTK_BOX (input_level_box),
 
1979
                            self->priv->input_level_bar,
 
1980
                            TRUE, TRUE, 0);        
 
1981
        
 
1982
        gtk_container_add (GTK_CONTAINER (box), self->priv->input_settings_box);
 
1983
        
 
1984
        /* Effects page */
 
1985
        self->priv->sound_effects_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
 
1986
        gtk_container_set_border_width (GTK_CONTAINER (self->priv->sound_effects_box), 12);
 
1987
        label = gtk_label_new (_("Sound Effects"));
 
1988
        gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
 
1989
                                  self->priv->sound_effects_box,
 
1990
                                  label);
 
1991
 
 
1992
        self->priv->effects_bar = create_bar (self, FALSE, TRUE);
 
1993
        gvc_channel_bar_set_name (GVC_CHANNEL_BAR (self->priv->effects_bar),
 
1994
                                  _("_Alert volume:"));
 
1995
        gtk_widget_set_sensitive (self->priv->effects_bar, FALSE);
 
1996
        gtk_box_pack_start (GTK_BOX (self->priv->sound_effects_box),
 
1997
                            self->priv->effects_bar, FALSE, FALSE, 0);
 
1998
 
 
1999
        self->priv->sound_theme_chooser = gvc_sound_theme_chooser_new ();
 
2000
        gtk_box_pack_start (GTK_BOX (self->priv->sound_effects_box),
 
2001
                            self->priv->sound_theme_chooser,
 
2002
                            TRUE, TRUE, 6);
 
2003
 
 
2004
        /* Applications */
 
2005
        self->priv->applications_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
 
2006
        gtk_container_set_border_width (GTK_CONTAINER (self->priv->applications_box), 12);
 
2007
        label = gtk_label_new (_("Applications"));
 
2008
        gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
 
2009
                                  self->priv->applications_box,
 
2010
                                  label);
 
2011
        self->priv->no_apps_label = gtk_label_new (_("No application is currently playing or recording audio."));
 
2012
        gtk_box_pack_start (GTK_BOX (self->priv->applications_box),
 
2013
                            self->priv->no_apps_label,
 
2014
                            TRUE, TRUE, 0);
 
2015
 
 
2016
        self->priv->output_stream_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
 
2017
        alignment = gtk_alignment_new (0, 0, 1, 1);
 
2018
        gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 0, 0);
 
2019
        gtk_container_add (GTK_CONTAINER (alignment), self->priv->output_stream_box);
 
2020
        gtk_box_pack_start (GTK_BOX (main_vbox),
 
2021
                            alignment,
 
2022
                            FALSE, FALSE, 0);
 
2023
        // Output volume
 
2024
        self->priv->output_bar = create_bar (self, FALSE, TRUE);
 
2025
        gvc_channel_bar_set_name (GVC_CHANNEL_BAR (self->priv->output_bar),
 
2026
                                  _("_Output volume:"));
 
2027
        gtk_widget_set_sensitive (self->priv->output_bar, FALSE);
 
2028
        gtk_widget_set_size_request (self->priv->output_bar, 460, -1);        
 
2029
 
 
2030
        gtk_box_pack_start (GTK_BOX (self->priv->output_stream_box),
 
2031
                            self->priv->output_bar, TRUE, FALSE, 12);
 
2032
 
 
2033
        gtk_widget_show_all (main_vbox);
 
2034
 
 
2035
        g_signal_connect (self->priv->mixer_control,
 
2036
                          "stream-added",
 
2037
                          G_CALLBACK (on_control_stream_added),
 
2038
                          self);
 
2039
        g_signal_connect (self->priv->mixer_control,
 
2040
                          "stream-removed",
 
2041
                          G_CALLBACK (on_control_stream_removed),
 
2042
                          self);
 
2043
        g_signal_connect (self->priv->mixer_control,
 
2044
                          "output-added",
 
2045
                          G_CALLBACK (on_control_output_added),
 
2046
                          self);
 
2047
        g_signal_connect (self->priv->mixer_control,
 
2048
                          "output-removed",
 
2049
                          G_CALLBACK (on_control_output_removed),
 
2050
                          self);
 
2051
        g_signal_connect (self->priv->mixer_control,
 
2052
                          "input-added",
 
2053
                          G_CALLBACK (on_control_input_added),
 
2054
                          self);
 
2055
        g_signal_connect (self->priv->mixer_control,
 
2056
                          "input-removed",
 
2057
                          G_CALLBACK (on_control_input_removed),
 
2058
                          self);        
 
2059
        return object;
 
2060
}
 
2061
 
 
2062
static void
 
2063
gvc_mixer_dialog_dispose (GObject *object)
 
2064
{
 
2065
        GvcMixerDialog *dialog = GVC_MIXER_DIALOG (object);
 
2066
 
 
2067
        g_clear_object (&dialog->priv->indicator_settings);
 
2068
 
 
2069
        if (dialog->priv->mixer_control != NULL) {
 
2070
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2071
                                                      on_control_output_added,
 
2072
                                                      dialog);
 
2073
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2074
                                                      on_control_output_removed,
 
2075
                                                      dialog);
 
2076
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2077
                                                      on_control_active_input_update,
 
2078
                                                      dialog);
 
2079
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2080
                                                      on_control_active_output_update,
 
2081
                                                      dialog);                                            
 
2082
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2083
                                                      on_control_input_added,
 
2084
                                                      dialog);
 
2085
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2086
                                                      on_control_input_removed,
 
2087
                                                      dialog);
 
2088
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2089
                                                      on_control_stream_added,
 
2090
                                                      dialog);
 
2091
                g_signal_handlers_disconnect_by_func (dialog->priv->mixer_control,
 
2092
                                                      on_control_stream_removed,
 
2093
                                                      dialog);
 
2094
                g_object_unref (dialog->priv->mixer_control);
 
2095
                dialog->priv->mixer_control = NULL;
 
2096
        }
 
2097
 
 
2098
        if (dialog->priv->bars != NULL) {
 
2099
                g_hash_table_destroy (dialog->priv->bars);
 
2100
                dialog->priv->bars = NULL;
 
2101
        }
 
2102
 
 
2103
        G_OBJECT_CLASS (gvc_mixer_dialog_parent_class)->dispose (object);
 
2104
}
 
2105
 
 
2106
static void
 
2107
gvc_mixer_dialog_class_init (GvcMixerDialogClass *klass)
 
2108
{
 
2109
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
2110
 
 
2111
        object_class->constructor = gvc_mixer_dialog_constructor;
 
2112
        object_class->dispose = gvc_mixer_dialog_dispose;
 
2113
        object_class->finalize = gvc_mixer_dialog_finalize;
 
2114
        object_class->set_property = gvc_mixer_dialog_set_property;
 
2115
        object_class->get_property = gvc_mixer_dialog_get_property;
 
2116
 
 
2117
        g_object_class_install_property (object_class,
 
2118
                                         PROP_MIXER_CONTROL,
 
2119
                                         g_param_spec_object ("mixer-control",
 
2120
                                                              "mixer control",
 
2121
                                                              "mixer control",
 
2122
                                                              GVC_TYPE_MIXER_CONTROL,
 
2123
                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
 
2124
 
 
2125
        g_type_class_add_private (klass, sizeof (GvcMixerDialogPrivate));
 
2126
}
 
2127
 
 
2128
 
 
2129
static void
 
2130
gvc_mixer_dialog_init (GvcMixerDialog *dialog)
 
2131
{
 
2132
        dialog->priv = GVC_MIXER_DIALOG_GET_PRIVATE (dialog);
 
2133
        dialog->priv->bars = g_hash_table_new (NULL, NULL);
 
2134
        dialog->priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
2135
}
 
2136
 
 
2137
static void
 
2138
gvc_mixer_dialog_finalize (GObject *object)
 
2139
{
 
2140
        GvcMixerDialog *mixer_dialog;
 
2141
 
 
2142
        g_return_if_fail (object != NULL);
 
2143
        g_return_if_fail (GVC_IS_MIXER_DIALOG (object));
 
2144
 
 
2145
        mixer_dialog = GVC_MIXER_DIALOG (object);
 
2146
 
 
2147
        g_return_if_fail (mixer_dialog->priv != NULL);
 
2148
        G_OBJECT_CLASS (gvc_mixer_dialog_parent_class)->finalize (object);
 
2149
}
 
2150
 
 
2151
GvcMixerDialog *
 
2152
gvc_mixer_dialog_new (GvcMixerControl *control)
 
2153
{
 
2154
        GObject *dialog;
 
2155
        dialog = g_object_new (GVC_TYPE_MIXER_DIALOG,
 
2156
                               "mixer-control", control,
 
2157
                               NULL);
 
2158
        return GVC_MIXER_DIALOG (dialog);
 
2159
}
 
2160
 
 
2161
enum {
 
2162
        PAGE_EVENTS,
 
2163
        PAGE_HARDWARE,
 
2164
        PAGE_INPUT,
 
2165
        PAGE_OUTPUT,
 
2166
        PAGE_APPLICATIONS
 
2167
};
 
2168
 
 
2169
gboolean
 
2170
gvc_mixer_dialog_set_page (GvcMixerDialog *self,
 
2171
                           const char     *page)
 
2172
{
 
2173
        guint num;
 
2174
 
 
2175
        g_return_val_if_fail (self != NULL, FALSE);
 
2176
 
 
2177
        if (page == NULL)
 
2178
                num = 0;
 
2179
        else if (g_str_equal (page, "effects"))
 
2180
                num = PAGE_EVENTS;
 
2181
        else if (g_str_equal (page, "input"))
 
2182
                num = PAGE_INPUT;
 
2183
        else if (g_str_equal (page, "output"))
 
2184
                num = PAGE_OUTPUT;
 
2185
        else if (g_str_equal (page, "applications"))
 
2186
                num = PAGE_APPLICATIONS;
 
2187
        else
 
2188
                num = 0;
 
2189
 
 
2190
        gtk_notebook_set_current_page (GTK_NOTEBOOK (self->priv->notebook), num);
 
2191
 
 
2192
        return TRUE;
 
2193
}