~ubuntu-branches/ubuntu/vivid/brasero/vivid

« back to all changes in this revision

Viewing changes to .pc/05_populate-tree-model-after-construction.patch/libbrasero-media/brasero-drive-selection.c

  • Committer: Package Import Robot
  • Author(s): Phillip Susi
  • Date: 2013-10-08 21:51:54 UTC
  • Revision ID: package-import@ubuntu.com-20131008215154-1zl2pbxtkkteb79f
Tags: 3.8.0-1ubuntu3
debian/patches/05_populate-tree-model-after-construction.patch:
backport upstream commit to fix drive selection not showing
up correctly (LP: #1237169).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * Libbrasero-media
 
4
 * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
 
5
 *
 
6
 * Libbrasero-media 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
 * The Libbrasero-media authors hereby grant permission for non-GPL compatible
 
12
 * GStreamer plugins to be used and distributed together with GStreamer
 
13
 * and Libbrasero-media. This permission is above and beyond the permissions granted
 
14
 * by the GPL license by which Libbrasero-media is covered. If you modify this code
 
15
 * you may extend this exception to your version of the code, but you are not
 
16
 * obligated to do so. If you do not wish to do so, delete this exception
 
17
 * statement from your version.
 
18
 * 
 
19
 * Libbrasero-media is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 * GNU Library General Public License for more details.
 
23
 * 
 
24
 * You should have received a copy of the GNU General Public License
 
25
 * along with this program; if not, write to:
 
26
 *      The Free Software Foundation, Inc.,
 
27
 *      51 Franklin Street, Fifth Floor
 
28
 *      Boston, MA  02110-1301, USA.
 
29
 */
 
30
  
 
31
#ifdef HAVE_CONFIG_H
 
32
#  include <config.h>
 
33
#endif
 
34
  
 
35
#include <glib.h>
 
36
#include <glib-object.h>
 
37
#include <glib/gi18n-lib.h>
 
38
  
 
39
#include <gtk/gtk.h>
 
40
  
 
41
#include "brasero-drive-selection.h"
 
42
#include "brasero-medium-monitor.h"
 
43
#include "brasero-drive.h"
 
44
#include "brasero-units.h"
 
45
  
 
46
typedef struct _BraseroDriveSelectionPrivate BraseroDriveSelectionPrivate;
 
47
struct _BraseroDriveSelectionPrivate
 
48
{
 
49
        BraseroDrive *active;
 
50
 
 
51
        BraseroDriveType type;
 
52
        gulong added_sig;
 
53
        gulong removed_sig;
 
54
};
 
55
  
 
56
#define BRASERO_DRIVE_SELECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_DRIVE_SELECTION, BraseroDriveSelectionPrivate))
 
57
 
 
58
typedef enum {
 
59
        CHANGED_SIGNAL,
 
60
        LAST_SIGNAL
 
61
} BraseroDriveSelectionSignalType;
 
62
 
 
63
/* GtkBuildable */
 
64
static GtkBuildableIface *parent_buildable_iface;
 
65
 
 
66
static guint brasero_drive_selection_signals [LAST_SIGNAL] = { 0 };
 
67
 
 
68
enum {
 
69
        PROP_0,
 
70
        PROP_DRIVE,
 
71
        PROP_DRIVE_TYPE
 
72
};
 
73
  
 
74
enum {
 
75
        DRIVE_COL,
 
76
        NAME_COL,
 
77
        ICON_COL,
 
78
        NUM_COL
 
79
};
 
80
 
 
81
  
 
82
static void
 
83
brasero_drive_selection_buildable_init (GtkBuildableIface *iface)
 
84
{
 
85
        parent_buildable_iface = g_type_interface_peek_parent (iface);
 
86
}  
 
87
 
 
88
G_DEFINE_TYPE_WITH_CODE (BraseroDriveSelection, brasero_drive_selection, GTK_TYPE_COMBO_BOX, G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, brasero_drive_selection_buildable_init));
 
