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

« back to all changes in this revision

Viewing changes to src/burn-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Meredith
  • Date: 2006-11-08 05:31:37 UTC
  • mto: (1.4.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061108053137-fwis69a76eu8rapq
Tags: upstream-0.5.0
ImportĀ upstreamĀ versionĀ 0.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <gtk/gtkstock.h>
45
45
#include <gtk/gtklabel.h>
46
46
 
47
 
#ifdef HAVE_LIBNOTIFY
48
 
#include <libnotify/notify.h>
49
 
#endif
 
47
#include <nautilus-burn-drive-monitor.h>
 
48
#include <nautilus-burn-drive.h>
50
49
 
51
50
#include "utils.h"
 
51
#include "disc.h"
52
52
#include "tray.h"
53
53
#include "burn-basics.h"
 
54
#include "burn-session.h"
 
55
#include "burn-job.h"
 
56
#include "burn-imager.h"
54
57
#include "burn-dialog.h"
 
58
#include "burn-sum.h"
 
59
#include "burn-common.h"
 
60
#include "burn-md5.h"
 
61
#include "burn-local-image.h"
55
62
#include "recorder-selection.h"
56
63
#include "progress.h"
 
64
#include "brasero-sum-check.h"
57
65
#include "brasero-ncb.h"
 
66
#include "burn-task.h"
 
67
 
58
68
extern gint debug;
59
69
 
60
70
static void brasero_burn_dialog_class_init (BraseroBurnDialogClass *klass);
65
75
static gboolean
66
76
brasero_burn_dialog_delete (GtkWidget *widget,
67
77
                            GdkEventAny *event);
 
78
 
68
79
static void
69
80
brasero_burn_dialog_cancel_clicked_cb (GtkWidget *button,
70
81
                                       BraseroBurnDialog *dialog);
83
94
 
84
95
struct BraseroBurnDialogPrivate {
85
96
        BraseroBurn *burn;
 
97
        BraseroJob *checksum;
 
98
        BraseroJob *local_image;
 
99
 
 
100
        BraseroBurnSession *session;
 
101
 
 
102
        BraseroSumCheckCtx *file_ctx;
 
103
 
 
104
        gint64 isosize;
86
105
        NautilusBurnDrive *drive;
 
106
        NautilusBurnMediaType media_type;
87
107
        BraseroTrackSourceType track_type;
88
108
 
89
 
        GtkWidget *waiting_disc_dialog;
90
 
 
91
109
        GtkWidget *close_check;
92
110
        GtkWidget *progress;
93
111
        GtkWidget *header;
 
112
        GtkWidget *cancel;
94
113
        GtkWidget *image;
95
 
        GtkWidget *tray;
 
114
        BraseroTrayIcon *tray;
96
115
 
97
 
        GMainLoop *loop;
 
116
        gint close_timeout;
98
117
};
99
118
 
 
119
#define TIMEOUT 10000
 
120
#define WAITED_FOR_DRIVE        "WaitedForDriveKey"
100
121
 
101
122
static GObjectClass *parent_class = NULL;
102
123
 
139
160
        widget_class->delete_event = brasero_burn_dialog_delete;
140
161
}
141
162
 
142
 
static char *
 
163
static gchar *
143
164
brasero_burn_dialog_get_media_type_string (BraseroBurn *burn,
144
165
                                           BraseroMediaType type,
145
166
                                           gboolean insert)
