~snaggen/rhythmbox/bpm

« back to all changes in this revision

Viewing changes to sources/rb-playlist-source-recorder.c

  • Committer: Jonathan Matthew
  • Author(s): Jonathan Matthew
  • Date: 2007-01-07 12:16:12 UTC
  • Revision ID: git-v1:5b6958ea3cf24f2c8bcfa15b9cab1fc7798b7305
Moved lots of files around. Now everything should be in the directory it's

2007-01-07  Jonathan Matthew  <jonathan@kaolin.wh9.net>

        Moved lots of files around.  Now everything should be in the directory
        it's built in and all plugin-specific files should be installed into
        the plugin directory.

        * plugins/audioscrobbler/rb-audioscrobbler-plugin.c:
        (impl_create_configure_dialog):
        * plugins/audioscrobbler/rb-audioscrobbler.c:
        (rb_audioscrobbler_class_init), (rb_audioscrobbler_dispose),
        (rb_audioscrobbler_finalize),
        (rb_audioscrobbler_get_config_widget):
        * plugins/audioscrobbler/rb-audioscrobbler.h:
        Use rb_plugin_find_file where needed.

        * widgets/rb-uri-dialog.c: (rb_uri_dialog_class_init),
        (rb_uri_dialog_init), (rb_uri_dialog_finalize),
        (rb_uri_dialog_new), (rb_uri_dialog_response_cb),
        (rb_uri_dialog_text_changed):
        * widgets/rb-uri-dialog.h:
        New common 'enter a URI' dialog, used by iradio and podcast code.

        * plugins/iradio/rb-iradio-plugin.c: (impl_activate):
        * plugins/iradio/rb-iradio-source.c:
        (rb_iradio_source_constructor), (rb_iradio_source_new),
        (impl_song_properties), (rb_iradio_source_first_time_changed),
        (new_station_location_added), (rb_iradio_source_cmd_new_station):
        * plugins/iradio/rb-iradio-source.h:
        * plugins/iradio/rb-station-properties-dialog.c:
        (rb_station_properties_dialog_class_init),
        (rb_station_properties_dialog_init),
        (rb_station_properties_dialog_constructor),
        (rb_station_properties_dialog_set_property),
        (rb_station_properties_dialog_get_property),
        (rb_station_properties_dialog_new):
        * plugins/iradio/rb-station-properties-dialog.h:
        Use the common URI dialog, use rb_plugin_find_file where needed.

        * sources/rb-podcast-source.c:
        (rb_podcast_source_location_added_cb),
        (rb_podcast_source_cmd_new_podcast):
        Use the common URI dialog.

svn path=/trunk/; revision=4725

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2
 
 *
3
 
 *  arch-tag: Implementation of playlist source recorder object
4
 
 *
5
 
 *  Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org>
6
 
 *  Copyright (C) 2003 Colin Walters <walters@gnome.org>
7
 
 *  Copyright (C) 2004-2006 William Jon McCann <mccann@jhu.edu>
8
 
 *
9
 
 *  This program is free software; you can redistribute it and/or modify
10
 
 *  it under the terms of the GNU General Public License as published by
11
 
 *  the Free Software Foundation; either version 2 of the License, or
12
 
 *  (at your option) any later version.
13
 
 *
14
 
 *  This program is distributed in the hope that it will be useful,
15
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 *  GNU General Public License for more details.
18
 
 *
19
 
 *  You should have received a copy of the GNU General Public License
20
 
 *  along with this program; if not, write to the Free Software
21
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
22
 
 *
23
 
 */
24
 
 
25
 
#include "config.h"
26
 
 
27
 
#include <stdlib.h>
28
 
#include <unistd.h>
29
 
#include <string.h>
30
 
#include <errno.h>
31
 
#include <math.h>
32
 
 
33
 
#include <glib/gprintf.h>
34
 
#include <glib/gi18n.h>
35
 
#include <gtk/gtk.h>
36
 
#include <libgnomevfs/gnome-vfs-uri.h>
37
 
#include <libgnomevfs/gnome-vfs-utils.h>
38
 
#include <glade/glade.h>
39
 
#include <nautilus-burn-drive.h>
40
 
#include <nautilus-burn-drive-selection.h>
41
 
 
42
 
#ifndef NAUTILUS_BURN_CHECK_VERSION
43
 
#define NAUTILUS_BURN_CHECK_VERSION(a,b,c) FALSE
44
 
#endif
45
 
 
46
 
#if NAUTILUS_BURN_CHECK_VERSION(2,15,3)
47
 
#include <nautilus-burn.h>
48
 
#endif
49
 
 
50
 
#include "rb-file-helpers.h"
51
 
#include "rb-glade-helpers.h"
52
 
#include "rb-preferences.h"
53
 
#include "rb-dialog.h"
54
 
#include "rb-util.h"
55
 
#include "rb-shell.h"
56
 
#include "rb-playlist-source.h"
57
 
#include "rb-playlist-source-recorder.h"
58
 
#include "rb-debug.h"
59
 
#include "eel-gconf-extensions.h"
60
 
 
61
 
#ifndef HAVE_MKDTEMP
62
 
#include "mkdtemp.h"
63
 
#else
64
 
extern char *mkdtemp (char *template);
65
 
#endif
66
 
 
67
 
/* NAUTILUS_BURN_DRIVE_SIZE_TO_TIME was added in 2.12 */
68
 
#ifndef NAUTILUS_BURN_DRIVE_SIZE_TO_TIME
69
 
#define nautilus_burn_drive_eject _nautilus_burn_drive_eject
70
 
#define nautilus_burn_drive_new_from_path _nautilus_burn_drive_new_from_path
71
 
#define nautilus_burn_drive_media_type_get_string _nautilus_burn_drive_media_type_get_string
72
 
#endif
73
 
/* NAUTILUS_BURN_DRIVE_SIZE_TO_TIME was added in 2.14 */
74
 
#ifndef HAVE_BURN_DRIVE_UNREF
75
 
#define nautilus_burn_drive_unref nautilus_burn_drive_free
76
 
#define nautilus_burn_drive_ref nautilus_burn_drive_copy
77
 
#endif
78
 
 
79
 
#include "rb-recorder.h"
80
 
 
81
 
#define CONF_STATE_BURN_SPEED CONF_PREFIX "/state/burn_speed"
82
 
 
83
 
#define AUDIO_BYTERATE (2 * 44100 * 2)
84
 
#define MAX_PLAYLIST_DURATION 6000
85
 
 
86
 
static void rb_playlist_source_recorder_class_init (RBPlaylistSourceRecorderClass *klass);
87
 
static void rb_playlist_source_recorder_init       (RBPlaylistSourceRecorder *source);
88
 
static void rb_playlist_source_recorder_dispose    (GObject *object);
89
 
static void rb_playlist_source_recorder_finalize   (GObject *object);
90
 
 
91
 
void        rb_playlist_source_recorder_device_changed_cb  (NautilusBurnDriveSelection *selection,
92
 
                                                            const char                 *device_path,
93
 
                                                            RBPlaylistSourceRecorder   *source);
94
 
 
95
 
GtkWidget * rb_playlist_source_recorder_device_menu_create (void);
96
 
 
97
 
typedef struct
98
 
{
99
 
        char  *artist;
100
 
        char  *title;
101
 
        char  *uri;
102
 
        gulong duration;
103
 
} RBRecorderSong;
104
 
 
105
 
struct RBPlaylistSourceRecorderPrivate
106
 
{
107
 
        GtkWidget   *parent;
108
 
 
109
 
        RBShell     *shell;
110
 
 
111
 
        char        *name;
112
 
 
113
 
        RBRecorder  *recorder;
114
 
        GSList      *songs;
115
 
        GSList      *current;
116
 
        GTimer      *timer;
117
 
        guint64      start_pos;
118
 
 
119
 
        GtkWidget   *cd_icon;
120
 
        GtkWidget   *vbox;
121
 
        GtkWidget   *multiple_copies_checkbutton;
122
 
        GtkWidget   *cancel_button;
123
 
        GtkWidget   *burn_button;
124
 
        GtkWidget   *message_label;
125
 
        GtkWidget   *progress_label;
126
 
        GtkWidget   *progress;
127
 
        GtkWidget   *device_menu;
128
 
        GtkWidget   *speed_combobox;
129
 
        GtkWidget   *options_box;
130
 
        GtkWidget   *progress_frame;
131
 
 
132
 
        gboolean     burning;
133
 
        gboolean     already_converted;
134
 
        gboolean     handling_error;
135
 
        gboolean     confirmed_exit;
136
 
 
137
 
        char        *tmp_dir;
138
 
};
139
 
 
140
 
typedef enum {
141
 
        NAME_CHANGED,
142
 
        FILE_ADDED,
143
 
        ERROR,
144
 
        LAST_SIGNAL
145
 
} RBPlaylistSourceRecorderSignalType;
146
 
 
147
 
static guint rb_playlist_source_recorder_signals [LAST_SIGNAL] = { 0 };
148
 
 
149
 
#define RB_PLAYLIST_SOURCE_RECORDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_PLAYLIST_SOURCE_RECORDER, RBPlaylistSourceRecorderPrivate))
150
 
 
151
 
