~mfisch/brasero/update-to-3.8.0

« back to all changes in this revision

Viewing changes to libbrasero-burn/brasero-burn-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2009-06-03 10:36:30 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20090603103630-2r72408gk45sc0ws
Tags: 2.27.2-0ubuntu1
* New upstream release (LP: #380850)
  - Split burning backend into a new library called libbrasero-burn
  - Split some utilities into a new library called libbrasero-utils
  - Use Brasero as a single instance application using libunique
  - Data spanning
  - Memleak fixes
  - Bug Fixes
  - String fixes
  - Use autogenerated Changelog via git
  - Translation Updates
  - Fixes (LP: #360671)
* Bump GTK+ requirement and add libunique requirement

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * Libbrasero-burn
 
4
 * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
 
5
 *
 
6
 * Libbrasero-burn is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * The Libbrasero-burn authors hereby grant permission for non-GPL compatible
 
12
 * GStreamer plugins to be used and distributed together with GStreamer
 
13
 * and Libbrasero-burn. This permission is above and beyond the permissions granted
 
14
 * by the GPL license by which Libbrasero-burn is covered. If you modify this code
 
15
 * you may extend this exception to your version of the code, but you are not
 
16
 * obligated to do so. If you do not wish to do so, delete this exception
 
17
 * statement from your version.
 
18
 * 
 
19
 * Libbrasero-burn is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 * GNU Library General Public License for more details.
 
23
 * 
 
24
 * You should have received a copy of the GNU General Public License
 
25
 * along with this program; if not, write to:
 
26
 *      The Free Software Foundation, Inc.,
 
27
 *      51 Franklin Street, Fifth Floor
 
28
 *      Boston, MA  02110-1301, USA.
 
29
 */
 
30
 
 
31
#include <stdlib.h>
 
32
#include <string.h>
 
33
#include <errno.h>
 
34
 
 
35
#ifdef HAVE_CONFIG_H
 
36
#  include <config.h>
 
37
#endif
 
38
 
 
39
#include <glib.h>
 
40
#include <glib/gi18n-lib.h>
 
41
#include <glib/gstdio.h>
 
42
 
 
43
#include <gdk/gdk.h>
 
44
 
 
45
#include <gtk/gtk.h>
 
46
 
 
47
#include "brasero-tray.h"
 
48
#include "brasero-burn-dialog.h"
 
49
#include "brasero-session-cfg.h"
 
50
#include "brasero-session-helper.h"
 
51
 
 
52
#include "burn-basics.h"
 
53
#include "burn-debug.h"
 
54
#include "brasero-progress.h"
 
55
#include "brasero-cover.h"
 
56
#include "brasero-track-type-private.h"
 
57
 
 
58
#include "brasero-tags.h"
 
59
#include "brasero-session.h"
 
60
#include "brasero-track-image.h"
 
61
 
 
62
#include "brasero-medium.h"
 
63
#include "brasero-drive.h"
 
64
 
 
65
#include "brasero-misc.h"
 
66
 
 
67
 
 
68
static void brasero_burn_dialog_class_init (BraseroBurnDialogClass *klass);
 
69
static void brasero_burn_dialog_init (BraseroBurnDialog *obj);
 
70
static void brasero_burn_dialog_finalize (GObject *object);
 
71
static void brasero_burn_dialog_destroy (GtkObject *object);
 
72
 
 
73
static gboolean
 
74
brasero_burn_dialog_delete (GtkWidget *widget,
 
75
                            GdkEventAny *event);
 
76
 
 
77
static void
 
78
brasero_burn_dialog_cancel_clicked_cb (GtkWidget *button,
 
79
                                       BraseroBurnDialog *dialog);
 
80
 
 
81
static void
 
82
brasero_burn_dialog_tray_cancel_cb (BraseroTrayIcon *tray,
 
83
                                    BraseroBurnDialog *dialog);
 
84
static void
 
85
brasero_burn_dialog_tray_show_dialog_cb (BraseroTrayIcon *tray,
 
86
                                         gboolean show,
 
87
                                         GtkWidget *dialog);
 
88
 
 
89
typedef struct BraseroBurnDialogPrivate BraseroBurnDialogPrivate;
 
90
struct BraseroBurnDialogPrivate {
 
91
        BraseroBurn *burn;
 
92
        BraseroTrackType input;
 
93
        BraseroBurnSession *session;
 
94
 
 
95
        GtkWidget *progress;
 
96
        GtkWidget *header;
 
97
        GtkWidget *cancel;
 
98
        GtkWidget *image;
 
99
        BraseroTrayIcon *tray;
 
100
 
 
101
        /* for our final statistics */
 
102
        GTimer *total_time;
 
103
        gint64 total_size;
 
104
        GSList *rates;
 
105
 
 
106
        guint is_writing:1;
 
107
        guint is_creating_image:1;
 
108
};
 
109
 
 
110
#define BRASERO_BURN_DIALOG_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_BURN_DIALOG, BraseroBurnDialogPrivate))
 
111
 
 
112
#define TIMEOUT 10000
 
113
 
 
114
static GObjectClass *parent_class = NULL;
 
115
 
 
116
GType
 
117
brasero_burn_dialog_get_type ()
 
118
{
 
119
        static GType type = 0;
 
120
 
 
121
        if (type == 0) {
 
122
                static const GTypeInfo our_info = {
 
123
                        sizeof (BraseroBurnDialogClass),
 
124
                        NULL,
 
125
                        NULL,
 
126
                        (GClassInitFunc) brasero_burn_dialog_class_init,
 
127
                        NULL,
 
128
                        NULL,
 
129
                        sizeof (BraseroBurnDialog),
 
130
                        0,
 
131
                        (GInstanceInitFunc) brasero_burn_dialog_init,
 
132
                };
 
133
 
 
134
                type = g_type_register_static (GTK_TYPE_DIALOG,
 
135
                                               "BraseroBurnDialog",
 
136
                                               &our_info, 0);
 
137
        }
 
138
 
 
139
        return type;
 
140
}
 
141
 
 
142
static void
 
143
brasero_burn_dialog_class_init (BraseroBurnDialogClass * klass)
 
144
{
 
145
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
146
        GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
 
147
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
148
 
 
149
        g_type_class_add_private (klass, sizeof (BraseroBurnDialogPrivate));
 
150
 
 
151
        parent_class = g_type_class_peek_parent (klass);
 
152
        object_class->finalize = brasero_burn_dialog_finalize;
 
153
        gtk_object_class->destroy = brasero_burn_dialog_destroy;
 
154
        widget_class->delete_event = brasero_burn_dialog_delete;
 
155
}
 
156
 
 
157
/**
 
158
 * NOTE: if input is DISC then media is the media input
 
159
 */
 
160
 
 
161
static void
 
162
brasero_burn_dialog_update_info (BraseroBurnDialog *dialog,
 
163
                                 BraseroTrackType *input,
 
164
                                 BraseroMedia media)
 
165
{
 
166
        gchar *title = NULL;
 
167
        gchar *header = NULL;
 
168
        BraseroBurnFlag flags;
 
169
        BraseroBurnDialogPrivate *priv;
 
170
 
 
171
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
172
 
 
173
        flags = brasero_burn_session_get_flags (priv->session);
 
174
        if (media == BRASERO_MEDIUM_FILE) {
 
175
                /* we are creating an image to the hard drive */
 
176
                gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
177
                                              "iso-image-new",
 
178
                                              GTK_ICON_SIZE_DIALOG);
 
179
 
 
180
                header = g_strdup_printf ("<big><b>%s</b></big>", _("Creating image"));
 
181
                title = g_strdup (_("Brasero - Creating Image"));
 
182
        }
 
183
        else if (media & BRASERO_MEDIUM_DVD) {
 
184
                if (input->type == BRASERO_TRACK_TYPE_STREAM
 
185
                &&  BRASERO_STREAM_FORMAT_HAS_VIDEO (input->subtype.stream_format)) {
 
186
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
187
                                title = g_strdup (_("Brasero - Burning DVD (Simulation)"));
 
188
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of video DVD burning"));
 
189
                        }
 
190
                        else {
 
191
                                title = g_strdup (_("Brasero - Burning DVD"));
 
192
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning video DVD"));
 
193
                        }
 
194
 
 
195
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
196
                                                      "media-optical-video-new",
 
197
                                                      GTK_ICON_SIZE_DIALOG);
 
198
                }
 
199
                else if (input->type == BRASERO_TRACK_TYPE_DATA) {
 
200
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
201
                                title = g_strdup (_("Brasero - Burning DVD (Simulation)"));
 
202
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of data DVD burning"));
 
203
                        }
 
204
                        else {
 
205
                                title = g_strdup (_("Brasero - Burning DVD"));
 
206
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning data DVD"));
 
207
                        }
 
208
 
 
209
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
210
                                                      "media-optical-data-new",
 
211
                                                      GTK_ICON_SIZE_DIALOG);
 
212
                }
 
213
                else if (input->type == BRASERO_TRACK_TYPE_IMAGE) {
 
214
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
215
                                title = g_strdup (_("Burning DVD (Simulation)"));
 
216
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of image to DVD burning"));
 
217
                        }
 
218
                        else {
 
219
                                title = g_strdup (_("Burning DVD"));
 
220
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning image to DVD"));
 
221
                        }
 
222
 
 
223
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
224
                                                      "media-optical",
 
225
                                                      GTK_ICON_SIZE_DIALOG);
 
226
                }
 
227
                else if (input->type == BRASERO_TRACK_TYPE_DISC) {
 
228
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
229
                                title = g_strdup (_("Brasero - Copying DVD (Simulation)"));
 
230
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of data DVD copying"));
 
231
                        }
 
232
                        else {
 
233
                                title = g_strdup (_("Brasero - Copying DVD"));
 
234
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Copying data DVD"));
 
235
                        }
 
236
 
 
237
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
238
                                                      "media-optical-copy",
 
239
                                                      GTK_ICON_SIZE_DIALOG);
 
240
                }
 
241
        }
 
242
        else if (media & BRASERO_MEDIUM_CD) {
 
243
                if (input->type == BRASERO_TRACK_TYPE_STREAM
 
244
                &&  BRASERO_STREAM_FORMAT_HAS_VIDEO (input->subtype.stream_format)) {
 
245
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
246
                                title = g_strdup (_("Brasero - Burning CD (Simulation)"));
 
247
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of (S)VCD burning"));
 
248
                        }
 
249
                        else {
 
250
                                title = g_strdup (_("Brasero - Burning CD"));
 
251
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning (S)VCD"));
 
252
                        }
 
253
 
 
254
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
255
                                                      "drive-removable-media",
 
256
                                                      GTK_ICON_SIZE_DIALOG);
 
257
                }
 
258
                else if (input->type == BRASERO_TRACK_TYPE_STREAM) {
 
259
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
260
                                title = g_strdup (_("Brasero - Burning CD (Simulation)"));
 
261
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of audio CD burning"));
 
262
                        }
 
263
                        else {
 
264
                                title = g_strdup (_("Brasero - Burning CD"));
 
265
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning audio CD"));
 
266
                        }
 
267
 
 
268
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
269
                                                      "media-optical-audio-new",
 
270
                                                      GTK_ICON_SIZE_DIALOG);
 
271
                }
 
272
                else if (input->type == BRASERO_TRACK_TYPE_DATA) {
 
273
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
274
                                title = g_strdup (_("Brasero - Burning CD (Simulation)"));
 
275
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of data CD burning"));
 
276
                        }
 
277
                        else {
 
278
                                title = g_strdup (_("Brasero - Burning CD"));
 
279
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning data CD"));
 
280
                        }
 
281
 
 
282
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
283
                                                      "media-optical-data-new",
 
284
                                                      GTK_ICON_SIZE_DIALOG);
 
285
                }
 
286
                else if (input->type == BRASERO_TRACK_TYPE_DISC) {
 
287
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
288
                                title = g_strdup (_("Brasero - Copying CD (Simulation)"));
 
289
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of CD copying"));
 
290
                        }
 
291
                        else {
 
292
                                title = g_strdup (_("Brasero - Copying CD"));
 
293
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Copying CD"));
 
294
                        }
 
295
 
 
296
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
297
                                                      "media-optical-copy",
 
298
                                                      GTK_ICON_SIZE_DIALOG);
 
299
                }
 
300
                else if (input->type == BRASERO_TRACK_TYPE_IMAGE) {
 
301
                        if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
302
                                title = g_strdup (_("Brasero - Burning CD (Simulation)"));
 
303
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of image to CD burning"));
 
304
                        }
 
305
                        else {
 
306
                                title = g_strdup (_("Brasero - Burning CD"));
 
307
                                header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning image to CD"));
 
308
                        }
 
309
                
 
310
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
311
                                                      "media-optical",
 
312
                                                      GTK_ICON_SIZE_DIALOG);
 
313
                }
 
314
        }
 