146
167
{
147
 
        char *message = NULL;
 
168
        gchar *message = NULL;
148
169
 
149
170
        if (type & BRASERO_MEDIA_WITH_DATA) {
150
171
                if (!insert) {
167
188
                                     NULL,
168
189
                                     &isosize,
169
190
                                     NULL,
170
 
                                     NULL,
171
191
                                     NULL);
172
192
 
173
193
                if ((type & BRASERO_MEDIA_TYPE_CD) && !(type & BRASERO_MEDIA_TYPE_DVD)) {
174
194
                        if (!insert) {
175
195
                                if (isosize)
176
 
                                        message = g_strdup_printf (_("replace the disc with a recordable CD with a least %i Mb free."), 
 
196
                                        message = g_strdup_printf (_("replace the disc with a recordable CD with a least %i MiB free."), 
177
197
                                                                   (int) (isosize / 1048576));
178
198
                                else
179
199
                                        message = g_strdup_printf (_("replace the disc with a recordable CD."));
180
200
                        }
181
201
                        else {
182
202
                                if (isosize)
183
 
                                        message = g_strdup_printf (_("insert a recordable CD with a least %i Mb free."), 
 
203
                                        message = g_strdup_printf (_("insert a recordable CD with a least %i MiB free."), 
184
204
                                                                   (int) (isosize / 1048576));
185
205
                                else
186
206
                                        message = g_strdup_printf (_("insert a recordable CD."));
189
209
                else if (!(type & BRASERO_MEDIA_TYPE_CD) && (type & BRASERO_MEDIA_TYPE_DVD)) {
190
210
                        if (!insert) {
191
211
                                if (isosize)
192
 
                                        message = g_strdup_printf (_("replace the disc with a recordable DVD with a least %i Mb free."), 
 
212
                                        message = g_strdup_printf (_("replace the disc with a recordable DVD with a least %i MiB free."), 
193
213
                                                                   (int) (isosize / 1048576));
194
214
                                else
195
215
                                        message = g_strdup_printf (_("replace the disc with a recordable DVD."));
196
216
                        }
197
217
                        else {
198
218
                                if (isosize)
199
 
                                        message = g_strdup_printf (_("insert a recordable DVD with a least %i Mb free."), 
 
219
                                        message = g_strdup_printf (_("insert a recordable DVD with a least %i MiB free."), 
200
220
                                                                   (int) (isosize / 1048576));
201
221
                                else
202
222
                                        message = g_strdup_printf (_("insert a recordable DVD."));
204
224
                }
205
225
                else if (!insert) {
206
226
                        if (isosize)
207
 
                                message = g_strdup_printf (_("replace the disc with a recordable CD or DVD with a least %i Mb free."), 
 
227
                                message = g_strdup_printf (_("replace the disc with a recordable CD or DVD with a least %i MiB free."), 
208
228
                                                           (int) (isosize / 1048576));
209
229
                        else
210
230
                                message = g_strdup_printf (_("replace the disc with a recordable CD or DVD."));
211
231
                }
212
232
                else {
213
233
                        if (isosize)
214
 
                                message = g_strdup_printf (_("insert a recordable CD or DVD with a least %i Mb free."), 
 
234
                                message = g_strdup_printf (_("insert a recordable CD or DVD with a least %i MiB free."), 
215
235
                                                           (int) (isosize / 1048576));
216
236
                        else
217
237
                                message = g_strdup_printf (_("insert a recordable CD or DVD."));
221
241
        return message;
222
242
}
223
243
 
 
244
static void
 
245
brasero_burn_dialog_wait_for_insertion (NautilusBurnDriveMonitor *monitor,
 
246
                                        NautilusBurnDrive *drive,
 
247
                                        GtkDialog *message)
 
248
{
 
249
        NautilusBurnDrive *waited_drive;
 
250
 
 
251
        waited_drive = g_object_get_data (G_OBJECT (message), WAITED_FOR_DRIVE);
 
252
 
 
253
        /* we must make sure that the change was triggered
 
254
         * by the current selected drive */
 
255
        if (!nautilus_burn_drive_equal (drive, waited_drive))
 
256
                return;
 
257
 
 
258
        /* we might have a dialog waiting for the 
 
259
         * insertion of a disc if so close it */
 
260
        gtk_dialog_response (GTK_DIALOG (message), GTK_RESPONSE_OK);
 
261
}
 
262
 
224
263
static BraseroBurnResult
225
264
brasero_burn_dialog_insert_disc_cb (BraseroBurn *burn,
 
265
                                    NautilusBurnDrive *drive,
226
266
                                    BraseroBurnError error,
227
267
                                    BraseroMediaType type,
228
268
                                    BraseroBurnDialog *dialog)
229
269
{
230
270
        gint result;
 
271
        gint added_id;
 
272
        gchar *drive_name;
231
273
        GtkWindow *window;
232
274
        GtkWidget *message;
233
275
        gboolean hide = FALSE;
234
 
        char *main_message = NULL, *secondary_message = NULL;
 
276
        NautilusBurnDriveMonitor *monitor;
 
277
        gchar *main_message = NULL, *secondary_message = NULL;
235
278
 
236
279
        if (!GTK_WIDGET_VISIBLE (dialog)) {
237
280
                gtk_widget_show (GTK_WIDGET (dialog));
238
281
                hide = TRUE;
239
282
        }
240
283
 
 
284
        /* FIXME: we should specify the name of the drive where to put the disc */
 
285
        if (drive)
 
286
                drive_name = nautilus_burn_drive_get_name_for_display (drive);
 
287
        else
 
288
                drive_name = NULL;
 
289
 
241
290
        if (error == BRASERO_BURN_ERROR_MEDIA_BUSY) {
242
 
                main_message = g_strdup (_("The disc in the drive is busy:"));
243
 
                secondary_message = g_strdup (_("make sure another application is not using it and click OK"));
 
291
                main_message = g_strdup_printf (_("The disc in \"%s\" is busy:"),
 
292
                                                drive_name);
 
293
                secondary_message = g_strdup (_("make sure another application is not using it."));
244
294
        } 
245
295
        else if (error == BRASERO_BURN_ERROR_MEDIA_NONE) {
246
 
                main_message = g_strdup (_("There is no disc in the drive:"));
 
296
                main_message = g_strdup_printf (_("There is no disc in \"%s\":"),
 
297
                                                drive_name);
247
298
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, TRUE);
248
299
        }
249
300
        else if (error == BRASERO_BURN_ERROR_MEDIA_NOT_REWRITABLE) {
250
 
                main_message = g_strdup (_("The disc in the drive is not rewritable:"));
 
301
                main_message = g_strdup_printf (_("The disc in \"%s\" is not rewritable:"),
 
302
                                                drive_name);
251
303
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
252
304
        }
253
305
        else if (error == BRASERO_BURN_ERROR_MEDIA_BLANK) {
254
 
                main_message = g_strdup (_("The disc in the drive is empty:"));
 
306
                main_message = g_strdup_printf (_("The disc in \"%s\" is empty:"),
 
307
                                                drive_name);
255
308
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
256
309
        }
257
310
        else if (error == BRASERO_BURN_ERROR_MEDIA_NOT_WRITABLE) {
258
 
                main_message = g_strdup (_("The disc in the drive is not writable:"));
 
311
                main_message = g_strdup_printf (_("The disc in \"%s\" is not writable:"),
 
312
                                                drive_name);
259
313
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
260
314
        }
261
315
        else if (error == BRASERO_BURN_ERROR_DVD_NOT_SUPPORTED) {
262
 
                main_message = g_strdup (_("The disc in the drive is a DVD:"));
 
316
                main_message = g_strdup_printf (_("The disc in \"%s\" is a DVD:"),
 
317
                                                drive_name);
263
318
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
264
319
        }
265
320
        else if (error == BRASERO_BURN_ERROR_CD_NOT_SUPPORTED) {
266
 
                main_message = g_strdup (_("The disc in the drive is a CD:"));
 
321
                main_message = g_strdup_printf (_("The disc in \"%s\" is a CD:"),
 
322
                                                drive_name);
267
323
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
268
324
        }
269
325
        else if (error == BRASERO_BURN_ERROR_MEDIA_SPACE) {
270
 
                main_message = g_strdup (_("The disc in the drive is not big enough:"));
 
326
                main_message = g_strdup_printf (_("The disc in \"%s\" is not big enough:"),
 
327
                                                drive_name);
271
328
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
272
329
        }
273
330
        else if (error == BRASERO_BURN_ERROR_NONE) {
274
 
                main_message = g_strdup_printf ("<b><big>%s</big></b>",
275
 
                                                brasero_burn_dialog_get_media_type_string (burn, type, FALSE));
 
331
                secondary_message = brasero_burn_dialog_get_media_type_string (burn, type, FALSE);
 
332
                main_message = g_strdup_printf ("<b><big>%s</big></b>", secondary_message);
 
333
                g_free (secondary_message);
 
334
                secondary_message = NULL;
276
335
        }
277
336
        else if (error == BRASERO_BURN_ERROR_RELOAD_MEDIA) {
278
 
                main_message = g_strdup (_("The disc in the drive needs to be reloaded:"));
 
337
                main_message = g_strdup_printf (_("The disc in \"%s\" needs to be reloaded:"),
 
338
                                                drive_name);
279
339
                secondary_message = g_strdup (_("eject the disc and reload it."));
280
340
        }
281
341
 
 
342
        g_free (drive_name);
 
343
 
282
344
        window = GTK_WINDOW (dialog);
283
345
 
284
346
        if (secondary_message) {
310
372
        else
311
373
                gtk_window_set_title (GTK_WINDOW (message), _("Waiting for disc replacement"));
312
374
 
313
 
        dialog->priv->waiting_disc_dialog = message;
 
375
        /* connect to signals to be warned when media is inserted */
 
376
        g_object_set_data (G_OBJECT (message), WAITED_FOR_DRIVE, drive);
 
377
 
 
378
        monitor = nautilus_burn_get_drive_monitor ();
 
379
        added_id = g_signal_connect_after (monitor,
 
380
                                           "media-added",
 
381
                                           G_CALLBACK (brasero_burn_dialog_wait_for_insertion),
 
382
                                           message);
314
383
 
315
384
        result = gtk_dialog_run (GTK_DIALOG (message));
 
385
 
 
386
        g_signal_handler_disconnect (monitor, added_id);
316
387
        gtk_widget_destroy (message);
317
388
 
318
 
        dialog->priv->waiting_disc_dialog = NULL;
319
 
 
320
389
        if (hide)
321
390
                gtk_widget_hide (GTK_WIDGET (dialog));
322
391
 
349
418
                                          GTK_BUTTONS_NONE,
350
419
                                          _("The disc in the drive holds data:"));
351
420
 
352
 
        gtk_window_set_title (GTK_WINDOW (message), _("Erasing data"));
 
421
        gtk_window_set_title (GTK_WINDOW (message), _("Possible loss of data"));
353
422
 
354
423
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
355
 
                                                  _("Do you want to erase (you will lose all data previously written)\nor replace it ?"));
356
 
 
357
 
        button = brasero_utils_make_button (_("Replace the disc"), GTK_STOCK_REFRESH);
358
 
        gtk_widget_show_all (button);
359
 
        gtk_dialog_add_action_widget (GTK_DIALOG (message),
360
 
                                      button, GTK_RESPONSE_ACCEPT);
 
424
                                                 _("Do you want to erase the current disc?\nOr replace the current disc with a new disc?"));
361
425
 
362
426
        gtk_dialog_add_buttons (GTK_DIALOG (message),
363
427
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
364
 
                                GTK_STOCK_CLEAR, GTK_RESPONSE_OK,
365
428
                                NULL);
366
429
 
 
430
        button = brasero_utils_make_button (_("Replace disc"), GTK_STOCK_REFRESH, NULL);
 
431
        gtk_widget_show_all (button);
 
432
        gtk_dialog_add_action_widget (GTK_DIALOG (message),
 
433
                                      button, GTK_RESPONSE_ACCEPT);
 
434
 
 
435
        button = brasero_utils_make_button (_("Erase disc"), GTK_STOCK_CLEAR, NULL);
 
436
        gtk_widget_show_all (button);
 
437
        gtk_dialog_add_action_widget (GTK_DIALOG (message),
 
438
                                      button, GTK_RESPONSE_OK);
 
439
 
367
440
        result = gtk_dialog_run (GTK_DIALOG (message));
368
441
        gtk_widget_destroy (message);
369
442
 
407
480
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
408
481
                                                  _("you might not be able to listen to it with stereos.\nDo you want to continue anyway?"));
409
482
 
410
 
        button = brasero_utils_make_button (_("Replace the disc"), GTK_STOCK_REFRESH);
 
483
        button = brasero_utils_make_button (_("Replace the disc"), GTK_STOCK_REFRESH, NULL);
411
484
        gtk_widget_show_all (button);
412
485
        gtk_dialog_add_action_widget (GTK_DIALOG (message),
413
486
                                      button, GTK_RESPONSE_ACCEPT);
416
489
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
417
490
                                NULL);
418
491
 
419
 
        button = brasero_utils_make_button (_("Continue"), GTK_STOCK_OK);
 
492
        button = brasero_utils_make_button (_("Continue"), GTK_STOCK_OK, NULL);
420
493
        gtk_widget_show_all (button);
421
494
        gtk_dialog_add_action_widget (GTK_DIALOG (message),
422
495
                                      button, GTK_RESPONSE_OK);
467
540
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
468
541
                                NULL);
469
542
 
470
 
        button = brasero_utils_make_button (_("Continue"), GTK_STOCK_OK);
 
543
        button = brasero_utils_make_button (_("Continue"), GTK_STOCK_OK, NULL);
471
544
        gtk_widget_show_all (button);
472
545
        gtk_dialog_add_action_widget (GTK_DIALOG (message),
473
546
                                      button, GTK_RESPONSE_OK);
485
558
}
486
559
 
487
560
static void
 
561
brasero_burn_dialog_progress_changed_real (BraseroBurnDialog *dialog,
 
562
                                           gint64 written,
 
563
                                           gint64 isosize,
 
564
                                           gint64 rate,
 
565
                                           gdouble overall_progress,
 
566
                                           gdouble task_progress,
 
567
                                           glong remaining,
 
568
                                           gboolean is_DVD)
 
569
{
 
570
        gint mb_isosize = -1;
 
571
        gint mb_written = -1;
 
572
 
 
573
        if (written >= 0)
 
574
                mb_written = (gint) (written / 1048576);
 
575
        
 
576
        if (isosize > 0)
 
577
                mb_isosize = (gint) (isosize / 1048576);
 
578
 
 
579
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
580
                                          is_DVD,
 
581
                                          overall_progress,
 
582
                                          task_progress,
 
583
                                          remaining,
 
584
                                          mb_isosize,
 
585
                                          mb_written,
 
586
                                          rate);
 
587
 
 
588
        brasero_tray_icon_set_progress (BRASERO_TRAYICON (dialog->priv->tray),
 
589
                                        overall_progress,
 
590
                                        remaining);
 
591
}
 
592
 
 
593
static void
 
594
brasero_burn_dialog_job_progress_changed (BraseroTask *task,
 
595
                                          BraseroBurnDialog *dialog)
 
596
{
 
597
        gint64 total = 0;
 
598
        gint64 written = 0;
 
599
        glong remaining = -1;
 
600
        gdouble progress = -1.0;
 
601
 
 
602
        if (brasero_task_get_progress (task, &progress) != BRASERO_BURN_OK)
 
603
                return;
 
604
 
 
605
        brasero_task_get_total (task, &total);
 
606
        brasero_task_get_written (task, &written);
 
607
        brasero_task_get_remaining_time (task, &remaining);
 
608
 
 
609
        brasero_burn_dialog_progress_changed_real (dialog,
 
610
                                                   written,
 
611
                                                   total,
 
612
                                                   -1,
 
613
                                                   progress,
 
614
                                                   progress,
 
615
                                                   remaining,
 
616
                                                   FALSE);
 
617
}
 
618
 
 
619
static void
488
620
brasero_burn_dialog_progress_changed_cb (BraseroBurn *burn, 
489
621
                                         gdouble overall_progress,
490
622
                                         gdouble task_progress,
491
623
                                         glong remaining,
492
624
                                         BraseroBurnDialog *dialog)
493
625
{
494
 
        NautilusBurnMediaType type;
 
626
        NautilusBurnMediaType type = NAUTILUS_BURN_MEDIA_TYPE_UNKNOWN;
495
627
        gint64 isosize = -1;
496
628
        gint64 written = -1;
497
 
        gint mb_isosize = -1;
498
 
        gint mb_written = -1;
499
629
        gint64 rate = -1;
500
 
        gint fifo = -1;
501
630
 
502
631
        brasero_burn_status (dialog->priv->burn,
503
632
                             &type,
504
633
                             &isosize,
505
634
                             &written,
506
 
                             &rate,
507
 
                             &fifo);
508
 
 
509
 
        if (isosize > 0)
510
 
                mb_isosize = (gint) (isosize / 1048576);
511
 
        if (written >= 0)
512
 
                mb_written = (gint) (written / 1048576);
513
 
 
514
 
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (dialog->priv->progress),
515
 
                                          (type > NAUTILUS_BURN_MEDIA_TYPE_CDRW),
516
 
                                          overall_progress,
517
 
                                          task_progress,
518
 
                                          remaining,
519
 
                                          mb_isosize,
520
 
                                          mb_written,
521
 
                                          rate,
522
 
                                          fifo);
523
 
 
524
 
        brasero_tray_icon_set_progress (BRASERO_TRAYICON (dialog->priv->tray),
525
 
                                        overall_progress,
526
 
                                        remaining);
 
635
                             &rate);
 
636
 
 
637
        if (type != NAUTILUS_BURN_MEDIA_TYPE_UNKNOWN)
 
638
                dialog->priv->media_type = type;
 
639
 
 
640
        brasero_burn_dialog_progress_changed_real (dialog,
 
641
                                                   written,
 
642
                                                   isosize,
 
643
                                                   rate,
 
644
                                                   overall_progress,
 
645
                                                   task_progress,
 
646
                                                   remaining,
 
647
                                                   dialog->priv->media_type > NAUTILUS_BURN_MEDIA_TYPE_CDRW);
 
648
}
 
649
 
 
650
static void
 
651
brasero_burn_dialog_action_changed_real (BraseroBurnDialog *dialog,
 
652
                                         BraseroBurnAction action,
 
653
                                         const gchar *string)
 
654
{
 
655
        brasero_burn_progress_set_action (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
656
                                          action,
 
657
                                          string);
 
658
        brasero_tray_icon_set_action (BRASERO_TRAYICON (dialog->priv->tray),
 
659
                                      action);
527
660
}
528
661
 
529
662
static void
534
667
        gchar *string = NULL;
535
668
 
536
669
        brasero_burn_get_action_string (dialog->priv->burn, action, &string);
537
 
        brasero_burn_progress_set_action (BRASERO_BURN_PROGRESS (dialog->priv->progress),
538
 
                                          action,
539
 
                                          string);
540
 
        g_free (string);
541
 
 
542
 
        brasero_tray_icon_set_action (BRASERO_TRAYICON (dialog->priv->tray),
543
 
                                      action);
 
670
        brasero_burn_dialog_action_changed_real (dialog, action, string);
 
671
        g_free (string);
 
672
}
 
673
 
 
674
static void
 
675
brasero_burn_dialog_job_action_changed (BraseroTask *task,
 
676
                                        BraseroBurnAction action,
 
677
                                        BraseroBurnDialog *dialog)
 
678
{
 
679
        gchar *string;
 
680
 
 
681
        if (brasero_task_get_action_string (task, action, &string) != BRASERO_BURN_OK)
 
682
                string = g_strdup (brasero_burn_action_to_string (action));
 
683
 
 
684
        brasero_burn_dialog_action_changed_real (dialog, action, string);
 
685
        g_free (string);
544
686
}
545
687
 
546
688
static void
548
690
{
549
691
        GtkWidget *box;
550
692
        GtkWidget *vbox;
551
 
        GtkWidget *cancel;
552
693
        GtkWidget *alignment;
553
694
 
554
695
        obj->priv = g_new0 (BraseroBurnDialogPrivate, 1);
603
744
                            FALSE,
604
745
                            0);
605
746
 
606
 
        obj->priv->close_check = gtk_check_button_new_with_label (_("Close the application when the disc is successfully burnt"));
 
747
        obj->priv->close_check = gtk_check_button_new_with_label (_("Close the application if the burn process is successful"));
607
748
        gtk_box_pack_end (GTK_BOX (obj->priv->progress),
608
749
                          obj->priv->close_check,
609
750
                          FALSE,
610
751
                          FALSE,
611
752
                          0);
612
753
 
613
 
        /* Create tracks */
614
 
        obj->priv->burn = brasero_burn_new ();
615
 
        g_signal_connect (obj->priv->burn,
616
 
                          "insert-media",
617
 
                          G_CALLBACK (brasero_burn_dialog_insert_disc_cb),
618
 
                          obj);
619
 
        g_signal_connect (obj->priv->burn,
620
 
                          "warn-data-loss",
621
 
                          G_CALLBACK (brasero_burn_dialog_data_loss_cb),
622
 
                          obj);
623
 
        g_signal_connect (obj->priv->burn,
624
 
                          "warn-rewritable",
625
 
                          G_CALLBACK (brasero_burn_dialog_rewritable_cb),
626
 
                          obj);
627
 
        g_signal_connect (obj->priv->burn,
628
 
                          "disable-joliet",
629
 
                          G_CALLBACK (brasero_burn_dialog_disable_joliet_cb),
630
 
                          obj);
631
 
        g_signal_connect (obj->priv->burn,
632
 
                          "progress-changed",
633
 
                          G_CALLBACK (brasero_burn_dialog_progress_changed_cb),
634
 
                          obj);
635
 
        g_signal_connect (obj->priv->burn,
636
 
                          "action-changed",
637
 
                          G_CALLBACK (brasero_burn_dialog_action_changed_cb),
638
 
                          obj);
639
 
 
640
754
        /* buttons */
641
 
        cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
642
 
        g_signal_connect (G_OBJECT (cancel),
643
 
                          "clicked",
644
 
                          G_CALLBACK (brasero_burn_dialog_cancel_clicked_cb),
645
 
                          obj);
646
 
        gtk_dialog_add_action_widget (GTK_DIALOG (obj), cancel, GTK_RESPONSE_CANCEL);
 
755
        obj->priv->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
 
756
        gtk_dialog_add_action_widget (GTK_DIALOG (obj),
 
757
                                      obj->priv->cancel,
 
758
                                      GTK_RESPONSE_CANCEL);
647
759
}
648
760
 
