~ubuntu-branches/ubuntu/maverick/brasero/maverick

« back to all changes in this revision

Viewing changes to libbrasero-utils/brasero-io.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2009-11-26 16:20:01 UTC
  • mfrom: (1.1.34 upstream)
  • Revision ID: james.westby@ubuntu.com-20091126162001-adzp6h0x5ow9bc4b
Tags: 2.29.2-0ubuntu1
* New upstream release:
  - Integrate Brasero with PackageKit
  - Gobject-introspection support for libbrasero-media and libbrasero-burn
  - Added Tracker support for searches besides Beagle
  - Fix compile failure using --disable-introspection see bgo #602027
  - Removed deprecated GLib symbols fixes bgo #601040
  - Fix #601871 - Wrong remaining space when audio CD of size greater than 70
    min
  - Fix #601496 - Select disc image selector allows to selecd pictures
  - Fix #601109 - burning disks with burn:// doesn't set the disk label
  - Fix #601259 - Problems with folder depth
  - Fix #599655 - brasero crashed with SIGSEGV in g_main_context_dispatch()
  - Fix #588323 - crash in Disc Copier: Dragging a track from Banshee
  - Fix #600007 - Memory leaks in brasero
  - Fix #600293 - Fails to build error: cannot convert to a pointer type
* debian/control.in:
  - Bump build-depends on libglib2.0-dev
* debian/patches/012_build_error.patch:
  - Applied upstream
* debian/patches/010_lpi.patch:
* debian/patches/011_nautilus_menu_move.patch:
* debian/patches/99_autoconf.patch:
  - Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
#include <gio/gio.h>
44
44
 
 
45
#include <gdk/gdkx.h>
 
46
 
45
47
#include <gtk/gtk.h>
46
48
 
47
49
#ifdef BUILD_PLAYLIST
100
102
 
101
103
        guint progress_id;
102
104
        GSList *progress;
 
105
 
 
106
        BraseroIOGetParentWinCb win_callback;
 
107
        gpointer win_user_data;
103
108
};
104
109
 
105
110
#define BRASERO_IO_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_IO, BraseroIOPrivate))
182
187
 
183
188
                /* update our progress */
184
189
                progress->progress (progress->job, progress);
185
 
                progress->job->base->progress (progress->job->base->object,
186
 
                                               progress,
187
 
                                               callback_data);
 
190
                progress->job->base->methods->progress (progress->job->base->object,
 
191
                                                        progress,
 
192
                                                        callback_data);
188
193
        }
189
194
        g_mutex_unlock (priv->lock);
190
195
 
201
206
 
202
207
        priv = BRASERO_IO_PRIVATE (self);
203
208
 
204
 
        if (!job->base->progress)
 
209
        if (!job->base->methods->progress)
205
210
                return;
206
211
 
207
212
        progress = g_new0 (BraseroIOJobProgress, 1);
321
326
        BraseroIOJobResult *result;
322
327
        BraseroIOPrivate *priv;
323
328
        guint results_id;
324
 
        GSList *iter;
325
 
        GSList *next;
326
329
        int i;
327
330
 
328
331
        priv = BRASERO_IO_PRIVATE (self);
331
334
 
332
335
        /* Put that to 0 for now so that a new idle call will be scheduled while
333
336
         * we are in the loop. That way if we block the other one will be able 
334
 
         * to deliver the results. */
 
337
         * to deliver results. */
335
338
        results_id = priv->results_id;
336
339
        priv->results_id = 0;
337
340
 
338
341
        /* Return several results at a time that can be a huge speed gain.
339
342
         * What should be the value that provides speed and responsiveness? */