G_DEFINE_TYPE(RBPlaylistSourceRecorder, rb_playlist_source_recorder, GTK_TYPE_DIALOG)
152
 
 
153
 
static void
154
 
rb_playlist_source_recorder_style_set (GtkWidget *widget,
155
 
                                       GtkStyle  *previous_style)
156
 
{
157
 
        GtkDialog *dialog;
158
 
 
159
 
        if (GTK_WIDGET_CLASS (rb_playlist_source_recorder_parent_class)->style_set)
160
 
                GTK_WIDGET_CLASS (rb_playlist_source_recorder_parent_class)->style_set (widget, previous_style);
161
 
 
162
 
        dialog = GTK_DIALOG (widget);
163
 
 
164
 
        gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 12);
165
 
        gtk_box_set_spacing (GTK_BOX (dialog->vbox), 24);
166
 
 
167
 
        gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 0);
168
 
        gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
169
 
}
170
 
 
171
 
static void
172
 
rb_playlist_source_recorder_class_init (RBPlaylistSourceRecorderClass *klass)
173
 
{
174
 
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
175
 
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
176
 
 
177
 
        widget_class->style_set = rb_playlist_source_recorder_style_set;
178
 
 
179
 
        object_class->dispose = rb_playlist_source_recorder_dispose;
180
 
        object_class->finalize = rb_playlist_source_recorder_finalize;
181
 
 
182
 
        rb_playlist_source_recorder_signals [NAME_CHANGED] =
183
 
                g_signal_new ("name_changed",
184
 
                              G_OBJECT_CLASS_TYPE (object_class),
185
 
                              G_SIGNAL_RUN_LAST,
186
 
                              0,
187
 
                              NULL, NULL,
188
 
                              g_cclosure_marshal_VOID__STRING,
189
 
                              G_TYPE_NONE,
190
 
                              1,
191
 
                              G_TYPE_STRING);
192
 
 
193
 
        rb_playlist_source_recorder_signals [FILE_ADDED] =
194
 
                g_signal_new ("file_added",
195
 
                              G_OBJECT_CLASS_TYPE (object_class),
196
 
                              G_SIGNAL_RUN_LAST,
197
 
                              0,
198
 
                              NULL, NULL,
199
 
                              g_cclosure_marshal_VOID__STRING,
200
 
                              G_TYPE_NONE,
201
 
                              1,
202
 
                              G_TYPE_STRING);
203
 
 
204
 
        g_type_class_add_private (klass, sizeof (RBPlaylistSourceRecorderPrivate));
205
 
}
206
 
 
207
 
GtkWidget *
208
 
rb_playlist_source_recorder_device_menu_create (void)
209
 
{
210
 
        GtkWidget *widget;
211
 
        char      *value;
212
 
 
213
 
        widget = nautilus_burn_drive_selection_new ();
214
 
        g_object_set (widget, "file-image", FALSE, NULL);
215
 
        g_object_set (widget, "show-recorders-only", TRUE, NULL);
216
 
 
217
 
        value = eel_gconf_get_string (CONF_STATE_BURN_DEVICE);
218
 
        if (value) {
219
 
                nautilus_burn_drive_selection_set_device (NAUTILUS_BURN_DRIVE_SELECTION (widget),
220
 
                                                          value);
221
 
                g_free (value);
222
 
        }
223
 
 
224
 
        gtk_widget_show (widget);
225
 
 
226
 
        return widget;
227
 
}
228
 
 
229
 
static const NautilusBurnDrive *
230
 
lookup_current_recorder (RBPlaylistSourceRecorder *source)
231
 
{
232
 
        const NautilusBurnDrive *drive;
233
 
 
234
 
        drive = nautilus_burn_drive_selection_get_drive (NAUTILUS_BURN_DRIVE_SELECTION (source->priv->device_menu));
235
 
 
236
 
        return drive;
237
 
}
238
 
 
239
 
static int
240
 
get_speed_selection (GtkWidget *combobox)
241
 
{
242
 
        int           speed;
243
 
        GtkTreeModel *model;
244
 
        GtkTreeIter   iter;
245
 
 
246
 
        speed = 0;
247
 
 
248
 
        if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &iter))
249
 
                return speed;
250
 
 
251
 
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
252
 
        gtk_tree_model_get (model, &iter, 1, &speed, -1);
253
 
 
254
 
        return speed;
255
 
}
256
 
 
257
 
#ifndef HAVE_BURN_DRIVE_GET_WRITE_SPEEDS
258
 
 
259
 
#define nautilus_burn_drive_get_write_speeds get_write_speeds
260
 
 
261
 
static const int *
262
 
get_write_speeds (NautilusBurnDrive *drive)
263
 
{
264
 
        int  max_speed;
265
 
        int  i;
266
 
        static int *write_speeds = NULL;
267
 
 
268
 
        if (write_speeds == NULL) {
269
 
                max_speed = drive->max_speed_write;
270
 
                write_speeds = g_new0 (int, max_speed + 1);
271
 
 
272
 
                for (i = 0; i < max_speed; i++) {
273
 
                        write_speeds [i] = max_speed - i;
274
 
                }
275
 
        }
276
 
 
277
 
        return (const int*)write_speeds;
278
 
}
279
 
#endif
280
 
 
281
 
static void
282
 
update_speed_combobox (RBPlaylistSourceRecorder *source)
283
 
{
284
 
        GtkWidget               *combobox;
285
 
        char                    *name;
286
 
        int                      i;
287
 
        int                      default_speed;
288
 
        int                      default_speed_index;
289
 
        const NautilusBurnDrive *drive;
290
 
        GtkTreeModel            *model;
291
 
        GtkTreeIter              iter;
292
 
 
293
 
        /* Find active recorder: */
294
 
        drive = lookup_current_recorder (source);
295
 
 
296
 
        /* add speed items: */
297
 
        combobox = source->priv->speed_combobox;
298
 
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
299
 
        gtk_list_store_clear (GTK_LIST_STORE (model));
300
 
 
301
 
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
302
 
        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
303
 
                            0, _("Maximum possible"),
304
 
                            1, 0,
305
 
                            -1);
306
 
 
307
 
        default_speed = eel_gconf_get_integer (CONF_STATE_BURN_SPEED);
308
 
        default_speed_index = -1;
309
 
 
310
 
        i = 0;
311
 
        if (drive) {
312
 
                const int *write_speeds;
313
 
 
314
 
                write_speeds = nautilus_burn_drive_get_write_speeds ((NautilusBurnDrive *)drive);
315
 
 
316
 
                for (i = 0; write_speeds [i] > 0; i++) {
317
 
 
318
 
#ifdef NAUTILUS_BURN_DRIVE_CD_SPEED
319
 
                        name = g_strdup_printf ("%d \303\227", (int)NAUTILUS_BURN_DRIVE_CD_SPEED (write_speeds [i]));
320
 
#else
321
 
                        name = g_strdup_printf ("%d \303\227", write_speeds [i]);
322
 
#endif
323
 
 
324
 
                        if (write_speeds [i] == default_speed) {
325
 
                                default_speed_index = i + 1;
326
 
                        }
327
 
 
328
 
                        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
329
 
                        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
330
 
                                            0, name,
331
 
                                            1, write_speeds [i],
332
 
                                            -1);
333
 
                        g_free (name);
334
 
                }
335
 
 
336
 
        }
337
 
 
338
 
        /* Disable speed if no items in list */
339
 
        gtk_widget_set_sensitive (combobox, i > 0);
340
 
 
341
 
        /* if the default speed was not set then make it the minimum for safety */
342
 
        if (default_speed_index == -1) {
343
 
                default_speed_index = i;
344
 
        }
345
 
 
346
 
        /* for now assume equivalence between index in comboxbox and speed */
347
 
        gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), default_speed_index);
348
 
}
349
 
 
350
 
void
351
 
rb_playlist_source_recorder_device_changed_cb (NautilusBurnDriveSelection *selection,
352
 
                                               const char                 *device_path,
353
 
                                               RBPlaylistSourceRecorder   *source)
354
 
{
355
 
        if (!device_path)
356
 
                return;
357
 
 
358
 
        eel_gconf_set_string (CONF_STATE_BURN_DEVICE, device_path);
359
 
 
360
 
        update_speed_combobox (source);
361
 
}
362
 
 
363
 
static void
364
 
set_media_device (RBPlaylistSourceRecorder *source)
365
 
{
366
 
        const char *device;
367
 
        GError     *error;
368
 
 
369
 
        device = nautilus_burn_drive_selection_get_device (NAUTILUS_BURN_DRIVE_SELECTION (source->priv->device_menu));
370
 
 
371
 
        if (device && strcmp (device, "")) {
372
 
                rb_recorder_set_device (source->priv->recorder, device, &error);
373
 
                if (error) {
374
 
                        g_warning (_("Invalid writer device: %s"), device);
375
 
                        /* ignore and let rb_recorder try to find a default */
376
 
                }
377
 
        }
378
 
}
379
 
 
380
 
static void
381
 
set_message_text (RBPlaylistSourceRecorder *source,
382
 
                  const char               *message,
383
 
                  ...)
384
 