649
761
static void
670
782
        cobj = BRASERO_BURN_DIALOG (object);
671
783
 
672
784
        if (cobj->priv->burn) {
 
785
                brasero_burn_cancel (cobj->priv->burn, TRUE);
673
786
                g_object_unref (cobj->priv->burn);
674
787
                cobj->priv->burn = NULL;
675
788
        }
676
789
 
 
790
        if (cobj->priv->local_image) {
 
791
                brasero_job_cancel (cobj->priv->local_image, TRUE);
 
792
                g_object_unref (cobj->priv->local_image);
 
793
                cobj->priv->local_image = NULL;
 
794
        }
 
795
 
 
796
        if (cobj->priv->checksum) {
 
797
                brasero_job_cancel (cobj->priv->checksum, TRUE);
 
798
                g_object_unref (cobj->priv->checksum);
 
799
                cobj->priv->checksum = NULL;
 
800
        }
 
801
 
677
802
        if (cobj->priv->tray) {
678
 
                gtk_widget_destroy (cobj->priv->tray);
 
803
                g_object_unref (cobj->priv->tray);
679
804
                cobj->priv->tray = NULL;
680
805
        }
681
806
 
682
 
        if (cobj->priv->loop) {
683
 
                g_main_loop_quit (cobj->priv->loop);
684
 
                g_main_loop_unref (cobj->priv->loop);
685
 
                cobj->priv->loop = NULL;
 
807
        if (cobj->priv->close_timeout) {
 
808
                g_source_remove (cobj->priv->close_timeout);
 
809
                cobj->priv->close_timeout = 0;
 
810
        }
 
811
 
 
812
        if (cobj->priv->session) {
 
813
                g_object_unref (cobj->priv->session);
 
814
                cobj->priv->session = NULL;
686
815
        }
687
816
 
688
817
        g_free (cobj->priv);
700
829
}
701
830
 
702
831
static void
 
832
brasero_burn_dialog_activity_start (BraseroBurnDialog *dialog)
 
833
{
 
834
        GdkCursor *cursor;
 
835
 
 
836
        cursor = gdk_cursor_new (GDK_WATCH);
 
837
        gdk_window_set_cursor (GTK_WIDGET (dialog)->window, NULL);
 
838
        gdk_cursor_unref (cursor);
 
839
 
 
840
        gtk_button_set_use_stock (GTK_BUTTON (dialog->priv->cancel), TRUE);
 
841
        gtk_button_set_label (GTK_BUTTON (dialog->priv->cancel), GTK_STOCK_CANCEL);
 
842
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), FALSE);
 
843
 
 
844
        g_signal_connect (dialog->priv->cancel,
 
845
                          "clicked",
 
846
                          G_CALLBACK (brasero_burn_dialog_cancel_clicked_cb),
 
847
                          dialog);
 
848
 
 
849
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
850
                                          FALSE,
 
851
                                          0.0,
 
852
                                          0.0,
 
853
                                          -1,
 
854
                                          -1,
 
855
                                          -1,
 
856
                                          -1);
 
857
}
 
858
 
 
859
static void
 
860
brasero_burn_dialog_activity_stop (BraseroBurnDialog *dialog,
 
861
                                   const gchar *message)
 
862
{
 
863
        gchar *markup;
 
864
 
 
865
        gdk_window_set_cursor (GTK_WIDGET (dialog)->window, NULL);
 
866
 
 
867
        markup = g_strdup_printf ("<b><big>%s</big></b>", message);
 
868
        gtk_label_set_text (GTK_LABEL (dialog->priv->header), markup);
 
869
        gtk_label_set_use_markup (GTK_LABEL (dialog->priv->header), TRUE);
 
870
        g_free (markup);
 
871
 
 
872
        gtk_button_set_use_stock (GTK_BUTTON (dialog->priv->cancel), TRUE);
 
873
        gtk_button_set_label (GTK_BUTTON (dialog->priv->cancel), GTK_STOCK_CLOSE);
 
874
 
 
875
        g_signal_handlers_disconnect_by_func (dialog->priv->cancel,
 
876
                                              brasero_burn_dialog_cancel_clicked_cb,
 
877
                                              dialog);
 
878
 
 
879
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
880
                                          FALSE,
 
881
                                          1.0,
 
882
                                          1.0,
 
883
                                          -1,
 
884
                                          -1,
 
885
                                          -1,
 
886
                                          -1);
 
887
 
 
888
        gtk_widget_show (GTK_WIDGET (dialog));
 
889
        gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE);
 
890
}
 