340
 
        for (i = 0, iter = priv->results; iter && i < NUMBER_OF_RESULTS; iter = next) {
 
343
        for (i = 0; priv->results && i < NUMBER_OF_RESULTS;) {
341
344
                BraseroIOJobBase *base;
342
 
 
343
 
                result = iter->data;
344
 
                next = iter->next;
 
345
                GSList *iter;
 
346
 
 
347
                /* Find the next result that can be returned */
 
348
                result = NULL;
 
349
                for (iter = priv->results; iter; iter = iter->next) {
 
350
                        BraseroIOJobResult *tmp_result;
 
351
 
 
352
                        tmp_result = iter->data;
 
353
                        if (!tmp_result->base->methods->in_use) {
 
354
                                result = tmp_result;
 
355
                                break;
 
356
                        }
 
357
                }
 
358
 
 
359
                if (!result)
 
360
                        break;
345
361
 
346
362
                /* Make sure another result is not returned for this base. This 
347
363
                 * is to avoid BraseroDataDisc showing multiple dialogs for 
348
364
                 * various problems; like one dialog for joliet, one for deep,
349
365
                 * and one for name collision. */
350
 
                if (result->base->in_use)
351
 
                        continue;
 
366
                base = (BraseroIOJobBase *) result->base;
 
367
                base->methods->in_use = TRUE;
352
368
 
353
369
                priv->results = g_slist_remove (priv->results, result);
354
370
 
355
 
                base = (BraseroIOJobBase *) result->base;
356
 
                base->in_use = TRUE;
 
371
                /* This is to make sure the object
 
372
                 *  lives as long as we need it. */
 
373
                g_object_ref (base->object);
357
374
 
358
375
                g_mutex_unlock (priv->lock);
359
376
 
360
377
                data = result->callback_data;
361
378
 
362
 
                /* This is to make sure the object lives
363
 
                 * as long as we need it. */
364
 
                g_object_ref (base->object);
365
 
 
366
379
                if (result->uri || result->info || result->error)
367
 
                        result->base->callback (base->object,
368
 
                                                result->error,
369
 
                                                result->uri,
370
 
                                                result->info,
371
 
                                                data? data->callback_data:NULL);
 
380
                        base->methods->callback (base->object,
 
381
                                                  result->error,
 
382
                                                  result->uri,
 
383
                                                  result->info,
 
384
                                                  data? data->callback_data:NULL);
372
385
 
373
386
                /* call destroy () for callback data */
374
387
                brasero_io_unref_result_callback_data (data,
375
388
                                                       base->object,
376
 
                                                       base->destroy,
 
389
                                                       base->methods->destroy,
377
390
                                                       FALSE);
378
391
 
379
 
                g_object_unref (base->object);
380
 
 
381
392
                brasero_io_job_result_free (result);
382
393
 
383
394
                g_mutex_lock (priv->lock);
384
395
 
385
396
                i ++;
386
 
                base->in_use = FALSE;
 
397
 
 
398
                g_object_unref (base->object);
 
399
                base->methods->in_use = FALSE;
387
400
        }
388
401
 
389
 
        if (!priv->results_id && iter && i >= NUMBER_OF_RESULTS) {
 
402
        if (!priv->results_id && priv->results && i >= NUMBER_OF_RESULTS) {
390
403
                /* There are still results and no idle call is scheduled so we
391
404
                 * have to restart ourselves to make sure we empty the queue */
392
405
                priv->results_id = results_id;
514
527
                 * add a dummy result to destroy callback_data. */
515
528
                if (g_atomic_int_dec_and_test (&job->callback_data->ref)) {
516
529
                        if (cancelled) {
517
 
                                if (job->base->destroy)
518
 
                                        job->base->destroy (job->base->object,
519
 
                                                            TRUE,
520
 
                                                            job->callback_data->callback_data);
 
530
                                if (job->base->methods->destroy)
 
531
                                        job->base->methods->destroy (job->base->object,
 
532
                                                                      TRUE,
 
533
                                                                      job->callback_data->callback_data);
521
534
 
522
535
                                g_free (job->callback_data);
523
536
                        }
587
600
                                   GError **error)
588
601
{
589
602
        GMount *mounted;
 
603
        GtkWindow *parent;
 
604
        BraseroIOPrivate *priv;
590
605
        GMountOperation *operation;
591
606
        BraseroIOMount mount = { NULL, };
592
607
 
593
 
        /* FIXME: need a way to get a parent window for the operation */
594
 
        operation = gtk_mount_operation_new (NULL);
 
608
        priv = BRASERO_IO_PRIVATE (self);
 
609
 
 
610
        if (priv->win_callback)
 
611
                parent = priv->win_callback (priv->win_user_data);
 
612
 
 
613
        if (parent)
 
614
                operation = gtk_mount_operation_new (parent);
 
615
 
595
616
        g_file_mount_enclosing_volume (file,
596
617
                                       G_MOUNT_MOUNT_NONE,
597
618
                                       operation,
2156
2177
        data = result->callback_data;
2157
2178
        brasero_io_unref_result_callback_data (data,
2158
2179
                                               result->base->object,
2159
 
                                               result->base->destroy,
 
2180
                                               result->base->methods->destroy,
2160
2181
                                               TRUE);
2161
2182
        brasero_io_job_result_free (result);
2162
2183
}
2299
2320
                                                     
2300
2321
}
2301
2322
 
 
2323
BraseroIOJobCallbacks *
 
2324
brasero_io_register_job_methods (BraseroIOResultCallback callback,
 
2325
                                 BraseroIODestroyCallback destroy,
 
2326
                                 BraseroIOProgressCallback progress)
 
2327
{
 
2328
        BraseroIOJobCallbacks *methods;
 
2329
 
 
2330
        methods = g_new0 (BraseroIOJobCallbacks, 1);
 
2331
        methods->callback = callback;
 
2332
        methods->destroy = destroy;
 
2333
        methods->progress = progress;
 
2334
 
 
2335
        return methods;
 
2336
}
 
2337
 
 
2338
BraseroIOJobBase *
 
2339
brasero_io_register_with_methods (GObject *object,
 
2340
                                  BraseroIOJobCallbacks *methods)
 
2341
{
 
2342
        BraseroIOJobBase *base;
 
2343
 
 
2344
        base = g_new0 (BraseroIOJobBase, 1);
 
2345
        base->object = object;
 
2346
        base->methods = methods;
 
2347
        methods->ref ++;
 
2348
 
 
2349
        return base;
 
2350
}
 
2351
 
2302
2352
BraseroIOJobBase *
2303
2353
brasero_io_register (GObject *object,
2304
2354
                     BraseroIOResultCallback callback,
2305
2355
                     BraseroIODestroyCallback destroy,
2306
2356
                     BraseroIOProgressCallback progress)
2307
2357
{
2308
 
        BraseroIOJobBase *base;
2309
 
 
2310
 
        base = g_new0 (BraseroIOJobBase, 1);
2311
 
        base->object = object;
2312
 
        base->callback = callback;
2313
 
        base->destroy = destroy;
2314
 
        base->progress = progress;
2315
 
 
2316
 
        return base;
 
2358
        return brasero_io_register_with_methods (object, brasero_io_register_job_methods (callback, destroy, progress));
 
2359
}
 
2360
 
 
2361
void
 
2362
brasero_io_job_base_free (BraseroIOJobBase *base)
 
2363
{
 
2364
        BraseroIOJobCallbacks *methods;
 
2365
 
 
2366
        if (!base)
 
2367
                return;
 
2368
 
 
2369
        methods = base->methods;
 
2370
        g_free (base);
 
2371
 
 
2372
        methods->ref --;
 
2373
        if (methods->ref <= 0)
 
2374
                g_free (methods);
 
2375
}
 
2376
 
 
2377
static int
 
2378
 brasero_io_xid_for_metadata (gpointer user_data)
 
2379
{
 
2380
        BraseroIOPrivate *priv;
 
2381
 
 
2382
        priv = BRASERO_IO_PRIVATE (user_data);
 
2383
        if (priv->win_callback) {
 
2384
                int xid;
 
2385
                GtkWindow *parent;
 
2386
 
 
2387
                parent = priv->win_callback (priv->win_user_data);
 
2388
                xid = gdk_x11_drawable_get_xid (GDK_DRAWABLE (GTK_WIDGET (parent)->window));
 
2389
                return xid;
 
2390
        }
 
2391
 
 
2392
        return 0;
2317
2393
}
2318
2394
 
2319
2395
static void
2332
2408
         * a thread. */
2333
2409
        metadata = brasero_metadata_new ();
2334
2410
        priv->metadatas = g_slist_prepend (priv->metadatas, metadata);
 
2411
        brasero_metadata_set_get_xid_callback (metadata, brasero_io_xid_for_metadata, object);
2335
2412
        metadata = brasero_metadata_new ();
2336
2413
        priv->metadatas = g_slist_prepend (priv->metadatas, metadata);
 
2414
        brasero_metadata_set_get_xid_callback (metadata, brasero_io_xid_for_metadata, object);
2337
2415
}
2338
2416
 
2339
2417
static gboolean
2422
2500
                        mount = iter->data;
2423
2501
 
2424
2502
                        BRASERO_UTILS_LOG ("Unmountin volume");
2425
 
                        g_mount_unmount (mount,
2426
 
                                         G_MOUNT_UNMOUNT_NONE,
2427
 
                                         NULL,
2428
 
                                         NULL,
2429
 
                                         NULL);
 
2503
                        g_mount_unmount_with_operation (mount,
 
2504
                                                        G_MOUNT_UNMOUNT_NONE,
 
2505
                                                        NULL,
 
2506
                                                        NULL,
 
2507
                                                        NULL,
 
2508
                                                        NULL);
2430
2509
                        g_object_unref (mount);
2431
2510
                }
2432
2511
        }
2452
2531
                singleton = NULL;
2453
2532
        }
2454
2533
}
 
2534
 
 
2535
void
 
2536
brasero_io_set_parent_window_callback (BraseroIOGetParentWinCb callback,
 
2537
                                       gpointer user_data)
 
2538
{
 
2539
        BraseroIOPrivate *priv;
 
2540
        BraseroIO *self;
 
2541
 
 
2542
        self = brasero_io_get_default ();
 
2543
        priv = BRASERO_IO_PRIVATE (self);
 
2544
        priv->win_callback = callback;
 
2545
        priv->win_user_data = user_data;
 
2546
        g_object_unref (self);
 
2547
}