{
385
 
        char   *markup;
386
 
        char   *text = "";
387
 
        va_list args;
388
 
 
389
 
        va_start (args, message);
390
 
        g_vasprintf (&text, message, args);
391
 
        va_end (args);
392
 
 
393
 
        markup = g_strdup_printf ("%s", text);
394
 
 
395
 
        gtk_label_set_text (GTK_LABEL (source->priv->message_label), markup);
396
 
        g_free (markup);
397
 
        g_free (text);
398
 
}
399
 
 
400
 
static gboolean
401
 
response_idle_cb (RBPlaylistSourceRecorder *source)
402
 
{
403
 
        GDK_THREADS_ENTER ();
404
 
        gtk_dialog_response (GTK_DIALOG (source),
405
 
                             GTK_RESPONSE_CANCEL);
406
 
        GDK_THREADS_LEAVE ();
407
 
 
408
 
        return FALSE;
409
 
}
410
 
 
411
 
static gboolean
412
 
error_dialog_response_cb (GtkWidget *dialog,
413
 
                          gint       response_id,
414
 
                          gpointer   data)
415
 
{
416
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
417
 
 
418
 
        gtk_widget_destroy (GTK_WIDGET (dialog));
419
 
 
420
 
        g_idle_add ((GSourceFunc)response_idle_cb, source);
421
 
 
422
 
        return TRUE;
423
 
}
424
 
 
425
 
static void
426
 
error_dialog (RBPlaylistSourceRecorder *source,
427
 
              const char               *primary,
428
 
              const char               *secondary,
429
 
              ...)
430
 
{
431
 
        char      *text = "";
432
 
        va_list    args;
433
 
        GtkWidget *dialog;
434
 
 
435
 
        va_start (args, secondary);
436
 
        g_vasprintf (&text, secondary, args);
437
 
        va_end (args);
438
 
 
439
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (source),
440
 
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
441
 
                                         GTK_MESSAGE_ERROR,
442
 
                                         GTK_BUTTONS_CLOSE,
443
 
                                         primary);
444
 
 
445
 
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
446
 
                                                  text);
447
 
 
448
 
        gtk_window_set_title (GTK_WINDOW (dialog), "");
449
 
 
450
 
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
451
 
 
452
 
        g_signal_connect (dialog,
453
 
                          "response",
454
 
                          G_CALLBACK (error_dialog_response_cb),
455
 
                          source);
456
 
 
457
 
        gtk_widget_show (dialog);
458
 
 
459
 
        g_free (text);
460
 
}
461
 
 
462
 
/* Adapted from totem_time_to_string_text */
463
 
static char *
464
 
time_to_string_text (long time)
465
 
{
466
 
        char *secs, *mins, *hours, *string;
467
 
        int sec, min, hour;
468
 
 
469
 
        sec = time % 60;
470
 
        time = time - sec;
471
 
        min = (time % (60 * 60)) / 60;
472
 
        time = time - (min * 60);
473
 
        hour = time / (60 * 60);
474
 
 
475
 
        hours = g_strdup_printf (ngettext ("%d hour", "%d hours", hour), hour);
476
 
 
477
 
        mins = g_strdup_printf (ngettext ("%d minute",
478
 
                                          "%d minutes", min), min);
479
 
 
480
 
        secs = g_strdup_printf (ngettext ("%d second",
481
 
                                          "%d seconds", sec), sec);
482
 
 
483
 
        if (hour > 0) {
484
 
                /* hour:minutes:seconds */
485
 
                string = g_strdup_printf (_("%s %s %s"), hours, mins, secs);
486
 
        } else if (min > 0) {
487
 
                /* minutes:seconds */
488
 
                string = g_strdup_printf (_("%s %s"), mins, secs);
489
 
        } else if (sec > 0) {
490
 
                /* seconds */
491
 
                string = g_strdup_printf (_("%s"), secs);
492
 
        } else {
493
 
                /* 0 seconds */
494
 
                string = g_strdup (_("0 seconds"));
495
 
        }
496
 
 
497
 
        g_free (hours);
498
 
        g_free (mins);
499
 
        g_free (secs);
500
 
 
501
 
        return string;
502
 
}
503
 
 
504
 
static void
505
 
progress_set_time (GtkWidget *progress,
506
 
                   long       seconds)
507
 
{
508
 
        char *text;
509
 
 
510
 
        if (seconds >= 0) {
511
 
                char *remaining;
512
 
                remaining = time_to_string_text (seconds);
513
 
                text = g_strdup_printf (_("About %s left"), remaining);
514
 
                g_free (remaining);
515
 
        } else {
516
 
                text = g_strdup (" ");
517
 
        }
518
 
 
519
 
        gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress), text);
520
 
        g_free (text);
521
 
}
522
 
 
523
 
static void
524
 
progress_set_fraction (GtkWidget *progress,
525
 
                       gdouble    fraction)
526
 
{
527
 
        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), fraction);
528
 
}
529
 
 
530
 
#ifndef NAUTILUS_BURN_DRIVE_SIZE_TO_TIME
531
 
/* copied from nautilus-burn-drive 2.12 */
532
 
static gboolean
533
 
_nautilus_burn_drive_eject (NautilusBurnDrive *drive)
534
 
{
535
 
        char    *cmd;
536
 
        gboolean res;
537
 
 
538
 
        g_return_val_if_fail (drive != NULL, FALSE);
539
 
 
540
 
        if (drive->device == NULL)
541
 
                return FALSE;
542
 
 
543
 
        cmd = g_strdup_printf ("eject %s", drive->device);
544
 
        res = g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL);
545
 
        g_free (cmd);
546
 
 
547
 
        /* delay a bit to make sure eject finishes */
548
 
        sleep (2);
549
 
 
550
 
        return res;
551
 
}
552
 
/* copied from nautilus-burn-drive 2.12 */
553
 
static NautilusBurnDrive *
554
 
_nautilus_burn_drive_new_from_path (const char *device)
555
 
{
556
 
        GList             *drives, *l;
557
 
        NautilusBurnDrive *drive;
558
 
 
559
 
        drives = nautilus_burn_drive_get_list (FALSE, FALSE);
560
 
 
561
 
        drive = NULL;
562
 
 
563
 
        for (l = drives; l != NULL; l = l->next) {
564
 
                NautilusBurnDrive *d = l->data;
565
 
                if (g_str_equal (device, d->device)) {
566
 
                        drive = nautilus_burn_drive_ref (d);
567
 
                }
568
 
        }
569
 
 
570
 
        g_list_foreach (drives, (GFunc)nautilus_burn_drive_unref, NULL);
571
 
        g_list_free (drives);
572
 
 
573
 
        return drive;
574
 
}
575
 
 
576
 
/* copied from nautilus-burn-drive 2.12 */
577
 
static const char *
578
 
_nautilus_burn_drive_media_type_get_string (NautilusBurnMediaType type)
579
 
{
580
 
        switch (type) {
581
 
        case NAUTILUS_BURN_MEDIA_TYPE_BUSY:
582
 
                return _("Could not determine media type because CD drive is busy");
583
 
        case NAUTILUS_BURN_MEDIA_TYPE_ERROR:
584
 
                return _("Couldn't open media");
585
 
        case NAUTILUS_BURN_MEDIA_TYPE_UNKNOWN:
586
 
                return _("Unknown Media");
587
 
        case NAUTILUS_BURN_MEDIA_TYPE_CD:
588
 
                return _("Commercial CD or Audio CD");
589
 
        case NAUTILUS_BURN_MEDIA_TYPE_CDR:
590
 
                return _("CD-R");
591
 
        case NAUTILUS_BURN_MEDIA_TYPE_CDRW:
592
 
                return _("CD-RW");
593
 
        case NAUTILUS_BURN_MEDIA_TYPE_DVD:
594
 
                return _("DVD");
595
 
        case NAUTILUS_BURN_MEDIA_TYPE_DVDR:
596
 
                return _("DVD-R, or DVD-RAM");
597
 
        case NAUTILUS_BURN_MEDIA_TYPE_DVDRW:
598
 
                return _("DVD-RW");
599
 
        case NAUTILUS_BURN_MEDIA_TYPE_DVD_RAM:
600
 
                return _("DVD-RAM");
601
 
        case NAUTILUS_BURN_MEDIA_TYPE_DVD_PLUS_R:
602
 
                return _("DVD+R");
603
 
        case NAUTILUS_BURN_MEDIA_TYPE_DVD_PLUS_RW:
604
 
                return _("DVD+RW");
605
 
        default:
606
 
                break;
607
 
        }
608
 
 
609
 
        return _("Broken media type");
610
 
}
611
 
#endif /* NAUTILUS_BURN_DRIVE_SIZE_TO_TIME */
612
 
 
613
 
static int
614
 
burn_cd (RBPlaylistSourceRecorder *source,
615
 
         GError                  **error)
616
 