89
 
 
90
static void
 
91
brasero_drive_selection_set_current_drive (BraseroDriveSelection *self,
 
92
                                           GtkTreeIter *iter)
 
93
{
 
94
        BraseroDriveSelectionPrivate *priv;
 
95
        BraseroDrive *drive;
 
96
        GtkTreeModel *model;
 
97
 
 
98
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
 
99
 
 
100
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
 
101
        gtk_tree_model_get (model, iter,
 
102
                            DRIVE_COL, &drive,
 
103
                            -1);
 
104
 
 
105
        if (drive)
 
106
                gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
 
107
        else
 
108
                gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
 
109
 
 
110
        if (priv->active == drive)
 
111
                return;
 
112
  
 
113
        if (priv->active)
 
114
                g_object_unref (priv->active);
 
115
  
 
116
        priv->active = drive;
 
117
  
 
118
        if (priv->active)
 
119
                g_object_ref (priv->active);
 
120
  
 
121
        g_signal_emit (self,
 
122
                       brasero_drive_selection_signals [CHANGED_SIGNAL],
 
123
                       0,
 
124
                       priv->active);
 
125
}
 
126
  
 
127
static void
 
128
brasero_drive_selection_changed (GtkComboBox *combo)
 
129
{
 
130
        GtkTreeIter iter;
 
131
  
 
132
        if (!gtk_combo_box_get_active_iter (combo, &iter))
 
133
                return;
 
134
  
 
135
        brasero_drive_selection_set_current_drive (BRASERO_DRIVE_SELECTION (combo), &iter);
 
136
}
 
137
  
 
138
/**
 
139
 * brasero_drive_selection_set_active:
 
140
 * @selector: a #BraseroDriveSelection
 
141
 * @drive: a #BraseroDrive to set as the active one in the selector
 
142
 *
 
143
 * Sets the active drive. Emits the ::drive-changed signal.
 
144
 *
 
145
 * Return value: a #gboolean. TRUE if it succeeded, FALSE otherwise.
 
146
 **/
 
147
gboolean
 
148
brasero_drive_selection_set_active (BraseroDriveSelection *selector,
 
149
                                     BraseroDrive *drive)
 
150
{
 
151
        BraseroDriveSelectionPrivate *priv;
 
152
        gboolean result = FALSE;
 
153
        GtkTreeModel *model;
 
154
        GtkTreeIter iter;
 
155
 
 
156
        g_return_val_if_fail (selector != NULL, FALSE);
 
157
        g_return_val_if_fail (BRASERO_IS_DRIVE_SELECTION (selector), FALSE);
 
158
 
 
159
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (selector);
 
160
  
 
161
        if (priv->active == drive)
 
162
                return TRUE;
 
163
  
 
164
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (selector));
 
165
        if (!gtk_tree_model_get_iter_first (model, &iter))
 
166
                return FALSE;
 
167
  
 
168
        do {
 
169
                BraseroDrive *iter_drive;
 
170
  
 
171
                gtk_tree_model_get (model, &iter,
 
172
                                    DRIVE_COL, &iter_drive,
 
173
                                    -1);
 
174
  
 
175
                if (drive == iter_drive) {
 
176
                        if (iter_drive)
 
177
                                g_object_unref (iter_drive);
 
178
 
 
179
                        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (selector), &iter);
 
180
                        brasero_drive_selection_set_current_drive (selector, &iter);
 
181
                        result = TRUE;
 
182
                        break;
 
183
                }
 
184
 
 
185
                g_object_unref (iter_drive);
 
186
        } while (gtk_tree_model_iter_next (model, &iter));
 
187
 
 
188
        return result;
 
189
}
 
190
  
 
191
/**
 
192
 * brasero_drive_selection_get_active:
 
193
 * @selector: a #BraseroDriveSelection
 
194
 *
 
195
 * Gets the active drive.
 
196
 *
 
197
 * Return value: a #BraseroDrive or NULL. Unref when it is not needed anymore.
 
198
 **/
 