891
 
 
892
static void
703
893
brasero_burn_dialog_update_info (BraseroBurnDialog *dialog)
704
894
{
705
 
        char *title = NULL;
706
 
        char *header = NULL;
 
895
        gchar *title = NULL;
 
896
        gchar *header = NULL;
707
897
        GdkPixbuf *pixbuf = NULL;
708
898
        NautilusBurnDrive *drive;
709
899
        NautilusBurnMediaType media_type;
710
900
 
711
 
        char *types [] = {      NULL,
 
901
        gchar *types [] = {     NULL,
712
902
                                NULL,
713
903
                                NULL,
714
904
                                "gnome-dev-cdrom",
728
918
                /* we are creating an image to the hard drive */
729
919
                pixbuf = brasero_utils_get_icon_for_mime ("application/x-cd-image", 48);
730
920
 
731
 
                /* FIXME: we don't want to break strings */
732
 
                header = g_strdup_printf ("<big><b>%s</b></big>", _("Creating image"));
 
921
                header = g_strdup_printf ("<big><b>Creating image</b></big>");
733
922
                title = g_strdup (_("Creating image"));
734
923
                goto end;
735
924
        }
738
927
 
739
928
        if (media_type > NAUTILUS_BURN_MEDIA_TYPE_CDRW) {
740
929
                if (dialog->priv->track_type == BRASERO_TRACK_SOURCE_DATA
741
 
                ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_ISO
742
 
                ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_ISO_JOLIET
 
930
                ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_IMAGE
743
931
                ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_GRAFTS) {
744
932
                        title = g_strdup (_("Burning DVD"));
745
933
                        header = g_strdup (_("<big><b>Burning data DVD</b></big>"));
746
934
                }
 
935
                else if (dialog->priv->track_type == BRASERO_TRACK_SOURCE_IMAGE) {
 
936
                        title = g_strdup (_("Burning DVD"));
 
937
                        header = g_strdup (_("<big><b>Burning image to DVD</b></big>"));
 
938
                }
747
939
                else if (dialog->priv->track_type == BRASERO_TRACK_SOURCE_DISC) {
748
940
                        title = g_strdup (_("Copying DVD"));
749
941
                        header = g_strdup (_("<big><b>Copying data DVD</b></big>"));
756
948
                pixbuf = brasero_utils_get_icon ("gnome-dev-cdrom-audio", 48);
757
949
        }
758
950
        else if (dialog->priv->track_type == BRASERO_TRACK_SOURCE_DATA
759
 
              ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_ISO
760
 
              ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_ISO_JOLIET
761
951
              ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_GRAFTS) {
762
952
                title = g_strdup (_("Burning CD"));
763
953
                header = g_strdup_printf (_("<big><b>Burning data CD</b></big>"));
766
956
                title = g_strdup (_("Copying CD"));
767
957
                header = g_strdup(_("<big><b>Copying CD</b></big>"));
768
958
        }
769
 
        else if (dialog->priv->track_type == BRASERO_TRACK_SOURCE_CUE
770
 
              ||  dialog->priv->track_type == BRASERO_TRACK_SOURCE_RAW) {
 
959
        else if (dialog->priv->track_type == BRASERO_TRACK_SOURCE_IMAGE) {
771
960
                title = g_strdup (_("Burning CD"));
772
 
                header = g_strdup (_("<big><b>Burning disc image</b></big>"));
 
961
                header = g_strdup (_("<big><b>Burning image to CD</b></big>"));
773
962
        }
774
963
 
775
964
        if (!pixbuf) {
786
975
        gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->priv->image), pixbuf);
787
976
        g_object_unref (pixbuf);
788
977
 
789
 
        gtk_label_set_markup (GTK_LABEL (dialog->priv->header), header);
 
978
        gtk_label_set_text (GTK_LABEL (dialog->priv->header), header);
 
979
        gtk_label_set_use_markup (GTK_LABEL (dialog->priv->header), TRUE);
790
980
        g_free (header);
791
981
}
792
982
 
793
983
static void
794
 
brasero_burn_dialog_media_added_cb (NautilusBurnDrive *drive,
 
984
brasero_burn_dialog_media_added_cb (NautilusBurnDriveMonitor *monitor,
 
985
                                    NautilusBurnDrive *drive,
795
986
                                    BraseroBurnDialog *dialog)
796
987
{
 
988
        /* we must make sure that the change was triggered
 
989
         * by the current selected drive */
 
990
        if (!nautilus_burn_drive_equal (drive, dialog->priv->drive))
 
991
                return;
 
992
 
797
993
        brasero_burn_dialog_update_info (dialog);
798
 
 
799
 
        /* we might have a dialog waiting for the 
800
 
         * insertion of a disc if so close it */
801
 
        if (dialog->priv->waiting_disc_dialog) {
802
 
                gtk_dialog_response (GTK_DIALOG (dialog->priv->waiting_disc_dialog),
803
 
                                     GTK_RESPONSE_OK);
804
 
        }
805
994
}
806
995
 
807
996
static void
808
 
brasero_burn_dialog_media_removed_cb (NautilusBurnDrive *drive,
 
997
brasero_burn_dialog_media_removed_cb (NautilusBurnDriveMonitor *monitor,
 
998
                                      NautilusBurnDrive *drive,
809
999
                                      BraseroBurnDialog *dialog)
810
1000
{
811
1001
        GdkPixbuf *pixbuf;
812
1002
 
 
1003
        /* we must make sure that the change was triggered
 
1004
         * by the current selected drive */
 
1005
        if (!nautilus_burn_drive_equal (drive, dialog->priv->drive))
 
1006
                return;
 
1007
 
813
1008
        pixbuf = brasero_utils_get_icon ("gnome-dev-removable", 48);
814
1009
        gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->priv->image), pixbuf);
815
1010
        g_object_unref (pixbuf);
816
1011
}
817
1012
 
818
 
#ifdef HAVE_LIBNOTIFY
819
 
 
820
 
static void
821
 
brasero_burn_dialog_notify_daemon_close (NotifyNotification *notification,
822
 
                                         BraseroBurnDialog *dialog)
823
 
{
824
 
        if (dialog->priv->loop
825
 
        &&  g_main_loop_is_running (dialog->priv->loop))
826
 
                g_main_loop_quit (dialog->priv->loop);
827
 
}
828
 
 
829
 
gboolean
830
 
brasero_burn_dialog_notify_daemon (BraseroBurnDialog *dialog,
831
 
                                   const char *primary,
832
 
                                   const char *secondary)
833
 
{
834
 
        NotifyNotification *notification;
835
 
        gboolean result;
836
 
 
837
 
        notification = notify_notification_new (primary,
838
 
                                                secondary,
839
 
                                                GTK_STOCK_CDROM,
840
 
                                                dialog->priv->tray);
841
 
        if (!notification)
842
 
                return FALSE;
843
 
 
844
 
        g_signal_connect (notification,
845
 
                          "closed",
846
 
                          G_CALLBACK (brasero_burn_dialog_notify_daemon_close),
847
 
                          dialog);
848
 
 
849
 
        notify_notification_set_timeout (notification, 10000);
850
 
        notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
851
 
        result = notify_notification_show (notification, NULL);
852
 
 
853
 
        /* now we wait for the notification to disappear or for the user to
854
 
         * click on the icon in the tray */
855
 
        dialog->priv->loop = g_main_loop_new (NULL, FALSE);
856
 
        g_main_loop_run (dialog->priv->loop);
857
 
 
858
 
        if (dialog->priv->loop) {
859
 
                g_main_loop_unref (dialog->priv->loop);
860
 
                dialog->priv->loop = NULL;
861
 
        }
 
1013
static BraseroBurnResult
 
1014
brasero_burn_dialog_job_get_track (BraseroBurnDialog *dialog,
 
1015
                                   BraseroJob *job,
 
1016
                                   const BraseroTrackSource *source,
 
1017
                                   BraseroTrackSource **retval,
 
1018
                                   GError **error)
 
1019
{
 
1020
        BraseroBurnResult result;
 
1021
        BraseroTask *task;
 
1022
 
 
1023
        result = brasero_job_set_source (job,
 
1024
                                         source,
 
1025
                                         error);
 
1026
 
 
1027
        if (result != BRASERO_BURN_OK)
 
1028
                return result;
 
1029
 
 
1030
        brasero_job_set_debug (job, debug);
 
1031
        brasero_job_set_session (job, dialog->priv->session);
 
1032
 
 
1033
        /* NOTE: here we don't obey the flags as that data is ours and not
 
1034
         * part of the resulting track. */
 
1035
        result = brasero_imager_set_output (BRASERO_IMAGER (job),
 
1036
                                            NULL,
 
1037
                                            TRUE, /* we don't overwrite */
 
1038
                                            TRUE, /* we clean everything */
 
1039
                                            error);
 
1040
 
 
1041
        if (result != BRASERO_BURN_OK)
 
1042
                return result;
 
1043
 
 
1044
        task = brasero_task_new ();
 
1045
        brasero_task_set_total (task, dialog->priv->isosize);
 
1046
 
 
1047
        g_signal_connect (task,
 
1048
                          "progress_changed",
 
1049
                          G_CALLBACK (brasero_burn_dialog_job_progress_changed),
 
1050
                          dialog);
 
1051
        g_signal_connect (task,
 
1052
                          "action_changed",
 
1053
                          G_CALLBACK (brasero_burn_dialog_job_action_changed),
 
1054
                          dialog);
 
1055
 
 
1056
        brasero_job_set_task (job, task);
 
1057
        result = brasero_imager_get_track (BRASERO_IMAGER (job),
 
1058
                                           retval,
 
1059
                                           error);
 
1060
 
 
1061
        brasero_job_set_task (job, NULL);
 
1062
        g_object_unref (task);
862
1063
 
863
1064
        return result;
864
1065
}
865
1066
 
866
 
#endif
867
 
 
868
 
static gboolean
869
 
brasero_burn_dialog_success_timeout (GtkDialog *dialog)
870
 
{
871
 
        gtk_dialog_response (dialog, GTK_RESPONSE_CANCEL);
872
 
        return FALSE;
 
1067
static BraseroBurnResult
 
1068
brasero_burn_dialog_get_local_source (BraseroBurnDialog *dialog,
 
1069
                                      const BraseroTrackSource *source,
 
1070
                                      BraseroTrackSource **local,
 
1071
                                      GError **error)
 
1072
{
 
1073
        if (source->type == BRASERO_TRACK_SOURCE_DISC
 
1074
        ||  source->type == BRASERO_TRACK_SOURCE_INF) {
 
1075
                *local = brasero_track_source_copy (source);
 
1076
                return BRASERO_BURN_OK;
 
1077
        }
 
1078
 
 
1079
        if (dialog->priv->local_image)
 
1080
                g_object_unref (dialog->priv->local_image);
 
1081
 
 
1082
        dialog->priv->local_image = g_object_new (BRASERO_TYPE_LOCAL_IMAGE, NULL);
 
1083
        return brasero_burn_dialog_job_get_track (dialog,
 
1084
                                                   dialog->priv->local_image,
 
1085
                                                   source,
 
1086
                                                   local,
 
1087
                                                   error);
 
1088
}
 
1089
 
 
1090
static BraseroBurnResult
 
1091
brasero_burn_dialog_get_checksumed_source (BraseroBurnDialog *dialog,
 
1092
                                           const BraseroTrackSource *source,
 
1093
                                           BraseroTrackSource **checksum,
 
1094
                                           GError **error)
 
1095
{
 
1096
        if (source->type != BRASERO_TRACK_SOURCE_DATA) {
 
1097
                *checksum = brasero_track_source_copy (source);
 
1098
                return BRASERO_BURN_OK;
 
1099
        }
 
1100
 
 
1101
        if (dialog->priv->checksum)
 
1102
                g_object_unref (dialog->priv->checksum);
 
1103
 
 
1104
        dialog->priv->checksum = g_object_new (BRASERO_TYPE_BURN_SUM, NULL);
 
1105
        if (!dialog->priv->checksum)
 
1106
                return BRASERO_BURN_ERR;
 
1107
 
 
1108
        return brasero_burn_dialog_job_get_track (dialog,
 
1109
                                                   dialog->priv->checksum,
 
1110
                                                   source,
 
1111
                                                   checksum,
 
1112
                                                   error);
873
1113
}
874
1114
 
875
1115
static void
876
 
brasero_burn_dialog_notify_dialog (BraseroBurnDialog *dialog,
877
 
                                   const gchar *primary,
878
 
                                   const gchar *secondary,
879
 
                                   GtkMessageType type,
880
 
                                   gboolean timeout)
 
1116
brasero_burn_dialog_message (BraseroBurnDialog *dialog,
 
1117
                             const gchar *title,
 
1118
                             const gchar *primary_message,
 
1119
                             const gchar *secondary_message,
 
1120
                             GtkMessageType type)
881
1121
{
882
 
        gint id = 0;
883
1122
        GtkWidget *message;
884
 
        GtkResponseType response;
885
 
 
886
 
        if (!GTK_WIDGET_VISIBLE (dialog))
887
 
                gtk_widget_show (GTK_WIDGET (dialog));
888
1123
 
889
1124
        message = gtk_message_dialog_new (GTK_WINDOW (dialog),
890
 
                                          GTK_DIALOG_DESTROY_WITH_PARENT |
891
 
                                          GTK_DIALOG_MODAL,
 
1125
                                          GTK_DIALOG_MODAL |
 
1126
                                          GTK_DIALOG_DESTROY_WITH_PARENT,
892
1127
                                          type,
893
1128
                                          GTK_BUTTONS_CLOSE,
 
1129
                                          primary_message);
 
1130
 
 
1131
        gtk_window_set_title (GTK_WINDOW (message), title);
 
1132
 
 
1133
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
1134
                                                  secondary_message);
 
1135
        gtk_dialog_run (GTK_DIALOG (message));
 
1136
        gtk_widget_destroy (message);
 
1137
}
 
1138
 
 
1139
static void
 
1140
brasero_burn_dialog_integrity_ok (BraseroBurnDialog *dialog)
 
1141
{
 
1142
        brasero_burn_dialog_message (dialog,
 
1143
                                     _("Data integrity check"),
 
1144
                                     _("The file integrity check succeeded:"),
 
1145
                                     _("there seems to be no corrupted file on the disc."),
 
1146
                                     GTK_MESSAGE_INFO);
 
1147
}
 
1148
 
 
1149
static void
 
1150
brasero_burn_dialog_integrity_error (BraseroBurnDialog *dialog,
 
1151
                                     const GError *error)
 
1152
{
 
1153
        brasero_burn_dialog_message (dialog,
 
1154
                                     _("Data integrity check"),
 
1155
                                     _("The data integrity check could not be performed:"),
 
1156
                                     error ? error->message:_("unknown error."),
 
1157
                                     GTK_MESSAGE_ERROR);
 
1158
}
 
1159
 
 
1160
static void
 
1161
brasero_burn_dialog_integrity_wrong_sums (BraseroBurnDialog *dialog)
 
1162
{
 
1163
        brasero_burn_dialog_message (dialog,
 
1164
                                     _("Data integrity check"),
 
1165
                                     _("The file integrity check failed:"),
 
1166
                                     _("some files may be corrupted on the disc."),
 
1167
                                     GTK_MESSAGE_ERROR);
 
1168
}
 
1169
 
 
1170
static void
 
1171
brasero_burn_dialog_integrity_check_end (BraseroBurnDialog *dialog,
 
1172
                                         BraseroBurnResult result,
 
1173
                                         GError *error)
 
1174
{
 
1175
        if (result == BRASERO_BURN_CANCEL)
 
1176
                return;
 
1177
 
 
1178
        if (error) {
 
1179
                brasero_burn_dialog_integrity_error (dialog, error);
 
1180
                g_error_free (error);
 
1181
        }
 
1182
        else if (result != BRASERO_BURN_OK)
 
1183
                brasero_burn_dialog_integrity_wrong_sums (dialog);
 
1184
        else
 
1185
                brasero_burn_dialog_integrity_ok (dialog);
 
1186
}
 
1187
 
 
1188
static BraseroBurnResult
 
1189
brasero_burn_dialog_reload_disc_dlg (BraseroBurnDialog *dialog,
 
1190
                                     NautilusBurnDrive *drive,
 
1191
                                     const gchar *primary,
 
1192
                                     const gchar *secondary)
 
1193
{
 
1194
        gint answer;
 
1195
        gint added_id;
 
1196
        GtkWidget *message;
 
1197
        NautilusBurnDriveMonitor *monitor;
 
1198
 
 
1199
        /* display a dialog to the user explaining what we're
 
1200
         * going to do, that is reload the disc before checking */
 
1201
        message = gtk_message_dialog_new (GTK_WINDOW (dialog),
 
1202
                                          GTK_DIALOG_MODAL |
 
1203
                                          GTK_DIALOG_DESTROY_WITH_PARENT,
 
1204
                                          GTK_MESSAGE_INFO,
 
1205
                                          GTK_BUTTONS_CANCEL,
894
1206
                                          primary);
895
1207
 
 
1208
        gtk_window_set_title (GTK_WINDOW (message), _("Data integrity check"));
 
1209
 
896
1210
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
897
 
                                                  "%s.",
898
1211
                                                  secondary);
899
1212
 
900
 
        if (timeout
901
 
        &&  gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->close_check)))
902
 
                id = g_timeout_add (10000,
903
 
                                    (GSourceFunc) brasero_burn_dialog_success_timeout,
904
 
                                    message);
905
 
 
906
 
        response = gtk_dialog_run (GTK_DIALOG (message));
907
 
        gtk_widget_destroy (message);
908
 
 
909
 
        if (id && response != GTK_RESPONSE_CANCEL)
910
 
                g_source_remove (id);
 
1213
        g_object_set_data (G_OBJECT (message), WAITED_FOR_DRIVE, drive);
 
1214
        monitor = nautilus_burn_get_drive_monitor ();
 
1215
        added_id = g_signal_connect_after (monitor,
 
1216
                                           "media-added",
 
1217
                                           G_CALLBACK (brasero_burn_dialog_wait_for_insertion),
 
1218
                                           message);
 
1219
 
 
1220
        answer = gtk_dialog_run (GTK_DIALOG (message));
 
1221
 
 
1222
        g_signal_handler_disconnect (monitor, added_id);
 
1223
        gtk_widget_destroy (message);
 
1224
 
 
1225
        if (answer != GTK_RESPONSE_OK)
 
1226
                return BRASERO_BURN_CANCEL;
 
1227
 
 
1228
        return BRASERO_BURN_OK;
 
1229
}
 