{
617
 
        int res;
618
 
        int speed;
619
 
 
620
 
        speed = 1;
621
 
 
622
 
        set_media_device (source);
623
 
 
624
 
        set_message_text (source, _("Writing audio to CD"));
625
 
 
626
 
        speed = get_speed_selection (source->priv->speed_combobox);
627
 
 
628
 
        progress_set_fraction (source->priv->progress, 0);
629
 
        progress_set_time (source->priv->progress, -1);
630
 
 
631
 
        source->priv->burning = TRUE;
632
 
        res = rb_recorder_burn (source->priv->recorder, speed, error);
633
 
        source->priv->burning = FALSE;
634
 
 
635
 
        if (res == RB_RECORDER_RESULT_FINISHED) {
636
 
                NautilusBurnDrive *drive;
637
 
                gboolean           do_another;
638
 
                const char        *finished_msg;
639
 
 
640
 
                finished_msg = _("Finished creating audio CD.");
641
 
 
642
 
                rb_shell_hidden_notify (source->priv->shell, 0, finished_msg, source->priv->cd_icon, "", FALSE);
643
 
 
644
 
                /* save the write speed that was used */
645
 
                eel_gconf_set_integer (CONF_STATE_BURN_SPEED, speed);
646
 
 
647
 
                /* Always eject the disk after writing.  Too many drives mess up otherwise */
648
 
                drive = (NautilusBurnDrive *)lookup_current_recorder (source);
649
 
                nautilus_burn_drive_eject (drive);
650
 
 
651
 
                do_another = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (source->priv->multiple_copies_checkbutton));
652
 
                if (!do_another) {
653
 
                        set_message_text (source, finished_msg);
654
 
                        gtk_widget_set_sensitive (GTK_WIDGET (source), FALSE);
655
 
                        g_idle_add ((GSourceFunc)response_idle_cb, source);
656
 
                        return res;
657
 
                }
658
 
                set_message_text (source, _("Finished creating audio CD.\nCreate another copy?"));
659
 
        } else if (res == RB_RECORDER_RESULT_ERROR) {
660
 
                set_message_text (source, _("Writing failed.  Try again?"));
661
 
        } else {
662
 
                set_message_text (source, _("Writing cancelled.  Try again?"));
663
 
        }
664
 
 
665
 
        progress_set_fraction (source->priv->progress, 0);
666
 
        progress_set_time (source->priv->progress, -1);
667
 
 
668
 
        gtk_widget_set_sensitive (GTK_WIDGET (source->priv->burn_button), TRUE);
669
 
        gtk_widget_set_sensitive (GTK_WIDGET (source->priv->options_box), TRUE);
670
 
 
671
 
        return res;
672
 
}
673
 
 
674
 
static char *
675
 
get_song_description (RBRecorderSong *song)
676
 
{
677
 
        char *desc = NULL;
678
 
 
679
 
        if (song->artist && song->title)
680
 
                desc = g_strdup_printf ("%s - %s", song->title, song->artist);
681
 
        else if (song->title)
682
 
                desc = g_strdup (song->title);
683
 
        else if (song->artist)
684
 
                desc = g_strdup (song->artist);
685
 
 
686
 
        return desc;
687
 
}
688
 
 
689
 
static void
690
 
write_file (RBPlaylistSourceRecorder *source,
691
 
            GError                  **error)
692
 
{
693
 
        RBRecorderSong *song   = source->priv->current->data;
694
 
        char           *cdtext = NULL;
695
 
        char           *markup;
696
 
 
697
 
        gtk_widget_set_sensitive (source->priv->progress_frame, TRUE);
698
 
 
699
 
        cdtext = get_song_description (song);
700
 
 
701
 
        markup = g_markup_printf_escaped ("<i>Converting '%s'</i>", cdtext);
702
 
        gtk_label_set_markup (GTK_LABEL (source->priv->progress_label), markup);
703
 
        g_free (markup);
704
 
 
705
 
        rb_recorder_open (source->priv->recorder, song->uri, cdtext, error);
706
 
 
707
 
        g_free (cdtext);
708
 
 
709
 
        if (error && *error) {
710
 
                return;
711
 
        }
712
 
 
713
 
        rb_recorder_write (source->priv->recorder, error);
714
 
        if (error && *error) {
715
 
                return;
716
 
        }
717
 
}
718
 
 
719
 
static gboolean
720
 
burn_cd_idle (RBPlaylistSourceRecorder *source)
721
 
{
722
 
        GError *error = NULL;
723
 
        int     res;
724
 
 
725
 
        GDK_THREADS_ENTER ();
726
 
 
727
 
        res = burn_cd (source, &error);
728
 
        if (error) {
729
 
                error_dialog (source,
730
 
                              _("Audio recording error"),
731
 
                              error->message);
732
 
                g_error_free (error);
733
 
        }
734
 
 
735
 
        GDK_THREADS_LEAVE ();
736
 
        return FALSE;
737
 
}
738
 
 
739
 
static void
740
 
eos_cb (RBRecorder *recorder,
741
 
        gpointer    data)
742
 
{
743
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
744
 
        GError                   *error  = NULL;
745
 
 
746
 
        rb_debug ("Caught eos!");
747
 
 
748
 
        rb_recorder_close (source->priv->recorder, NULL);
749
 
 
750
 
        gtk_label_set_text (GTK_LABEL (source->priv->progress_label), "");
751
 
 
752
 
        if (source->priv->current->next) {
753
 
 
754
 
                source->priv->current = source->priv->current->next;
755
 
 
756
 
                write_file (source, &error);
757
 
                if (error) {
758
 
                        error_dialog (source,
759
 
                                      _("Audio Conversion Error"),
760
 
                                      error->message);
761
 
                        g_error_free (error);
762
 
                        return;
763
 
                }
764
 
        } else {
765
 
                if (source->priv->timer) {
766
 
                        g_timer_destroy (source->priv->timer);
767
 
                        source->priv->timer = NULL;
768
 
                }
769
 
 
770
 
                source->priv->already_converted = TRUE;
771
 
 
772
 
                g_idle_add ((GSourceFunc)burn_cd_idle, source);
773
 
        }
774
 
}
775
 
 
776
 
static void
777
 
rb_playlist_source_recorder_error (RBPlaylistSourceRecorder *source,
778
 
                                   GError                   *error)
779
 
{
780
 
 
781
 
        if (source->priv->handling_error) {
782
 
                rb_debug ("Ignoring error: %s", error->message);
783
 
                return;
784
 
        }
785
 
 
786
 
        rb_debug ("Error: %s", error->message);
787
 
 
788
 
        error_dialog (source,
789
 
                      _("Recording error"),
790
 
                      error->message);
791
 
 
792
 
        source->priv->handling_error = FALSE;
793
 
        rb_debug ("Exiting error hander");
794
 
}
795
 
 
796
 
static void
797
 
error_cb (GObject *object,
798
 
          GError  *error,
799
 
          gpointer data)
800
 
{
801
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
802
 
 
803
 
        if (source->priv->handling_error)
804
 
                return;
805
 
 
806
 
        source->priv->handling_error = TRUE;
807
 
 
808
 
        rb_playlist_source_recorder_error (source, error);
809
 
}
810
 
 
811
 
static void
812
 
track_progress_changed_cb (GObject *object,
813
 
                           double   fraction,
814
 
                           long     secs,
815
 
                           gpointer data)
816
 
{
817
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
818
 
        double  album_fraction;
819
 
        double  rate;
820
 
        double  elapsed;
821
 
        double  album_secs;
822
 
        GSList *l;
823
 
        guint64 total;
824
 
        guint64 prev_total;
825
 
        guint64 song_length;
826
 
        guint64 position;
827
 
 
828
 
        total = 0;
829
 
        prev_total = 0;
830
 
        song_length = 0;
831
 
        for (l = source->priv->songs; l; l = l->next) {
832
 
                RBRecorderSong *song = l->data;
833
 
 
834
 
                if (song == source->priv->current->data) {
835
 
                        prev_total = total;
836
 
                        song_length = song->duration;
837
 
                }
838
 
                total += song->duration;
839
 
        }
840
 
 
841
 
        position = prev_total + song_length * fraction;
842
 
        if (! source->priv->timer) {
843
 
                source->priv->timer = g_timer_new ();
844
 
                source->priv->start_pos = position;
845
 
        }
846
 
 
847
 
        album_fraction = (float)position / (float)total;
848
 
 
849
 
        elapsed = g_timer_elapsed (source->priv->timer, NULL);
850
 
 
851
 
        rate = (double)(position - source->priv->start_pos) / elapsed;
852
 
 
853
 
        if (rate >= 1)
854
 
                album_secs = ceil ((total - position) / rate);
855
 
        else
856
 
                album_secs = -1;
857
 
 
858
 
        progress_set_time (source->priv->progress, album_secs);
859
 
        progress_set_fraction (source->priv->progress, album_fraction);
860
 
}
861
 
static void
862
 
interrupt_burn_dialog_response_cb (GtkDialog *dialog,
863
 
                                   gint       response_id,
864
 
                                   gpointer   data)
865
 
{
866
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
867
 
 
868
 
        if (response_id == GTK_RESPONSE_ACCEPT) {
869
 
                if (source->priv->burning) {
870
 
                        rb_recorder_burn_cancel (source->priv->recorder);
871
 
                } else {
872
 
                        source->priv->confirmed_exit = TRUE;
873
 
                        gtk_dialog_response (GTK_DIALOG (source),
874
 
                                             GTK_RESPONSE_CANCEL);
875
 
                }
876
 
        } else {
877
 
                source->priv->confirmed_exit = FALSE;
878
 
        }
879
 
 
880
 
        gtk_widget_destroy (GTK_WIDGET (dialog));
881
 
}
882
 
 
883
 
