~nathwill-deactivatedaccount-deactivatedaccount/ubuntu/precise/gnome-control-center/fix-lp-978118

« back to all changes in this revision

Viewing changes to panels/sound-nua/gvc-combo-box.c

  • Committer: Package Import Robot
  • Author(s): Ken VanDine, Didier Roche, Ken VanDine
  • Date: 2012-02-09 16:44:44 UTC
  • Revision ID: package-import@ubuntu.com-20120209164444-nvlkg36obi95y6n0
Tags: 1:3.2.2-2ubuntu7
[ Didier Roche ]
* debian/patches/04_new_appearance_settings.patch:
  - fix a typo (LP: #929070)
  - new reveal sensitivity default is now 2.0

[ Ken VanDine ]
* debian/patches/96_sound_nua_panel.patch
  - Adding the new sound-nua panel for sound settings, only displayed 
    in Unity, the old sound panel will load in GNOME

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) 2009 Bastien Nocera
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <unistd.h>
 
26
 
 
27
#include <glib.h>
 
28
#include <glib/gi18n-lib.h>
 
29
#include <gtk/gtk.h>
 
30
#include <canberra-gtk.h>
 
31
#include <pulse/pulseaudio.h>
 
32
 
 
33
#include "gvc-combo-box.h"
 
34
#include "gvc-mixer-stream.h"
 
35
#include "gvc-mixer-card.h"
 
36
 
 
37
#define GVC_COMBO_BOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_COMBO_BOX, GvcComboBoxPrivate))
 
38
 
 
39
struct GvcComboBoxPrivate
 
40
{
 
41
        GtkWidget     *drop_box;
 
42
        GtkWidget     *start_box;
 
43
        GtkWidget     *end_box;
 
44
        GtkWidget     *label;
 
45
        GtkWidget     *button;
 
46
        GtkTreeModel  *model;
 
47
        GtkWidget     *combobox;
 
48
        gboolean       set_called;
 
49
        GtkSizeGroup  *size_group;
 
50
        gboolean       symmetric;
 
51
};
 
52
 
 
53
enum {
 
54
        COL_NAME,
 
55
        COL_HUMAN_NAME,
 
56
        NUM_COLS
 
57
};
 
58
 
 
59
enum {
 
60
        CHANGED,
 
61
        BUTTON_CLICKED,
 
62
        LAST_SIGNAL
 
63
};
 
64
 
 
65
enum {
 
66
        PROP_0,
 
67
        PROP_LABEL,
 
68
        PROP_SHOW_BUTTON,
 
69
        PROP_BUTTON_LABEL
 
70
};
 
71
 
 
72
static guint signals [LAST_SIGNAL] = { 0, };
 
73
 
 
74
static void     gvc_combo_box_class_init (GvcComboBoxClass *klass);
 
75
static void     gvc_combo_box_init       (GvcComboBox      *combo_box);
 
76
static void     gvc_combo_box_finalize   (GObject            *object);
 
77
 
 
78
G_DEFINE_TYPE (GvcComboBox, gvc_combo_box, GTK_TYPE_HBOX)
 
79
 
 
80
void
 
81
gvc_combo_box_set_size_group (GvcComboBox *combo_box,
 
82
                              GtkSizeGroup  *group,
 
83
                              gboolean       symmetric)
 
84
{
 
85
        g_return_if_fail (GVC_IS_COMBO_BOX (combo_box));
 
86
 
 
87
        combo_box->priv->size_group = group;
 
88
        combo_box->priv->symmetric = symmetric;
 
89
 
 
90
        if (combo_box->priv->size_group != NULL) {
 
91
                gtk_size_group_add_widget (combo_box->priv->size_group,
 
92
                                           combo_box->priv->start_box);
 
93
 
 
94
                if (combo_box->priv->symmetric) {
 
95
                        gtk_size_group_add_widget (combo_box->priv->size_group,
 
96
                                                   combo_box->priv->end_box);
 
97
                }
 
98
        }
 
99
        gtk_widget_queue_draw (GTK_WIDGET (combo_box));
 
100
}
 
101
 
 
102
static void
 
103
gvc_combo_box_set_property (GObject       *object,
 
104
                            guint          prop_id,
 
105
                            const GValue  *value,
 
106
                            GParamSpec    *pspec)
 