199
BraseroDrive *
 
200
brasero_drive_selection_get_active (BraseroDriveSelection *selector)
 
201
{
 
202
        BraseroDriveSelectionPrivate *priv;
 
203
 
 
204
        g_return_val_if_fail (selector != NULL, NULL);
 
205
        g_return_val_if_fail (BRASERO_IS_DRIVE_SELECTION (selector), NULL);
 
206
 
 
207
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (selector);
 
208
        if (!priv->active)
 
209
                return NULL;
 
210
 
 
211
        return g_object_ref (priv->active);
 
212
}
 
213
 
 
214
static void
 
215
brasero_drive_selection_update_no_disc_entry (BraseroDriveSelection *self,
 
216
                                              GtkTreeModel *model,
 
217
                                              GtkTreeIter *iter)
 
218
{
 
219
        GIcon *icon;
 
220
 
 
221
        icon = g_themed_icon_new_with_default_fallbacks ("drive-optical");
 
222
 
 
223
        /* FIXME: that needs a string */
 
224
        gtk_list_store_set (GTK_LIST_STORE (model), iter,
 
225
                            NAME_COL, NULL,
 
226
                            ICON_COL, NULL,
 
227
                            -1);
 
228
 
 
229
        g_object_unref (icon);
 
230
 
 
231
        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), iter);
 
232
        brasero_drive_selection_set_current_drive (self, iter);
 
233
}
 
234
  
 
235
static void
 
236
brasero_drive_selection_add_no_disc_entry (BraseroDriveSelection *self)
 
237
{
 
238
        GtkTreeIter iter;
 
239
        GtkTreeModel *model;
 
240
 
 
241
        /* Nothing's available. Say it. Two cases here, either we're
 
242
         * still probing drives or there isn't actually any available
 
243
         * drive. */
 
244
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
 
245
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
246
        brasero_drive_selection_update_no_disc_entry (self, model, &iter);
 
247
}
 
248
  
 
249
/**
 
250
 * brasero_drive_selection_show_type:
 
251
 * @selector: a #BraseroDriveSelection
 
252
 * @type: a #BraseroDriveType
 
253
 *
 
254
 * Filters and displays drive corresponding to @type.
 
255
 *
 
256
 **/
 
257
void
 
258
brasero_drive_selection_show_type (BraseroDriveSelection *selector,
 
259
                                   BraseroDriveType type)
 
260
{
 
261
        BraseroDriveSelectionPrivate *priv;
 
262
        BraseroMediumMonitor *monitor;
 
263
        GtkTreeModel *model;
 
264
        GtkTreeIter iter;
 
265
        GSList *list;
 
266
        GSList *item;
 
267
 
 
268
        g_return_if_fail (selector != NULL);
 
269
        g_return_if_fail (BRASERO_IS_DRIVE_SELECTION (selector));
 
270
 
 
271
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (selector);
 
272
 
 
273
        priv->type = type;
 
274
 
 
275
        monitor = brasero_medium_monitor_get_default ();
 
276
        list = brasero_medium_monitor_get_drives (monitor, type);
 
277
        g_object_unref (monitor);
 
278
  
 
279
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (selector));
 
280
        if (gtk_tree_model_get_iter_first (model, &iter)) {
 
281
                /* First filter */
 
282
                do {
 
283
                        GSList *node;
 
284
                        BraseroDrive *drive;
 
285
  
 
286
                        gtk_tree_model_get (model, &iter,
 
287
                                            DRIVE_COL, &drive,
 
288
                                            -1);
 
289
  
 
290
                        if (!drive) {
 
291
                                /* That's the dummy line saying there isn't any
 
292
                                 * available drive for whatever action it is */
 
293
                                gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
294
                                break;
 
295
                        }
 
296
  
 
297
                        node = g_slist_find (list, drive);
 
298
                        g_object_unref (drive);
 
299
  
 
300
                        if (!node) {
 
301
                                if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
 
302
                                        continue;
 
303
  
 
304
                                /* no more iter in the tree get out */
 
305
                                break;
 
306
                        }
 
307
  
 
308
                        g_object_unref (node->data);
 
309
                        list = g_slist_delete_link (list, node);
 
310
                } while (gtk_tree_model_iter_next (model, &iter));
 
311
        }
 