static void
884
 
response_cb (GtkDialog *dialog,
885
 
             gint       response_id)
886
 
{
887
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (dialog);
888
 
        GError                   *error  = NULL;
889
 
 
890
 
        /* Act only on response IDs we recognize */
891
 
        if (!(response_id == GTK_RESPONSE_ACCEPT
892
 
              || response_id == GTK_RESPONSE_CANCEL
893
 
              || response_id == GTK_RESPONSE_DELETE_EVENT)) {
894
 
                g_signal_stop_emission_by_name (dialog, "response");
895
 
                return;
896
 
        }
897
 
 
898
 
        if (response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) {
899
 
                if (source->priv->burning
900
 
                    && !source->priv->confirmed_exit) {
901
 
                        GtkWidget *interrupt_dialog;
902
 
 
903
 
                        source->priv->confirmed_exit = FALSE;
904
 
 
905
 
                        interrupt_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
906
 
                                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
907
 
                                                                   GTK_MESSAGE_QUESTION,
908
 
                                                                   GTK_BUTTONS_NONE,
909
 
                                                                   _("Do you wish to interrupt writing this disc?"));
910
 
 
911
 
                        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (interrupt_dialog),
912
 
                                                                  _("This may result in an unusable disc."));
913
 
 
914
 
                        gtk_window_set_title (GTK_WINDOW (interrupt_dialog), "");
915
 
 
916
 
                        gtk_container_set_border_width (GTK_CONTAINER (interrupt_dialog), 6);
917
 
 
918
 
                        gtk_dialog_add_buttons (GTK_DIALOG (interrupt_dialog),
919
 
                                                _("_Cancel"), GTK_RESPONSE_CANCEL,
920
 
                                                _("_Interrupt"), GTK_RESPONSE_ACCEPT,
921
 
                                                NULL);
922
 
 
923
 
                        gtk_dialog_set_default_response (GTK_DIALOG (interrupt_dialog),
924
 
                                                         GTK_RESPONSE_CANCEL);
925
 
 
926
 
                        g_signal_connect (interrupt_dialog,
927
 
                                          "response",
928
 
                                          G_CALLBACK (interrupt_burn_dialog_response_cb),
929
 
                                          source);
930
 
 
931
 
                        gtk_widget_show (interrupt_dialog);
932
 
 
933
 
                        g_signal_stop_emission_by_name (dialog, "response");
934
 
                }
935
 
                return;
936
 
        }
937
 
 
938
 
        if (response_id == GTK_RESPONSE_ACCEPT) {
939
 
                rb_playlist_source_recorder_start (source, &error);
940
 
                if (error) {
941
 
                        error_dialog (source,
942
 
                                      _("Could not create audio CD"),
943
 
                                      error->message);
944
 
                        g_error_free (error);
945
 
                }
946
 
                g_signal_stop_emission_by_name (dialog, "response");
947
 
        }
948
 
}
949
 
 
950
 
static gboolean
951
 
insert_media_request_cb (RBRecorder *recorder,
952
 
                         gboolean    is_reload,
953
 
                         gboolean    can_rewrite,
954
 
                         gboolean    busy_cd,
955
 
                         gpointer    data)
956
 
{
957
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
958
 
        GtkWidget  *dialog;
959
 
        const char *msg;
960
 
        const char *title;
961
 
        int         res;
962
 
 
963
 
        if (busy_cd) {
964
 
                msg = N_("Please make sure another application is not using the drive.");
965
 
                title = N_("Drive is busy");
966
 
        } else if (is_reload && can_rewrite) {
967
 
                msg = N_("Please put a rewritable or blank CD in the drive.");
968
 
                title = N_("Insert a rewritable or blank CD");
969
 
        } else if (is_reload && !can_rewrite) {
970
 
                msg = N_("Please put a blank CD in the drive.");
971
 
                title = N_("Insert a blank CD");
972
 
        } else if (can_rewrite) {
973
 
                msg = N_("Please replace the disc in the drive with a rewritable or blank CD.");
974
 
                title = N_("Reload a rewritable or blank CD");
975
 
        } else {
976
 
                msg = N_("Please replace the disc in the drive with a blank CD.");
977
 
                title = N_("Reload a blank CD");
978
 
        }
979
 
 
980
 
        GDK_THREADS_ENTER ();
981
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (source),
982
 
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
983
 
                                         GTK_MESSAGE_ERROR,
984
 
                                         GTK_BUTTONS_OK_CANCEL,
985
 
                                         "%s", title);
986
 
 
987
 
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), msg);
988
 
 
989
 
        gtk_window_set_title (GTK_WINDOW (dialog), "");
990
 
 
991
 
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
992
 
 
993
 
        res = gtk_dialog_run (GTK_DIALOG (dialog));
994
 
 
995
 
        gtk_widget_destroy (dialog);
996
 
        GDK_THREADS_LEAVE ();
997
 
 
998
 
        if (res == GTK_RESPONSE_CANCEL)
999
 
                return FALSE;
1000
 
 
1001
 
        return TRUE;
1002
 
}
1003
 
 
1004
 
static void
1005
 
burn_progress_changed_cb (RBRecorder *recorder,
1006
 
                          gdouble     fraction,
1007
 
                          long        secs,
1008
 
                          gpointer    data)
1009
 
{
1010
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
1011
 
 
1012
 
        progress_set_fraction (source->priv->progress, fraction);
1013
 
        progress_set_time (source->priv->progress, secs);
1014
 
}
1015
 
 
1016
 
static void
1017
 
burn_action_changed_cb (RBRecorder        *recorder,
1018
 
                        RBRecorderAction   action,
1019
 
                        gpointer           data)
1020
 
{
1021
 
        RBPlaylistSourceRecorder *source = RB_PLAYLIST_SOURCE_RECORDER (data);
1022
 
        const char *text;
1023
 
 
1024
 
        text = NULL;
1025
 
 
1026
 
        switch (action) {
1027
 
        case RB_RECORDER_ACTION_FILE_CONVERTING:
1028
 
                text = N_("Converting audio tracks");
1029
 
                break;
1030
 
        case RB_RECORDER_ACTION_DISC_PREPARING_WRITE:
1031
 
                text = N_("Preparing to write CD");
1032
 
                break;
1033
 
        case RB_RECORDER_ACTION_DISC_WRITING:
1034
 
                text = N_("Writing CD");
1035
 
                break;
1036
 
        case RB_RECORDER_ACTION_DISC_FIXATING:
1037
 
                text = N_("Finishing write");
1038
 
                break;
1039
 
        case RB_RECORDER_ACTION_DISC_BLANKING:
1040
 
                text = N_("Erasing CD");
1041
 
                break;
1042
 
        default:
1043
 
                g_warning (_("Unhandled action in burn_action_changed_cb"));
1044
 
        }
1045
 
 
1046
 
        if (text)
1047
 
                set_message_text (source, text);
1048
 
}
1049
 
 
1050
 
static int
1051
 
ask_rewrite_disc (RBPlaylistSourceRecorder *source,
1052
 
                  const char               *device)
1053
 
{
1054
 
        GtkWidget            *dialog;
1055
 
        GtkWidget            *button;
1056
 
        GtkWidget            *image;
1057
 
        int                   res;
1058
 
        NautilusBurnMediaType type;
1059
 
        char                 *msg;
1060
 
        NautilusBurnDrive    *drive;
1061
 
 
1062
 
#if NAUTILUS_BURN_CHECK_VERSION(2,15,3)
1063
 
        drive = nautilus_burn_drive_monitor_get_drive_for_device (nautilus_burn_get_drive_monitor (),
1064
 
                                                                  device);
1065
 
#else
1066
 
        drive = nautilus_burn_drive_new_from_path (device);
1067
 
#endif
1068
 
 
1069
 
        type = nautilus_burn_drive_get_media_type (drive);
1070
 
 
1071
 
        msg = g_strdup_printf (_("This %s appears to have information already recorded on it."),
1072
 
                               nautilus_burn_drive_media_type_get_string (type));
1073
 
 
1074
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (source),
1075
 
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
1076
 
                                         GTK_MESSAGE_WARNING,
1077
 
                                         GTK_BUTTONS_NONE,
1078
 
                                         "%s", _("Erase information on this disc?"));
1079
 
 
1080
 
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), msg);
1081
 
        g_free (msg);
1082
 
 
1083
 
        gtk_window_set_title (GTK_WINDOW (dialog), "");
1084
 
 
1085
 
        image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
1086
 
        gtk_widget_show (image);
1087
 
        button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Try Another"), RB_RECORDER_RESPONSE_RETRY);
1088
 
        g_object_set (button, "image", image, NULL);
1089
 
 
1090
 
        gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, RB_RECORDER_RESPONSE_CANCEL);
1091
 
 
1092
 
        image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON);
1093
 
        gtk_widget_show (image);
1094
 
        button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Erase Disc"), RB_RECORDER_RESPONSE_ERASE);
1095
 
        g_object_set (button, "image", image, NULL);
1096
 
 
1097
 
        gtk_dialog_set_default_response (GTK_DIALOG (dialog),
1098
 
                                         RB_RECORDER_RESPONSE_CANCEL);
