~ubuntu-branches/ubuntu/wily/brasero/wily

« back to all changes in this revision

Viewing changes to src/burn-medium-monitor.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-11-18 11:30:50 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20081118113050-hoy0pi04uv7ww9d8
Tags: 0.8.3-0ubuntu1
* New upstream release (LP: #299411)
  - allow use of remote files
  - drives are now probed asynchronously and may not popup immediatly
    but brasero starts faster
  - some parts of GUI were revisited (in particular the burn
    option dialogs)
  - command line option for video projects (LP: #273140)
  - brasero crashed with SIGSEGV in g_main_context_dispatch()
    (LP: #281599)
  - Brasero main GUI appears after closing the dialog
    when opening an ISO file using Nautilus (LP: #242022)
  - brasero delete original files in VIDEO_TS folder (LP: #280835)
  - brasero crashed with SIGSEGV in 
    brasero_mkisofs_base_write_to_files() (LP: #275312)
  - brasero crashed with SIGSEGV in 
    brasero_project_save_project_as() (LP: #275086)
  - brasero crashed with SIGSEGV in 
    IA__g_sequence_iter_get_sequence() (LP: #282622)
  - brasero crashed with SIGSEGV in brasero_medium_get_drive()
    (LP: #283197)
  - Dialog contains a lot of empty space (LP: #190192)
 * debian/patches/008-add-gettext-domain-to-desktop-file.patch:
   - Dropped, we don't need this anymore
 * debian/control:
  - Add Build-deps on libeel2-dev and libnautilus-extension-dev
 * debian/brasero.install:
  - Install nautilus extension

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
#include <libhal.h>
39
39
 
 
40
#include "burn-debug.h"
40
41
#include "burn-drive.h"
41
 
 
42
42
#include "burn-medium.h"
43
 
#include "burn-volume-obj.h"
 
43
#include "burn-hal-watch.h"
44
44
#include "burn-medium-monitor.h"
45
45
 
46
46
#if defined(HAVE_STRUCT_USCSI_CMD)
52
52
typedef struct _BraseroMediumMonitorPrivate BraseroMediumMonitorPrivate;
53
53
struct _BraseroMediumMonitorPrivate
54
54
{
55
 
        GSList *media;
56
55
        GSList *drives;
57
 
 
58
 
        LibHalContext *ctx;
59
56
        GVolumeMonitor *gmonitor;
60
57
};
61
58
 
82
79
        BraseroMediumMonitorPrivate *priv;
83
80
 
84
81
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
85
 
        for (iter = priv->media; iter; iter = iter->next) {
 
82
        for (iter = priv->drives; iter; iter = iter->next) {
86
83
                BraseroDrive *drive;
87
 
                BraseroMedium *medium;
88
84
                const gchar *drive_device;
89
85
 
90
 
                medium = iter->data;
91
 
                drive = brasero_medium_get_drive (medium);
92
 
 
 
86
                drive = iter->data;
93
87
                drive_device = brasero_drive_get_device (drive);
94
88
                if (drive_device && !strcmp (drive_device, device)) {
95
89
                        g_object_ref (drive);
110
104
 
111
105
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
112
106
 
113
 
        for (iter = priv->media; iter; iter = iter->next) {
 
107
        for (iter = priv->drives; iter; iter = iter->next) {
114
108
                BraseroMedium *medium;
115
109
                BraseroDrive *drive;
116
110
 
117
 
                medium = iter->data;
118
 
                drive = brasero_medium_get_drive (medium);
 
111
                drive = iter->data;
 
112
                medium = brasero_drive_get_medium (drive);
 
113
                if (!medium)
 
114
                        continue;
119
115
 
120
116
                if ((type & BRASERO_MEDIA_TYPE_ANY_IN_BURNER)
121
117
                &&  (brasero_drive_can_write (drive))) {
160
156
}
161
157
 
162
158
static void
163
 
brasero_medium_monitor_drive_inserted (LibHalContext *ctx,
164
 
                                       const gchar *udi)
 
159
brasero_medium_monitor_medium_added_cb (BraseroDrive *drive,
 
160
                                        BraseroMedium *medium,
 
161
                                        BraseroMediumMonitor *self)
 
162
{
 
163
        g_signal_emit (self,
 
164
                       medium_monitor_signals [MEDIUM_INSERTED],
 
165
                       0,
 
166
                       medium);
 
167
}
 
168
 
 
169
static void
 
170
brasero_medium_monitor_medium_removed_cb (BraseroDrive *drive,
 
171
                                          BraseroMedium *medium,
 
172
                                          BraseroMediumMonitor *self)
 
173
{
 
174
        g_signal_emit (self,
 
175
                       medium_monitor_signals [MEDIUM_REMOVED],
 
176
                       0,
 
177
                       medium);
 
178
}
 
179
 
 
180
static void
 
181
brasero_medium_monitor_inserted_cb (BraseroHALWatch *watch,
 
182
                                    const char *udi,
 
183
                                    BraseroMediumMonitor *self)
165
184
{
166
185
        BraseroMediumMonitorPrivate *priv;
167
 
        BraseroMediumMonitor *self;
168
186
        BraseroDrive *drive = NULL;
169
 
 
170
 
        self = libhal_ctx_get_user_data (ctx);
 
187
        LibHalContext *ctx;
 
188
 
 
189
        ctx = brasero_hal_watch_get_ctx (watch);
 
190
        if (!libhal_device_query_capability (ctx, udi, "storage.cdrom", NULL))
 
191
                return;
 
192
 
 
193
        BRASERO_BURN_LOG ("New drive inserted");
 
194
 
171
195
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
172
196
 
173
197
        drive = brasero_drive_new (udi);
174
198
        priv->drives = g_slist_prepend (priv->drives, drive);
175
 
}
176
 
 
177
 
static void
178
 
brasero_medium_monitor_medium_inserted (LibHalContext *ctx,
179
 
                                        const gchar *udi)
180
 
{
181
 
        BraseroMediumMonitorPrivate *priv;
182
 
        BraseroMediumMonitor *self;
183
 
        BraseroDrive *drive = NULL;
184
 
        BraseroMedium *medium;
185
 
        gchar *drive_path;
186
 
        GSList *iter;
187
 
 
188
 
        drive_path = libhal_device_get_property_string (ctx,
189
 
                                                        udi,
190
 
                                                        BLOCK_DEVICE,
191
 
                                                        NULL);
192
 
        if (!drive_path)
193
 
                return;
194
 
 
195
 
        self = libhal_ctx_get_user_data (ctx);
196
 
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
197
 
 
198
 
        /* Search the drive */
199
 
        for (iter = priv->drives; iter; iter = iter->next) {
200
 
                BraseroDrive *tmp;
201
 
 
202
 
                tmp = iter->data;
203
 
                if (!brasero_drive_get_device (tmp))
204
 
                        continue;
205
 
 
206
 
                if (!strcmp (brasero_drive_get_device (tmp), drive_path)) {
207
 
                        drive = tmp;
208
 
                        break;
209
 
                }
210
 
        }
211
 
        g_free (drive_path);
212
 
 
213
 
        if (!drive)
214
 
                return;
215
 
 
216
 
        /* Create medium */
217
 
        medium = BRASERO_MEDIUM (brasero_volume_new (drive, udi));
218
 
        priv->media = g_slist_prepend (priv->media, medium);
219
 
        brasero_drive_set_medium (drive, medium);
220
 
 
221
 
        g_signal_emit (self,
222
 
                       medium_monitor_signals [MEDIUM_INSERTED],
223
 
                       0,
224
 
                       medium);
225
 
}
226
 
 
227
 
static void
228
 
brasero_medium_monitor_inserted_cb (LibHalContext *ctx,
229
 
                                    const char *udi)
230
 
{
231
 
        if (libhal_device_property_exists (ctx, udi, "volume.is_disc", NULL)
232
 
        &&  libhal_device_get_property_bool (ctx, udi, "volume.is_disc", NULL))
233
 
                brasero_medium_monitor_medium_inserted (ctx, udi);
234
 
        else if (libhal_device_property_exists (ctx, udi, "storage.cdrom", NULL)
235
 
             &&  libhal_device_get_property_bool (ctx, udi, "storage.cdrom", NULL))
236
 
                brasero_medium_monitor_drive_inserted (ctx, udi);
237
 
}
238
 
 
239
 
static void
240
 
brasero_medium_monitor_removed_cb (LibHalContext *ctx,
241
 
                                   const char *udi)
242
 
{
243
 
        BraseroMediumMonitorPrivate *priv;
244
 
        BraseroMediumMonitor *self;
245
 
        GSList *iter;
246
 
 
247
 
        self = libhal_ctx_get_user_data (ctx);
248
 
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
249
 
 
250
 
        for (iter = priv->media; iter; iter = iter->next) {
251
 
                const gchar *device_udi;
252
 
                BraseroMedium *medium;
253
 
 
254
 
                medium = iter->data;
255
 
                device_udi = brasero_medium_get_udi (medium);
256
 
                if (!device_udi)
257
 
                        continue;
258
 
 
259
 
                if (!strcmp (device_udi, udi)) {
260
 
                        BraseroDrive *drive;
261
 
 
262
 
                        drive = brasero_medium_get_drive (medium);
263
 
                        if (drive)
264
 
                                brasero_drive_set_medium (drive, NULL);
265
 
 
266
 
                        priv->media = g_slist_remove (priv->media, medium);
267
 
                        g_signal_emit (self,
268
 
                                       medium_monitor_signals [MEDIUM_REMOVED],
269
 
                                       0,
270
 
                                       medium);
271
 
 
272
 
                        g_object_unref (medium);
273
 
                        break;
274
 
                }
275
 
        }
276
 
 
277
 
        for (iter = priv->drives; iter; iter = iter->next) {
 
199
 
 
200
        /* check if a medium is inserted */
 
201
        if (brasero_drive_get_medium (drive))
 
202
                g_signal_emit (self,
 
203
                               medium_monitor_signals [MEDIUM_INSERTED],
 
204
                               0,
 
205
                               brasero_drive_get_medium (drive));
 
206
 
 
207
        /* connect to signals */
 
208
        g_signal_connect (drive,
 
209
                          "medium-added",
 
210
                          G_CALLBACK (brasero_medium_monitor_medium_added_cb),
 
211
                          self);
 
212
        g_signal_connect (drive,
 
213
                          "medium-removed",
 
214
                          G_CALLBACK (brasero_medium_monitor_medium_removed_cb),
 
215
                          self);
 
216
}
 
217
 
 
218
static void
 
219
brasero_medium_monitor_removed_cb (BraseroHALWatch *watch,
 
220
                                   const char *udi,
 
221
                                   BraseroMediumMonitor *self)
 
222
{
 
223
        BraseroMediumMonitorPrivate *priv;
 
224
        LibHalContext *ctx;
 
225
        GSList *iter;
 
226
        GSList *next;
 
227
 
 
228
        ctx = brasero_hal_watch_get_ctx (watch);
 
229
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
 
230
 
 
231
        BRASERO_BURN_LOG ("Drive removed");
 
232
 
 
233
        for (iter = priv->drives; iter; iter = next) {
278
234
                const gchar *device_udi;
279
235
                BraseroDrive *drive;
280
236
 
281
237
                drive = iter->data;
 
238
                next = iter->next;
 
239
 
282
240
                device_udi = brasero_drive_get_udi (drive);
283
241
                if (!device_udi)
284
242
                        continue;
287
245
                        BraseroMedium *medium;
288
246
 
289
247
                        medium = brasero_drive_get_medium (drive);
290
 
                        brasero_drive_set_medium (drive, NULL);
291
 
 
292
 
                        if (medium) {
293
 
                                priv->media = g_slist_remove (priv->media, medium);
 
248
                        if (medium)
294
249
                                g_signal_emit (self,
295
250
                                               medium_monitor_signals [MEDIUM_REMOVED],
296
251
                                               0,
297
252
                                               medium);
298
 
                                g_object_unref (medium);
299
 
                                return;
300
 
                        }
301
253
 
302
254
                        priv->drives = g_slist_remove (priv->drives, drive);
303
255
                        g_object_unref (drive);
304
 
                        break;
305
256
                }
306
257
        }
307
258
}
308
259
 
309
260
static void
310
 
brasero_medium_monitor_add_file (BraseroMediumMonitor *self)
311
 
{
312
 
        BraseroMediumMonitorPrivate *priv;
313
 
        BraseroMedium *medium;
314
 
        BraseroDrive *drive;
315
 
 
316
 
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
317
 
 
318
 
        drive = brasero_drive_new (NULL);
319
 
        priv->drives = g_slist_prepend (priv->drives, drive);
320
 
        
321
 
        medium = g_object_new (BRASERO_TYPE_VOLUME,
322
 
                               "drive", drive,
323
 
                               NULL);
324
 
        priv->media = g_slist_prepend (priv->media, medium);
325
 
        brasero_drive_set_medium (drive, medium);
326
 
}
327
 
 
328
 
static void
329
261
brasero_medium_monitor_init (BraseroMediumMonitor *object)
330
262
{
331
263
        DBusError error;
332
264
        int nb_devices, i;
 
265
        LibHalContext *ctx;
 
266
        BraseroDrive *drive;
333
267
        char **devices = NULL;
334
 
        DBusConnection *dbus_connection;
 
268
        BraseroHALWatch *watch;
335
269
        BraseroMediumMonitorPrivate *priv;
336
270
 
337
271
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (object);
341
275
         * connect to HAL before us. */
342
276
        priv->gmonitor = g_volume_monitor_get ();
343
277
 
344
 
        /* initialize the connection with hal */
345
 
        priv->ctx = libhal_ctx_new ();
346
 
        if (priv->ctx == NULL) {
347
 
                g_warning ("Cannot initialize hal library\n");
348
 
                goto error;
349
 
        }
350
 
 
 
278
        watch = brasero_hal_watch_get_default ();
 
279
        ctx = brasero_hal_watch_get_ctx (watch);
 
280
 
 
281
        g_signal_connect (watch,
 
282
                          "device-added",
 
283
                          G_CALLBACK (brasero_medium_monitor_inserted_cb),
 
284
                          object);
 
285
        g_signal_connect (watch,
 
286
                          "device-removed",
 
287
                          G_CALLBACK (brasero_medium_monitor_removed_cb),
 
288
                          object);
 
289
 
 
290
        /* Now we get the list and cache it */
351
291
        dbus_error_init (&error);
352
 
        dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
353
 
        if (dbus_error_is_set (&error)) {
354
 
                g_warning ("Cannot connect to DBus %s\n", error.message);
355
 
                dbus_error_free (&error);
356
 
                goto error;
357
 
        }
358
 
 
359
 
        dbus_connection_setup_with_g_main (dbus_connection, NULL);
360
 
        libhal_ctx_set_dbus_connection (priv->ctx, dbus_connection);
361
 
 
362
 
        libhal_ctx_set_user_data (priv->ctx, object);
363
 
        libhal_ctx_set_cache (priv->ctx, FALSE);
364
 
 
365
 
        /* monitor devices addition and removal */
366
 
        libhal_ctx_set_device_added (priv->ctx, brasero_medium_monitor_inserted_cb);
367
 
        libhal_ctx_set_device_removed (priv->ctx, brasero_medium_monitor_removed_cb);
368
 
 
369
 
        if (libhal_ctx_init (priv->ctx, &error) == FALSE) {
370
 
                g_warning ("Failed to initialize hal : %s\n", error.message);
371
 
                dbus_error_free (&error);
372
 
                goto error;
373
 
        }
374
 
 
375
 
        /* Now we get the list and cache it */
376
 
        devices = libhal_find_device_by_capability (priv->ctx,
 
292
        BRASERO_BURN_LOG ("Polling for drives");
 
293
        devices = libhal_find_device_by_capability (ctx,
377
294
                                                    "storage.cdrom", &nb_devices,
378
295
                                                    &error);
379
296
        if (dbus_error_is_set (&error)) {
380
 
                g_warning ("Hal is not running : %s\n", error.message);
 
297
                BRASERO_BURN_LOG ("Hal is not running : %s\n", error.message);
381
298
                dbus_error_free (&error);
382
 
                goto error;
 
299
                return;
383
300
        }
384
301
 
 
302
        BRASERO_BURN_LOG ("Found %d drives", nb_devices);
385
303
        for (i = 0; i < nb_devices; i++) {
386
 
                int j;
387
 
                int nb_volumes;
388
 
                BraseroDrive *drive;
389
 
                char **volumes = NULL;
390
 
 
391
304
                /* create the drive */
 
305
                BRASERO_BURN_LOG ("Probing %s", devices [i]);
392
306
                drive = brasero_drive_new (devices [i]);
393
307
                priv->drives = g_slist_prepend (priv->drives, drive);
394
308
 
395
 
                /* Now search for a possible medium inside */
396
 
                volumes = libhal_manager_find_device_string_match (priv->ctx,
397
 
                                                                   "info.parent",
398
 
                                                                   devices [i],
399
 
                                                                   &nb_volumes,
400
 
                                                                   &error);
401
 
                if (dbus_error_is_set (&error)) {
402
 
                        g_warning ("Hal connection problem :  %s\n",
403
 
                                   error.message);
404
 
                        dbus_error_free (&error);
405
 
 
406
 
                        if (volumes)
407
 
                                libhal_free_string_array (volumes);
408
 
                        goto error;
409
 
                }
410
 
 
411
 
                for (j = 0; j < nb_volumes; j++) {
412
 
                        BraseroMedium *medium;
413
 
 
414
 
                        medium = BRASERO_MEDIUM (brasero_volume_new (drive, volumes [j]));
415
 
                        priv->media = g_slist_prepend (priv->media, medium);
416
 
                        brasero_drive_set_medium (drive, medium);
417
 
                }
418
 
 
419
 
                libhal_free_string_array (volumes);
 
309
                g_signal_connect (drive,
 
310
                                  "medium-added",
 
311
                                  G_CALLBACK (brasero_medium_monitor_medium_added_cb),
 
312
                                  object);
 
313
                g_signal_connect (drive,
 
314
                                  "medium-removed",
 
315
                                  G_CALLBACK (brasero_medium_monitor_medium_removed_cb),
 
316
                                  object);
420
317
        }
421
318
        libhal_free_string_array (devices);
422
319
 
423
 
        brasero_medium_monitor_add_file (object);
424
 
 
425
 
        return;
426
 
 
427
 
      error:
428
 
        libhal_ctx_shutdown (priv->ctx, NULL);
429
 
        libhal_ctx_free (priv->ctx);
430
 
        priv->ctx = NULL;
431
 
 
432
 
        if (devices)
433
 
                libhal_free_string_array (devices);
 
320
        /* add fake/file drive */
 
321
        drive = brasero_drive_new (NULL);
 
322
        priv->drives = g_slist_prepend (priv->drives, drive);
434
323
 
435
324
        return;
436
325
}
442
331
 
443
332
        priv = BRASERO_MEDIUM_MONITOR_PRIVATE (object);
444
333
 
445
 
        if (priv->media) {
446
 
                g_slist_foreach (priv->media, (GFunc) g_object_unref, NULL);
447
 
                g_slist_free (priv->media);
448
 
                priv->media = NULL;
449
 
        }
450
 
 
451
334
        if (priv->drives) {
452
335
                g_slist_foreach (priv->drives, (GFunc) g_object_unref, NULL);
453
336
                g_slist_free (priv->drives);
454
337
                priv->drives = NULL;
455
338
        }
456
339
 
457
 
        if (priv->ctx) {
458
 
                DBusConnection *connection;
459
 
 
460
 
                connection = libhal_ctx_get_dbus_connection (priv->ctx);
461
 
                dbus_connection_unref (connection);
462
 
 
463
 
                libhal_ctx_shutdown (priv->ctx, NULL);
464
 
                libhal_ctx_free (priv->ctx);
465
 
                priv->ctx = NULL;
466
 
        }
467
 
 
468
340
        if (priv->gmonitor) {
469
341
                g_object_unref (priv->gmonitor);
470
342
                priv->gmonitor = NULL;