1230
 
 
1231
static BraseroBurnResult
 
1232
brasero_burn_dialog_check_image_integrity (BraseroBurnDialog *dialog,
 
1233
                                           NautilusBurnDrive *drive,
 
1234
                                           const BraseroTrackSource *source,
 
1235
                                           GError **error)
 
1236
{
 
1237
        gboolean success;
 
1238
        BraseroBurnResult result;
 
1239
        BraseroTrackSource track;
 
1240
        BraseroTrackSource *checksum_disc, *checksum_track;
 
1241
 
 
1242
        /* NOTE: since we don't want to destroy that track we don't ref drive */
 
1243
        track.type = BRASERO_TRACK_SOURCE_DISC;
 
1244
        track.format = BRASERO_IMAGE_FORMAT_NONE;
 
1245
        track.contents.drive.disc = drive;
 
1246
 
 
1247
        if (dialog->priv->checksum)
 
1248
                g_object_unref (dialog->priv->checksum);
 
1249
 
 
1250
        dialog->priv->checksum = g_object_new (BRASERO_TYPE_BURN_SUM, NULL);
 
1251
        if (!dialog->priv->checksum)
 
1252
                return BRASERO_BURN_ERR;
 
1253
 
 
1254
        result = brasero_burn_dialog_job_get_track (dialog,
 
1255
                                                    dialog->priv->checksum,
 
1256
                                                    &track,
 
1257
                                                    &checksum_disc,
 
1258
                                                    error);
 
1259
        if (result != BRASERO_BURN_OK)
 
1260
                return result;
 
1261
 
 
1262
        if (source->type == BRASERO_TRACK_SOURCE_DISC) {
 
1263
                NautilusBurnMediaType media;
 
1264
                NautilusBurnDrive *src_drive;
 
1265
 
 
1266
                src_drive = source->contents.drive.disc;
 
1267
                media = nautilus_burn_drive_get_media_type (src_drive);
 
1268
                if (media == NAUTILUS_BURN_MEDIA_TYPE_ERROR) {
 
1269
                        gchar *message;
 
1270
                        gchar *name;
 
1271
 
 
1272
                        name = nautilus_burn_drive_get_name_for_display (src_drive);
 
1273
                        message = g_strdup_printf (_("Please insert it in \"%s\"."),
 
1274
                                                   name);
 
1275
                        g_free (name);
 
1276
 
 
1277
                        result = brasero_burn_dialog_reload_disc_dlg (dialog,
 
1278
                                                                      src_drive,
 
1279
                                                                      _("The source media needs to be inserted:"),
 
1280
                                                                      message);
 
1281
                        g_free (message);
 
1282
                }
 
1283
                else if (nautilus_burn_drive_equal (drive, src_drive)) {
 
1284
                        gchar *message;
 
1285
                        gchar *name;
 
1286
 
 
1287
                        nautilus_burn_drive_eject (src_drive);
 
1288
 
 
1289
                        name = nautilus_burn_drive_get_name_for_display (src_drive);
 
1290
                        message = g_strdup_printf (_("Please insert it again in \"%s\"."), name);
 
1291
                        g_free (name);
 
1292
 
 
1293
                        result = brasero_burn_dialog_reload_disc_dlg (dialog,
 
1294
                                                                      src_drive,
 
1295
                                                                      _("The source media needs to be reloaded:"),
 
1296
                                                                      message);
 
1297
                        g_free (message);
 
1298
                }
 
1299
 
 
1300
                if (result == BRASERO_BURN_CANCEL) {
 
1301
                        brasero_track_source_free (checksum_disc);
 
1302
                        return result;
 
1303
                }
 
1304
        }
 
1305
 
 
1306
        /* now that we have a checksum for the drive we compare get one
 
1307
         * for the image */
 
1308
        result = brasero_burn_dialog_job_get_track (dialog,
 
1309
                                                    dialog->priv->checksum,
 
1310
                                                    source,
 
1311
                                                    &checksum_track,
 
1312
                                                    error);
 
1313
        if (result != BRASERO_BURN_OK) {
 
1314
                brasero_track_source_free (checksum_disc);
 
1315
                return result;
 
1316
        }
 
1317
 
 
1318
        /* compare the checksums */
 
1319
        success = brasero_md5_equal (&checksum_track->contents.sum.md5,
 
1320
                                     &checksum_disc->contents.sum.md5);
 
1321
 
 
1322
        brasero_track_source_free (checksum_disc);
 
1323
        brasero_track_source_free (checksum_track);
 
1324
 
 
1325
        if (success)
 
1326
                return BRASERO_BURN_OK;
 
1327
 
 
1328
        return BRASERO_BURN_ERR;
 
1329
}
 
1330
 
 
1331
static gboolean
 
1332
brasero_burn_dialog_check_integrity_report (gpointer user_data)
 
1333
{
 
1334
        BraseroBurnDialog *dialog = BRASERO_BURN_DIALOG (user_data);
 
1335
 
 
1336
        if (dialog->priv->file_ctx) {
 
1337
                gint checked, total;
 
1338
                gdouble progress;
 
1339
 
 
1340
                brasero_sum_check_progress (dialog->priv->file_ctx,
 
1341
                                            &checked,
 
1342
                                            &total);
 
1343
 
 
1344
                progress = (gdouble) checked / (gdouble) total;
 
1345
                brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
1346
                                                  FALSE,
 
1347
                                                  progress,
 
1348
                                                  progress,
 
1349
                                                  -1,
 
1350
                                                  -1,
 
1351
                                                  -1,
 
1352
                                                  -1);
 
1353
        }
 
1354
 
 
1355
        return TRUE;
 
1356
}
 
1357
 
 
1358
static BraseroBurnResult
 
1359
brasero_burn_dialog_check_files_integrity (BraseroBurnDialog *dialog,
 
1360
                                           const gchar *mount_point,
 
1361
                                           GError **error)
 
1362
{
 
1363
        gint id;
 
1364
        BraseroBurnResult result;
 
1365
        GSList *wrong_sums = NULL;
 
1366
 
 
1367
        id = g_timeout_add (500,
 
1368
                            brasero_burn_dialog_check_integrity_report,
 
1369
                            dialog);
 
1370
 
 
1371
        brasero_burn_progress_set_action (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
1372
                                          BRASERO_BURN_ACTION_CHECKSUM,
 
1373
                                          _("Checking files integrity"));
 
1374
 
 
1375
        /* check the sum of every file */
 
1376
        dialog->priv->file_ctx = brasero_sum_check_new ();
 
1377
        result = brasero_sum_check (dialog->priv->file_ctx,
 
1378
                                    mount_point,
 
1379
                                    &wrong_sums,
 
1380
                                    error);
 
1381
 
 
1382
        brasero_sum_check_free (dialog->priv->file_ctx);
 
1383
        g_source_remove (id);
 
1384
 
 
1385
        if (wrong_sums) {
 
1386
                g_slist_foreach (wrong_sums, (GFunc) g_free, NULL);
 
1387
                g_slist_free (wrong_sums);
 
1388
 
 
1389
                result = BRASERO_BURN_ERR;
 
1390
        }
 
1391
 
 
1392
        return result;
 
1393
}
 
1394
 
 
1395
static void
 
1396
brasero_burn_dialog_get_mount_point_cb (NautilusBurnDrive *drive,
 
1397
                                        const gchar *mount_point,
 
1398
                                        gboolean mounted_by_us,
 
1399
                                        const GError *error,
 
1400
                                        gpointer callback_data)
 
1401
{
 
1402
        BraseroBurnDialog *dialog = callback_data;
 
1403
        GError *local_error = NULL;
 
1404
        gboolean success;
 
1405
 
 
1406
        if (error) {
 
1407
                brasero_burn_dialog_integrity_error (dialog, error);
 
1408
                gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
1409
                return;
 
1410
        }
 
1411
 
 
1412
        success = brasero_burn_dialog_check_files_integrity (dialog,
 
1413
                                                             mount_point,
 
1414
                                                             &local_error);
 
1415
 
 
1416
        if (mounted_by_us)
 
1417
                NCB_DRIVE_UNMOUNT (drive, NULL);
 
1418
 
 
1419
        brasero_burn_dialog_integrity_check_end (dialog, success, local_error);
 
1420
        if (local_error)
 
1421
                g_error_free (local_error);
 
1422
 
 
1423
        gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
1424
}
 
1425
 
 
1426
static void
 
1427
brasero_burn_dialog_integrity_start (BraseroBurnDialog *dialog,
 
1428
                                     NautilusBurnDrive *burner,
 
1429
                                     const BraseroTrackSource *source)
 