107
{
 
108
        GvcComboBox *self = GVC_COMBO_BOX (object);
 
109
 
 
110
        switch (prop_id) {
 
111
        case PROP_LABEL:
 
112
                gtk_label_set_text_with_mnemonic (GTK_LABEL (self->priv->label), g_value_get_string (value));
 
113
                break;
 
114
        case PROP_BUTTON_LABEL:
 
115
                gtk_button_set_label (GTK_BUTTON (self->priv->button), g_value_get_string (value));
 
116
                break;
 
117
        case PROP_SHOW_BUTTON:
 
118
                gtk_widget_set_visible (self->priv->button, g_value_get_boolean (value));
 
119
                break;
 
120
        default:
 
121
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
122
                break;
 
123
        }
 
124
}
 
125
 
 
126
static void
 
127
gvc_combo_box_get_property (GObject     *object,
 
128
                            guint        prop_id,
 
129
                            GValue      *value,
 
130
                            GParamSpec  *pspec)
 
131
{
 
132
        GvcComboBox *self = GVC_COMBO_BOX (object);
 
133
 
 
134
        switch (prop_id) {
 
135
        case PROP_LABEL:
 
136
                g_value_set_string (value,
 
137
                                    gtk_label_get_text (GTK_LABEL (self->priv->label)));
 
138
                break;
 
139
        case PROP_BUTTON_LABEL:
 
140
                g_value_set_string (value,
 
141
                                    gtk_button_get_label (GTK_BUTTON (self->priv->button)));
 
142
                break;
 
143
        case PROP_SHOW_BUTTON:
 
144
                g_value_set_boolean (value,
 
145
                                     gtk_widget_get_visible (self->priv->button));
 
146
                break;
 
147
        default:
 
148
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
149
                break;
 
150
        }
 
151
}
 
152
 
 
153
static void
 
154
gvc_combo_box_class_init (GvcComboBoxClass *klass)
 
