240
if ((type & BRASERO_MEDIA_TYPE_CD) == type
241
&& (brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD)) {
242
/* If used alone, returns all CDs */
243
list = g_slist_prepend (list, medium);
244
g_object_ref (medium);
248
236
if ((type & BRASERO_MEDIA_TYPE_ANY_IN_BURNER)
249
237
&& (brasero_drive_can_write (drive))) {
250
if ((type & BRASERO_MEDIA_TYPE_CD)) {
251
if ((brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD)) {
252
list = g_slist_prepend (list, medium);
253
g_object_ref (medium);
258
list = g_slist_prepend (list, medium);
259
g_object_ref (medium);
238
list = g_slist_prepend (list, medium);
239
g_object_ref (medium);
265
243
if ((type & BRASERO_MEDIA_TYPE_AUDIO)
266
244
&& !(brasero_medium_get_status (medium) & BRASERO_MEDIUM_FILE)
267
245
&& (brasero_medium_get_status (medium) & BRASERO_MEDIUM_HAS_AUDIO)) {
268
if ((type & BRASERO_MEDIA_TYPE_CD)) {
269
if ((brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD)) {
270
list = g_slist_prepend (list, medium);
271
g_object_ref (medium);
276
list = g_slist_prepend (list, medium);
277
g_object_ref (medium);
246
list = g_slist_prepend (list, medium);
247
g_object_ref (medium);
283
251
if ((type & BRASERO_MEDIA_TYPE_DATA)
284
252
&& !(brasero_medium_get_status (medium) & BRASERO_MEDIUM_FILE)
285
253
&& (brasero_medium_get_status (medium) & BRASERO_MEDIUM_HAS_DATA)) {
286
if ((type & BRASERO_MEDIA_TYPE_CD)) {
287
if ((brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD)) {
288
list = g_slist_prepend (list, medium);
289
g_object_ref (medium);
294
list = g_slist_prepend (list, medium);
295
g_object_ref (medium);
254
list = g_slist_prepend (list, medium);
255
g_object_ref (medium);
301
259
if (type & BRASERO_MEDIA_TYPE_WRITABLE) {
302
260
if (brasero_medium_can_be_written (medium)) {
303
if ((type & BRASERO_MEDIA_TYPE_CD)) {
304
if ((brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD)) {
305
list = g_slist_prepend (list, medium);
306
g_object_ref (medium);
311
list = g_slist_prepend (list, medium);
312
g_object_ref (medium);
261
list = g_slist_prepend (list, medium);
262
g_object_ref (medium);
318
267
if (type & BRASERO_MEDIA_TYPE_REWRITABLE) {
319
268
if (brasero_medium_can_be_rewritten (medium)) {
320
if ((type & BRASERO_MEDIA_TYPE_CD)) {
321
if ((brasero_medium_get_status (medium) & BRASERO_MEDIUM_CD)) {
322
list = g_slist_prepend (list, medium);
323
g_object_ref (medium);
328
list = g_slist_prepend (list, medium);
329
g_object_ref (medium);
269
list = g_slist_prepend (list, medium);
270
g_object_ref (medium);
336
275
if (type & BRASERO_MEDIA_TYPE_FILE) {
337
278
/* make sure the drive is indeed a fake one
338
279
* since it can happen that some medium did
339
280
* not properly carry out their initialization
340
281
* and are flagged as BRASERO_MEDIUM_FILE
341
282
* whereas they are not */
283
drive = brasero_medium_get_drive (medium);
342
284
if (brasero_drive_is_fake (drive)) {
343
285
list = g_slist_prepend (list, medium);
344
286
g_object_ref (medium);
400
brasero_medium_monitor_device_added (BraseroMediumMonitor *self,
346
brasero_medium_monitor_connected_cb (GVolumeMonitor *monitor,
348
BraseroMediumMonitor *self)
404
350
BraseroMediumMonitorPrivate *priv;
405
351
BraseroDrive *drive = NULL;
407
priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
409
/* See if the drive is waiting removal.
410
* This is necessary as GIO behaves strangely sometimes
411
* since it sends the "disconnected" signal when a medium
412
* is removed soon followed by a "connected" signal */
413
drive = brasero_medium_monitor_get_drive (self, device);
415
/* Just in case that drive was waiting removal */
416
priv->waiting_removal = g_slist_remove (priv->waiting_removal, drive);
418
BRASERO_MEDIA_LOG ("Added signal was emitted but the drive is in the removal list. Updating GDrive associated object.");
423
g_object_unref (drive);
427
/* Make sure it's an optical drive */
428
if (!brasero_medium_monitor_is_drive (self, device))
353
if (!brasero_medium_monitor_is_drive (self, gdrive))
431
356
BRASERO_MEDIA_LOG ("New drive added");
358
priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
433
359
drive = g_object_new (BRASERO_TYPE_DRIVE,
435
360
"gdrive", gdrive,
437
362
priv->drives = g_slist_prepend (priv->drives, drive);
464
brasero_medium_monitor_connected_cb (GVolumeMonitor *monitor,
466
BraseroMediumMonitor *self)
470
BRASERO_MEDIA_LOG ("GDrive addition signal");
472
device = g_drive_get_identifier (gdrive, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
473
brasero_medium_monitor_device_added (self, device, gdrive);
478
brasero_medium_monitor_volume_added_cb (GVolumeMonitor *monitor,
480
BraseroMediumMonitor *self)
485
BRASERO_MEDIA_LOG ("GVolume addition signal");
487
/* No need to signal that addition if the GVolume
488
* object has an associated GDrive as this is just
489
* meant to trap blank discs which have no GDrive
490
* associated but a GVolume. */
491
gdrive = g_volume_get_drive (gvolume);
493
g_object_unref (gdrive);
497
device = g_volume_get_identifier (gvolume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
501
brasero_medium_monitor_device_added (self, device, NULL);
506
brasero_medium_monitor_disconnected_real (gpointer data)
508
BraseroMediumMonitor *self = BRASERO_MEDIUM_MONITOR (data);
509
BraseroMediumMonitorPrivate *priv;
510
BraseroMedium *medium;
513
priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
515
if (!priv->waiting_removal) {
516
priv->waiting_removal_id = 0;
520
drive = priv->waiting_removal->data;
521
priv->waiting_removal = g_slist_remove (priv->waiting_removal, drive);
523
BRASERO_MEDIA_LOG ("Drive removed");
524
medium = brasero_drive_get_medium (drive);
526
/* disconnect the signal handlers to avoid having the "medium-removed" fired twice */
527
g_signal_handlers_disconnect_by_func (drive,
528
brasero_medium_monitor_medium_added_cb,
530
g_signal_handlers_disconnect_by_func (drive,
531
brasero_medium_monitor_medium_removed_cb,
536
medium_monitor_signals [MEDIUM_REMOVED],
540
priv->drives = g_slist_remove (priv->drives, drive);
542
medium_monitor_signals [DRIVE_REMOVED],
545
g_object_unref (drive);
547
/* in case there are more */
552
brasero_medium_monitor_device_removed (BraseroMediumMonitor *self,
556
BraseroMediumMonitorPrivate *priv;
557
GDrive *associated_gdrive;
560
priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
562
/* Make sure it's one already detected */
563
/* GIO behaves strangely: every time a medium
564
* is removed from a drive it emits the disconnected
565
* signal (which IMO it shouldn't) soon followed by
566
* a connected signal.
567
* So delay the removal by one or two seconds. */
569
drive = brasero_medium_monitor_get_drive (self, device);
573
if (G_UNLIKELY (g_slist_find (priv->waiting_removal, drive) != NULL)) {
574
g_object_unref (drive);
578
associated_gdrive = brasero_drive_get_gdrive (drive);
579
if (associated_gdrive == gdrive) {
580
BRASERO_MEDIA_LOG ("Found device to remove");
581
priv->waiting_removal = g_slist_append (priv->waiting_removal, drive);
583
if (!priv->waiting_removal_id)
584
priv->waiting_removal_id = g_timeout_add_seconds (2,
585
brasero_medium_monitor_disconnected_real,
588
else if (associated_gdrive) {
589
/* do nothing and wait for a "drive-disconnected" signal */
590
g_object_unref (associated_gdrive);
593
g_object_unref (drive);
597
brasero_medium_monitor_volume_removed_cb (GVolumeMonitor *monitor,
599
BraseroMediumMonitor *self)
604
BRASERO_MEDIA_LOG ("Volume removal signal");
606
/* No need to signal that removal if the GVolume
607
* object has an associated GDrive as this is just
608
* meant to trap blank discs which have no GDrive
609
* associated but a GVolume. */
610
gdrive = g_volume_get_drive (gvolume);
612
g_object_unref (gdrive);
616
device = g_volume_get_identifier (gvolume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
620
brasero_medium_monitor_device_removed (self, device, NULL);
625
389
brasero_medium_monitor_disconnected_cb (GVolumeMonitor *monitor,
627
391
BraseroMediumMonitor *self)
631
BRASERO_MEDIA_LOG ("Drive removal signal");
633
device = g_drive_get_identifier (gdrive, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
634
brasero_medium_monitor_device_removed (self, device, gdrive);
393
BraseroMediumMonitorPrivate *priv;
397
priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
399
BRASERO_MEDIA_LOG ("Device removed");
401
for (iter = priv->drives; iter; iter = next) {
408
gdrive_iter = brasero_drive_get_gdrive (drive);
409
if (gdrive == gdrive_iter) {
410
BraseroMedium *medium;
412
BRASERO_MEDIA_LOG ("Drive removed");
413
medium = brasero_drive_get_medium (drive);
416
medium_monitor_signals [MEDIUM_REMOVED],
420
priv->drives = g_slist_remove (priv->drives, drive);
422
medium_monitor_signals [DRIVE_REMOVED],
425
g_object_unref (drive);
677
466
G_CALLBACK (brasero_medium_monitor_medium_removed_cb),
682
470
g_list_foreach (drives, (GFunc) g_object_unref, NULL);
683
471
g_list_free (drives);
685
volumes = g_volume_monitor_get_volumes (priv->gmonitor);
686
BRASERO_MEDIA_LOG ("Found %d volumes", g_list_length (volumes));
688
for (iter = volumes; iter; iter = iter->next) {
692
gvolume = iter->data;
693
device = g_volume_get_identifier (gvolume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
697
/* make sure it isn't already in our list */
698
drive = brasero_medium_monitor_get_drive (object, device);
701
g_object_unref (drive);
705
if (brasero_medium_monitor_is_drive (object, device)) {
706
drive = g_object_new (BRASERO_TYPE_DRIVE,
710
priv->drives = g_slist_prepend (priv->drives, drive);
712
g_signal_connect (drive,
714
G_CALLBACK (brasero_medium_monitor_medium_added_cb),
716
g_signal_connect (drive,
718
G_CALLBACK (brasero_medium_monitor_medium_removed_cb),
724
g_list_foreach (volumes, (GFunc) g_object_unref, NULL);
725
g_list_free (volumes);
727
g_signal_connect (priv->gmonitor,
729
G_CALLBACK (brasero_medium_monitor_volume_added_cb),
731
g_signal_connect (priv->gmonitor,
733
G_CALLBACK (brasero_medium_monitor_volume_removed_cb),
735
473
g_signal_connect (priv->gmonitor,
736
474
"drive-connected",
737
475
G_CALLBACK (brasero_medium_monitor_connected_cb),