1430
{
 
1431
        BraseroBurnResult result;
 
1432
        gchar *header;
 
1433
 
 
1434
        if (nautilus_burn_drive_get_media_type (burner) < NAUTILUS_BURN_MEDIA_TYPE_CD) {
 
1435
                gchar *message;
 
1436
                gchar *name;
 
1437
 
 
1438
                /* display a dialog to the user explaining what we're
 
1439
                 * going to do, that is reload the disc before checking */
 
1440
                name = nautilus_burn_drive_get_name_for_display (burner);
 
1441
                message = g_strdup_printf (_("please, insert it again in \"%s\"."),
 
1442
                                           name);
 
1443
                g_free (name);
 
1444
 
 
1445
                result = brasero_burn_dialog_reload_disc_dlg (dialog,
 
1446
                                                              burner,
 
1447
                                                              _("The burnt media needs to be reloaded to perform integrity check:"),
 
1448
                                                              message);
 
1449
                g_free (message);
 
1450
 
 
1451
                if (result == BRASERO_BURN_CANCEL)
 
1452
                        return;
 
1453
        }
 
1454
 
 
1455
        /* change the text */
 
1456
        header = g_strdup (gtk_label_get_text (GTK_LABEL (dialog->priv->header)));
 
1457
 
 
1458
        brasero_burn_dialog_activity_start (dialog);
 
1459
        gtk_label_set_text (GTK_LABEL (dialog->priv->header), 
 
1460
                            _("<b><big>Performing integrity check</big></b>"));
 
1461
        gtk_label_set_use_markup (GTK_LABEL (dialog->priv->header), TRUE);
 
1462
 
 
1463
        /* get the mount point */
 
1464
        if (source->type == BRASERO_TRACK_SOURCE_DATA) {
 
1465
                BraseroMountHandle *handle;
 
1466
                GtkResponseType answer;
 
1467
 
 
1468
                brasero_burn_dialog_action_changed_real (dialog,
 
1469
                                                         BRASERO_BURN_ACTION_CHECKSUM,
 
1470
                                                         _("Mounting disc"));
 
1471
 
 
1472
                handle = NCB_DRIVE_GET_MOUNT_POINT (burner,
 
1473
                                                    brasero_burn_dialog_get_mount_point_cb,
 
1474
                                                    dialog);
 
1475
 
 
1476
                answer = gtk_dialog_run (GTK_DIALOG (dialog));
 
1477
                if (answer == GTK_RESPONSE_CANCEL)
 
1478
                        NCB_DRIVE_GET_MOUNT_POINT_CANCEL (handle);
 
1479
        }
 
1480
        else {
 
1481
                GError *error = NULL;
 
1482
 
 
1483
                result = brasero_burn_dialog_check_image_integrity (dialog,
 
1484
                                                                    burner,
 
1485
                                                                    source,
 
1486
                                                                    &error);
 
1487
 
 
1488
                brasero_burn_dialog_integrity_check_end (dialog,
 
1489
                                                         result,
 
1490
                                                         error);
 
1491
        }
 
1492
 
 
1493
        brasero_burn_progress_set_action (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
1494
                                          BRASERO_BURN_ACTION_FINISHED,
 
1495
                                          _("Success"));
 
1496
 
 
1497
        brasero_burn_dialog_activity_stop (dialog, header);
 
1498
        g_free (header);
 
1499
}
 
1500
 
 
1501
static BraseroBurnResult
 
1502
brasero_burn_dialog_setup_session (BraseroBurnDialog *dialog,
 
1503
                                   const BraseroTrackSource *source,
 
1504
                                   BraseroTrackSource **track,
 
1505
                                   gboolean checksum,
 
1506
                                   GError **error)
 
1507
{
 
1508
        BraseroTrackSource *local_track;
 
1509
        BraseroBurnResult result;
 
1510
 
 
1511
        dialog->priv->session = brasero_burn_session_new ();
 
1512
        brasero_burn_session_start (dialog->priv->session);
 
1513
 
 
1514
        /* make sure all files in track are local if not download */
 
1515
        result = brasero_burn_dialog_get_local_source (dialog,
 
1516
                                                       source,
 
1517
                                                       &local_track,
 
1518
                                                       error);
 
1519
 
 
1520
        if (result != BRASERO_BURN_OK)
 
1521
                return result;
 
1522
 
 
1523
        /* generates a checksum if the user wants it */
 
1524
        if (checksum && local_track->type == BRASERO_TRACK_SOURCE_DATA) {
 
1525
                result = brasero_burn_dialog_get_checksumed_source (dialog,
 
1526
                                                                    local_track,
 
1527
                                                                    track,
 
1528
                                                                    error);
 
1529
                brasero_track_source_free (local_track);
 
1530
                if (result != BRASERO_BURN_OK)
 
1531
                        return result;
 
1532
        }
 
1533
        else
 
1534
                *track = local_track;
 
1535
 
 
1536
        dialog->priv->burn = brasero_burn_new ();
 
1537
        g_signal_connect (dialog->priv->burn,
 
1538
                          "insert-media",
 
1539
                          G_CALLBACK (brasero_burn_dialog_insert_disc_cb),
 
1540
                          dialog);
 
1541
        g_signal_connect (dialog->priv->burn,
 
1542
                          "warn-data-loss",
 
1543
                          G_CALLBACK (brasero_burn_dialog_data_loss_cb),
 
1544
                          dialog);
 
1545
        g_signal_connect (dialog->priv->burn,
 
1546
                          "warn-rewritable",
 
1547
                          G_CALLBACK (brasero_burn_dialog_rewritable_cb),
 
1548
                          dialog);
 
1549
        g_signal_connect (dialog->priv->burn,
 
1550
                          "disable-joliet",
 
1551
                          G_CALLBACK (brasero_burn_dialog_disable_joliet_cb),
 
1552
                          dialog);
 
1553
        g_signal_connect (dialog->priv->burn,
 
1554
                          "progress-changed",
 
1555
                          G_CALLBACK (brasero_burn_dialog_progress_changed_cb),
 
1556
                          dialog);
 
1557
        g_signal_connect (dialog->priv->burn,
 
1558
                          "action-changed",
 
1559
                          G_CALLBACK (brasero_burn_dialog_action_changed_cb),
 
1560
                          dialog);
 
1561
 
 
1562
        brasero_burn_set_session (dialog->priv->burn,
 
1563
                                  dialog->priv->session);
 
1564
 
 
1565
        brasero_burn_progress_set_status (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
1566
                                          FALSE,
 
1567
                                          0.0,
 
1568
                                          -1.0,
 
1569
                                          -1,
 
1570
                                          -1,
 
1571
                                          -1,
 
1572
                                          -1);
 
1573
 
 
1574
        brasero_tray_icon_set_progress (BRASERO_TRAYICON (dialog->priv->tray),
 
1575
                                        0.0,
 
1576
                                        -1);
 
1577
 
 
1578
        brasero_burn_progress_set_action (BRASERO_BURN_PROGRESS (dialog->priv->progress),
 
1579
                                          BRASERO_BURN_ACTION_NONE,
 
1580
                                          NULL);
 
1581
 
 
1582
        brasero_tray_icon_set_action (BRASERO_TRAYICON (dialog->priv->tray),
 
1583
                                      BRASERO_BURN_ACTION_NONE);
 
1584
        return BRASERO_BURN_OK;
 
1585
}
 
1586
 
 
1587
static void
 
1588
brasero_burn_dialog_save_log (BraseroBurnDialog *dialog)
 
1589
{
 
1590
        gchar *contents;
 
1591
        gchar *path = NULL;
 
1592
        GtkWidget *chooser;
 
1593
        GtkResponseType answer;
 
1594
 
 
1595
        chooser = gtk_file_chooser_dialog_new (_("Save current session"),
 
1596
                                               GTK_WINDOW (dialog),
 
1597
                                               GTK_FILE_CHOOSER_ACTION_SAVE,
 
1598
                                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
1599
                                               GTK_STOCK_SAVE, GTK_RESPONSE_OK,
 
1600
                                               NULL);
 
1601
 
 
1602
        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
 
1603
        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
 
1604
                                             g_get_home_dir ());
 
1605
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser),
 
1606
                                           "brasero-session.log");
 
1607
 
 
1608
        gtk_widget_show (chooser);
 
1609
        answer = gtk_dialog_run (GTK_DIALOG (chooser));
 
1610
        if (answer != GTK_RESPONSE_OK) {
 
1611
                gtk_widget_destroy (chooser);
 
1612
                return;
 
1613
        }
 
1614
 
 
1615
        path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
 
1616
        gtk_widget_destroy (chooser);
 
1617
 
 
1618
        if (!path)
 
1619
                return;
 
1620
 
 
1621
        if (path && *path == '\0') {
 
1622
                g_free (path);
 
1623
                return;
 
1624
        }
 
1625
 
 
1626
        g_file_get_contents (brasero_burn_session_get_log_path (dialog->priv->session),
 
1627
                             &contents,
 
1628
                             NULL,
 
1629
                             NULL);
 
1630
        g_file_set_contents (path, contents, -1, NULL);
 
1631
 
 
1632
        g_free (contents);
 
1633
        g_free (path);
 
1634
}
 
1635
 
 
1636
static void
 
1637
brasero_burn_dialog_show_log (BraseroBurnDialog *dialog)
 
1638
{
 
1639
        gint words_num;
 
1640
        gchar *contents;
 
1641
        GtkWidget *view;
 
1642
        GtkTextIter iter;
 
1643
        GtkWidget *message;
 
1644
        GtkWidget *scrolled;
 
1645
        GtkTextBuffer *text;
 
1646
        GtkTextTag *object_tag;
 
1647
        GtkTextTag *domain_tag;
 
1648
 
 
1649
        message = gtk_dialog_new_with_buttons (_("Session log"),
 
1650
                                               GTK_WINDOW (dialog),
 
1651
                                               GTK_DIALOG_DESTROY_WITH_PARENT |
 
1652
                                               GTK_DIALOG_MODAL,
 
1653
                                               GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 
1654
                                               NULL);
 
1655
        gtk_window_set_default_size (GTK_WINDOW (message), 500, 375);
 
1656
        scrolled = gtk_scrolled_window_new (NULL, NULL);
 
1657
        gtk_container_set_border_width (GTK_CONTAINER (scrolled), 6);
 
1658
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
 
1659
                                        GTK_POLICY_AUTOMATIC,
 
1660
                                        GTK_POLICY_AUTOMATIC);
 
1661
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
 
1662
                                             GTK_SHADOW_ETCHED_IN);
 
1663
        gtk_box_pack_end (GTK_BOX (GTK_DIALOG (message)->vbox),
 
1664
                          scrolled,
 
1665
                          TRUE,
 
1666
                          TRUE,
 
1667
                          0);
 
1668
 
 
1669
        view = gtk_text_view_new ();
 
1670
        gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
 
1671
        gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled), view);
 
1672
 
 
1673
        /* fill the buffer */
 
1674
        text = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 
1675
        g_file_get_contents (brasero_burn_session_get_log_path (dialog->priv->session),
 
1676
                             &contents,
 
1677
                             NULL,
 
1678
                             NULL);
 
1679
        gtk_text_buffer_set_text (text, contents, -1);
 
1680
        g_free (contents);
 
1681
 
 
1682
        /* create tags and apply them */
 
1683
        object_tag = gtk_text_buffer_create_tag (text,
 
1684
                                                 NULL,
 
1685
                                                 "foreground", "red",
 
1686
                                                 "weight", PANGO_WEIGHT_BOLD,
 
1687
                                                 NULL);
 
1688
        domain_tag = gtk_text_buffer_create_tag (text,
 
1689
                                                 NULL,
 
1690
                                                 "foreground", "blue",
 
1691
                                                 NULL);
 
1692
        gtk_text_buffer_get_start_iter (text, &iter);
 
1693
        words_num = 0;
 
1694
        while (gtk_text_iter_forward_word_end (&iter)) {
 
1695
                GtkTextIter start = iter;
 
1696
 
 
1697
                gtk_text_iter_backward_word_start (&start);
 
1698
 
 
1699
                if (words_num == 2)
 
1700
                        gtk_text_buffer_apply_tag (text, object_tag, &start, &iter);
 
1701
                else if (gtk_text_iter_starts_line (&start)) {
 
1702
                        words_num = 1;
 
1703
                        gtk_text_buffer_apply_tag (text, domain_tag, &start, &iter);
 
1704
                }
 
1705
 
 
1706
                words_num ++;
 
1707
        }
 
1708
 
 
1709
        /* run everything */
 
1710
        gtk_widget_show_all (scrolled);
 
1711
        gtk_dialog_run (GTK_DIALOG (message));
 
1712
 
 
1713
        gtk_widget_destroy (message);
911
1714
}
912
1715
 
913
1716
static void
914
1717
brasero_burn_dialog_notify_error (BraseroBurnDialog *dialog,
915
1718
                                  GError *error)