1099
 
 
1100
 
        res = gtk_dialog_run (GTK_DIALOG (dialog));
1101
 
 
1102
 
        gtk_widget_destroy (dialog);
1103
 
 
1104
 
        if (res == RB_RECORDER_RESPONSE_RETRY) {
1105
 
                nautilus_burn_drive_eject (drive);
1106
 
        }
1107
 
 
1108
 
        nautilus_burn_drive_unref (drive);
1109
 
 
1110
 
        return res;
1111
 
}
1112
 
 
1113
 
static int
1114
 
warn_data_loss_cb (RBRecorder               *recorder,
1115
 
                   RBPlaylistSourceRecorder *source)
1116
 
{
1117
 
        char *device;
1118
 
        int   res;
1119
 
 
1120
 
        device = rb_recorder_get_device (recorder, NULL);
1121
 
        GDK_THREADS_ENTER();
1122
 
        res = ask_rewrite_disc (source, device);
1123
 
        GDK_THREADS_LEAVE();
1124
 
 
1125
 
        g_free (device);
1126
 
 
1127
 
        return res;
1128
 
}
1129
 
 
1130
 
static void
1131
 
setup_speed_combobox (GtkWidget *combobox)
1132
 
{
1133
 
        GtkCellRenderer *cell;
1134
 
        GtkListStore    *store;
1135
 
 
1136
 
        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
1137
 
 
1138
 
        gtk_combo_box_set_model (GTK_COMBO_BOX (combobox),
1139
 
                                 GTK_TREE_MODEL (store));
1140
 
        g_object_unref (store);
1141
 
 
1142
 
        cell = gtk_cell_renderer_text_new ();
1143
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), cell, TRUE);
1144
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), cell,
1145
 
                                        "text", 0,
1146
 
                                        NULL);
1147
 
}
1148
 
 
1149
 
static int
1150
 
delete_event_handler (GtkWidget   *widget,
1151
 
                      GdkEventAny *event,
1152
 
                      gpointer     user_data)
1153
 
{
1154
 
        /* emit response signal */
1155
 
        gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_DELETE_EVENT);
1156
 
 
1157
 
        /* Do the destroy by default */
1158
 
        return TRUE;
1159
 
}
1160
 
 
1161
 
static void
1162
 
rb_playlist_source_recorder_init (RBPlaylistSourceRecorder *source)
1163
 
{
1164
 
        GladeXML       *xml;
1165
 
        GError         *error = NULL;
1166
 
        GtkWidget      *widget;
1167
 
        GtkWidget      *hbox;
1168
 
        int             font_size;
1169
 
        PangoAttrList  *pattrlist;
1170
 
        PangoAttribute *attr;
1171
 
 
1172
 
        g_signal_connect (GTK_DIALOG (source),
1173
 
                          "delete_event",
1174
 
                          G_CALLBACK (delete_event_handler),
1175
 
                          NULL);
1176
 
 
1177
 
        source->priv = RB_PLAYLIST_SOURCE_RECORDER_GET_PRIVATE (source);
1178
 
 
1179
 
        gtk_window_set_resizable (GTK_WINDOW (source), FALSE);
1180
 
        gtk_dialog_set_has_separator (GTK_DIALOG (source), FALSE);
1181
 
        source->priv->cancel_button =  gtk_dialog_add_button (GTK_DIALOG (source),
1182
 
                                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1183
 
 
1184
 
        source->priv->burn_button = gtk_button_new ();
1185
 
        GTK_WIDGET_SET_FLAGS (source->priv->burn_button, GTK_CAN_DEFAULT);
1186
 
 
1187
 
        widget = gtk_alignment_new (0.5, 0.5, 0, 0);
1188
 
        gtk_container_add (GTK_CONTAINER (source->priv->burn_button), widget);
1189
 
        gtk_widget_show (widget);
1190
 
        hbox = gtk_hbox_new (FALSE, 6);
1191
 
        gtk_container_add (GTK_CONTAINER (widget), hbox);
1192
 
        gtk_widget_show (hbox);
1193
 
        widget = gtk_image_new_from_stock (GTK_STOCK_CDROM, GTK_ICON_SIZE_BUTTON);
1194
 
        source->priv->cd_icon = widget;
1195
 
        g_object_ref (source->priv->cd_icon);
1196
 
        gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1197
 
        gtk_widget_show (widget);
1198
 
        widget = gtk_label_new_with_mnemonic (_("C_reate"));
1199
 
        gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1200
 
        gtk_widget_show (widget);
1201
 
        gtk_dialog_add_action_widget (GTK_DIALOG (source),
1202
 
                                      source->priv->burn_button,
1203
 
                                      GTK_RESPONSE_ACCEPT);
1204
 
        gtk_widget_show (source->priv->burn_button);
1205
 
 
1206
 
        gtk_dialog_set_default_response (GTK_DIALOG (source), GTK_RESPONSE_ACCEPT);
1207
 
 
1208
 
        xml = rb_glade_xml_new ("recorder.glade",
1209
 
                                "recorder_vbox",
1210
 
                                source);
1211
 
 
1212
 
        source->priv->vbox = glade_xml_get_widget (xml, "recorder_vbox");
1213
 
 
1214
 
        source->priv->message_label  = glade_xml_get_widget (xml, "message_label");
1215
 
        source->priv->progress_label  = glade_xml_get_widget (xml, "progress_label");
1216
 
 
1217
 
        source->priv->progress = glade_xml_get_widget (xml, "progress");
1218
 
        gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (source->priv->progress), PANGO_ELLIPSIZE_END);
1219
 
        gtk_progress_bar_set_text (GTK_PROGRESS_BAR (source->priv->progress), " ");
1220
 
        gtk_widget_set_size_request (source->priv->progress, 400, -1);
1221
 
 
1222
 
        source->priv->progress_frame = glade_xml_get_widget (xml, "progress_frame");
1223
 
 
1224
 
        source->priv->options_box    = glade_xml_get_widget (xml, "options_box");
1225
 
        source->priv->device_menu    = glade_xml_get_widget (xml, "device_menu");
1226
 
        source->priv->multiple_copies_checkbutton = glade_xml_get_widget (xml, "multiple_copies_checkbutton");
1227
 
 
1228
 
        source->priv->speed_combobox = glade_xml_get_widget (xml, "speed_combobox");
1229
 
        setup_speed_combobox (source->priv->speed_combobox);
1230
 
 
1231
 
        widget = glade_xml_get_widget (xml, "device_label");
1232
 
        gtk_label_set_mnemonic_widget (GTK_LABEL (widget), source->priv->device_menu);
1233
 
 
1234
 
        rb_glade_boldify_label (xml, "progress_frame_label");
1235
 
        rb_glade_boldify_label (xml, "options_expander_label");
1236
 
 
1237
 
        pattrlist = pango_attr_list_new ();
1238
 
        attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
1239
 
        attr->start_index = 0;
1240
 
        attr->end_index = G_MAXINT;
1241
 
        pango_attr_list_insert (pattrlist, attr);
1242
 
 
1243
 
        font_size = pango_font_description_get_size (GTK_WIDGET (source->priv->message_label)->style->font_desc);
1244
 
        attr = pango_attr_size_new (font_size * 1.2);
1245
 
        attr->start_index = 0;
1246
 
        attr->end_index = G_MAXINT;
1247
 
        pango_attr_list_insert (pattrlist, attr);
1248
 
 
1249
 
        gtk_label_set_attributes (GTK_LABEL (source->priv->message_label), pattrlist);
1250
 
 
1251
 
        pango_attr_list_unref (pattrlist);
1252
 
 
1253
 
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (source)->vbox),
1254
 
                            source->priv->vbox,
1255
 
                            TRUE, TRUE, 0);
1256
 
        gtk_widget_show_all (source->priv->vbox);
1257
 
 
1258
 
        source->priv->recorder = rb_recorder_new (&error);
1259
 
        if (error) {
1260
 
                GtkWidget *dialog;
1261
 
                char      *msg = g_strdup_printf (_("Failed to create the recorder: %s"),
1262
 
                                                  error->message);
1263
 
                g_error_free (error);
1264
 
                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
1265
 
                                                 GTK_MESSAGE_ERROR,
1266
 
                                                 GTK_BUTTONS_CLOSE,
1267
 
                                                 msg);
1268
 
                gtk_dialog_run (GTK_DIALOG (dialog));
1269
 
                g_free (msg);
1270
 
                return;
1271
 
        }
1272
 
 
1273
 
        update_speed_combobox (source);
1274
 
        g_signal_connect (source->priv->device_menu, "device-changed",
1275
 
                          G_CALLBACK (rb_playlist_source_recorder_device_changed_cb),
1276
 
                          xml);
1277
 
 
1278
 
        g_signal_connect_object (G_OBJECT (source->priv->recorder), "eos",
1279
 
                                 G_CALLBACK (eos_cb), source, 0);
1280
 
 
1281
 
        g_signal_connect_object (G_OBJECT (source->priv->recorder), "error",
1282
 
                                 G_CALLBACK (error_cb), source, 0);
1283
 
 
1284
 
        g_signal_connect_object (G_OBJECT (source->priv->recorder), "action-changed",
1285
 
                                 G_CALLBACK (burn_action_changed_cb), source, 0);