315
        else if (input->type == BRASERO_TRACK_TYPE_STREAM
 
316
             &&  BRASERO_STREAM_FORMAT_HAS_VIDEO (input->subtype.stream_format)) {
 
317
                if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
318
                        title = g_strdup (_("Brasero - Burning disc (Simulation)"));
 
319
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of video disc burning"));
 
320
                }
 
321
                else {
 
322
                        title = g_strdup (_("Brasero - Burning disc"));
 
323
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning video disc"));
 
324
                }
 
325
 
 
326
                gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
327
                                              "drive-removable-media",
 
328
                                              GTK_ICON_SIZE_DIALOG);
 
329
        }
 
330
        else if (input->type == BRASERO_TRACK_TYPE_STREAM) {
 
331
                if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
332
                        title = g_strdup (_("Brasero - Burning CD (Simulation)"));
 
333
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of audio CD burning"));
 
334
                }
 
335
                else {
 
336
                        title = g_strdup (_("Brasero - Burning CD"));
 
337
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning audio CD"));
 
338
                }
 
339
 
 
340
                gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
341
                                              "drive-removable-media",
 
342
                                              GTK_ICON_SIZE_DIALOG);
 
343
        }
 
344
        else if (input->type == BRASERO_TRACK_TYPE_DATA) {
 
345
                if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
346
                        title = g_strdup (_("Brasero - Burning Disc (Simulation)"));
 
347
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of data disc burning"));
 
348
                }
 
349
                else {
 
350
                        title = g_strdup (_("Brasero - Burning Disc"));
 
351
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning data disc"));
 
352
                }
 
353
 
 
354
                gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
355
                                              "drive-removable-media",
 
356
                                              GTK_ICON_SIZE_DIALOG);
 
357
        }
 
358
        else if (input->type == BRASERO_TRACK_TYPE_DISC) {
 
359
                if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
360
                        title = g_strdup (_("Brasero - Copying Disc (Simulation)"));
 
361
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of disc copying"));
 
362
                }
 
363
                else {
 
364
                        title = g_strdup (_("Brasero - Copying Disc"));
 
365
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Copying disc"));
 
366
                }
 
367
                gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
368
                                              "drive-removable-media",
 
369
                                              GTK_ICON_SIZE_DIALOG);
 
370
        }
 
371
        else if (input->type == BRASERO_TRACK_TYPE_IMAGE) {
 
372
                if (flags & BRASERO_BURN_FLAG_DUMMY) {
 
373
                        title = g_strdup (_("Brasero - Burning Disc (Simulation)"));
 
374
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Simulation of image to disc burning"));
 
375
                }
 
376
                else {
 
377
                        title = g_strdup (_("Brasero - Burning Disc"));
 
378
                        header = g_strdup_printf ("<big><b>%s</b></big>", _("Burning image to disc"));
 
379
                }
 
380
 
 
381
                gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
 
382
                                              "drive-removable-media",
 
383
                                              GTK_ICON_SIZE_DIALOG);
 
384
        }
 
385
 
 
386
 
 
387
        if (title) {
 
388
                gtk_window_set_title (GTK_WINDOW (dialog), title);
 
389
                g_free (title);
 
390
        }
 
391
 
 
392
        gtk_label_set_text (GTK_LABEL (priv->header), header);
 
393
        gtk_label_set_use_markup (GTK_LABEL (priv->header), TRUE);
 
394
        g_free (header);
 
395
 
 
396
        /* it may have changed */
 
397
        gtk_window_set_icon_name (GTK_WINDOW (dialog), "brasero");
 
398
}
 
399
 
 
400
static void
 
401
brasero_burn_dialog_wait_for_insertion_cb (BraseroDrive *drive,
 
402
                                           BraseroMedium *medium,
 
403
                                           GtkDialog *message)
 
404
{
 
405
        /* we might have a dialog waiting for the 
 
406
         * insertion of a disc if so close it */
 
407
        gtk_dialog_response (GTK_DIALOG (message), GTK_RESPONSE_OK);
 
408
}
 
409
 
 
410
static gint
 
411
brasero_burn_dialog_wait_for_insertion (BraseroBurnDialog *dialog,
 
412
                                        BraseroDrive *drive,
 
413
                                        const gchar *main_message,
 
414
                                        const gchar *secondary_message)
 
415
{
 
416
        gint result;
 
417
        gint added_id;
 
418
        GtkWindow *window;
 
419
        GtkWidget *message;
 
420
        gboolean hide = FALSE;
 
421
        BraseroBurnDialogPrivate *priv;
 
422
 
 
423
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
424
        window = GTK_WINDOW (dialog);
 
425
 
 
426
        if (!GTK_WIDGET_VISIBLE (dialog)) {
 
427
                gtk_widget_show (GTK_WIDGET (dialog));
 
428
                hide = TRUE;
 
429
        }
 
430
 
 
431
        g_timer_stop (priv->total_time);
 
432
 
 
433
        if (secondary_message) {
 
434
                message = gtk_message_dialog_new (window,
 
435
                                                  GTK_DIALOG_DESTROY_WITH_PARENT|
 
436
                                                  GTK_DIALOG_MODAL,
 
437
                                                  GTK_MESSAGE_WARNING,
 
438
                                                  GTK_BUTTONS_CANCEL,
 
439
                                                  "%s", main_message);
 
440
 
 
441
                if (secondary_message)
 
442
                        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
443
                                                                  "%s", secondary_message);
 
444
        }
 
445
        else {
 
446
                gchar *string;
 
447
 
 
448
                message = gtk_message_dialog_new_with_markup (window,
 
449
                                                              GTK_DIALOG_DESTROY_WITH_PARENT|
 
450
                                                              GTK_DIALOG_MODAL,
 
451
                                                              GTK_MESSAGE_WARNING,
 
452
                                                              GTK_BUTTONS_CANCEL,
 
453
                                                              NULL);
 
454
 
 
455
                string = g_strdup_printf ("<b><big>%s</big></b>", main_message);
 
456
                gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (message), string);
 
457
                g_free (string);
 
458
        }
 
459
 
 
460
        /* connect to signals to be warned when media is inserted */
 
461
        added_id = g_signal_connect_after (drive,
 
462
                                           "medium-added",
 
463
                                           G_CALLBACK (brasero_burn_dialog_wait_for_insertion_cb),
 
464
                                           message);
 
465
 
 
466
        result = gtk_dialog_run (GTK_DIALOG (message));
 
467
 
 
468
        g_signal_handler_disconnect (drive, added_id);
 
469
        gtk_widget_destroy (message);
 
470
 
 
471
        if (hide)
 
472
                gtk_widget_hide (GTK_WIDGET (dialog));
 
473
 
 
474
        g_timer_start (priv->total_time);
 
475
 
 
476
        return result;
 
477
}
 
478
 
 
479
static gchar *
 
480
brasero_burn_dialog_get_media_type_string (BraseroBurn *burn,
 
481
                                           BraseroMedia type,
 
482
                                           gboolean insert)
 
483
{
 
484
        gchar *message = NULL;
 
485
 
 
486
        if (type & BRASERO_MEDIUM_HAS_DATA) {
 
487
                if (!insert) {
 
488
                        if (type & BRASERO_MEDIUM_REWRITABLE)
 
489
                                message = g_strdup (_("Please replace the disc with a rewritable disc holding data."));
 
490
                        else
 
491
                                message = g_strdup (_("Please replace the disc with a disc holding data."));
 
492
                }
 
493
                else {
 
494
                        if (type & BRASERO_MEDIUM_REWRITABLE)
 
495
                                message = g_strdup (_("Please insert a rewritable disc holding data."));
 
496
                        else
 
497
                                message = g_strdup (_("Please insert a disc holding data."));
 
498
                }
 
499
        }
 
500
        else if (type & BRASERO_MEDIUM_WRITABLE) {
 
501
                gint64 isosize = 0;
 
502
        
 
503
                brasero_burn_status (burn,
 
504
                                     NULL,
 
505
                                     &isosize,
 
506
                                     NULL,
 
507
                                     NULL);
 
508
 
 
509
                if ((type & BRASERO_MEDIUM_CD) && !(type & BRASERO_MEDIUM_DVD)) {
 
510
                        if (!insert) {
 
511
                                if (isosize)
 
512
                                        message = g_strdup_printf (_("Please replace the disc with a recordable CD with at least %i MiB of free space."), 
 
513
                                                                   (int) (isosize / 1048576));
 
514
                                else
 
515
                                        message = g_strdup (_("Please replace the disc with a recordable CD."));
 
516
                        }
 
517
                        else {
 
518
                                if (isosize)
 
519
                                        message = g_strdup_printf (_("Please insert a recordable CD with at least %i MiB of free space."), 
 
520
                                                                   (int) (isosize / 1048576));
 
521
                                else
 
522
                                        message = g_strdup (_("Please insert a recordable CD."));
 
523
                        }
 
524
                }
 
525
                else if (!(type & BRASERO_MEDIUM_CD) && (type & BRASERO_MEDIUM_DVD)) {
 
526
                        if (!insert) {
 
527
                                if (isosize)
 
528
                                        message = g_strdup_printf (_("Please replace the disc with a recordable DVD with at least %i MiB of free space."), 
 
529
                                                                   (int) (isosize / 1048576));
 
530
                                else
 
531
                                        message = g_strdup (_("Please replace the disc with a recordable DVD."));
 
532
                        }
 
533
                        else {
 
534
                                if (isosize)
 
535
                                        message = g_strdup_printf (_("Please insert a recordable DVD with at least %i MiB of free space."), 
 
536
                                                                   (int) (isosize / 1048576));
 
537
                                else
 
538
                                        message = g_strdup (_("Please insert a recordable DVD."));
 
539
                        }
 
540
                }
 
541
                else if (!insert) {
 
542
                        if (isosize)
 
543
                                message = g_strdup_printf (_("Please replace the disc with a recordable CD or DVD with at least %i MiB of free space."), 
 
544
                                                           (int) (isosize / 1048576));
 
545
                        else
 
546
                                message = g_strdup (_("Please replace the disc with a recordable CD or DVD."));
 
547
                }
 
548
                else {
 
549
                        if (isosize)
 
550
                                message = g_strdup_printf (_("Please insert a recordable CD or DVD with at least %i MiB of free space."), 
 
551
                                                           (int) (isosize / 1048576));
 
552
                        else
 
553
                                message = g_strdup (_("Please insert a recordable CD or DVD."));
 
554
                }
 
555
        }
 
556
 
 
557
        return message;
 
558
}
 
559
 
 
560
static BraseroBurnResult
 
561
brasero_burn_dialog_insert_disc_cb (BraseroBurn *burn,
 
562
                                    BraseroDrive *drive,
 
563
                                    BraseroBurnError error,
 
564
                                    BraseroMedia type,
 
565
                                    BraseroBurnDialog *dialog)
 
566
{
 
567
        gint result;
 
568
        gchar *drive_name;
 
569
        BraseroBurnDialogPrivate *priv;
 
570
        gchar *main_message = NULL, *secondary_message = NULL;
 
571
 
 
572
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
573
 
 
574
        if (drive)
 
575
                drive_name = brasero_drive_get_display_name (drive);
 
576
        else
 
577
                drive_name = NULL;
 
578
 
 
579
        if (error == BRASERO_BURN_WARNING_INSERT_AFTER_COPY) {
 
580
                secondary_message = g_strdup (_("An image of the disc has been created on your hard drive."
 
581
                                                "\nBurning will begin as soon as a recordable disc is inserted."));
 
582
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
 
583
        }
 
584
        else if (error == BRASERO_BURN_WARNING_CHECKSUM) {
 
585
                secondary_message = g_strdup (_("A data integrity test will begin as soon as the disc is inserted."));
 
586
                main_message = g_strdup (_("Please re-insert the disc in the CD/DVD burner."));
 
587
        }
 
588
        else if (error == BRASERO_BURN_ERROR_DRIVE_BUSY) {
 
589
                /* Translators: %s is the name of a drive */
 
590
                main_message = g_strdup_printf (_("\"%s\" is busy."), drive_name);
 
591
                secondary_message = g_strdup_printf ("%s.", _("Make sure another application is not using it"));
 
592
        } 
 
593
        else if (error == BRASERO_BURN_ERROR_MEDIUM_NONE) {
 
594
                secondary_message = g_strdup_printf (_("There is no disc in \"%s\"."), drive_name);
 
595
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, TRUE);
 
596
        }
 
597
        else if (error == BRASERO_BURN_ERROR_MEDIUM_INVALID) {
 
598
                secondary_message = g_strdup_printf (_("The disc in \"%s\" is not supported."), drive_name);
 
599
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, TRUE);
 
600
        }
 
601
        else if (error == BRASERO_BURN_ERROR_MEDIUM_NOT_REWRITABLE) {
 
602
                secondary_message = g_strdup_printf (_("The disc in \"%s\" is not rewritable."), drive_name);
 
603
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
 
604
        }
 