312
  
 
313
        if (list) {
 
314
                /* add remaining drive */
 
315
                for (item = list; item; item = item->next) {
 
316
                        gchar *drive_name;
 
317
                        BraseroDrive *drive;
 
318
                        GIcon *drive_icon = NULL;
 
319
 
 
320
                        drive = item->data;
 
321
 
 
322
                        drive_name = brasero_drive_get_display_name (drive);
 
323
 
 
324
                        if (!brasero_drive_is_fake (drive)) {
 
325
                                GDrive *gdrive;
 
326
 
 
327
                                gdrive = brasero_drive_get_gdrive (drive);
 
328
                                if (gdrive) {
 
329
                                        drive_icon = g_drive_get_icon (gdrive);
 
330
                                        g_object_unref (gdrive);
 
331
                                }
 
332
                                else
 
333
                                        drive_icon = g_themed_icon_new_with_default_fallbacks ("drive-optical");
 
334
                        }
 
335
                        else
 
336
                                drive_icon = g_themed_icon_new_with_default_fallbacks ("iso-image-new");
 
337
  
 
338
                        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
339
                        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
340
                                            DRIVE_COL, drive,
 
341
                                            NAME_COL, drive_name?drive_name:_("Unnamed CD/DVD Drive"),
 
342
                                            ICON_COL, drive_icon,
 
343
                                            -1);
 
344
                        g_free (drive_name);
 
345
                        g_object_unref (drive_icon);
 
346
                }
 
347
                g_slist_foreach (list, (GFunc) g_object_unref, NULL);
 
348
                g_slist_free (list);
 
349
        }
 
350
  
 
351
        if (!gtk_tree_model_get_iter_first (model, &iter)) {
 
352
                brasero_drive_selection_add_no_disc_entry (selector);
 
353
                return;
 
354
        }
 
355
 
 
356
        gtk_widget_set_sensitive (GTK_WIDGET (selector), TRUE);
 
357
        if (gtk_combo_box_get_active (GTK_COMBO_BOX (selector)) == -1) {
 
358
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (selector), &iter);
 
359
                brasero_drive_selection_set_current_drive (selector, &iter);
 
360
        }
 
361
}
 
362
 
 
363
static void
 
364
brasero_drive_selection_drive_added_cb (BraseroMediumMonitor *monitor,
 
365
                                        BraseroDrive *drive,
 
366
                                        BraseroDriveSelection *self)
 
