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