605
        else if (error == BRASERO_BURN_ERROR_MEDIUM_NO_DATA) {
 
606
                secondary_message = g_strdup_printf (_("The disc in \"%s\" is empty."), drive_name);
 
607
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
 
608
        }
 
609
        else if (error == BRASERO_BURN_ERROR_MEDIUM_NOT_WRITABLE) {
 
610
                secondary_message = g_strdup_printf (_("The disc in \"%s\" is not writable."), drive_name);
 
611
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
 
612
        }
 
613
        else if (error == BRASERO_BURN_ERROR_MEDIUM_SPACE) {
 
614
                secondary_message = g_strdup_printf (_("Not enough space available on the disc in \"%s\"."), drive_name);
 
615
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
 
616
        }
 
617
        else if (error == BRASERO_BURN_ERROR_NONE) {
 
618
                main_message = brasero_burn_dialog_get_media_type_string (burn, type, TRUE);
 
619
                secondary_message = NULL;
 
620
        }
 
621
        else if (error == BRASERO_BURN_ERROR_MEDIUM_NEED_RELOADING) {
 
622
                secondary_message = g_strdup_printf (_("The disc in \"%s\" needs to be reloaded."), drive_name);
 
623
                main_message = g_strdup (_("Please eject the disc and reload it."));
 
624
        }
 
625
 
 
626
        g_free (drive_name);
 
627
 
 
628
        result = brasero_burn_dialog_wait_for_insertion (dialog, drive, main_message, secondary_message);
 
629
        g_free (main_message);
 
630
        g_free (secondary_message);
 
631
 
 
632
        /* update the infos */
 
633
        brasero_burn_dialog_update_info (dialog,
 
634
                                         &priv->input, 
 
635
                                         brasero_burn_session_get_dest_media (priv->session));
 
636
 
 
637
        if (result != GTK_RESPONSE_OK)
 
638
                return BRASERO_BURN_CANCEL;
 
639
 
 
640
        return BRASERO_BURN_OK;
 
641
}
 
642
 
 
643
static BraseroBurnResult
 
644
brasero_burn_dialog_image_error (BraseroBurn *burn,
 
645
                                 GError *error,
 
646
                                 gboolean is_temporary,
 
647
                                 BraseroBurnDialog *dialog)
 
648
{
 
649
        gint result;
 
650
        gchar *path;
 
651
        gchar *string;
 
652
        GtkWindow *window;
 
653
        GtkWidget *message;
 
654
        gboolean hide = FALSE;
 
655
        BraseroBurnDialogPrivate *priv;
 
656
 
 
657
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
658
 
 
659
        if (!GTK_WIDGET_VISIBLE (dialog)) {
 
660
                gtk_widget_show (GTK_WIDGET (dialog));
 
661
                hide = TRUE;
 
662
        }
 
663
 
 
664
        g_timer_stop (priv->total_time);
 
665
 
 
666
        window = GTK_WINDOW (dialog);
 
667
 
 
668
        string = g_strdup_printf ("%s. %s",
 
669
                                  is_temporary?
 
670
                                  _("A file could not be created at the location specified for temporary files"):
 
671
                                  _("The image could not be created at the specified location"),
 
672
                                  _("Do you want to specify another location for this session or retry with the current location?"));
 
673
 
 
674
        message = gtk_message_dialog_new (window,
 
675
                                          GTK_DIALOG_DESTROY_WITH_PARENT|
 
676
                                          GTK_DIALOG_MODAL,
 
677
                                          GTK_MESSAGE_ERROR,
 
678
                                          GTK_BUTTONS_NONE,
 
679
                                          "%s",
 
680
                                          string);
 
681
        g_free (string);
 
682
 
 
683
        if (error && error->code == BRASERO_BURN_ERROR_DISK_SPACE)
 
684
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
685
                                                         "%s.\n%s.",
 
686
                                                          error->message,
 
687
                                                          _("You may want to free some space on the disc and retry"));
 
688
        else
 
689
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
690
                                                         "%s.",
 
691
                                                          error->message);
 
692
 
 
693
        gtk_dialog_add_buttons (GTK_DIALOG (message),
 
694
                                _("_Keep Current Location"), GTK_RESPONSE_OK,
 
695
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
696
                                _("_Change Location"), GTK_RESPONSE_ACCEPT,
 
697
                                NULL);
 
698
 
 
699
        result = gtk_dialog_run (GTK_DIALOG (message));
 
700
        gtk_widget_destroy (message);
 
701
 
 
702
        if (hide)
 
703
                gtk_widget_hide (GTK_WIDGET (dialog));
 
704
 
 
705
        if (result == GTK_RESPONSE_OK) {
 
706
                g_timer_start (priv->total_time);
 
707
                return BRASERO_BURN_OK;
 
708
        }
 
709
 
 
710
        if (result != GTK_RESPONSE_ACCEPT) {
 
711
                g_timer_start (priv->total_time);
 
712
                return BRASERO_BURN_CANCEL;
 
713
        }
 
714
 
 
715
        /* Show a GtkFileChooserDialog */
 
716
        if (!is_temporary) {
 
717
                gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (message), TRUE);
 
718
                message = gtk_file_chooser_dialog_new (_("Location for Image File"),
 
719
                                                       GTK_WINDOW (dialog),
 
720
                                                       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
 
721
                                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
722
                                                       GTK_STOCK_SAVE, GTK_RESPONSE_OK,
 
723
                                                       NULL);
 
724
        }
 
725
        else
 
726
                message = gtk_file_chooser_dialog_new (_("Location for Temporary Files"),
 
727
                                                       GTK_WINDOW (dialog),
 
728
                                                       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
 
729
                                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
730
                                                       GTK_STOCK_SAVE, GTK_RESPONSE_OK,
 
731
                                                       NULL);
 
732
 
 
733
        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (message), TRUE);
 
734
        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (message), g_get_home_dir ());
 
735
 
 
736
        result = gtk_dialog_run (GTK_DIALOG (message));
 
737
        if (result != GTK_RESPONSE_OK) {
 
738
                gtk_widget_destroy (message);
 
739
                g_timer_start (priv->total_time);
 
740
                return BRASERO_BURN_CANCEL;
 
741
        }
 
742
 
 
743
        path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (message));
 
744
        gtk_widget_destroy (message);
 
745
 
 
746
        if (!is_temporary) {
 
747
                BraseroImageFormat format;
 
748
                gchar *image = NULL;
 
749
                gchar *toc = NULL;
 
750
 
 
751
                format = brasero_burn_session_get_output_format (priv->session);
 
752
                brasero_burn_session_get_output (priv->session,
 
753
                                                 &image,
 
754
                                                 &toc,
 
755
                                                 NULL);
 
756
 
 
757
                if (toc) {
 
758
                        gchar *name;
 
759
 
 
760
                        name = g_path_get_basename (toc);
 
761
                        g_free (toc);
 
762
 
 
763
                        toc = g_build_filename (path, name, NULL);
 
764
                        BRASERO_BURN_LOG ("New toc location %s", toc);
 
765
                }
 
766
 
 
767
                if (image) {
 
768
                        gchar *name;
 
769
 
 
770
                        name = g_path_get_basename (image);
 
771
                        g_free (image);
 
772
 
 
773
                        image = g_build_filename (path, name, NULL);
 
774
                        BRASERO_BURN_LOG ("New image location %s", toc);
 
775
                }
 
776
 
 
777
                brasero_burn_session_set_image_output_full (priv->session,
 
778
                                                            format,
 
779
                                                            image,
 
780
                                                            toc);
 
781
        }
 
782
        else
 
783
                brasero_burn_session_set_tmpdir (priv->session, path);
 
784
 
 
785
        g_free (path);
 
786
 
 
787
        g_timer_start (priv->total_time);
 
788
        return BRASERO_BURN_OK;
 
789
}
 
790
 
 
791
static BraseroBurnResult
 
792
brasero_burn_dialog_loss_warnings_cb (GtkDialog *dialog, 
 
793
                                      const gchar *main_message,
 
794
                                      const gchar *secondary_message,
 
795
                                      const gchar *button_text,
 
796
                                      const gchar *button_icon)
 
797
{
 
798
        gint result;
 
799
        GtkWindow *window;
 
800
        GtkWidget *button;
 
801
        GtkWidget *message;
 
802
        gboolean hide = FALSE;
 
803
        BraseroBurnDialogPrivate *priv;
 
804
 
 
805
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
806
 
 
807
        if (!GTK_WIDGET_VISIBLE (dialog)) {
 
808
                gtk_widget_show (GTK_WIDGET (dialog));
 
809
                hide = TRUE;
 
810
        }
 
811
 
 
812
        g_timer_stop (priv->total_time);
 
813
 
 
814
        window = GTK_WINDOW (dialog);
 
815
        message = gtk_message_dialog_new (window,
 
816
                                          GTK_DIALOG_DESTROY_WITH_PARENT|
 
817
                                          GTK_DIALOG_MODAL,
 
818
                                          GTK_MESSAGE_WARNING,
 
819
                                          GTK_BUTTONS_NONE,
 
820
                                          "%s", main_message);
 
821
 
 
822
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
823
                                                 "%s", secondary_message);
 
824
 
 
825
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
826
                                        _("_Replace Disc"),
 
827
                                        GTK_RESPONSE_ACCEPT);
 
828
        gtk_button_set_image (GTK_BUTTON (button),
 
829
                              gtk_image_new_from_stock (GTK_STOCK_REFRESH,
 
830
                                                        GTK_ICON_SIZE_BUTTON));
 
831
 
 
832
        gtk_dialog_add_button (GTK_DIALOG (message),
 
833
                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
 
834
 
 
835
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
836
                                        button_text,
 
837
                                        GTK_RESPONSE_OK);
 
838
        gtk_button_set_image (GTK_BUTTON (button),
 
839
                              gtk_image_new_from_icon_name (button_icon,
 
840
                                                            GTK_ICON_SIZE_BUTTON));
 
841
 
 
842
        result = gtk_dialog_run (GTK_DIALOG (message));
 
843
        gtk_widget_destroy (message);
 
844
 
 
845
        if (hide)
 
846
                gtk_widget_hide (GTK_WIDGET (dialog));
 
847
 
 
848
        g_timer_start (priv->total_time);
 
849
 
 
850
        if (result == GTK_RESPONSE_ACCEPT)
 
851
                return BRASERO_BURN_NEED_RELOAD;
 
852
 
 
853
        if (result != GTK_RESPONSE_OK)
 
854
                return BRASERO_BURN_CANCEL;
 
855
 
 
856
        return BRASERO_BURN_OK;
 
857
}
 
858
 
 
859
static BraseroBurnResult
 
860
brasero_burn_dialog_data_loss_cb (BraseroBurn *burn,
 
861
                                  GtkDialog *dialog)
 
862
{
 
863
        return brasero_burn_dialog_loss_warnings_cb (dialog,
 
864
                                                     _("Do you really want to erase the current disc?"),
 
865
                                                     _("The disc in the drive holds data."),
 
866
                                                     _("_Erase Disc"),
 
867
                                                     "media-optical-blank");
 
868
}
 
869
 
 
870
static BraseroBurnResult
 
871
brasero_burn_dialog_previous_session_loss_cb (BraseroBurn *burn,
 
872
                                              GtkDialog *dialog)
 
873
{
 
874
        gchar *secondary;
 
875
        BraseroBurnResult result;
 
876
 
 
877
        secondary = g_strdup_printf ("%s\n%s",
 
878
                                     _("Already burnt files will be invisible (though still readable)."),
 
879
                                     _("Do you want to continue anyway?"));
 
880
                                     
 
881
        result = brasero_burn_dialog_loss_warnings_cb (dialog,
 
882
                                                       _("Appending new files to a multisession disc is not advised."),
 
883
                                                       secondary,
 
884
                                                       _("_Continue"),
 
885
                                                       "media-optical-burn");
 
886
        g_free (secondary);
 
887
        return result;
 
888
}
 
889
 
 
890
static BraseroBurnResult
 
891
brasero_burn_dialog_audio_to_appendable_cb (BraseroBurn *burn,
 
892
                                            GtkDialog *dialog)
 
893
{
 
894
        gchar *secondary;
 
895
        BraseroBurnResult result;
 
896
 
 
897
        secondary = g_strdup_printf ("%s\n%s",
 
898
                                     _("You might not be able to listen to them with stereos and CD-TEXT won't be written."),
 
899
                                     _("Do you want to continue anyway?"));
 
900
 
 
901
        result = brasero_burn_dialog_loss_warnings_cb (dialog,
 
902
                                                       _("Appending audio tracks to a CD is not advised."),
 
903
                                                       secondary,
 
904
                                                       _("_Continue"),
 
905
                                                       "media-optical-burn");
 
906
        g_free (secondary);
 
907
        return result;
 
908
}
 
909
 
 
910
static BraseroBurnResult
 
911
brasero_burn_dialog_rewritable_cb (BraseroBurn *burn,
 
912
                                   GtkDialog *dialog)
 