367
{
 
368
        BraseroDriveSelectionPrivate *priv;
 
369
        gchar *drive_name = NULL;
 
370
        gboolean add = FALSE;
 
371
        GtkTreeModel *model;
 
372
        GIcon *drive_icon;
 
373
        GtkTreeIter iter;
 
374
 
 
375
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
 
376
 
 
377
        if ((priv->type & BRASERO_DRIVE_TYPE_WRITER)
 
378
        &&  (brasero_drive_can_write (drive)))
 
379
                add = TRUE;
 
380
        else if (priv->type & BRASERO_DRIVE_TYPE_READER)
 
381
                add = TRUE;
 
382
 
 
383
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
 
384
 
 
385
        if (!add) {
 
386
                /* Try to get the first iter (it shouldn't fail) */
 
387
                if (!gtk_tree_model_get_iter_first (model, &iter)) {
 
388
                        brasero_drive_selection_add_no_disc_entry (self);
 
389
                        return;
 
390
                }
 
391
  
 
392
                /* See if that's a real drive or not; if so, return. */
 
393
                drive = NULL;
 
394
                gtk_tree_model_get (model, &iter,
 
395
                                    DRIVE_COL, &drive,
 
396
                                    -1);
 
397
                if (drive)
 
398
                        return;
 
399
  
 
400
                brasero_drive_selection_update_no_disc_entry (self, model, &iter);
 
401
                return;
 
402
        }
 
403
  
 
404
        /* remove warning message */
 
405
        if (gtk_tree_model_get_iter_first (model, &iter)) {
 
406
                BraseroDrive *tmp;
 
407
  
 
408
                gtk_tree_model_get (model, &iter,
 
409
                                    DRIVE_COL, &tmp,
 
410
                                    -1);
 
411
                if (!tmp)
 
412
                        gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
413
                else
 
414
                        g_object_unref (tmp);
 
415
        }
 
416
 
 
417
        if (!brasero_drive_is_fake (drive)) {
 
418
                GDrive *gdrive;
 
419
 
 
420
                gdrive = brasero_drive_get_gdrive (drive);
 
421
                if (gdrive) {
 
422
                        drive_icon = g_drive_get_icon (gdrive);
 
423
                        g_object_unref (gdrive);
 
424
                }
 
425
                else
 
426
                        drive_icon = g_themed_icon_new_with_default_fallbacks ("drive-optical");
 
427
        }
 
428
        else
 
429
                drive_icon = g_themed_icon_new_with_default_fallbacks ("iso-image-new");
 
430
 
 
431
        drive_name = brasero_drive_get_display_name (drive);
 
432
 
 
433
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
434
        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
435
                            DRIVE_COL, drive,
 
436
                            NAME_COL, drive_name?drive_name:_("Unnamed CD/DVD Drive"),
 
437
                            ICON_COL, drive_icon,
 
438
                            -1);
 
439
        g_free (drive_name);
 
440
        g_object_unref (drive_icon);
 
441
 
 
442
        gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
 
443
        if (gtk_combo_box_get_active (GTK_COMBO_BOX (self)) == -1) {
 
444
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
 
445
                brasero_drive_selection_set_current_drive (self, &iter);
 
446
        }
 
447
}
 
448
  
 
449
static void
 
450
brasero_drive_selection_drive_removed_cb (BraseroMediumMonitor *monitor,
 
451
                                            BraseroDrive *drive,
 
452
                                            BraseroDriveSelection *self)
 
453
{
 
454
        GtkTreeModel *model;
 
455
        GtkTreeIter iter;
 
456
  
 
457
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
 
458
        if (!gtk_tree_model_get_iter_first (model, &iter))
 
459
                return;
 
460
  
 
461
        do {
 
462
                BraseroDrive *iter_drive;
 
463
  
 
464
                gtk_tree_model_get (model, &iter,
 
465
                                    DRIVE_COL, &iter_drive,
 
466
                                    -1);
 
467
  
 
468
                if (drive == iter_drive) {
 
469
                        g_object_unref (iter_drive);
 
470
                        gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
471
                        break;
 
472
                }
 
473
  
 
474
                /* Could be NULL if a message "there is no drive ..." is on */
 
475
                if (iter_drive)
 
476
                        g_object_unref (iter_drive);
 
477
  
 
478
        } while (gtk_tree_model_iter_next (model, &iter));
 
479
 
 
480
        if (!gtk_tree_model_get_iter_first (model, &iter)) {
 
481
                brasero_drive_selection_add_no_disc_entry (self);
 
482
                return;
 
483
        }
 
484
 
 
485
        if (gtk_combo_box_get_active (GTK_COMBO_BOX (self)) == -1) {
 
486
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
 
487
                brasero_drive_selection_set_current_drive (self, &iter);
 
488
        }
 
489
}
 
490
  
 
491
static void
 
492
brasero_drive_selection_init (BraseroDriveSelection *object)
 