1286
 
 
1287
 
        g_signal_connect_object (G_OBJECT (source->priv->recorder), "track-progress-changed",
1288
 
                                 G_CALLBACK (track_progress_changed_cb), source, 0);
1289
 
 
1290
 
        g_signal_connect_object (G_OBJECT (source->priv->recorder), "insert-media-request",
1291
 
                                 G_CALLBACK (insert_media_request_cb), source, 0);
1292
 
 
1293
 
        g_signal_connect_object (G_OBJECT (source->priv->recorder), "warn-data-loss",
1294
 
                                 G_CALLBACK (warn_data_loss_cb), source, 0);
1295
 
 
1296
 
        g_signal_connect_object (G_OBJECT (source->priv->recorder), "burn-progress-changed",
1297
 
                                 G_CALLBACK (burn_progress_changed_cb), source, 0);
1298
 
 
1299
 
        g_signal_connect (GTK_DIALOG (source), "response",
1300
 
                          G_CALLBACK (response_cb), NULL);
1301
 
}
1302
 
 
1303
 
static RBRecorderSong *
1304
 
recorder_song_new ()
1305
 
{
1306
 
        RBRecorderSong *song = g_new0 (RBRecorderSong, 1);
1307
 
        return song;
1308
 
}
1309
 
 
1310
 
static void
1311
 
recorder_song_free (RBRecorderSong *song)
1312
 
{
1313
 
        g_return_if_fail (song != NULL);
1314
 
 
1315
 
        g_free (song->title);
1316
 
        g_free (song->uri);
1317
 
        g_free (song);
1318
 
}
1319
 
 
1320
 
static void
1321
 
free_song_list (GSList *songs)
1322
 
{
1323
 
        GSList *l;
1324
 
 
1325
 
        for (l = songs; l; l = l->next) {
1326
 
                recorder_song_free ((RBRecorderSong *)l->data);
1327
 
        }
1328
 
 
1329
 
        g_slist_free (songs);
1330
 
        songs = NULL;
1331
 
}
1332
 
 
1333
 
static void
1334
 
rb_playlist_source_recorder_dispose (GObject *object)
1335
 
{
1336
 
        RBPlaylistSourceRecorder *source;
1337
 
 
1338
 
        g_return_if_fail (object != NULL);
1339
 
        g_return_if_fail (RB_IS_PLAYLIST_SOURCE_RECORDER (object));
1340
 
 
1341
 
        source = RB_PLAYLIST_SOURCE_RECORDER (object);
1342
 
 
1343
 
        g_return_if_fail (source->priv != NULL);
1344
 
 
1345
 
        if (source->priv->shell != NULL) {
1346
 
                g_object_unref (source->priv->shell);
1347
 
                source->priv->shell = NULL;
1348
 
        }
1349
 
 
1350
 
        if (source->priv->cd_icon != NULL) {
1351
 
                g_object_unref (source->priv->cd_icon);
1352
 
                source->priv->cd_icon = NULL;
1353
 
        }
1354
 
 
1355
 
        if (source->priv->recorder != NULL) {
1356
 
                g_object_unref (source->priv->recorder);
1357
 
                source->priv->recorder = NULL;
1358
 
        }
1359
 
 
1360
 
        G_OBJECT_CLASS (rb_playlist_source_recorder_parent_class)->dispose (object);
1361
 
}
1362
 
 
1363
 
static void
1364
 
rb_playlist_source_recorder_finalize (GObject *object)
1365
 
{
1366
 
        RBPlaylistSourceRecorder *source;
1367
 
 
1368
 
        g_return_if_fail (object != NULL);
1369
 
        g_return_if_fail (RB_IS_PLAYLIST_SOURCE_RECORDER (object));
1370
 
 
1371
 
        source = RB_PLAYLIST_SOURCE_RECORDER (object);
1372
 
 
1373
 
        g_return_if_fail (source->priv != NULL);
1374
 
 
1375
 
        rb_debug ("Finalize source recorder");
1376
 
 
1377
 
        g_free (source->priv->name);
1378
 
        source->priv->name = NULL;
1379
 
 
1380
 
        free_song_list (source->priv->songs);
1381
 
 
1382
 
        if (source->priv->tmp_dir) {
1383
 
                if (rmdir (source->priv->tmp_dir) < 0)
1384
 
                        g_warning (_("Could not remove temporary directory '%s': %s"),
1385
 
                                   source->priv->tmp_dir,
1386
 
                                   g_strerror (errno));
1387
 
                g_free (source->priv->tmp_dir);
1388
 
                source->priv->tmp_dir = NULL;
1389
 
        }
1390
 
 
1391
 
        G_OBJECT_CLASS (rb_playlist_source_recorder_parent_class)->finalize (object);
1392
 
}
1393
 
 
1394
 
GtkWidget *
1395
 
rb_playlist_source_recorder_new (GtkWidget  *parent,
1396
 
                                 RBShell    *shell,
1397
 
                                 const char *name)
1398
 
{
1399
 
        GtkWidget *result;
1400
 
        RBPlaylistSourceRecorder *source;
1401
 
 
1402
 
        result = g_object_new (RB_TYPE_PLAYLIST_SOURCE_RECORDER,
1403
 
                               "title", _("Create Audio CD"),
1404
 
                               NULL);
1405
 
 
1406
 
        source = RB_PLAYLIST_SOURCE_RECORDER (result);
1407
 
        if (parent) {
1408
 
                source->priv->parent = gtk_widget_get_toplevel (parent);
1409
 
 
1410
 
                gtk_window_set_transient_for (GTK_WINDOW (source),
1411
 
                                              GTK_WINDOW (source->priv->parent));
1412
 
                gtk_window_set_destroy_with_parent (GTK_WINDOW (source), TRUE);
1413
 
        }
1414
 
 
1415
 
        source->priv->shell = g_object_ref (shell);
1416
 
 
1417
 
        if (name) {
1418
 
                source->priv->name = g_strdup (name);
1419
 
 
1420
 
                set_message_text (source, _("Create audio CD from '%s'?"), name);
1421
 
        }
1422
 
 
1423
 
        return result;
1424
 
}
1425
 
 
1426
 
void
1427
 
rb_playlist_source_recorder_set_name (RBPlaylistSourceRecorder *source,
1428
 
                                      const char               *name,
1429
 
                                      GError                  **error)
1430
 
{
1431
 
        g_return_if_fail (source != NULL);
1432
 
        g_return_if_fail (RB_IS_PLAYLIST_SOURCE_RECORDER (source));
1433
 
 
1434
 
        g_return_if_fail (name != NULL);
1435
 
 
1436
 
        g_free (source->priv->name);
1437
 
        source->priv->name = g_strdup (name);
1438
 
 
1439
 
        g_signal_emit (G_OBJECT (source),
1440
 
                       rb_playlist_source_recorder_signals [NAME_CHANGED],
1441
 
                       0,
1442
 
                       name);
1443
 
}
1444
 
 
1445
 
gboolean
1446
 
rb_playlist_source_recorder_add_from_model (RBPlaylistSourceRecorder *source,
1447
 
                                            GtkTreeModel             *model,
1448
 
                                            RBPlaylistSourceIterFunc  func,
1449
 
                                            GError                  **error)
1450
 
{
1451
 
        GtkTreeIter iter;
1452
 
        gboolean    failed;
1453
 
        GSList     *songs  = NULL;
1454
 
        GSList     *l;
1455
 
        guint64     length = 0;
1456
 
 
1457
 
        g_return_val_if_fail (source != NULL, FALSE);
1458
 
        g_return_val_if_fail (RB_IS_PLAYLIST_SOURCE_RECORDER (source), FALSE);
1459
 
 
1460
 
        g_return_val_if_fail (model != NULL, FALSE);
1461
 
 
1462
 
        if (! gtk_tree_model_get_iter_first (model, &iter)) {
1463
 
                g_set_error (error,
1464
 
                             RB_RECORDER_ERROR,
1465
 
                             RB_RECORDER_ERROR_GENERAL,
1466
 
                             _("Unable to build an audio track list."));
1467
 
 
1468
 
                return FALSE;
1469
 
        }
1470
 
 
1471
 
        /* Make sure we can use all of the songs before we
1472
 
           modify the song list */
1473
 
        failed = FALSE;
1474
 
        do {
1475
 
                RBRecorderSong *song = recorder_song_new ();
1476
 
                gboolean        res;
1477
 
 
1478
 
                res = func (model, &iter, &song->uri, &song->artist, &song->title, &song->duration);
1479
 
                if (! res) {
1480
 
                        failed = TRUE;
1481
 
                        g_set_error (error,
1482
 
                                     RB_RECORDER_ERROR,
1483
 
                                     RB_RECORDER_ERROR_GENERAL,
1484
 
                                     _("Unable to build an audio track list."));
1485
 
                        break;
1486
 
                }
1487
 
 
1488
 
                length += song->duration;
1489
 
                if (length > MAX_PLAYLIST_DURATION) {
1490
 
                        failed = TRUE;
1491
 
                        g_set_error (error,
1492
 
                                     RB_RECORDER_ERROR,
1493
 
                                     RB_RECORDER_ERROR_GENERAL,
1494
 
                                     _("This playlist is too long to write to an audio CD."));
1495
 
                        break;
1496
 
                }
1497
 
 
1498
 
                songs = g_slist_append (songs, song);
1499
 
        } while (gtk_tree_model_iter_next (model, &iter));
1500
 
 
1501
 
        if (failed) {
1502
 
                free_song_list (songs);
1503
 
 
1504
 
                return FALSE;
1505
 
        }
1506
 
 
1507
 
        /* now that we've checked all the songs, add them to the song list */
1508
 
        for (l = songs; l; l = l->next) {
1509
 
                RBRecorderSong *song = l->data;
1510
 
 
1511
 
                source->priv->songs = g_slist_append (source->priv->songs, song);
1512
 
 
1513
 
                g_signal_emit (G_OBJECT (source),
1514
 
                               rb_playlist_source_recorder_signals [FILE_ADDED],
1515
 
                               0,
1516
 
                               song->uri);
1517
 
        }
1518
 
 
1519
 
        return TRUE;
1520
 
}
1521
 
 
1522
 