913
{
 
914
        gchar *secondary;
 
915
        BraseroBurnResult result;
 
916
 
 
917
        secondary = g_strdup_printf ("%s\n%s",
 
918
                                     _("You might not be able to listen to it with stereos."),
 
919
                                     _("Do you want to continue anyway?"));
 
920
 
 
921
        result = brasero_burn_dialog_loss_warnings_cb (dialog,
 
922
                                                       _("Recording audio tracks on a rewritable disc is not advised."),
 
923
                                                       secondary,
 
924
                                                       _("_Continue"),
 
925
                                                       "media-optical-burn");
 
926
        g_free (secondary);
 
927
        return result;
 
928
}
 
929
 
 
930
static BraseroBurnResult
 
931
brasero_burn_dialog_disable_joliet_cb (BraseroBurn *burn,
 
932
                                       GtkDialog *dialog)
 
933
{
 
934
        gint result;
 
935
        GtkWindow *window;
 
936
        GtkWidget *button;
 
937
        GtkWidget *message;
 
938
        gboolean hide = FALSE;
 
939
        BraseroBurnDialogPrivate *priv;
 
940
 
 
941
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
942
 
 
943
        if (!GTK_WIDGET_VISIBLE (dialog)) {
 
944
                gtk_widget_show (GTK_WIDGET (dialog));
 
945
                hide = TRUE;
 
946
        }
 
947
 
 
948
        g_timer_stop (priv->total_time);
 
949
 
 
950
        window = GTK_WINDOW (dialog);
 
951
        message = gtk_message_dialog_new (window,
 
952
                                          GTK_DIALOG_DESTROY_WITH_PARENT|
 
953
                                          GTK_DIALOG_MODAL,
 
954
                                          GTK_MESSAGE_WARNING,
 
955
                                          GTK_BUTTONS_NONE,
 
956
                                          _("Do you want to continue with full Windows compatibility disabled?"));
 
957
 
 
958
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
959
                                                  _("Some files don't have a suitable name for a fully Windows-compatible CD."));
 
960
 
 
961
        gtk_dialog_add_button (GTK_DIALOG (message),
 
962
                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
 
963
 
 
964
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
965
                                        _("_Continue"),
 
966
                                        GTK_RESPONSE_OK);
 
967
        gtk_button_set_image (GTK_BUTTON (button),
 
968
                              gtk_image_new_from_stock (GTK_STOCK_OK,
 
969
                                                        GTK_ICON_SIZE_BUTTON));
 
970
        
 
971
        result = gtk_dialog_run (GTK_DIALOG (message));
 
972
        gtk_widget_destroy (message);
 
973
 
 
974
        if (hide)
 
975
                gtk_widget_hide (GTK_WIDGET (dialog));
 
976
 
 
977
        g_timer_start (priv->total_time);
 
978
 
 
979
        if (result != GTK_RESPONSE_OK)
 
980
                return BRASERO_BURN_CANCEL;
 
981
 
 
982
        return BRASERO_BURN_OK;
 
983
}
 
984
 
 
985
static void
 
986
brasero_burn_dialog_update_title_writing_progress (BraseroBurnDialog *dialog,
 
987
                                                   BraseroTrackType *input,
 
988
                                                   BraseroMedia media,
 
989
                                                   guint percent)
 
990
{
 
991
        BraseroBurnDialogPrivate *priv;
 
992
        BraseroBurnFlag flags;
 
993
        gchar *title = NULL;
 
994
        gchar *icon_name;
 
995
        guint remains;
 
996
 
 
997
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
998
 
 
999
        flags = brasero_burn_session_get_flags (priv->session);
 
1000
 
 
1001
        /* This is used only when actually writing to a disc */
 
1002
        if (media == BRASERO_MEDIUM_FILE)
 
1003
                title = g_strdup_printf (_("Brasero - Creating Image (%i%% Done)"), percent);
 
1004
        else if (media & BRASERO_MEDIUM_DVD) {
 
1005
                if (input->type == BRASERO_TRACK_TYPE_DISC) {
 
1006
                        if (flags & BRASERO_BURN_FLAG_DUMMY)
 
1007
                                title = g_strdup (_("Brasero - Copying DVD (Simulation)"));
 
1008
                        else
 
1009
                                title = g_strdup_printf (_("Brasero - Copying DVD (%i%% Done)"), percent);
 
1010
                }
 
1011
                else {
 
1012
                        if (flags & BRASERO_BURN_FLAG_DUMMY)
 
1013
                                title = g_strdup (_("Brasero - Burning DVD (Simulation)"));
 
1014
                        else
 
1015
                                title = g_strdup_printf (_("Brasero - Burning DVD (%i%% Done)"), percent);
 
1016
                }
 
1017
        }
 
1018
        else if (media & BRASERO_MEDIUM_CD) {
 
1019
                if (input->type == BRASERO_TRACK_TYPE_DISC) {
 
1020
                        if (flags & BRASERO_BURN_FLAG_DUMMY)
 
1021
                                title = g_strdup (_("Brasero - Copying CD (Simulation)"));
 
1022
                        else
 
1023
                                title = g_strdup_printf (_("Brasero - Copying CD (%i%% Done)"), percent);
 
1024
                }
 
1025
                else {
 
1026
                        if (flags & BRASERO_BURN_FLAG_DUMMY)
 
1027
                                title = g_strdup (_("Brasero - Burning CD (simulation)"));
 
1028
                        else
 
1029
                                title = g_strdup_printf (_("Brasero - Burning CD (%i%% Done)"), percent);
 
1030
                }
 
1031
        }
 
1032
        else if (input->type == BRASERO_TRACK_TYPE_DISC) {
 
1033
                if (flags & BRASERO_BURN_FLAG_DUMMY)
 
1034
                        title = g_strdup (_("Brasero - Copying Disc (Simulation)"));
 
1035
                else
 
1036
                        title = g_strdup_printf (_("Brasero - Copying Disc (%i%% Done)"), percent);
 
1037
        }
 
1038
        else {
 
1039
                if (flags & BRASERO_BURN_FLAG_DUMMY)
 
1040
                        title = g_strdup (_("Brasero - Burning Disc (Simulation)"));
 
1041
                else
 
1042
                        title = g_strdup_printf (_("Brasero - Burning Disc (%i%% Done)"), percent);
 
1043
        }
 
1044
 
 
1045
        gtk_window_set_title (GTK_WINDOW (dialog), title);
 
1046
        g_free (title);
 
1047
 
 
1048
        /* also update the icon */
 
1049
        remains = percent % 5;
 
1050
        if (remains > 3)
 
1051
                percent += 5 - remains;
 
1052
        else
 
1053
                percent -= remains;
 
1054
 
 
1055
        if (percent < 0 || percent > 100)
 
1056
                return;
 
1057
 
 
1058
        icon_name = g_strdup_printf ("brasero-disc-%02i", percent);
 
1059
        gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name);
 
1060
        g_free (icon_name);
 
1061
}
 
1062
 
 
1063
static void
 
1064
brasero_burn_dialog_progress_changed_real (BraseroBurnDialog *dialog,
 
1065
                                           gint64 written,
 
1066
                                           gint64 isosize,
 
1067
                                           gint64 rate,
 
1068
                                           gdouble overall_progress,
 
1069
                                           gdouble task_progress,
 
1070
                                           glong remaining,
 
1071
                                           BraseroMedia media)
 
1072
{
 
1073
        gint mb_isosize = -1;
 
1074
        gint mb_written = -1;
 
1075
        BraseroBurnDialogPrivate *priv;
 
1076
 
 
1077
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1078
 
 
1079
        if (written >= 0)
 
1080
                mb_written = (gint) (written / 1048576);
 
1081
        
 
1082
        if (isosize > 0)
 
1083
                mb_isosize = (gint) (isosize / 1048576);
 
1084
 
 
1085
        if (task_progress >= 0.0 && priv->is_writing)
 
1086
                brasero_burn_dialog_update_title_writing_progress (dialog,
 
1087
                                                                   &priv->input,
 
1088
                                                                   media,
 
1089
                                                                   (guint) (task_progress * 100.0));
 
1090
 
 
1091
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (priv->progress),
 
1092
                                          media,
 
1093
                                          overall_progress,
 
1094
                                          task_progress,
 
1095
                                          remaining,
 
1096
                                          mb_isosize,
 
1097
                                          mb_written,
 
1098
                                          rate);
 
1099
 
 
1100
        brasero_tray_icon_set_progress (BRASERO_TRAYICON (priv->tray),
 
1101
                                        task_progress,
 
1102
                                        remaining);
 
1103
 
 
1104
        if (rate > 0 && priv->is_writing)
 
1105
                priv->rates = g_slist_prepend (priv->rates, GINT_TO_POINTER ((gint) rate));
 
1106
}
 
1107
 
 
1108
static void
 
1109
brasero_burn_dialog_progress_changed_cb (BraseroBurn *burn, 
 
1110
                                         gdouble overall_progress,
 
1111
                                         gdouble task_progress,
 
1112
                                         glong remaining,
 
1113
                                         BraseroBurnDialog *dialog)
 
1114
{
 
1115
        BraseroMedia media = BRASERO_MEDIUM_NONE;
 
1116
        BraseroBurnDialogPrivate *priv;
 
1117
        goffset isosize = -1;
 
1118
        goffset written = -1;
 
1119
        guint64 rate = -1;
 
1120
 
 
1121
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1122
 
 
1123
        brasero_burn_status (priv->burn,
 
1124
                             &media,
 
1125
                             &isosize,
 
1126
                             &written,
 
1127
                             &rate);
 
1128
 
 
1129
        brasero_burn_dialog_progress_changed_real (dialog,
 
1130
                                                   written,
 
1131
                                                   isosize,
 
1132
                                                   rate,
 
1133
                                                   overall_progress,
 
1134
                                                   task_progress,
 
1135
                                                   remaining,
 
1136
                                                   media);
 
1137
        if ((priv->is_writing || priv->is_creating_image) && isosize > 0)
 
1138
                priv->total_size = isosize;
 
1139
}
 
1140
 
 
1141
static void
 
1142
brasero_burn_dialog_action_changed_real (BraseroBurnDialog *dialog,
 
1143
                                         BraseroBurnAction action,
 
1144
                                         const gchar *string)
 
1145
{
 
1146
        BraseroBurnDialogPrivate *priv;
 
1147
 
 
1148
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1149
 
 
1150
        brasero_burn_progress_set_action (BRASERO_BURN_PROGRESS (priv->progress),
 
1151
                                          action,
 
1152
                                          string);
 
1153
        brasero_tray_icon_set_action (BRASERO_TRAYICON (priv->tray),
 
1154
                                      action,
 
1155
                                      string);
 
1156
}
 
1157
 
 
1158
static void
 
1159
brasero_burn_dialog_action_changed_cb (BraseroBurn *burn, 
 
1160
                                       BraseroBurnAction action,
 
1161
                                       BraseroBurnDialog *dialog)
 
1162
{
 
1163
        BraseroBurnDialogPrivate *priv;
 
1164
        gchar *string = NULL;
 
1165
        gboolean is_writing;
 
1166
 
 
1167
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1168
 
 
1169
        is_writing = (action == BRASERO_BURN_ACTION_RECORDING ||
 
1170
                      action == BRASERO_BURN_ACTION_DRIVE_COPY ||
 
1171
                      action == BRASERO_BURN_ACTION_RECORDING_CD_TEXT ||
 
1172
                      action == BRASERO_BURN_ACTION_LEADIN ||
 
1173
                      action == BRASERO_BURN_ACTION_LEADOUT ||
 
1174
                      action == BRASERO_BURN_ACTION_FIXATING);
 
1175
 
 
1176
        if (action == BRASERO_BURN_ACTION_START_RECORDING
 
1177
        || (priv->is_writing && !is_writing)) {
 
1178
                BraseroMedia media = BRASERO_MEDIUM_NONE;
 
1179
 
 
1180
                brasero_burn_status (burn, &media, NULL, NULL, NULL);
 
1181
                brasero_burn_dialog_update_info (dialog,
 
1182
                                                 &priv->input,
 
1183
                                                 media);
 
1184
        }
 
1185
 
 
1186
        priv->is_creating_image = (action == BRASERO_BURN_ACTION_CREATING_IMAGE);
 
1187
        priv->is_writing = is_writing;
 
1188
 
 
1189
        brasero_burn_get_action_string (priv->burn, action, &string);
 
1190
        brasero_burn_dialog_action_changed_real (dialog, action, string);
 
1191
        g_free (string);
 
1192
}
 
1193
 
 
1194
static gboolean
 
1195
brasero_burn_dialog_dummy_success_timeout (gpointer data)
 
1196
{
 
1197
        GtkDialog *dialog = data;
 
1198
        gtk_dialog_response (dialog, GTK_RESPONSE_OK);
 
1199
        return FALSE;
 
1200
}
 