493
{
 
494
        GtkListStore *model;
 
495
        GtkCellRenderer *renderer;
 
496
        BraseroMediumMonitor *monitor;
 
497
        BraseroDriveSelectionPrivate *priv;
 
498
 
 
499
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (object);
 
500
 
 
501
        monitor = brasero_medium_monitor_get_default ();
 
502
        priv->added_sig = g_signal_connect (monitor,
 
503
                                            "drive-added",
 
504
                                            G_CALLBACK (brasero_drive_selection_drive_added_cb),
 
505
                                            object);
 
506
        priv->removed_sig = g_signal_connect (monitor,
 
507
                                              "drive-removed",
 
508
                                              G_CALLBACK (brasero_drive_selection_drive_removed_cb),
 
509
                                              object);
 
510
 
 
511
        g_object_unref (monitor);
 
512
 
 
513
        /* get the list and fill the model */
 
514
        model = gtk_list_store_new (NUM_COL,
 
515
                                    G_TYPE_OBJECT,
 
516
                                    G_TYPE_STRING,
 
517
                                    G_TYPE_ICON);
 
518
 
 
519
        gtk_combo_box_set_model (GTK_COMBO_BOX (object), GTK_TREE_MODEL (model));
 
520
        g_object_unref (model);
 
521
 
 
522
        renderer = gtk_cell_renderer_pixbuf_new ();
 
523
        g_object_set (renderer, "follow-state", TRUE, NULL);
 
524
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE);
 
525
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer,
 
526
                                        "gicon", ICON_COL,
 
527
                                        NULL);
 
528
 
 
529
        renderer = gtk_cell_renderer_text_new ();
 
530
        g_object_set (renderer, "xpad", 8, NULL);
 
531
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, TRUE);
 
532
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer,
 
533
                                        "markup", NAME_COL,
 
534
                                        NULL);
 
535
 
 
536
        brasero_drive_selection_show_type (BRASERO_DRIVE_SELECTION (object),
 
537
                                           BRASERO_DRIVE_TYPE_ALL_BUT_FILE);
 
538
                                                 
 
539
}
 
540
  
 
541
static void
 
542
brasero_drive_selection_finalize (GObject *object)
 
543
{
 
544
        BraseroDriveSelectionPrivate *priv;
 
545
        BraseroMediumMonitor *monitor;
 
546
  
 
547
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (object);
 
548
  
 
549
        monitor = brasero_medium_monitor_get_default ();
 
550
  
 
551
        g_signal_handler_disconnect (monitor, priv->added_sig);
 
552
        g_signal_handler_disconnect (monitor, priv->removed_sig);
 
553
        priv->removed_sig = 0;
 
554
        priv->added_sig = 0;
 
555
 
 
556
        g_object_unref (monitor);
 
557
 
 
558
        G_OBJECT_CLASS (brasero_drive_selection_parent_class)->finalize (object);
 
559
  }
 
560
  
 
561
static void
 
562
brasero_drive_selection_set_property (GObject *object,
 
563
                                       guint prop_id,
 
564
                                       const GValue *value,
 
565
                                       GParamSpec *pspec)
 
566
{
 
567
        g_return_if_fail (BRASERO_IS_DRIVE_SELECTION (object));
 
568
  
 
569
        switch (prop_id)
 
570
        {
 
571
        case PROP_DRIVE_TYPE:
 
572
                brasero_drive_selection_show_type (BRASERO_DRIVE_SELECTION (object),
 
573
                                                   g_value_get_uint (value));
 
574
                break;
 
575
        case PROP_DRIVE:
 
576
                brasero_drive_selection_set_active (BRASERO_DRIVE_SELECTION (object),
 
577
                                                     BRASERO_DRIVE (g_value_get_object (value)));
 
578
                break;
 
579
        default:
 
580
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
581
                break;
 
582
        }
 
583
  }
 
584
  
 
585
static void
 
586
brasero_drive_selection_get_property (GObject *object,
 
587
                                       guint prop_id,
 
588
                                       GValue *value,
 
589
                                       GParamSpec *pspec)
 