155
{
 
156
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
157
 
 
158
        object_class->finalize = gvc_combo_box_finalize;
 
159
        object_class->set_property = gvc_combo_box_set_property;
 
160
        object_class->get_property = gvc_combo_box_get_property;
 
161
 
 
162
        g_object_class_install_property (object_class,
 
163
                                         PROP_LABEL,
 
164
                                         g_param_spec_string ("label",
 
165
                                                              "label",
 
166
                                                              "The combo box label",
 
167
                                                              _("_Profile:"),
 
168
                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
 
169
        g_object_class_install_property (object_class,
 
170
                                         PROP_SHOW_BUTTON,
 
171
                                         g_param_spec_boolean ("show-button",
 
172
                                                               "show-button",
 
173
                                                               "Whether to show the button",
 
174
                                                               FALSE,
 
175
                                                               G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
 
176
        g_object_class_install_property (object_class,
 
177
                                         PROP_BUTTON_LABEL,
 
178
                                         g_param_spec_string ("button-label",
 
179
                                                              "button-label",
 
180
                                                              "The button's label",
 
181
                                                              "APPLICATION BUG",
 
182
                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
 
183
        signals [CHANGED] =
 
184
                g_signal_new ("changed",
 
185
                              G_TYPE_FROM_CLASS (klass),
 
186
                              G_SIGNAL_RUN_LAST,
 
187
                              G_STRUCT_OFFSET (GvcComboBoxClass, changed),
 
188
                              NULL, NULL,
 
189
                              g_cclosure_marshal_VOID__STRING,
 
190
                              G_TYPE_NONE, 1, G_TYPE_STRING);
 
191
        signals [BUTTON_CLICKED] =
 
192
                g_signal_new ("button-clicked",
 
193
                              G_TYPE_FROM_CLASS (klass),
 
194
                              G_SIGNAL_RUN_LAST,
 
195
                              G_STRUCT_OFFSET (GvcComboBoxClass, button_clicked),
 
196
                              NULL, NULL,
 
197
                              g_cclosure_marshal_VOID__VOID,
 
198
                              G_TYPE_NONE, 0, G_TYPE_NONE);
 
199
 
 
200
        g_type_class_add_private (klass, sizeof (GvcComboBoxPrivate));
 
201
}
 
202
 
 
203
void
 
204
gvc_combo_box_set_profiles (GvcComboBox *combo_box,
 
205
                            const GList       *profiles)
 
206
{
 
207
        const GList *l;
 
208
 
 
209
        g_return_if_fail (GVC_IS_COMBO_BOX (combo_box));
 
210
        g_return_if_fail (combo_box->priv->set_called == FALSE);
 
211
 
 
212
        for (l = profiles; l != NULL; l = l->next) {
 
213
                GvcMixerCardProfile *p = l->data;
 
214
 
 
215
                gtk_list_store_insert_with_values (GTK_LIST_STORE (combo_box->priv->model),
 
216
                                                   NULL,
 
217
                                                   G_MAXINT,
 
218
                                                   COL_NAME, p->profile,
 
219
                                                   COL_HUMAN_NAME, p->human_profile,
 
220
                                                   -1);
 
221
        }
 
222
        combo_box->priv->set_called = TRUE;
 
223
}
 
224
 
 
225
void
 
226
gvc_combo_box_set_ports (GvcComboBox *combo_box,
 
227
                         const GList       *ports)
 
228
{
 
229
        const GList *l;
 
230
 
 
231
        g_return_if_fail (GVC_IS_COMBO_BOX (combo_box));
 
232
        g_return_if_fail (combo_box->priv->set_called == FALSE);
 
233
 
 
234
        for (l = ports; l != NULL; l = l->next) {
 
235
                GvcMixerStreamPort *p = l->data;
 
236
 
 
237
                gtk_list_store_insert_with_values (GTK_LIST_STORE (combo_box->priv->model),
 
238
                                                   NULL,
 
239
                                                   G_MAXINT,
 
240
                                                   COL_NAME, p->port,
 
241
                                                   COL_HUMAN_NAME, p->human_port,
 
242
                                                   -1);
 
243
        }
 
244
        combo_box->priv->set_called = TRUE;
 
245
}
 
246
 
 
247
void
 
248
gvc_combo_box_set_active (GvcComboBox *combo_box,
 
249
                          const char  *id)
 
250
{
 
251
        GtkTreeIter iter;
 
252
        gboolean cont;
 
253
 
 
254
        cont = gtk_tree_model_get_iter_first (combo_box->priv->model, &iter);
 
255
        while (cont != FALSE) {
 
256
                char *name;
 
257
 
 
258
                gtk_tree_model_get (combo_box->priv->model, &iter,
 
259
                                    COL_NAME, &name,
 
260
                                    -1);
 
261
                if (g_strcmp0 (name, id) == 0) {
 
262
                        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box->priv->combobox), &iter);
 
263
                        return;
 
264
                }
 
265
                cont = gtk_tree_model_iter_next (combo_box->priv->model, &iter);
 
266
        }
 
267
        g_warning ("Could not find id '%s' in combo box", id);
 
268
}
 
269
 
 
270
static void
 
271
on_combo_box_changed (GtkComboBox *widget,
 
272
                      GvcComboBox *combo_box)
 
273
{
 
274
        GtkTreeIter          iter;
 
275
        char                *profile;
 
276
 
 
277
        if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter) == FALSE) {
 
278
                g_warning ("Could not find an active profile or port");
 
279
                return;
 
280
        }
 
281
 
 
282
        gtk_tree_model_get (combo_box->priv->model, &iter,
 
283
                            COL_NAME, &profile,
 
284
                            -1);
 
285
        g_signal_emit (combo_box, signals[CHANGED], 0, profile);
 
286
        g_free (profile);
 
287
}
 
288
 
 
289
static void
 
290
on_combo_box_button_clicked (GtkButton   *button,
 
291
                             GvcComboBox *combo_box)
 
292
{
 
293
        g_signal_emit (combo_box, signals[BUTTON_CLICKED], 0);
 
294
}
 
295
 
 
296
static void
 
297
gvc_combo_box_init (GvcComboBox *combo_box)
 
298
{
 
299
        GtkWidget *frame;
 
300
        GtkWidget            *box;
 
301
        GtkWidget            *sbox;
 
302
        GtkWidget            *ebox;
 
303
        GtkCellRenderer      *renderer;
 
304
 
 
305
        combo_box->priv = GVC_COMBO_BOX_GET_PRIVATE (combo_box);
 
306
 
 
307
        combo_box->priv->model = GTK_TREE_MODEL (gtk_list_store_new (NUM_COLS,
 
308
                                                                     G_TYPE_STRING,
 
309
                                                                     G_TYPE_STRING));
 
310
 
 
311
        combo_box->priv->label = gtk_label_new (NULL);
 
312
        gtk_misc_set_alignment (GTK_MISC (combo_box->priv->label),
 
313
                                0.0,
 
314
                                0.5);
 
315
 
 
316
        /* frame */
 
317
        frame = gtk_frame_new (NULL);
 
318
        gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
 
319
        gtk_container_add (GTK_CONTAINER (combo_box), frame);
 
320
 
 
321
        combo_box->priv->drop_box = box = gtk_hbox_new (FALSE, 6);
 
322
        combo_box->priv->combobox = gtk_combo_box_new_with_model (combo_box->priv->model);
 
323
        renderer = gtk_cell_renderer_text_new ();
 
324
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->combobox),
 
325
                                    renderer, TRUE);
 
326
        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->combobox),
 