1201
 
 
1202
static BraseroBurnResult
 
1203
brasero_burn_dialog_dummy_success_cb (BraseroBurn *burn,
 
1204
                                      BraseroBurnDialog *dialog)
 
1205
{
 
1206
        BraseroBurnDialogPrivate *priv;
 
1207
        GtkResponseType answer;
 
1208
        GtkWidget *message;
 
1209
        GtkWindow *window;
 
1210
        GtkWidget *button;
 
1211
        gboolean hide;
 
1212
        gint id;
 
1213
 
 
1214
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1215
 
 
1216
        if (!GTK_WIDGET_MAPPED (dialog)) {
 
1217
                gtk_widget_show (GTK_WIDGET (dialog));
 
1218
                hide = TRUE;
 
1219
        }
 
1220
        else
 
1221
                hide = FALSE;
 
1222
 
 
1223
        g_timer_stop (priv->total_time);
 
1224
 
 
1225
        window = GTK_WINDOW (dialog);
 
1226
        message = gtk_message_dialog_new (window,
 
1227
                                          GTK_DIALOG_DESTROY_WITH_PARENT|
 
1228
                                          GTK_DIALOG_MODAL,
 
1229
                                          GTK_MESSAGE_INFO,
 
1230
                                          GTK_BUTTONS_CANCEL,
 
1231
                                          _("The simulation was successful."));
 
1232
 
 
1233
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
1234
                                                  _("Real disc burning will take place in 10 seconds."));
 
1235
 
 
1236
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
1237
                                        _("Burn _Now"),
 
1238
                                        GTK_RESPONSE_OK);
 
1239
        gtk_button_set_image (GTK_BUTTON (button),
 
1240
                              gtk_image_new_from_icon_name ("media-optical-burn",
 
1241
                                                            GTK_ICON_SIZE_BUTTON));
 
1242
        id = g_timeout_add_seconds (10,
 
1243
                                    brasero_burn_dialog_dummy_success_timeout,
 
1244
                                    message);
 
1245
 
 
1246
        gtk_widget_show (GTK_WIDGET (dialog));
 
1247
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE);
 
1248
 
 
1249
        answer = gtk_dialog_run (GTK_DIALOG (message));
 
1250
        gtk_widget_destroy (message);
 
1251
 
 
1252
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), FALSE);
 
1253
 
 
1254
        if (hide)
 
1255
                gtk_widget_hide (GTK_WIDGET (dialog));
 
1256
 
 
1257
        g_timer_start (priv->total_time);
 
1258
 
 
1259
        if (answer == GTK_RESPONSE_OK) {
 
1260
                if (id)
 
1261
                        g_source_remove (id);
 
1262
 
 
1263
                return BRASERO_BURN_OK;
 
1264
        }
 
1265
 
 
1266
        if (id)
 
1267
                g_source_remove (id);
 
1268
 
 
1269
        return BRASERO_BURN_CANCEL;
 
1270
}
 
1271
 
 
1272
static void
 
1273
brasero_burn_dialog_init (BraseroBurnDialog * obj)
 
1274
{
 
1275
        GtkWidget *box;
 
1276
        GtkWidget *vbox;
 
1277
        GtkWidget *alignment;
 
1278
        BraseroBurnDialogPrivate *priv;
 
1279
 
 
1280
        priv = BRASERO_BURN_DIALOG_PRIVATE (obj);
 
1281
 
 
1282
        gtk_window_set_default_size (GTK_WINDOW (obj), 500, 0);
 
1283
 
 
1284
        gtk_dialog_set_has_separator (GTK_DIALOG (obj), FALSE);
 
1285
 
 
1286
        priv->tray = brasero_tray_icon_new ();
 
1287
        g_signal_connect (priv->tray,
 
1288
                          "cancel",
 
1289
                          G_CALLBACK (brasero_burn_dialog_tray_cancel_cb),
 
1290
                          obj);
 
1291
        g_signal_connect (priv->tray,
 
1292
                          "show-dialog",
 
1293
                          G_CALLBACK (brasero_burn_dialog_tray_show_dialog_cb),
 
1294
                          obj);
 
1295
 
 
1296
        alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
 
1297
        gtk_widget_show (alignment);
 
1298
        gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 8, 6, 6);
 
1299
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (obj)->vbox),
 
1300
                            alignment,
 
1301
                            TRUE,
 
1302
                            TRUE,
 
1303
                            0);
 
1304
 
 
1305
        vbox = gtk_vbox_new (FALSE, 0);
 
1306
        gtk_widget_show (vbox);
 
1307
        gtk_container_add (GTK_CONTAINER (alignment), vbox);
 
1308
 
 
1309
        box = gtk_hbox_new (FALSE, 0);
 
1310
        gtk_widget_show (box);
 
1311
        gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0);
 
1312
 
 
1313
        priv->header = gtk_label_new (NULL);
 
1314
        gtk_widget_show (priv->header);
 
1315
        gtk_misc_set_alignment (GTK_MISC (priv->header), 0.0, 0.5);
 
1316
        gtk_misc_set_padding (GTK_MISC (priv->header), 0, 18);
 
1317
        gtk_box_pack_start (GTK_BOX (box), priv->header, FALSE, TRUE, 0);
 
1318
 
 
1319
        priv->image = gtk_image_new ();
 
1320
        gtk_misc_set_alignment (GTK_MISC (priv->image), 1.0, 0.5);
 
1321
        gtk_widget_show (priv->image);
 
1322
        gtk_box_pack_start (GTK_BOX (box), priv->image, TRUE, TRUE, 0);
 
1323
 
 
1324
        priv->progress = brasero_burn_progress_new ();
 
1325
        gtk_widget_show (priv->progress);
 
1326
        gtk_box_pack_start (GTK_BOX (vbox),
 
1327
                            priv->progress,
 
1328
                            FALSE,
 
1329
                            TRUE,
 
1330
                            0);
 
1331
 
 
1332
        /* buttons */
 
1333
        priv->cancel = gtk_dialog_add_button (GTK_DIALOG (obj),
 
1334
                                              GTK_STOCK_CANCEL,
 
1335
                                              GTK_RESPONSE_CANCEL);
 
1336
}
 
1337
 
 
1338
static void
 
1339
brasero_burn_dialog_destroy (GtkObject * object)
 
1340
{
 
1341
        BraseroBurnDialogPrivate *priv;
 
1342
 
 
1343
        priv = BRASERO_BURN_DIALOG_PRIVATE (object);
 
1344
 
 
1345
        if (priv->burn) {
 
1346
                g_object_unref (priv->burn);
 
1347
                priv->burn = NULL;
 
1348
        }
 
1349
 
 
1350
        if (GTK_OBJECT_CLASS (parent_class)->destroy)
 
1351
                GTK_OBJECT_CLASS (parent_class)->destroy (object);
 
1352
}
 
1353
 
 
1354
static void
 
1355
brasero_burn_dialog_finalize (GObject * object)
 
1356
{
 
1357
        BraseroBurnDialogPrivate *priv;
 
1358
 
 
1359
        priv = BRASERO_BURN_DIALOG_PRIVATE (object);
 
1360
 
 
1361
        if (priv->burn) {
 
1362
                brasero_burn_cancel (priv->burn, TRUE);
 
1363
                g_object_unref (priv->burn);
 
1364
                priv->burn = NULL;
 
1365
        }
 
1366
 
 
1367
        if (priv->tray) {
 
1368
                g_object_unref (priv->tray);
 
1369
                priv->tray = NULL;
 
1370
        }
 
1371
 
 
1372
        if (priv->session) {
 
1373
                g_object_unref (priv->session);
 
1374
                priv->session = NULL;
 
1375
        }
 
1376
 
 
1377
        if (priv->total_time) {
 
1378
                g_timer_destroy (priv->total_time);
 
1379
                priv->total_time = NULL;
 
1380
        }
 
1381
 
 
1382
        if (priv->rates) {
 
1383
                g_slist_free (priv->rates);
 
1384
                priv->rates = NULL;
 
1385
        }
 
1386
 
 
1387
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
1388
}
 
1389
 
 
1390
GtkWidget *
 
1391
brasero_burn_dialog_new (void)
 
1392
{
 
1393
        BraseroBurnDialog *obj;
 
1394
 
 
1395
        obj = BRASERO_BURN_DIALOG (g_object_new (BRASERO_TYPE_BURN_DIALOG, NULL));
 
1396
 
 
1397
        return GTK_WIDGET (obj);
 
1398
}
 
1399
 
 
1400
static void
 
1401
brasero_burn_dialog_activity_start (BraseroBurnDialog *dialog)
 
1402
{
 
1403
        GdkCursor *cursor;
 
1404
        GdkWindow *window;
 
1405
        BraseroBurnDialogPrivate *priv;
 
1406
 
 
1407
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1408
 
 
1409
        window = gtk_widget_get_window (GTK_WIDGET (dialog));
 
1410
        if (window) {
 
1411
                cursor = gdk_cursor_new (GDK_WATCH);
 
1412
                gdk_window_set_cursor (window, NULL);
 
1413
                gdk_cursor_unref (cursor);
 
1414
        }
 
1415
 
 
1416
        gtk_button_set_use_stock (GTK_BUTTON (priv->cancel), TRUE);
 
1417
        gtk_button_set_label (GTK_BUTTON (priv->cancel), GTK_STOCK_CANCEL);
 
1418
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), FALSE);
 
1419
 
 
1420
        g_signal_connect (priv->cancel,
 
1421
                          "clicked",
 
1422
                          G_CALLBACK (brasero_burn_dialog_cancel_clicked_cb),
 
1423
                          dialog);
 
1424
 
 
1425
        /* Reset or set the speed info */
 
1426
        g_object_set (priv->progress,
 
1427
                      "show-info", TRUE,
 
1428
                      NULL);
 
1429
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (priv->progress),
 
1430
                                          FALSE,
 
1431
                                          0.0,
 
1432
                                          0.0,
 
1433
                                          -1,
 
1434
                                          -1,
 
1435
                                          -1,
 
1436
                                          -1);
 
1437
}
 
1438
 
 
1439
static void
 
1440
brasero_burn_dialog_activity_stop (BraseroBurnDialog *dialog,
 
1441
                                   const gchar *message)
 
1442
{
 
1443
        gchar *markup;
 
1444
        BraseroBurnDialogPrivate *priv;
 
1445
 
 
1446
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1447
 
 
1448
        gdk_window_set_cursor (GTK_WIDGET (dialog)->window, NULL);
 
1449
 
 
1450
        markup = g_strdup_printf ("<b><big>%s</big></b>", message);
 
1451
        gtk_label_set_text (GTK_LABEL (priv->header), markup);
 
1452
        gtk_label_set_use_markup (GTK_LABEL (priv->header), TRUE);
 
1453
        g_free (markup);
 
1454
 
 
1455
        gtk_button_set_use_stock (GTK_BUTTON (priv->cancel), TRUE);
 
1456
        gtk_button_set_label (GTK_BUTTON (priv->cancel), GTK_STOCK_CLOSE);
 
1457
 
 
1458
        g_signal_handlers_disconnect_by_func (priv->cancel,
 
1459
                                              brasero_burn_dialog_cancel_clicked_cb,
 
1460
                                              dialog);
 
1461
 
 
1462
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (priv->progress),
 
1463
                                          FALSE,
 
1464
                                          1.0,
 
1465
                                          1.0,
 
1466
                                          -1,
 
1467
                                          -1,
 
1468
                                          -1,
 
1469
                                          -1);
 
1470
 
 
1471
        gtk_widget_show (GTK_WIDGET (dialog));
 
1472
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE);
 
1473
}
 
1474
 
 
1475
static BraseroBurnResult
 
1476
brasero_burn_dialog_setup_session (BraseroBurnDialog *dialog,
 
1477
                                   GError **error)
 