static guint64
1523
 
rb_playlist_source_recorder_get_total_duration (RBPlaylistSourceRecorder *source)
1524
 
{
1525
 
        GSList *l;
1526
 
        guint64 length = 0;
1527
 
 
1528
 
        for (l = source->priv->songs; l; l = l->next) {
1529
 
                RBRecorderSong *song = l->data;
1530
 
                length += song->duration;
1531
 
        }
1532
 
 
1533
 
        return length;
1534
 
}
1535
 
 
1536
 
static guint64
1537
 
rb_playlist_source_recorder_estimate_total_size (RBPlaylistSourceRecorder *source)
1538
 
{
1539
 
        guint64 length;
1540
 
 
1541
 
        length = rb_playlist_source_recorder_get_total_duration (source);
1542
 
 
1543
 
        return length * AUDIO_BYTERATE;
1544
 
}
1545
 
 
1546
 
static gboolean
1547
 
check_dir_has_space (const char *path,
1548
 
                     guint64     bytes_needed)
1549
 
{
1550
 
        GnomeVFSResult   result     = GNOME_VFS_OK;
1551
 
        GnomeVFSURI     *dir_uri    = NULL;
1552
 
        GnomeVFSFileSize free_bytes = 0;
1553
 
 
1554
 
        if (!g_file_test (path, G_FILE_TEST_IS_DIR))
1555
 
                return FALSE;
1556
 
 
1557
 
        dir_uri = gnome_vfs_uri_new (path);
1558
 
        if (dir_uri == NULL) {
1559
 
                g_warning (_("Cannot get free space at %s"), path);
1560
 
                return FALSE;
1561
 
        }
1562
 
 
1563
 
        result = gnome_vfs_get_volume_free_space (dir_uri, &free_bytes);
1564
 
 
1565
 
        gnome_vfs_uri_unref (dir_uri);
1566
 
 
1567
 
        if (result != GNOME_VFS_OK) {
1568
 
                g_warning (_("Cannot get free space at %s"), path);
1569
 
                return FALSE;
1570
 
        }
1571
 
 
1572
 
        if (bytes_needed >= free_bytes)
1573
 
                return FALSE;
1574
 
 
1575
 
        return TRUE;
1576
 
}
1577
 
 
1578
 
static char *
1579
 
find_tmp_dir (RBPlaylistSourceRecorder *source,
1580
 
              guint64                   bytes_needed,
1581
 
              GError                  **error)
1582
 
{
1583
 
        char *path;
1584
 
 
1585
 
        g_return_val_if_fail (source != NULL, NULL);
1586
 
        g_return_val_if_fail (RB_IS_PLAYLIST_SOURCE_RECORDER (source), NULL);
1587
 
 
1588
 
        /* Use a configurable temporary directory? */
1589
 
        path = NULL;
1590
 
        if (path && strcmp (path, "")
1591
 
            && check_dir_has_space (path, bytes_needed))
1592
 
                return path;
1593
 
        else if (g_get_tmp_dir () &&
1594
 
                   check_dir_has_space (g_get_tmp_dir (), bytes_needed))
1595
 
                return g_strdup (g_get_tmp_dir ());
1596
 
        else if (g_get_home_dir () &&
1597
 
                   check_dir_has_space (g_get_home_dir (), bytes_needed))
1598
 
                return g_strdup (g_get_home_dir ());
1599
 
        else
1600
 
                return NULL;
1601
 
}
1602
 
 
1603
 
static gboolean
1604
 
check_tmp_dir (RBPlaylistSourceRecorder *source,
1605
 
               GError                  **error)
1606
 
{
1607
 
        char   *path;
1608
 
        char   *template;
1609
 
        char   *subdir;
1610
 
        guint64 bytes_needed;
1611
 
 
1612
 
        g_return_val_if_fail (source != NULL, FALSE);
1613
 
        g_return_val_if_fail (RB_IS_PLAYLIST_SOURCE_RECORDER (source), FALSE);
1614
 
 
1615
 
        bytes_needed = rb_playlist_source_recorder_estimate_total_size (source);
1616
 
 
1617
 
        path = find_tmp_dir (source, bytes_needed, error);
1618
 
        if (!path)
1619
 
                return FALSE;
1620
 
 
1621
 
        template = g_build_filename (path, "rb-burn-tmp-XXXXXX", NULL);
1622
 
        subdir = mkdtemp (template);
1623
 
 
1624
 
        if (!subdir)
1625
 
                return FALSE;
1626
 
 
1627
 
        g_free (source->priv->tmp_dir);
1628
 
        source->priv->tmp_dir = subdir;
1629
 
        rb_recorder_set_tmp_dir (source->priv->recorder,
1630
 
                                 source->priv->tmp_dir,
1631
 
                                 error);
1632
 
 
1633
 
        if (error && *error)
1634
 
                return FALSE;
1635
 
 
1636
 
        return TRUE;
1637
 
}
1638
 
 
1639
 
static gboolean
1640
 
check_media_length (RBPlaylistSourceRecorder *source,
1641
 
                    GError                  **error)
1642
 
{
1643
 
        gint64  duration = rb_playlist_source_recorder_get_total_duration (source);
1644
 
        char   *message  = NULL;
1645
 
        gint64  media_duration;
1646
 
        char   *duration_string;
1647
 
 
1648
 
        media_duration = rb_recorder_get_media_length (source->priv->recorder, NULL);
1649
 
        duration_string = g_strdup_printf ("%" G_GINT64_FORMAT, duration / 60);
1650
 
 
1651
 
        /* Only check if the playlist is greater than 74 minutes */
1652
 
        if ((media_duration < 0) && (duration > 4440)) {
1653
 
                message = g_strdup_printf (_("This playlist is %s minutes long.  "
1654
 
                                             "This exceeds the length of a standard audio CD.  "
1655
 
                                             "If the destination media is larger than a standard audio CD "
1656
 
                                             "please insert it in the drive and try again."),
1657
 
                                           duration_string);
1658
 
        }
1659
 
 
1660
 
        g_free (duration_string);
1661
 
 
1662
 
        if (message) {
1663
 
                error_dialog (source,
1664
 
                              _("Playlist too long"),
1665
 
                              message);
1666
 
                g_free (message);
1667
 
 
1668
 
                return FALSE;
1669
 
        }
1670
 
 
1671
 
        return TRUE;
1672
 
}
1673
 
 
1674
 
void
1675
 
rb_playlist_source_recorder_start (RBPlaylistSourceRecorder *source,
1676
 
                                   GError                  **error)
1677
 
{
1678
 
        g_return_if_fail (source != NULL);
1679
 
        g_return_if_fail (RB_IS_PLAYLIST_SOURCE_RECORDER (source));
1680
 
 
1681
 
        source->priv->current = source->priv->songs;
1682
 
 
1683
 
        gtk_widget_set_sensitive (source->priv->burn_button, FALSE);
1684
 
        gtk_widget_set_sensitive (source->priv->options_box, FALSE);
1685
 
 
1686
 
        if (source->priv->already_converted) {
1687
 
                g_idle_add ((GSourceFunc)burn_cd_idle, source);
1688
 
        } else {
1689
 
                gboolean is_ok;
1690
 
 
1691
 
                set_media_device (source);
1692
 
 
1693
 
                is_ok = check_media_length (source, error);
1694
 
                if (! is_ok) {
1695
 
                        return;
1696
 
                }
1697
 
 
1698
 
                is_ok = check_tmp_dir (source, error);
1699
 
                if (! is_ok) {
1700
 
                        guint64 mib_needed = rb_playlist_source_recorder_estimate_total_size (source) / 1048576;
1701
 
                        char   *mib_needed_string = g_strdup_printf ("%" G_GUINT64_FORMAT, mib_needed);
1702
 
 
1703
 
                        error_dialog (source,
1704
 
                                      _("Could not find temporary space!"),
1705
 
                                      _("Could not find enough temporary space to convert audio tracks.  %s MiB required."),
1706
 
                                      mib_needed_string);
1707
 
                        g_free (mib_needed_string);
1708
 
 
1709
 
                        return;
1710
 
                }
1711
 
 
1712
 
                write_file (source, error);
1713
 
        }
1714
 
}