~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to shell/rb-track-transfer-queue.c

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2011-07-29 16:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 191.
  • Revision ID: james.westby@ubuntu.com-20110729164138-wwicy8nqalm18ck7
Tags: upstream-2.90.1~20110802
ImportĀ upstreamĀ versionĀ 2.90.1~20110802

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "rb-debug.h"
36
36
#include "rb-dialog.h"
37
37
#include "rb-alert-dialog.h"
 
38
#include "rb-gst-media-types.h"
 
39
#include "rb-missing-plugins.h"
38
40
 
39
41
#include <glib/gi18n.h>
40
42
 
 
43
#include <gst/gst.h>
 
44
#include <gst/pbutils/install-plugins.h>
 
45
 
41
46
enum
42
47
{
43
48
        PROP_0,
236
241
        g_signal_emit (queue, signals[TRANSFER_PROGRESS], 0, done, total, fraction, estimate_time_left (queue, fraction));
237
242
}
238
243
 
239
 
#if 0
240
 
static void
241
 
missing_plugins_retry_cb (gpointer inst, gboolean retry, RBTrackTransferQueue *queue)
242
 
{
243
 
        _rb_track_transfer_batch_start (queue->priv->current, G_OBJECT (queue));
244
 
}
245
 
#endif
246
 
 
247
244
static void
248
245
actually_start_batch (RBTrackTransferQueue *queue)
249
246
{
262
259
        _rb_track_transfer_batch_start (queue->priv->current, G_OBJECT (queue));
263
260
}
264
261
 
 
262
static GPtrArray *
 
263
get_missing_plugin_strings (GList *profiles, gboolean get_descriptions)
 
264
{
 
265
        RBEncoder *encoder;
 
266
        GPtrArray *strings;
 
267
        GList *l;
 
268
 
 
269
        encoder = rb_encoder_new ();
 
270
        strings = g_ptr_array_new_with_free_func (g_free);
 
271
        for (l = profiles; l != NULL; l = l->next) {
 
272
                GstEncodingProfile *profile = GST_ENCODING_PROFILE (l->data);
 
273
                char **details, **descriptions;
 
274
                char **d;
 
275
                int i;
 
276
 
 
277
                rb_encoder_get_missing_plugins (encoder, profile, &details, &descriptions);
 
278
                d = get_descriptions ? descriptions : details;
 
279
                for (i = 0; d[i] != NULL; i++) {
 
280
                        g_ptr_array_add (strings, g_strdup (d[i]));
 
281
                }
 
282
                g_strfreev (details);
 
283
                g_strfreev (descriptions);
 
284
        }
 
285
        g_ptr_array_add (strings, NULL);
 
286
        g_object_unref (encoder);
 
287
 
 
288
        return strings;
 
289
}
 
290
 
265
291
static void
266
 
error_response_cb (GtkDialog *dialog, gint response, RBTrackTransferQueue *queue)
 
292
missing_plugins_retry_cb (gpointer inst, gboolean retry, RBTrackTransferQueue *queue)
267
293
{
268
 
        _rb_track_transfer_batch_cancel (queue->priv->current);
269
 
        g_object_unref (queue->priv->current);
 
294
        rb_debug ("plugin install finished (retry %d), checking media types again", retry);
 
295
        g_queue_push_head (queue->priv->batch_queue, queue->priv->current);
270
296
        queue->priv->current = NULL;
271
 
 
272
297
        start_next_batch (queue);
273
 
        gtk_widget_destroy (GTK_WIDGET (dialog));
274
298
}
275
299
 