1478
{
 
1479
        BraseroBurnDialogPrivate *priv;
 
1480
 
 
1481
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1482
 
 
1483
        brasero_burn_session_start (priv->session);
 
1484
 
 
1485
        priv->burn = brasero_burn_new ();
 
1486
        g_signal_connect (priv->burn,
 
1487
                          "insert-media",
 
1488
                          G_CALLBACK (brasero_burn_dialog_insert_disc_cb),
 
1489
                          dialog);
 
1490
        g_signal_connect (priv->burn,
 
1491
                          "location-request",
 
1492
                          G_CALLBACK (brasero_burn_dialog_image_error),
 
1493
                          dialog);
 
1494
        g_signal_connect (priv->burn,
 
1495
                          "warn-data-loss",
 
1496
                          G_CALLBACK (brasero_burn_dialog_data_loss_cb),
 
1497
                          dialog);
 
1498
        g_signal_connect (priv->burn,
 
1499
                          "warn-previous-session-loss",
 
1500
                          G_CALLBACK (brasero_burn_dialog_previous_session_loss_cb),
 
1501
                          dialog);
 
1502
        g_signal_connect (priv->burn,
 
1503
                          "warn-audio-to-appendable",
 
1504
                          G_CALLBACK (brasero_burn_dialog_audio_to_appendable_cb),
 
1505
                          dialog);
 
1506
        g_signal_connect (priv->burn,
 
1507
                          "warn-rewritable",
 
1508
                          G_CALLBACK (brasero_burn_dialog_rewritable_cb),
 
1509
                          dialog);
 
1510
        g_signal_connect (priv->burn,
 
1511
                          "disable-joliet",
 
1512
                          G_CALLBACK (brasero_burn_dialog_disable_joliet_cb),
 
1513
                          dialog);
 
1514
        g_signal_connect (priv->burn,
 
1515
                          "progress-changed",
 
1516
                          G_CALLBACK (brasero_burn_dialog_progress_changed_cb),
 
1517
                          dialog);
 
1518
        g_signal_connect (priv->burn,
 
1519
                          "action-changed",
 
1520
                          G_CALLBACK (brasero_burn_dialog_action_changed_cb),
 
1521
                          dialog);
 
1522
        g_signal_connect (priv->burn,
 
1523
                          "dummy-success",
 
1524
                          G_CALLBACK (brasero_burn_dialog_dummy_success_cb),
 
1525
                          dialog);
 
1526
 
 
1527
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (priv->progress),
 
1528
                                          FALSE,
 
1529
                                          0.0,
 
1530
                                          -1.0,
 
1531
                                          -1,
 
1532
                                          -1,
 
1533
                                          -1,
 
1534
                                          -1);
 
1535
 
 
1536
        brasero_tray_icon_set_progress (BRASERO_TRAYICON (priv->tray),
 
1537
                                        0.0,
 
1538
                                        -1);
 
1539
 
 
1540
        brasero_burn_progress_set_action (BRASERO_BURN_PROGRESS (priv->progress),
 
1541
                                          BRASERO_BURN_ACTION_NONE,
 
1542
                                          NULL);
 
1543
 
 
1544
        brasero_tray_icon_set_action (BRASERO_TRAYICON (priv->tray),
 
1545
                                      BRASERO_BURN_ACTION_NONE,
 
1546
                                      NULL);
 
1547
 
 
1548
        if (priv->total_time)
 
1549
                g_timer_destroy (priv->total_time);
 
1550
 
 
1551
        priv->total_time = g_timer_new ();
 
1552
        g_timer_start (priv->total_time);
 
1553
 
 
1554
        return BRASERO_BURN_OK;
 
1555
}
 
1556
 
 
1557
static void
 
1558
brasero_burn_dialog_save_log (BraseroBurnDialog *dialog)
 
1559
{
 
1560
        gchar *contents;
 
1561
        gchar *path = NULL;
 
1562
        GtkWidget *chooser;
 
1563
        GtkResponseType answer;
 
1564
        BraseroBurnDialogPrivate *priv;
 
1565
 
 
1566
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1567
 
 
1568
        chooser = gtk_file_chooser_dialog_new (_("Save Current Session"),
 
1569
                                               GTK_WINDOW (dialog),
 
1570
                                               GTK_FILE_CHOOSER_ACTION_SAVE,
 
1571
                                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
1572
                                               GTK_STOCK_SAVE, GTK_RESPONSE_OK,
 
1573
                                               NULL);
 
1574
 
 
1575
        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
 
1576
        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
 
1577
                                             g_get_home_dir ());
 
1578
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser),
 
1579
                                           "brasero-session.log");
 
1580
        gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (chooser), TRUE);
 
1581
 
 
1582
        gtk_widget_show (chooser);
 
1583
        answer = gtk_dialog_run (GTK_DIALOG (chooser));
 
1584
        if (answer != GTK_RESPONSE_OK) {
 
1585
                gtk_widget_destroy (chooser);
 
1586
                return;
 
1587
        }
 
1588
 
 
1589
        path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
 
1590
        gtk_widget_destroy (chooser);
 
1591
 
 
1592
        if (!path)
 
1593
                return;
 
1594
 
 
1595
        if (path && *path == '\0') {
 
1596
                g_free (path);
 
1597
                return;
 
1598
        }
 
1599
 
 
1600
        g_file_get_contents (brasero_burn_session_get_log_path (priv->session),
 
1601
                             &contents,
 
1602
                             NULL,
 
1603
                             NULL);
 
1604
        g_file_set_contents (path, contents, -1, NULL);
 
1605
 
 
1606
        g_free (contents);
 
1607
        g_free (path);
 
1608
}
 
1609
 
 
1610
static void
 
1611
brasero_burn_dialog_show_log (BraseroBurnDialog *dialog)
 
1612
{
 
1613
        gint words_num;
 
1614
        GtkWidget *view;
 
1615
        GtkTextIter iter;
 
1616
        struct stat stats;
 
1617
        GtkWidget *message;
 
1618
        GtkWidget *scrolled;
 
1619
        GtkTextBuffer *text;
 
1620
        const gchar *logfile;
 
1621
        GtkTextTag *object_tag;
 
1622
        GtkTextTag *domain_tag;
 
1623
        BraseroBurnDialogPrivate *priv;
 
1624
 
 
1625
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1626
 
 
1627
        message = gtk_dialog_new_with_buttons (_("Session Log"),
 
1628
                                               GTK_WINDOW (dialog),
 
1629
                                               GTK_DIALOG_DESTROY_WITH_PARENT |
 
1630
                                               GTK_DIALOG_MODAL,
 
1631
                                               GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 
1632
                                               NULL);
 
1633
        gtk_window_set_default_size (GTK_WINDOW (message), 500, 375);
 
1634
        scrolled = gtk_scrolled_window_new (NULL, NULL);
 
1635
        gtk_container_set_border_width (GTK_CONTAINER (scrolled), 6);
 
1636
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
 
1637
                                        GTK_POLICY_AUTOMATIC,
 
1638
                                        GTK_POLICY_AUTOMATIC);
 
1639
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
 
1640
                                             GTK_SHADOW_ETCHED_IN);
 
1641
        gtk_box_pack_end (GTK_BOX (GTK_DIALOG (message)->vbox),
 
1642
                          scrolled,
 
1643
                          TRUE,
 
1644
                          TRUE,
 
1645
                          0);
 
1646
 
 
1647
        view = gtk_text_view_new ();
 
1648
        gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
 
1649
        gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled), view);
 
1650
 
 
1651
        /* we better make sure the session log is not too big < 10 MB otherwise
 
1652
         * everything will freeze and will take a huge part of memory. If it is
 
1653
         * bigger then only show the end which is the most relevant. */
 
1654
        logfile = brasero_burn_session_get_log_path (priv->session);
 
1655
        if (g_stat (logfile, &stats) == -1) {
 
1656
                brasero_utils_message_dialog (GTK_WIDGET (dialog),
 
1657
                                              _("The session log cannot be displayed."),
 
1658
                                              _("The log file could not be found"),
 
1659
                                              GTK_MESSAGE_ERROR);
 
1660
                gtk_widget_destroy (message);
 
1661
                return;
 
1662
        }
 
1663
 
 
1664
        text = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 
1665
        if (stats.st_size > 1 * 1024 * 1024) {
 
1666
                gchar contents [1 * 1024 * 1024];
 
1667
                GtkTextIter iter;
 
1668
                FILE *file;
 
1669
 
 
1670
                gtk_text_buffer_get_start_iter (text, &iter);
 
1671
                gtk_text_buffer_insert (text,
 
1672
                                        &iter,
 
1673
                                        _("This is a excerpt from the session log (the last 10 MiB):\n\n"),
 
1674
                                        -1);
 
1675
 
 
1676
                file = g_fopen (logfile, "r");
 
1677
                if (!file) {
 
1678
                        int errsv = errno;
 
1679
 
 
1680
                        brasero_utils_message_dialog (GTK_WIDGET (dialog),
 
1681
                                                      _("The session log cannot be displayed."),
 
1682
                                                      g_strerror (errsv),
 
1683
                                                      GTK_MESSAGE_ERROR);
 
1684
                        gtk_widget_destroy (message);
 
1685
                        return;
 
1686
                }
 
1687
 
 
1688
                if (fread (contents, 1, sizeof (contents), file) != sizeof (contents)) {
 
1689
                        int errsv = errno;
 
1690
 
 
1691
                        brasero_utils_message_dialog (GTK_WIDGET (dialog),
 
1692
                                                      _("The session log cannot be displayed."),
 
1693
                                                      g_strerror (errsv),
 
1694
                                                      GTK_MESSAGE_ERROR);
 
1695
                        gtk_widget_destroy (message);
 
1696
                        return;
 
1697
                }
 
1698
 
 
1699
                gtk_text_buffer_insert (text, &iter, contents, sizeof (contents));
 
1700
        }
 
1701
        else {
 
1702
                gchar *contents;
 
1703
 
 
1704
                /* fill the buffer */
 
1705
                g_file_get_contents (brasero_burn_session_get_log_path (priv->session),
 
1706
                                     &contents,
 
1707
                                     NULL,
 
1708
                                     NULL);
 
1709
                gtk_text_buffer_set_text (text, contents, -1);
 
1710
                g_free (contents);
 
1711
        }
 
1712
 
 
1713
        /* create tags and apply them */
 
1714
        object_tag = gtk_text_buffer_create_tag (text,
 
1715
                                                 NULL,
 
1716
                                                 "foreground", "red",
 
1717
                                                 "weight", PANGO_WEIGHT_BOLD,
 
1718
                                                 NULL);
 
1719
        domain_tag = gtk_text_buffer_create_tag (text,
 
1720
                                                 NULL,
 
1721
                                                 "foreground", "blue",
 
1722
                                                 NULL);
 
1723
        gtk_text_buffer_get_start_iter (text, &iter);
 
1724
        words_num = 0;
 
1725
        while (gtk_text_iter_forward_word_end (&iter)) {
 
1726
                GtkTextIter start = iter;
 
1727
 
 
1728
                gtk_text_iter_backward_word_start (&start);
 
1729
 
 
1730
                if (words_num == 2)
 
1731
                        gtk_text_buffer_apply_tag (text, object_tag, &start, &iter);
 
1732
                else if (gtk_text_iter_starts_line (&start)) {
 
1733
                        words_num = 1;
 
1734
                        gtk_text_buffer_apply_tag (text, domain_tag, &start, &iter);
 
1735
                }
 
1736
 
 
1737
                words_num ++;
 
1738
        }
 
1739
 
 
1740
        /* run everything */
 
1741
        gtk_widget_show_all (scrolled);
 
1742
        gtk_dialog_run (GTK_DIALOG (message));
 
1743
 
 
1744
        gtk_widget_destroy (message);
 
1745
}
 
1746
 
 
1747
static void
 
1748
brasero_burn_dialog_notify_error (BraseroBurnDialog *dialog,
 
1749
                                  GError *error)
 
1750
{
 
1751
        gchar *secondary;
 
1752
        GtkWidget *button;
 
1753
        GtkWidget *message;
 
1754
        GtkResponseType response;
 
1755
 
 
1756
        if (error) {
 
1757
                secondary =  g_strdup (error->message);
 
1758
                g_error_free (error);
 
1759
        }
 
1760
        else
 
1761
                secondary = g_strdup (_("An unknown error occured."));
 
1762
 
 
1763
        if (!GTK_WIDGET_VISIBLE (dialog))
 
1764
                gtk_widget_show (GTK_WIDGET (dialog));
 
1765
 
 
1766
        message = gtk_message_dialog_new (GTK_WINDOW (dialog),
 
1767
                                          GTK_DIALOG_DESTROY_WITH_PARENT |
 
1768
                                          GTK_DIALOG_MODAL,
 
1769
                                          GTK_MESSAGE_ERROR,
 
1770
                                          GTK_BUTTONS_NONE,
 
1771
                                          _("Error while burning."));
 
1772
 
 
1773
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
1774
                                                  "%s",
 
1775
                                                  secondary);
 
1776
        g_free (secondary);
 
1777
 
 
1778
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
1779
                                        _("_Save Log"),
 
1780
                                        GTK_RESPONSE_APPLY);
 
1781
        gtk_button_set_image (GTK_BUTTON (button),
 
1782
                              gtk_image_new_from_stock (GTK_STOCK_SAVE_AS,
 
1783
                                                        GTK_ICON_SIZE_BUTTON));
 
1784
 
 
1785
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
1786
                                        _("_View Log"),
 
1787
                                        GTK_RESPONSE_OK);
 
1788
        gtk_button_set_image (GTK_BUTTON (button),
 
1789
                              gtk_image_new_from_stock (GTK_STOCK_SAVE_AS,
 
1790
                                                        GTK_ICON_SIZE_BUTTON));
 
1791
 
 
1792
        gtk_dialog_add_button (GTK_DIALOG (message),
 
1793
                               GTK_STOCK_CLOSE,
 
1794
                               GTK_RESPONSE_CLOSE);
 