590
{
 
591
        BraseroDriveSelectionPrivate *priv;
 
592
  
 
593
        g_return_if_fail (BRASERO_IS_DRIVE_SELECTION (object));
 
594
  
 
595
        priv = BRASERO_DRIVE_SELECTION_PRIVATE (object);
 
596
  
 
597
        switch (prop_id)
 
598
        {
 
599
        case PROP_DRIVE_TYPE:
 
600
                g_value_set_uint (value, priv->type);
 
601
                break;
 
602
        case PROP_DRIVE:
 
603
                g_value_set_object (value, brasero_drive_selection_get_active (BRASERO_DRIVE_SELECTION (object)));
 
604
                break;
 
605
        default:
 
606
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
607
                break;
 
608
        }
 
609
}
 
610
  
 
611
static void
 
612
brasero_drive_selection_class_init (BraseroDriveSelectionClass *klass)
 
613
{
 
614
        GObjectClass* object_class = G_OBJECT_CLASS (klass);
 
615
        GtkComboBoxClass *combo_class = GTK_COMBO_BOX_CLASS (klass);
 
616
  
 
617
        g_type_class_add_private (klass, sizeof (BraseroDriveSelectionPrivate));
 
618
  
 
619
        object_class->finalize = brasero_drive_selection_finalize;
 
620
        object_class->set_property = brasero_drive_selection_set_property;
 
621
        object_class->get_property = brasero_drive_selection_get_property;
 
622
  
 
623
        combo_class->changed = brasero_drive_selection_changed;
 
624
 
 
625
        g_object_class_install_property (object_class, PROP_DRIVE,
 
626
                                         g_param_spec_object ("Drive",
 
627
                                                              "Selected drive",
 
628
                                                              "The currently selected drive",
 
629
                                                              BRASERO_TYPE_DRIVE, G_PARAM_READWRITE));
 
630
 
 
631
        g_object_class_install_property (object_class, PROP_DRIVE_TYPE,
 
632
                                         g_param_spec_uint ("drive-type",
 
633
                                                            "The type of drives",
 
634
                                                            "The type of drives displayed",
 
635
                                                            0, BRASERO_DRIVE_TYPE_ALL,
 
636
                                                            BRASERO_DRIVE_TYPE_ALL_BUT_FILE,
 
637
                                                            G_PARAM_READWRITE));
 
638
        /**
 
639
        * BraseroDriveSelection::drive-changed:
 
640
        * @selector: the object which received the signal
 
641
        * @drive: the drive which is now selected
 
642
        *
 
643
        * This signal gets emitted when the selected medium has changed
 
644
        *
 
645
        */
 
646
        brasero_drive_selection_signals [CHANGED_SIGNAL] =
 
647
            g_signal_new ("drive_changed",
 
648
                          BRASERO_TYPE_DRIVE_SELECTION,
 
649
                          G_SIGNAL_RUN_FIRST|G_SIGNAL_ACTION|G_SIGNAL_NO_RECURSE,
 
650
                          G_STRUCT_OFFSET (BraseroDriveSelectionClass, drive_changed),
 
651
                          NULL,
 
652
                          NULL,
 
653
                          g_cclosure_marshal_VOID__OBJECT,
 
654
                          G_TYPE_NONE,
 
655
                          1,
 
656
                          BRASERO_TYPE_DRIVE);
 
657
}
 
658
 
 
659
/**
 
660
 * brasero_drive_selection_new:
 
661
 *
 
662
 * Creates a new #BraseroDriveSelection object
 
663
 *
 
664
 * Return value: a #GtkWidget. Unref when it is not needed anymore.
 
665
 **/
 
666
 
 
667
GtkWidget *
 
668
brasero_drive_selection_new (void)
 
669
{
 
670
        return g_object_new (BRASERO_TYPE_DRIVE_SELECTION, NULL);
 
671
}