276
300
static void
277
301
missing_encoder_response_cb (GtkDialog *dialog, gint response, RBTrackTransferQueue *queue)
278
302
{
 
303
        GClosure *retry;
 
304
        GstEncodingTarget *target;
 
305
        GPtrArray *details;
 
306
        GList *profiles;
 
307
        const GList *l;
 
308
        RBEncoder *encoder;
 
309
 
279
310
        switch (response) {
280
311
        case GTK_RESPONSE_YES:
281
312
                /* 'continue' -> start the batch */
 
313
                rb_debug ("starting batch regardless of missing plugins");
282
314
                actually_start_batch (queue);
283
315
                break;
284
316
 
285
317
        case GTK_RESPONSE_CANCEL:
286
318
        case GTK_RESPONSE_DELETE_EVENT:
287
319
                /* 'cancel' -> cancel the batch and start the next one */
 
320
                rb_debug ("cancelling batch");
288
321
                _rb_track_transfer_batch_cancel (queue->priv->current);
289
322
                g_object_unref (queue->priv->current);
290
323
                queue->priv->current = NULL;
292
325
                start_next_batch (queue);
293
326
                break;
294
327
 
295
 
#if 0
296
328
        case GTK_RESPONSE_ACCEPT:
297
 
                /* 'install an encoder' -> try to install an encoder */
298
 
                /*
299
 
                 * probably need RBEncoder API to get missing plugin installer details
300
 
                 * for a specific pipeline or profile or something.
301
 
                 * since gnome-media profiles use specific element names, installing by
302
 
                 * caps won't necessarily install something that works.  guh.
303
 
                 */
304
 
 
 
329
                /* 'install plugins' -> try to install encoder/muxer */
 
330
 
 
331
                /* get profiles that need plugins installed */
 
332
                profiles = NULL;
 
333
                encoder = rb_encoder_new ();
 
334
                g_object_get (queue->priv->current, "encoding-target", &target, NULL);
 
335
                for (l = gst_encoding_target_get_profiles (target); l != NULL; l = l->next) {
 
336
                        GstEncodingProfile *profile = GST_ENCODING_PROFILE (l->data);
 
337
                        char *profile_media_type;
 
338
                        profile_media_type = rb_gst_encoding_profile_get_media_type (profile);
 
339
                        if ((rb_gst_media_type_is_lossless (profile_media_type) == FALSE) &&
 
340
                            rb_encoder_get_missing_plugins (encoder, profile, NULL, NULL)) {
 
341
                                profiles = g_list_append (profiles, profile);
 
342
                        }
 
343
                        g_free (profile_media_type);
 
344
                }
 
345
                g_object_unref (encoder);
 
346
                g_object_unref (target);
 
347
 
 
348
                if (profiles == NULL) {
 
349
                        rb_debug ("apparently we don't need any plugins any more");
 
350
                        actually_start_batch (queue);
 
351
                        break;
 
352
                }
 
353
 
 
354
                rb_debug ("attempting plugin installation");
 
355
                details = get_missing_plugin_strings (profiles, FALSE);
305
356
                retry = g_cclosure_new ((GCallback) missing_plugins_retry_cb,
306
357
                                        g_object_ref (queue),
307
358
                                        (GClosureNotify) g_object_unref);
308
359
                g_closure_set_marshal (retry, g_cclosure_marshal_VOID__BOOLEAN);
309
 
                g_signal_emit (queue,
310
 
                               signals[MISSING_PLUGINS], 0,
311
 
                               details, descriptions, retry,
312
 
                               &processing);
313
 
                if (processing) {
 
360
                if (rb_missing_plugins_install ((const char **)details->pdata, FALSE, retry)) {
314
361
                        rb_debug ("attempting to install missing plugins for transcoding");
315
362
                } else {
316
363
                        rb_debug ("proceeding without the missing plugins for transcoding");
 
364
                        actually_start_batch (queue);
317
365
                }
318
366
 
319
367
                g_closure_sink (retry);
 
368
                g_ptr_array_free (details, TRUE);
 
369
                g_list_free (profiles);
320
370
                break;
321
 
#endif
322
371
 
323
372
        default:
324
373
                g_assert_not_reached ();
325
374
        }
326
375
 
327
376
        gtk_widget_destroy (GTK_WIDGET (dialog));
328
 
        g_object_unref (dialog);
329
377
}
330
378
 
331
379
static void
333
381
{
334
382
        int count;
335
383
        int total;
 
384
        gboolean can_continue;
 
385
        GtkWidget *dialog;
 
386
        GtkWindow *window;
 
387
        GList *profiles = NULL;
 
388
        char *message;
336
389
 
337
390
        if (queue->priv->current != NULL) {
338
391
                return;
350
403
        queue->priv->overwrite_decision = OVERWRITE_PROMPT;
351
404
        g_object_get (queue->priv->current, "total-entries", &total, NULL);
352
405
 
353
 
        count = rb_track_transfer_batch_check_media_types (queue->priv->current);
354
 
        rb_debug ("%d tracks in the batch, %d of which cannot be transferred", total, count);
355
 
        if (total == 0) {
356
 
                rb_debug ("what is this batch doing here anyway");
357
 
        } else if (count == total) {
358
 
                GtkWindow *window;
359
 
                GtkWidget *dialog;
360
 
                g_object_get (queue->priv->shell, "window", &window, NULL);
361
 
                /* once we do encoder installation this should turn into a
362
 
                 * normal confirmation dialog with no 'continue' option.
363
 
                 */
364
 
                dialog = rb_alert_dialog_new (window,
365
 
                                              0,
366
 
                                              GTK_MESSAGE_ERROR,
367
 
                                              GTK_BUTTONS_CANCEL,
368
 
                                              _("Unable to transfer tracks"),
369
 
                                              _("None of the tracks to be transferred "
370
 
                                                "are in a format supported by the target "
371
 
                                                "device, and no encoders are available "
372
 
                                                "for the supported formats."));
373
 
                rb_alert_dialog_set_details_label (RB_ALERT_DIALOG (dialog), NULL);
374
 
                g_object_unref (window);
375
 
                g_signal_connect_object (dialog, "response", G_CALLBACK (error_response_cb), queue, 0);
376
 
                gtk_widget_show (dialog);
377
 
                return;
378
 
 
379
 
        } else if (count > 0) {
380
 
                GtkWindow *window;
381
 
                GtkWidget *dialog;
382
 
                char *text;
383
 
 
384
 
 
385
 
                rb_debug ("can't find a supported media type for %d/%d files, prompting", count, total);
386
 
                text = g_strdup_printf (_("%d of the %d files to be transferred are not in a format supported"
387
 
                                          " by the target device, and no encoders are available for the"
388
 
                                          " supported formats."),
389
 
                                        count, total);
390
 
                g_object_get (queue->priv->shell, "window", &window, NULL);
391
 
                dialog = rb_alert_dialog_new (window,
392
 
                                              0,
393
 
                                              GTK_MESSAGE_WARNING,
394
 
                                              GTK_BUTTONS_NONE,
395
 
                                              _("Unable to transfer all tracks. Do you want to continue?"),
396
 
                                              text);
397
 
                g_object_unref (window);
398
 
                g_free (text);
399
 
 
400
 
                rb_alert_dialog_set_details_label (RB_ALERT_DIALOG (dialog), NULL);
401
 
                gtk_dialog_add_buttons (GTK_DIALOG (dialog),
402
 
                                        _("_Cancel"), GTK_RESPONSE_CANCEL,
403
 
                                        _("C_ontinue"), GTK_RESPONSE_YES,
404
 
                                        /*_("_Install an encoder"), GTK_RESPONSE_ACCEPT,*/
405
 
                                        NULL);
406
 
 
407
 
                g_signal_connect_object (dialog, "response", G_CALLBACK (missing_encoder_response_cb), queue, 0);
408
 
                gtk_widget_show (dialog);
409
 
                return;
410
 
        }
411
 
 
412
 
        actually_start_batch (queue);
 
406
        count = 0;
 
407
        can_continue = rb_track_transfer_batch_check_profiles (queue->priv->current,
 
408
                                                               &profiles,
 
409
                                                               &count);
 
410
 
 
411
        if (can_continue && count == 0 && profiles == NULL) {
 
412
                /* no problems, go ahead */
 
413
                actually_start_batch (queue);
 
414
                return;
 
415
        }
 
416
 
 
417
        if (profiles == NULL) {
 
418
                if (total == 1) {
 
419
                        message = g_strdup (_("This file cannot be transferred as it is not in a "
 
420
                                              "format supported by the target device and no suitable "
 
421
                                              "encoding profiles are available."));
 
422
                } else {
 
423
                        message = g_strdup_printf (_("%d of the %d files cannot be transferred as "
 
424
                                                     "they must be converted into a format supported "
 
425
                                                     "by the target device but no suitable encoding "
 
426
                                                     "profiles are available."), count, total);
 
427
                }
 
428
        } else {
 
429
                GPtrArray *descriptions;
 
430
                GstEncodingTarget *target;
 
431
                char *plugins;
 
432
                gboolean is_library;
 
433
 
 
434
                descriptions = get_missing_plugin_strings (profiles, TRUE);
 
435
                plugins = g_strjoinv ("\n", (char **)descriptions->pdata);
 
436
 
 
437
                /* this is a tiny bit hackish */
 
438
                g_object_get (queue->priv->current, "encoding-target", &target, NULL);
 
439
                is_library = (g_strcmp0 (gst_encoding_target_get_name (target), "rhythmbox-library") == 0);
 
440
                gst_encoding_target_unref (target);
 
441
 
 
442
                if (is_library) {
 
443
                        /* XXX should provide the option of picking a different format? */
 
444
                        message = g_strdup_printf (_("Additional software is required to encode media "
 
445
                                                     "in your preferred format:\n%s"), plugins);
 
446
                } else if (total == 1) {
 
447
                        message = g_strdup_printf (_("Additional software is required to convert this "
 
448
                                                     "file into a format supported by the target "
 
449
                                                     "device:\n%s"), plugins);
 
450
                } else {
 
451
                        message = g_strdup_printf (_("Additional software is required to convert %d "
 
452
                                                     "of the %d files to be transferred into a format "
 
453
                                                     "supported by the target device:\n%s"),
 
454
                                                     count, total, plugins);
 
455
                }
 
456
 
 
457
                g_free (plugins);
 
458
                g_ptr_array_free (descriptions, TRUE);
 
459
        }
 
460
 
 
461
        g_object_get (queue->priv->shell, "window", &window, NULL);
 
462
        dialog = rb_alert_dialog_new (window,
 
463
                                      0,
 
464
                                      GTK_MESSAGE_ERROR,
 
465
                                      GTK_BUTTONS_NONE,
 
466
                                      _("Unable to transfer tracks"),
 
467
                                      message);
 
468
        g_object_unref (window);
 
469
        g_free (message);
 
470
 
 
471
        gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel the transfer"), GTK_RESPONSE_CANCEL);
 
472
        if (can_continue) {
 
473
                gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip these files"), GTK_RESPONSE_YES);
 
474
        }
 
475
        if (profiles != NULL && gst_install_plugins_supported ()) {
 
476
                gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Install"), GTK_RESPONSE_ACCEPT);
 
477
        }
 
478
 
 
479
        rb_alert_dialog_set_details_label (RB_ALERT_DIALOG (dialog), NULL);
 
480
        g_signal_connect_object (dialog, "response", G_CALLBACK (missing_encoder_response_cb), queue, 0);
 
481
        gtk_widget_show (dialog);
 
482
 
 
483
        if (profiles != NULL) {
 
484
                g_list_free (profiles);
 
485
        }
413
486
}
414
487
 
415
488
/**