1795
 
 
1796
        response = gtk_dialog_run (GTK_DIALOG (message));
 
1797
        while (1) {
 
1798
                if (response == GTK_RESPONSE_APPLY)
 
1799
                        brasero_burn_dialog_save_log (dialog);
 
1800
                else if (response == GTK_RESPONSE_OK)
 
1801
                        brasero_burn_dialog_show_log (dialog);
 
1802
                else
 
1803
                        break;
 
1804
 
 
1805
                response = gtk_dialog_run (GTK_DIALOG (message));
 
1806
        }
 
1807
 
 
1808
        gtk_widget_destroy (message);
 
1809
}
 
1810
 
 
1811
static gboolean
 
1812
brasero_burn_dialog_success_run (BraseroBurnDialog *dialog)
 
1813
{
 
1814
        gint answer;
 
1815
        BraseroBurnDialogPrivate *priv;
 
1816
 
 
1817
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1818
 
 
1819
        answer = gtk_dialog_run (GTK_DIALOG (dialog));
 
1820
        if (answer == GTK_RESPONSE_CLOSE) {
 
1821
                GtkWidget *window;
 
1822
 
 
1823
                window = brasero_session_edit_cover (priv->session, GTK_WIDGET (dialog));
 
1824
                gtk_dialog_run (GTK_DIALOG (window));
 
1825
                gtk_widget_destroy (window);
 
1826
                return FALSE;
 
1827
        }
 
1828
 
 
1829
        return (answer == GTK_RESPONSE_OK);
 
1830
}
 
1831
 
 
1832
static gchar *
 
1833
brasero_burn_dialog_get_success_message (BraseroBurnDialog *dialog)
 
1834
{
 
1835
        BraseroBurnDialogPrivate *priv;
 
1836
        BraseroDrive *drive;
 
1837
        BraseroMedia media;
 
1838
 
 
1839
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1840
 
 
1841
        drive = brasero_burn_session_get_burner (priv->session);
 
1842
        if (priv->input.type != BRASERO_TRACK_TYPE_DISC)
 
1843
                media = brasero_burn_session_get_dest_media (priv->session);
 
1844
        else
 
1845
                media = priv->input.subtype.media;
 
1846
 
 
1847
        switch (priv->input.type) {
 
1848
        case BRASERO_TRACK_TYPE_STREAM:
 
1849
                return g_strdup (_("Audio CD successfully burnt"));
 
1850
 
 
1851
        case BRASERO_TRACK_TYPE_DISC:
 
1852
                if (!brasero_drive_is_fake (drive)) {
 
1853
                        if (media & BRASERO_MEDIUM_DVD)
 
1854
                                return g_strdup (_("DVD successfully copied"));
 
1855
                        else
 
1856
                                return g_strdup (_("CD successfully copied"));
 
1857
                }
 
1858
                else {
 
1859
                        if (media & BRASERO_MEDIUM_DVD)
 
1860
                                return g_strdup (_("Image of DVD successfully created"));
 
1861
                        else
 
1862
                                return g_strdup (_("Image of CD successfully created"));
 
1863
                }
 
1864
                break;
 
1865
        case BRASERO_TRACK_TYPE_IMAGE:
 
1866
                if (!brasero_drive_is_fake (drive)) {
 
1867
                        if (media & BRASERO_MEDIUM_DVD)
 
1868
                                return g_strdup (_("Image successfully burnt to DVD"));
 
1869
                        else
 
1870
                                return g_strdup (_("Image successfully burnt to CD"));
 
1871
                }
 
1872
                break;
 
1873
        default:
 
1874
                if (!brasero_drive_is_fake (drive)) {
 
1875
                        if (media & BRASERO_MEDIUM_DVD)
 
1876
                                return g_strdup (_("Data DVD successfully burnt"));
 
1877
                        else
 
1878
                                return g_strdup (_("Data CD successfully burnt"));
 
1879
                }
 
1880
 
 
1881
                return g_strdup (_("Image successfully created"));
 
1882
        }
 
1883
 
 
1884
        return NULL;
 
1885
}
 
1886
 
 
1887
static gboolean
 
1888
brasero_burn_dialog_notify_success (BraseroBurnDialog *dialog)
 
1889
{
 
1890
        gint64 rate;
 
1891
        gboolean res;
 
1892
        BraseroMedia media;
 
1893
        gchar *primary = NULL;
 
1894
        GtkWidget *make_another = NULL;
 
1895
        GtkWidget *create_cover = NULL;
 
1896
        BraseroBurnDialogPrivate *priv;
 
1897
 
 
1898
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
1899
 
 
1900
        primary = brasero_burn_dialog_get_success_message (dialog);
 
1901
        brasero_burn_dialog_activity_stop (dialog, primary);
 
1902
        g_free (primary);
 
1903
 
 
1904
        if (!brasero_burn_session_is_dest_file (priv->session)) {
 
1905
                /* Useful button but it shouldn't be used for images */
 
1906
                make_another = gtk_dialog_add_button (GTK_DIALOG (dialog),
 
1907
                                                      _("Make _Another Copy"),
 
1908
                                                      GTK_RESPONSE_OK);
 
1909
        }
 
1910
 
 
1911
        /* show total required time and average speed */
 
1912
        rate = 0;
 
1913
        if (priv->rates) {
 
1914
                int num = 0;
 
1915
                GSList *iter;
 
1916
 
 
1917
                for (iter = priv->rates; iter; iter = iter->next) {
 
1918
                        rate += GPOINTER_TO_INT (iter->data);
 
1919
                        num ++;
 
1920
                }
 
1921
                rate /= num;
 
1922
        }
 
1923
 
 
1924
        media = brasero_burn_session_get_dest_media (priv->session);
 
1925
        brasero_burn_progress_display_session_info (BRASERO_BURN_PROGRESS (priv->progress),
 
1926
                                                    g_timer_elapsed (priv->total_time, NULL),
 
1927
                                                    rate,
 
1928
                                                    media,
 
1929
                                                    priv->total_size);
 
1930
 
 
1931
        if (priv->input.type == BRASERO_TRACK_TYPE_STREAM
 
1932
        || (priv->input.type == BRASERO_TRACK_TYPE_DISC
 
1933
        && (priv->input.subtype.media & BRASERO_MEDIUM_HAS_AUDIO))) {
 
1934
                /* since we succeed offer the possibility to create cover if that's an audio disc */
 
1935
                create_cover = gtk_dialog_add_button (GTK_DIALOG (dialog),
 
1936
                                                      _("_Create Cover"),
 
1937
                                                      GTK_RESPONSE_CLOSE);
 
1938
        }
 
1939
 
 
1940
        res = brasero_burn_dialog_success_run (dialog);
 
1941
 
 
1942
        if (make_another)
 
1943
                gtk_widget_destroy (make_another);
 
1944
 
 
1945
        if (create_cover)
 
1946
                gtk_widget_destroy (create_cover);
 
1947
 
 
1948
        return res;
 
1949
}
 
1950
 
 
1951
static void
 
1952
brasero_burn_dialog_add_track_to_recent (BraseroTrack *track)
 
1953
{
 
1954
        gchar *uri = NULL;
 
1955
        GtkRecentManager *recent;
 
1956
        BraseroImageFormat format;
 
1957
        gchar *groups [] = { "brasero", NULL };
 
1958
        gchar *mimes [] = { "application/x-cd-image",
 
1959
                            "application/x-cue",
 
1960
                            "application/x-toc",
 
1961
                            "application/x-cdrdao-toc" };
 
1962
        GtkRecentData recent_data = { NULL,
 
1963
                                      NULL,
 
1964
                                      NULL,
 
1965
                                      "brasero",
 
1966
                                      "brasero -p %u",
 
1967
                                      groups,
 
1968
                                      FALSE };
 
1969
 
 
1970
        if (!BRASERO_IS_TRACK_IMAGE (track))
 
1971
                return;
 
1972
 
 
1973
        format = brasero_track_image_get_format (BRASERO_TRACK_IMAGE (track));
 
1974
        if (format == BRASERO_IMAGE_FORMAT_NONE)
 
1975
                return;
 
1976
 
 
1977
        /* Add it to recent file manager */
 
1978
        switch (format) {
 
1979
        case BRASERO_IMAGE_FORMAT_BIN:
 
1980
                recent_data.mime_type = mimes [0];
 
1981
                uri = brasero_track_image_get_source (BRASERO_TRACK_IMAGE (track), TRUE);
 
1982
                break;
 
1983
 
 
1984
        case BRASERO_IMAGE_FORMAT_CUE:
 
1985
                recent_data.mime_type = mimes [1];
 
1986
                uri = brasero_track_image_get_toc_source (BRASERO_TRACK_IMAGE (track), TRUE);
 
1987
                break;
 
1988
 
 
1989
        case BRASERO_IMAGE_FORMAT_CLONE:
 
1990
                recent_data.mime_type = mimes [2];
 
1991
                uri = brasero_track_image_get_toc_source (BRASERO_TRACK_IMAGE (track), TRUE);
 
1992
                break;
 
1993
 
 
1994
        case BRASERO_IMAGE_FORMAT_CDRDAO:
 
1995
                recent_data.mime_type = mimes [3];
 
1996
                uri = brasero_track_image_get_toc_source (BRASERO_TRACK_IMAGE (track), TRUE);
 
1997
                break;
 
1998
 
 
1999
        default:
 
2000
                break;
 
2001
        }
 
2002
 
 
2003
        if (!uri)
 
2004
                return;
 
2005
 
 
2006
        recent = gtk_recent_manager_get_default ();
 
2007
        gtk_recent_manager_add_full (recent,
 
2008
                                     uri,
 
2009
                                     &recent_data);
 
2010
        g_free (uri);
 
2011
}
 
2012
 
 
2013
static gboolean
 
2014
brasero_burn_dialog_end_session (BraseroBurnDialog *dialog,
 
2015
                                 BraseroBurnResult result,
 
2016
                                 GError *error)
 
2017
{
 
2018
        gboolean retry = FALSE;
 
2019
        BraseroBurnDialogPrivate *priv;
 
2020
 
 
2021
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
2022
 
 
2023
        if (priv->total_time)
 
2024
                g_timer_stop (priv->total_time);
 
2025
 
 
2026
        brasero_burn_session_stop (priv->session);
 
2027
 
 
2028
        if (result == BRASERO_BURN_CANCEL) {
 
2029
                /* nothing to do */
 
2030
        }
 
2031
        else if (error || result != BRASERO_BURN_OK) {
 
2032
                brasero_burn_dialog_notify_error (dialog, error);
 
2033
        }
 
2034
        else {
 
2035
                /* see if an image was created. If so, add it to GtkRecent */
 
2036
                if (brasero_burn_session_is_dest_file (priv->session)) {
 
2037
                        GSList *tracks;
 
2038
 
 
2039
                        tracks = brasero_burn_session_get_tracks (priv->session);
 
2040
                        for (; tracks; tracks = tracks->next) {
 
2041
                                BraseroTrack *track;
 
2042
 
 
2043
                                track = tracks->data;
 
2044
                                brasero_burn_dialog_add_track_to_recent (track);
 
2045
                        }
 
2046
                }
 
2047
 
 
2048
                retry = brasero_burn_dialog_notify_success (dialog);
 
2049
        }
 
2050
 
 
2051
        if (priv->burn) {
 
2052
                g_object_unref (priv->burn);
 
2053
                priv->burn = NULL;
 
2054
        }
 
2055
 
 
2056
        if (priv->rates) {
 
2057
                g_slist_free (priv->rates);
 
2058
                priv->rates = NULL;
 
2059
        }
 
2060
 
 
2061
        if (priv->total_time) {
 
2062
                g_timer_destroy (priv->total_time);
 
2063
                priv->total_time = NULL;
 
2064
        }
 
2065
 
 
2066
        return retry;
 
2067
}
 
2068
 
 
2069
static BraseroBurnResult
 
2070
brasero_burn_dialog_record_spanned_session (BraseroBurnDialog *dialog,
 
2071
                                            GError **error)
 