916
1719
{
917
 
        char *secondary;
 
1720
        gchar *secondary;
 
1721
        GtkWidget *button;
 
1722
        GtkWidget *message;
 
1723
        GtkResponseType response;
918
1724
 
919
1725
        if (error) {
920
1726
                secondary =  g_strdup (error->message);
923
1729
        else
924
1730
                secondary = g_strdup (_("An unknown error occured. Check your disc"));
925
1731
 
926
 
        brasero_burn_dialog_notify_dialog (dialog,
927
 
                                           _("Error while burning:"),
928
 
                                           secondary,
929
 
                                           GTK_MESSAGE_ERROR,
930
 
                                           FALSE);
931
 
 
 
1732
        if (!GTK_WIDGET_VISIBLE (dialog))
 
1733
                gtk_widget_show (GTK_WIDGET (dialog));
 
1734
 
 
1735
        message = gtk_message_dialog_new (GTK_WINDOW (dialog),
 
1736
                                          GTK_DIALOG_DESTROY_WITH_PARENT |
 
1737
                                          GTK_DIALOG_MODAL,
 
1738
                                          GTK_MESSAGE_ERROR,
 
1739
                                          GTK_BUTTONS_NONE,
 
1740
                                          _("Error while burning:"));
 
1741
 
 
1742
        gtk_window_set_title (GTK_WINDOW (message), _("Burning error"));
 
1743
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
 
1744
                                                  "%s.",
 
1745
                                                  secondary);
932
1746
        g_free (secondary);
 
1747
 
 
1748
        button = brasero_utils_make_button (_("Save log"), GTK_STOCK_SAVE_AS, NULL);
 
1749
        gtk_widget_show_all (button);
 
1750
        gtk_dialog_add_action_widget (GTK_DIALOG (message), button, GTK_RESPONSE_APPLY);
 
1751
 
 
1752
        button = brasero_utils_make_button (_("View log"), GTK_STOCK_EDIT, NULL);
 
1753
        gtk_widget_show_all (button);
 
1754
        gtk_dialog_add_action_widget (GTK_DIALOG (message), button, GTK_RESPONSE_OK);
 
1755
 
 
1756
        button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
 
1757
        gtk_widget_show (button);
 
1758
        gtk_dialog_add_action_widget (GTK_DIALOG (message), button, GTK_RESPONSE_CLOSE);
 
1759
 
 
1760
        response = gtk_dialog_run (GTK_DIALOG (message));
 
1761
        while (1) {
 
1762
                if (response == GTK_RESPONSE_APPLY)
 
1763
                        brasero_burn_dialog_save_log (dialog);
 
1764
                else if (response == GTK_RESPONSE_OK)
 
1765
                        brasero_burn_dialog_show_log (dialog);
 
1766
                else
 
1767
                        break;
 
1768
 
 
1769
                response = gtk_dialog_run (GTK_DIALOG (message));
 
1770
        }
 
1771
 
 
1772
        gtk_widget_destroy (message);
 
1773
}
 
1774
 
 
1775
static gboolean
 
1776
brasero_burn_dialog_success_timeout (BraseroBurnDialog *dialog)
 
1777
{
 
1778
        gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
1779
        dialog->priv->close_timeout = 0;
 
1780
 
 
1781
        return FALSE;
 
1782
}
 
1783
 
 
1784
static void
 
1785
brasero_burn_dialog_success_run (BraseroBurnDialog *dialog,
 
1786
                                 NautilusBurnDrive *drive,
 
1787
                                 const BraseroTrackSource *source,
 
1788
                                 gboolean checksum)
 
1789
{
 
1790
        gint answer;
 
1791
        GtkWidget *button = NULL;
 
1792
 
 
1793
        if (checksum) {
 
1794
                button = brasero_utils_make_button (_("Check integrity"),
 
1795
                                                    GTK_STOCK_FIND, NULL);
 
1796
                gtk_widget_show_all (button);
 
1797
 
 
1798
                gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
 
1799
                                              button,
 
1800
                                              GTK_RESPONSE_APPLY);
 
1801
        }
 
1802
 
 
1803
start:
 
1804
 
 
1805
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->close_check))) {
 
1806
                dialog->priv->close_timeout = g_timeout_add (TIMEOUT,
 
1807
                                                             (GSourceFunc) brasero_burn_dialog_success_timeout,
 
1808
                                                             dialog);
 
1809
 
 
1810
        }
 
1811
 
 
1812
        answer = gtk_dialog_run (GTK_DIALOG (dialog));
 
1813
 
 
1814
        /* remove the timeout if need be */
 
1815
        if (dialog->priv->close_timeout) {
 
1816
                g_source_remove (dialog->priv->close_timeout);
 
1817
                dialog->priv->close_timeout = 0;
 
1818
        }
 
1819
 
 
1820
        if (answer == GTK_RESPONSE_APPLY) {
 
1821
                gtk_widget_set_sensitive (button, FALSE);
 
1822
                brasero_burn_dialog_integrity_start (dialog,
 
1823
                                                     drive,
 
1824
                                                     source);
 
1825
                gtk_widget_set_sensitive (button, TRUE);
 
1826
                goto start;
 
1827
        }
933
1828
}
934
1829
 
935
1830
static void
936
1831
brasero_burn_dialog_notify_success (BraseroBurnDialog *dialog,
 
1832
                                    NautilusBurnDrive *burner,
937
1833
                                    const BraseroTrackSource *track,
938
 
                                    gboolean to_disc)
 
1834
                                    gboolean checksum)
939
1835
{
940
 
        char *primary = NULL;
941
 
        char *secondary = NULL;
 
1836
        gchar *primary = NULL;
 
1837
        gchar *secondary = NULL;
 
1838
        NautilusBurnDrive *drive;
 
1839
 
 
1840
        drive = dialog->priv->drive;
942
1841
 
943
1842
        switch (track->type) {
944
1843
        case BRASERO_TRACK_SOURCE_SONG:
945
 
                primary = g_strdup (_("Audio disc successfully burnt:"));
 
1844
                primary = g_strdup (_("Audio CD successfully burnt"));
946
1845
                secondary = g_strdup_printf (_("\"%s\" is now ready for use"), track->contents.songs.album);
947
1846
                break;
948
1847
        case BRASERO_TRACK_SOURCE_DISC:
949
 
                if (to_disc) {
950
 
                        primary = g_strdup (_("Disc successfully copied to disc:"));
951
 
                        secondary = g_strdup_printf (_("disc is now ready for use"));
 
1848
                if (NCB_DRIVE_GET_TYPE (drive) != NAUTILUS_BURN_DRIVE_TYPE_FILE) {
 
1849
                        if (dialog->priv->media_type > NAUTILUS_BURN_MEDIA_TYPE_CDRW) {
 
1850
                                primary = g_strdup (_("DVD successfully copied"));
 
1851
                                secondary = g_strdup_printf (_("DVD is now ready for use"));
 
1852
                        }
 
1853
                        else {
 
1854
                                primary = g_strdup (_("CD successfully copied"));
 
1855
                                secondary = g_strdup_printf (_("CD is now ready for use"));
 
1856
                        }
952
1857
                }
953
1858
                else {
954
 
                        primary = g_strdup (_("Disc successfully copied:"));
955
 
                        secondary = g_strdup_printf (_("Image is now ready for use"));
 
1859
                        if (dialog->priv->media_type > NAUTILUS_BURN_MEDIA_TYPE_CDRW) {
 
1860
                                primary = g_strdup (_("Image of DVD successfully created"));
 
1861
                                secondary = g_strdup_printf (_("DVD is now ready for use"));
 
1862
                        }
 
1863
                        else {
 
1864
                                primary = g_strdup (_("Image of CD successfully created"));
 
1865
                                secondary = g_strdup_printf (_("CD is now ready for use"));
 
1866
                        }
956
1867
                }
957
1868
                break;
958
 
        case BRASERO_TRACK_SOURCE_ISO:
959
 
        case BRASERO_TRACK_SOURCE_RAW:
960
 
        case BRASERO_TRACK_SOURCE_ISO_JOLIET:
961
 
        case BRASERO_TRACK_SOURCE_CUE:
962
 
                primary = g_strdup (_("Image successfully burnt to disc:"));
963
 
                secondary = g_strdup_printf (_("disc is now ready for use"));
 
1869
        case BRASERO_TRACK_SOURCE_IMAGE:
 
1870
                if (NCB_DRIVE_GET_TYPE (drive) != NAUTILUS_BURN_DRIVE_TYPE_FILE) {
 
1871
                        if (dialog->priv->media_type > NAUTILUS_BURN_MEDIA_TYPE_CDRW) {
 
1872
                                primary = g_strdup (_("Image successfully burnt to DVD"));
 
1873
                                secondary = g_strdup_printf (_("DVD is now ready for use"));
 
1874
                        }
 
1875
                        else {
 
1876
                                primary = g_strdup (_("Image successfully burnt to CD"));
 
1877
                                secondary = g_strdup_printf (_("CD is now ready for use"));
 
1878
                        }
 
1879
                }
964
1880
                break;
965
1881
        default:
966
 
                if (to_disc) {
967
 
                        primary = g_strdup (_("Data disc successfully burnt:"));
968
 
                        secondary = g_strdup_printf (_("\"%s\" is now ready for use"), track->contents.data.label);
 
1882
                if (NCB_DRIVE_GET_TYPE (drive) != NAUTILUS_BURN_DRIVE_TYPE_FILE) {
 
1883
                        if (dialog->priv->media_type > NAUTILUS_BURN_MEDIA_TYPE_CDRW) {
 
1884
                                primary = g_strdup (_("Data DVD successfully burnt"));
 
1885
                                secondary = g_strdup_printf (_("\"%s\" is now ready for use"), track->contents.data.label);
 
1886
                        }
 
1887
                        else {
 
1888
                                primary = g_strdup (_("Data CD successfully burnt"));
 
1889
                                secondary = g_strdup_printf (_("\"%s\" is now ready for use"), track->contents.data.label);
 
1890
                        }
969
1891
                }
970
1892
                else {
971
 
                        primary = g_strdup (_("Image successfully created on disc:"));
 
1893
                        primary = g_strdup (_("Image successfully created"));
972
1894
                        secondary = g_strdup_printf (_("\"%s\" is now ready for use"), track->contents.data.label);
973
1895
                }
974
1896
                break;
975
1897
        }
976
1898
 
977
 
#ifdef HAVE_LIBNOTIFY
978
 
 
979
 
        if (GTK_WIDGET_VISIBLE (dialog))
980
 
                brasero_burn_dialog_notify_dialog (dialog,
981
 
                                                   primary,
982
 
                                                   secondary,
983
 
                                                   GTK_MESSAGE_INFO,
984
 
                                                   TRUE);
985
 
        else if (!brasero_burn_dialog_notify_daemon (dialog,
986
 
                                                     primary,
987
 
                                                     secondary))
988
 
 
989
 
#endif
990
 
 
991
 
                brasero_burn_dialog_notify_dialog (dialog,
992
 
                                                   primary,
993
 
                                                   secondary,
994
 
                                                   GTK_MESSAGE_INFO,
995
 
                                                   TRUE);
 
1899
        brasero_burn_dialog_activity_stop (dialog, primary);
 
1900
        brasero_burn_dialog_success_run (dialog,
 
1901
                                         burner,
 
1902
                                         track,
 
1903
                                         checksum);
 
1904
 
996
1905
        g_free (primary);
997
1906
        g_free (secondary);
998
1907
}
999
1908
 
 
1909
static gboolean
 
1910
brasero_burn_dialog_end_session (BraseroBurnDialog *dialog,
 
1911
                                 NautilusBurnDrive *burner,
 
1912
                                 const BraseroTrackSource *track,
 
1913
                                 gboolean checksum,
 
1914
                                 BraseroBurnResult result,
 
1915
                                 GError *error)
 
1916
{
 
1917
        gboolean close_dialog;
 
1918
 
 
1919
        if (dialog->priv->local_image) {
 
1920
                g_object_unref (dialog->priv->local_image);
 
1921
                dialog->priv->local_image = NULL;
 
1922
        }
 
1923
 
 
1924
        if (dialog->priv->checksum) {
 
1925
                g_object_unref (dialog->priv->checksum);
 
1926
                dialog->priv->checksum = NULL;
 
1927
        }
 
1928
 
 
1929
        if (dialog->priv->burn) {
 
1930
                g_object_unref (dialog->priv->burn);
 
1931
                dialog->priv->burn = NULL;
 
1932
        }
 
1933
 
 
1934
        brasero_burn_session_stop (dialog->priv->session);
 
1935
 
 
1936
        if (result == BRASERO_BURN_CANCEL) {
 
1937
                /* nothing to do */
 
1938
                close_dialog = FALSE;
 
1939
        }
 
1940
        else if (error || result != BRASERO_BURN_OK) {
 
1941
                close_dialog = FALSE;
 
1942
                brasero_burn_dialog_notify_error (dialog,
 
1943
                                                  error);
 
1944
        }
 
1945
        else {
 
1946
                brasero_burn_dialog_notify_success (dialog,
 
1947
                                                    burner,
 
1948
                                                    track,
 
1949
                                                    checksum);
 
1950
 
 
1951
                close_dialog = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->close_check));
 
1952
        }
 
1953
 
 
1954
        return close_dialog;
 
1955
}
 