327
                                       renderer,
 
328
                                       "text", COL_HUMAN_NAME);
 
329
 
 
330
        /* Make sure that the combo box isn't too wide when human names are overly long,
 
331
         * but that we can still read the full length of it */
 
332
        g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
 
333
        g_object_set (G_OBJECT (combo_box->priv->combobox), "popup-fixed-width", FALSE, NULL);
 
334
 
 
335
        combo_box->priv->start_box = sbox = gtk_hbox_new (FALSE, 6);
 
336
        gtk_box_pack_start (GTK_BOX (box), sbox, FALSE, FALSE, 0);
 
337
 
 
338
        gtk_box_pack_start (GTK_BOX (sbox), combo_box->priv->label, FALSE, FALSE, 0);
 
339
 
 
340
        gtk_box_pack_start (GTK_BOX (box), combo_box->priv->combobox, TRUE, TRUE, 0);
 
341
 
 
342
        combo_box->priv->button = gtk_button_new_with_label ("APPLICATION BUG");
 
343
        gtk_button_set_use_underline (GTK_BUTTON (combo_box->priv->button), TRUE);
 
344
        gtk_widget_set_no_show_all (combo_box->priv->button, TRUE);
 
345
        gtk_box_pack_start (GTK_BOX (box), combo_box->priv->button, FALSE, FALSE, 0);
 
346
 
 
347
 
 
348
        combo_box->priv->end_box = ebox = gtk_hbox_new (FALSE, 6);
 
349
        gtk_box_pack_start (GTK_BOX (box), ebox, FALSE, FALSE, 0);
 
350
 
 
351
        if (combo_box->priv->size_group != NULL) {
 
352
                gtk_size_group_add_widget (combo_box->priv->size_group, sbox);
 
353
 
 
354
                if (combo_box->priv->symmetric) {
 
355
                        gtk_size_group_add_widget (combo_box->priv->size_group, ebox);
 
356
                }
 
357
        }
 
358
 
 
359
        gtk_container_add (GTK_CONTAINER (frame), combo_box->priv->drop_box);
 
360
        gtk_widget_show_all (frame);
 
361
 
 
362
        gtk_label_set_mnemonic_widget (GTK_LABEL (combo_box->priv->label),
 
363
                                       combo_box->priv->combobox);
 
364
 
 
365
        g_signal_connect (G_OBJECT (combo_box->priv->combobox), "changed",
 
366
                          G_CALLBACK (on_combo_box_changed), combo_box);
 
367
        g_signal_connect (G_OBJECT (combo_box->priv->button), "clicked",
 
368
                          G_CALLBACK (on_combo_box_button_clicked), combo_box);
 
369
}
 
370
 
 
371
static void
 
372
gvc_combo_box_finalize (GObject *object)
 
373
{
 
374
        GvcComboBox *combo_box;
 
375
 
 
376
        g_return_if_fail (object != NULL);
 
377
        g_return_if_fail (GVC_IS_COMBO_BOX (object));
 
378
 
 
379
        combo_box = GVC_COMBO_BOX (object);
 
380
 
 
381
        g_return_if_fail (combo_box->priv != NULL);
 
382
 
 
383
        g_object_unref (combo_box->priv->model);
 
384
        combo_box->priv->model = NULL;
 
385
 
 
386
        G_OBJECT_CLASS (gvc_combo_box_parent_class)->finalize (object);
 
387
}
 
388
 
 
389
GtkWidget *
 
390
gvc_combo_box_new (const char *label)
 
391
{
 
392
        GObject *combo_box;
 
393
        combo_box = g_object_new (GVC_TYPE_COMBO_BOX,
 
394
                                  "label", label,
 
395
                                  NULL);
 
396
        return GTK_WIDGET (combo_box);
 
397
}
 
398