2072
{
 
2073
        BraseroDrive *burner;
 
2074
        BraseroTrackType *type;
 
2075
        gchar *success_message;
 
2076
        BraseroBurnResult result;
 
2077
        BraseroBurnDialogPrivate *priv;
 
2078
        gchar *secondary_message = NULL;
 
2079
 
 
2080
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
2081
        burner = brasero_burn_session_get_burner (priv->session);
 
2082
 
 
2083
        type = brasero_track_type_new ();
 
2084
        brasero_burn_session_get_input_type (priv->session, type);
 
2085
        success_message = brasero_burn_dialog_get_success_message (dialog);
 
2086
        if (brasero_track_type_get_has_data (type)) {
 
2087
                secondary_message = g_strdup_printf ("%s.\n%s.",
 
2088
                                                     success_message,
 
2089
                                                     _("There are some files left to burn"));
 
2090
                g_free (success_message);
 
2091
        }
 
2092
        else if (brasero_track_type_get_has_stream (type)) {
 
2093
                if (BRASERO_STREAM_FORMAT_HAS_VIDEO (brasero_track_type_get_stream_format (type)))
 
2094
                        secondary_message = g_strdup_printf ("%s.\n%s.",
 
2095
                                                             success_message,
 
2096
                                                             _("There are some more videos left to burn"));
 
2097
                else
 
2098
                        secondary_message = g_strdup_printf ("%s.\n%s.",
 
2099
                                                             success_message,
 
2100
                                                             _("There are some more songs left to burn"));
 
2101
                g_free (success_message);
 
2102
        }
 
2103
        else
 
2104
                secondary_message = success_message;
 
2105
 
 
2106
        brasero_track_type_free (type);
 
2107
 
 
2108
        do {
 
2109
                gint res;
 
2110
 
 
2111
                result = brasero_burn_record (priv->burn,
 
2112
                                              priv->session,
 
2113
                                              error);
 
2114
                if (result != BRASERO_BURN_OK) {
 
2115
                        g_free (secondary_message);
 
2116
                        return result;
 
2117
                }
 
2118
 
 
2119
                /* See if we have more data to burn and ask for a new medium */
 
2120
                result = brasero_session_span_again (BRASERO_SESSION_SPAN (priv->session));
 
2121
                if (result == BRASERO_BURN_OK)
 
2122
                        break;
 
2123
 
 
2124
                res = brasero_burn_dialog_wait_for_insertion (dialog,
 
2125
                                                              burner,
 
2126
                                                              _("Please insert a recordable CD or DVD."),
 
2127
                                                              secondary_message);
 
2128
                if (res != GTK_RESPONSE_OK) {
 
2129
                        g_free (secondary_message);
 
2130
                        return BRASERO_BURN_CANCEL;
 
2131
                }
 
2132
 
 
2133
                result = brasero_session_span_next (BRASERO_SESSION_SPAN (priv->session));
 
2134
                while (result == BRASERO_BURN_ERR) {
 
2135
                        brasero_drive_eject (burner, FALSE, NULL);
 
2136
                        res = brasero_burn_dialog_wait_for_insertion (dialog,
 
2137
                                                                      burner,
 
2138
                                                                      _("Please insert a recordable CD or DVD."),
 
2139
                                                                      _("Not enough space available on the disc"));
 
2140
                        if (res != GTK_RESPONSE_OK) {
 
2141
                                g_free (secondary_message);
 
2142
                                return BRASERO_BURN_CANCEL;
 
2143
                        }
 
2144
                        result = brasero_session_span_next (BRASERO_SESSION_SPAN (priv->session));
 
2145
                }
 
2146
 
 
2147
        } while (result == BRASERO_BURN_RETRY);
 
2148
 
 
2149
        g_free (secondary_message);
 
2150
        brasero_session_span_stop (BRASERO_SESSION_SPAN (priv->session));
 
2151
        return result;
 
2152
}
 
2153
 
 
2154
static BraseroBurnResult
 
2155
brasero_burn_dialog_record_session (BraseroBurnDialog *dialog,
 
2156
                                    BraseroMedia media)
 
2157
{
 
2158
        gboolean retry;
 
2159
        GError *error = NULL;
 
2160
        BraseroBurnResult result;
 
2161
        BraseroBurnDialogPrivate *priv;
 
2162
 
 
2163
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
2164
 
 
2165
        brasero_burn_dialog_update_info (dialog, &priv->input, media);
 
2166
 
 
2167
        /* start the recording session */
 
2168
        brasero_burn_dialog_activity_start (dialog);
 
2169
        result = brasero_burn_dialog_setup_session (dialog, &error);
 
2170
        if (result != BRASERO_BURN_OK)
 
2171
                return result;
 
2172
 
 
2173
        if (BRASERO_IS_SESSION_SPAN (priv->session))
 
2174
                result = brasero_burn_dialog_record_spanned_session (dialog, &error);
 
2175
        else
 
2176
                result = brasero_burn_record (priv->burn,
 
2177
                                              priv->session,
 
2178
                                              &error);
 
2179
 
 
2180
        retry = brasero_burn_dialog_end_session (dialog,
 
2181
                                                 result,
 
2182
                                                 error);
 
2183
        if (result == BRASERO_BURN_RETRY)
 
2184
                return result;
 
2185
 
 
2186
        if (retry)
 
2187
                return BRASERO_BURN_RETRY;
 
2188
 
 
2189
        return BRASERO_BURN_OK;
 
2190
}
 
2191
 
 
2192
static gboolean
 
2193
brasero_burn_dialog_wait_for_ready_state (BraseroBurnDialog *dialog)
 
2194
{
 
2195
        BraseroBurnDialogPrivate *priv;
 
2196
        BraseroBurnResult result;
 
2197
        BraseroStatus *status;
 
2198
 
 
2199
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
2200
 
 
2201
        status = brasero_status_new ();
 
2202
        result = brasero_burn_session_get_status (priv->session, status);
 
2203
        while (brasero_status_get_result (status) == BRASERO_BURN_NOT_READY) {
 
2204
                gdouble progress;
 
2205
                gchar *action;
 
2206
 
 
2207
                action = brasero_status_get_current_action (status);
 
2208
                brasero_burn_dialog_action_changed_real (dialog,
 
2209
                                                         BRASERO_BURN_ACTION_GETTING_SIZE,
 
2210
                                                         action);
 
2211
                g_free (action);
 
2212
 
 
2213
                progress = brasero_status_get_progress (status);
 
2214
                brasero_burn_dialog_progress_changed_real (dialog,
 
2215
                                                           0,
 
2216
                                                           0,
 
2217
                                                           0,
 
2218
                                                           progress,
 
2219
                                                           progress,
 
2220
                                                           -1.0,
 
2221
                                                           brasero_burn_session_get_dest_media (priv->session));
 
2222
 
 
2223
                result = brasero_burn_session_get_status (priv->session, status);
 
2224
        }
 
2225
        brasero_status_free (status);
 
2226
 
 
2227
        return (result == BRASERO_BURN_OK);
 
2228
}
 
2229
 
 
2230
gboolean
 
2231
brasero_burn_dialog_run (BraseroBurnDialog *dialog,
 
2232
                         BraseroBurnSession *session)
 
2233
{
 
2234
        BraseroMedia media;
 
2235
        BraseroBurnResult result;
 
2236
        BraseroBurnDialogPrivate *priv;
 
2237
 
 
2238
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
2239
 
 
2240
        g_object_ref (session);
 
2241
        priv->session = session;
 
2242
 
 
2243
        /* wait for ready state */
 
2244
        if (!brasero_burn_dialog_wait_for_ready_state (dialog))
 
2245
                return FALSE;
 
2246
 
 
2247
        /* disable autoconfiguration */
 
2248
        if (BRASERO_IS_SESSION_CFG (priv->session))
 
2249
                brasero_session_cfg_disable (BRASERO_SESSION_CFG (priv->session));
 
2250
 
 
2251
        /* update what we should display */
 
2252
        brasero_burn_session_get_input_type (session, &priv->input);
 
2253
        if (brasero_burn_session_is_dest_file (session))
 
2254
                media = BRASERO_MEDIUM_FILE;
 
2255
        else if (priv->input.type != BRASERO_TRACK_TYPE_DISC)
 
2256
                media = brasero_burn_session_get_dest_media (session);
 
2257
        else {
 
2258
                BraseroMedium *medium;
 
2259
 
 
2260
                medium = brasero_burn_session_get_src_medium (priv->session);
 
2261
                media = brasero_medium_get_status (medium);
 
2262
        }
 
2263
 
 
2264
        do {
 
2265
                result = brasero_burn_dialog_record_session (dialog, media);
 
2266
        } while (result == BRASERO_BURN_RETRY);
 
2267
 
 
2268
        priv->session = NULL;
 
2269
        g_object_unref (session);
 
2270
 
 
2271
        return (result == BRASERO_BURN_OK);
 
2272
}
 
2273
 
 
2274
static gboolean
 
2275
brasero_burn_dialog_cancel_dialog (GtkWidget *toplevel)
 
2276
{
 
2277
        gint result;
 
2278
        GtkWidget *button;
 
2279
        GtkWidget *message;
 
2280
 
 
2281
        message = gtk_message_dialog_new (GTK_WINDOW (toplevel),
 
2282
                                          GTK_DIALOG_DESTROY_WITH_PARENT |
 
2283
                                          GTK_DIALOG_MODAL,
 
2284
                                          GTK_MESSAGE_WARNING,
 
2285
                                          GTK_BUTTONS_NONE,
 
2286
                                          _("Do you really want to quit?"));
 
2287
 
 
2288
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG
 
2289
                                                  (message),
 
2290
                                                  _("Interrupting the process may make disc unusable."));
 
2291
 
 
2292
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
2293
                                        _("C_ontinue Burning"),
 
2294
                                        GTK_RESPONSE_OK);
 
2295
        gtk_button_set_image (GTK_BUTTON (button),
 
2296
                              gtk_image_new_from_stock (GTK_STOCK_OK,
 
2297
                                                        GTK_ICON_SIZE_BUTTON));
 
2298
 
 
2299
        button = gtk_dialog_add_button (GTK_DIALOG (message),
 
2300
                                        _("_Cancel Burning"),
 
2301
                                        GTK_RESPONSE_CANCEL);
 
2302
        gtk_button_set_image (GTK_BUTTON (button),
 
2303
                              gtk_image_new_from_stock (GTK_STOCK_CANCEL,
 
2304
                                                        GTK_ICON_SIZE_BUTTON));
 
2305
        
 
2306
        result = gtk_dialog_run (GTK_DIALOG (message));
 
2307
        gtk_widget_destroy (message);
 
2308
 
 
2309
        return (result != GTK_RESPONSE_OK);
 
2310
}
 
2311
 
 
2312
gboolean
 
2313
brasero_burn_dialog_cancel (BraseroBurnDialog *dialog,
 
2314
                            gboolean force_cancellation)
 
2315
{
 
2316
        BraseroBurnDialogPrivate *priv;
 
2317
 
 
2318
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
2319
 
 
2320
        if (!priv->burn)
 
2321
                return TRUE;
 
2322
 
 
2323
        if (brasero_burn_cancel (priv->burn, (force_cancellation == TRUE)) == BRASERO_BURN_DANGEROUS) {
 
2324
                if (!brasero_burn_dialog_cancel_dialog (GTK_WIDGET (dialog)))
 
2325
                        return FALSE;
 
2326
 
 
2327
                brasero_burn_cancel (priv->burn, FALSE);
 
2328
        }
 
2329
 
 
2330
        return TRUE;
 
2331
}
 
2332
 
 
2333
static gboolean
 
2334
brasero_burn_dialog_delete (GtkWidget *widget, 
 
2335
                            GdkEventAny *event)
 
2336
{
 
2337
        BraseroBurnDialogPrivate *priv;
 
2338
 
 
2339
        priv = BRASERO_BURN_DIALOG_PRIVATE (widget);
 
2340
 
 
2341
        brasero_tray_icon_set_show_dialog (BRASERO_TRAYICON (priv->tray), FALSE);
 
2342
        return TRUE;
 
2343
}
 
2344
 
 
2345
static void
 
2346
brasero_burn_dialog_cancel_clicked_cb (GtkWidget *button,
 
2347
                                       BraseroBurnDialog *dialog)
 
2348
{
 
2349
        /* a burning is ongoing cancel it */
 
2350
        brasero_burn_dialog_cancel (dialog, FALSE);
 
2351
}
 
2352
 
 
2353
static void
 
2354
brasero_burn_dialog_tray_cancel_cb (BraseroTrayIcon *tray,
 
2355
                                    BraseroBurnDialog *dialog)
 
2356
{
 
2357
        brasero_burn_dialog_cancel (dialog, FALSE);
 
2358
}
 
2359
 
 
2360
static void
 
2361
brasero_burn_dialog_tray_show_dialog_cb (BraseroTrayIcon *tray,
 
2362
                                         gboolean show,
 
2363
                                         GtkWidget *dialog)
 
2364
{
 
2365
        BraseroBurnDialogPrivate *priv;
 
2366
 
 
2367
        priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
 
2368
 
 
2369
        /* we prevent to show the burn dialog once the success dialog has been 
 
2370
         * shown to avoid the following strange behavior:
 
2371
         * Steps:
 
2372
         * - start burning
 
2373
         * - move to another workspace (ie, virtual desktop)
 
2374
         * - when the burning finishes, double-click the notification icon
 
2375
         * - you'll be unable to dismiss the dialogues normally and their behaviour will
 
2376
         *   be generally strange */
 
2377
        if (!priv->burn)
 
2378
                return;
 
2379
 
 
2380
        if (show)
 
2381
                gtk_widget_show (dialog);
 
2382
        else
 
2383
                gtk_widget_hide (dialog);
 
2384
}