1956
 
1000
1957
gboolean
1001
1958
brasero_burn_dialog_run (BraseroBurnDialog *dialog,
1002
1959
                         NautilusBurnDrive *drive,
1003
1960
                         gint speed,
1004
 
                         const char *output,
1005
 
                         const BraseroTrackSource *track,
1006
 
                         BraseroBurnFlag flags)
 
1961
                         const gchar *output,
 
1962
                         const BraseroTrackSource *source,
 
1963
                         BraseroBurnFlag flags,
 
1964
                         gint64 sectors,
 
1965
                         gboolean checksum)
1007
1966
{
1008
 
        int added_id;
1009
 
        int removed_id;
1010
 
        GdkCursor *cursor;
 
1967
        gint added_id;
 
1968
        gint removed_id;
1011
1969
        GError *error = NULL;
1012
1970
        gboolean close_dialog;
1013
1971
        BraseroBurnResult result;
1014
 
 
1015
 
        gtk_widget_show_all (dialog->priv->tray);
1016
 
 
1017
 
        dialog->priv->track_type = track->type;
 
1972
        BraseroTrackSource *track = NULL;
 
1973
        NautilusBurnDriveMonitor *monitor;
 
1974
 
 
1975
        dialog->priv->track_type = source->type;
 
1976
        dialog->priv->isosize = sectors * 2048;
1018
1977
 
1019
1978
        if (debug)
1020
1979
                flags |= BRASERO_BURN_FLAG_DEBUG;
1021
1980
 
 
1981
        /* try to get the media type for the title */
1022
1982
        if (NCB_DRIVE_GET_TYPE (drive) == NAUTILUS_BURN_DRIVE_TYPE_FILE
1023
 
        &&  track->type == BRASERO_TRACK_SOURCE_DISC)
1024
 
                dialog->priv->drive = track->contents.drive.disc;
 
1983
        &&  source->type == BRASERO_TRACK_SOURCE_DISC)
 
1984
                dialog->priv->drive = source->contents.drive.disc;
1025
1985
        else
1026
1986
                dialog->priv->drive = drive;
1027
1987
 
1028
 
        g_object_ref (dialog->priv->drive);
 
1988
        nautilus_burn_drive_ref (dialog->priv->drive);
1029
1989
 
1030
 
        nautilus_burn_drive_ref (drive);
1031
 
        added_id = g_signal_connect (drive,
1032
 
                                     "media-added",
1033
 
                                     G_CALLBACK (brasero_burn_dialog_media_added_cb),
1034
 
                                     dialog);
1035
 
        removed_id = g_signal_connect (drive,
1036
 
                                       "media-removed",
1037
 
                                       G_CALLBACK (brasero_burn_dialog_media_removed_cb),
1038
 
                                       dialog);
 
1990
        /* Leave the time to all sub systems and libs to get notified */
 
1991
        monitor = nautilus_burn_get_drive_monitor ();
 
1992
        added_id = g_signal_connect_after (monitor,
 
1993
                                           "media-added",
 
1994
                                           G_CALLBACK (brasero_burn_dialog_media_added_cb),
 
1995
                                           dialog);
 
1996
        removed_id = g_signal_connect_after (monitor,
 
1997
                                             "media-removed",
 
1998
                                             G_CALLBACK (brasero_burn_dialog_media_removed_cb),
 
1999
                                             dialog);
1039
2000
 
1040
2001
        brasero_burn_dialog_update_info (dialog);               
1041
 
 
1042
 
        cursor = gdk_cursor_new (GDK_WATCH);
1043
 
        gdk_window_set_cursor (GTK_WIDGET (dialog)->window, cursor);
1044
 
        gdk_cursor_unref (cursor);
1045
 
 
1046
 
        result = brasero_burn_record (dialog->priv->burn,
1047
 
                                      flags,
1048
 
                                      drive,
1049
 
                                      speed,
1050
 
                                      track,
1051
 
                                      output,
1052
 
                                      &error);
 
2002
        brasero_burn_dialog_activity_start (dialog);
 
2003
 
 
2004
        /* start the recording session */
 
2005
        result = brasero_burn_dialog_setup_session (dialog,
 
2006
                                                    source,
 
2007
                                                    &track,
 
2008
                                                    checksum,
 
2009
                                                    &error);
 
2010
 
 
2011
        if (result == BRASERO_BURN_OK) {
 
2012
                if ((flags & (BRASERO_BURN_FLAG_APPEND|BRASERO_BURN_FLAG_MERGE)) == 0
 
2013
                &&   NCB_DRIVE_GET_TYPE (drive) != NAUTILUS_BURN_DRIVE_TYPE_FILE)
 
2014
                        flags |= BRASERO_BURN_FLAG_DAO;
 
2015
 
 
2016
                result = brasero_burn_record (dialog->priv->burn,
 
2017
                                              flags,
 
2018
                                              drive,
 
2019
                                              speed,
 
2020
                                              track,
 
2021
                                              output,
 
2022
                                              &error);
 
2023
        }
 
2024
 
1053
2025
        if (added_id) {
1054
 
                g_signal_handler_disconnect (drive, added_id);
 
2026
                g_signal_handler_disconnect (monitor, added_id);
1055
2027
                added_id = 0;
1056
2028
        }
1057
2029
 
1058
2030
        if (removed_id) {
1059
 
                g_signal_handler_disconnect (drive, removed_id);
 
2031
                g_signal_handler_disconnect (monitor, removed_id);
1060
2032
                removed_id = 0;
1061
2033
        }
1062
2034
 
1063
 
        g_object_unref (dialog->priv->burn);
1064
 
        dialog->priv->burn = NULL;
 
2035
        checksum = NCB_DRIVE_GET_TYPE (drive) != NAUTILUS_BURN_DRIVE_TYPE_FILE &&
 
2036
                   (checksum ||
 
2037
                   (source->type == BRASERO_TRACK_SOURCE_IMAGE && (source->format & BRASERO_IMAGE_FORMAT_ISO)) ||
 
2038
                   (source->type == BRASERO_TRACK_SOURCE_DISC));
 
2039
        
 
2040
        close_dialog = brasero_burn_dialog_end_session (dialog,
 
2041
                                                        drive,
 
2042
                                                        track,
 
2043
                                                        checksum,
 
2044
                                                        result,
 
2045
                                                        error);
1065
2046
 
1066
 
        g_object_unref (dialog->priv->drive);
 
2047
        nautilus_burn_drive_unref (dialog->priv->drive);
1067
2048
        dialog->priv->drive = NULL;
1068
2049
 
1069
 
        /* tell the user the result of the operation */
1070
 
        if (result == BRASERO_BURN_CANCEL) {
1071
 
                /* nothing to do */
1072
 
                close_dialog = FALSE;
1073
 
        }
1074
 
        else if (error || result != BRASERO_BURN_OK) {
1075
 
                close_dialog = FALSE;
1076
 
                brasero_burn_dialog_notify_error (dialog,
1077
 
                                                  error);
1078
 
        }
1079
 
        else {
1080
 
                brasero_burn_dialog_notify_success (dialog,
1081
 
                                                    track,
1082
 
                                                    (NCB_DRIVE_GET_TYPE (drive) != NAUTILUS_BURN_DRIVE_TYPE_FILE));
1083
 
 
1084
 
                close_dialog = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->close_check));
1085
 
        }
1086
 
 
1087
 
        nautilus_burn_drive_unref (drive);
 
2050
        if (track)
 
2051
                brasero_track_source_free (track);
 
2052
 
1088
2053
        return close_dialog;
1089
2054
}
1090
2055
 
1112
2077
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1113
2078
                                NULL);
1114
2079
 
1115
 
        button = brasero_utils_make_button (_("Continue"), GTK_STOCK_OK);
 
2080
        button = brasero_utils_make_button (_("Continue"), GTK_STOCK_OK, NULL);
1116
2081
        gtk_widget_show_all (button);
1117
2082
        gtk_dialog_add_action_widget (GTK_DIALOG (message),
1118
2083
                                      button, GTK_RESPONSE_OK);
1126
2091
static gboolean
1127
2092
brasero_burn_dialog_cancel (BraseroBurnDialog *dialog)
1128
2093
{
1129
 
        if (dialog->priv->burn) {
 
2094
        if (dialog->priv->file_ctx)
 
2095
                brasero_sum_check_cancel (dialog->priv->file_ctx);
 
2096
        else if (dialog->priv->local_image
 
2097
              &&  brasero_job_is_running (dialog->priv->local_image))
 
2098
                brasero_job_cancel (dialog->priv->local_image, TRUE);
 
2099
        else if (dialog->priv->checksum
 
2100
              &&  brasero_job_is_running (dialog->priv->checksum))
 
2101
                brasero_job_cancel (dialog->priv->checksum, TRUE);
 
2102
        else if (dialog->priv->burn) {
1130
2103
                BraseroBurnResult result;
1131
2104
 
1132
2105
                result = brasero_burn_cancel (dialog->priv->burn, TRUE);
1138
2111
                                return FALSE;
1139
2112
                }
1140
2113
        }
1141
 
        else
1142
 
                gtk_widget_destroy (GTK_WIDGET (dialog));
1143
2114
 
1144
2115
        return TRUE;
1145
2116
}
1160
2131
brasero_burn_dialog_cancel_clicked_cb (GtkWidget *button,
1161
2132
                                       BraseroBurnDialog *dialog)
1162
2133
{
 
2134
        /* a burning is ongoing cancel it */
1163
2135
        brasero_burn_dialog_cancel (dialog);
1164
2136
}
1165
2137
 
1175
2147
                                         gboolean show,
1176
2148
                                         GtkWidget *dialog)
1177
2149
{
1178
 
        /* this is when the dialog is minimized and a notification is shown
1179
 
         * after a successful burning */
1180
 
        if (BRASERO_BURN_DIALOG (dialog)->priv->loop
1181
 
        &&  g_main_loop_is_running (BRASERO_BURN_DIALOG (dialog)->priv->loop)) {
1182
 
                g_main_loop_quit (BRASERO_BURN_DIALOG (dialog)->priv->loop);
1183
 
                return;
1184
 
        }
1185
 
 
1186
2150
        /* we prevent to show the burn dialog once the success dialog has been 
1187
2151
         * shown to avoid the following strange behavior:
1188
2152
         * Steps: