? a.c
? lala.iso
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus-cd-burner/ChangeLog,v
retrieving revision 1.309
diff -u -u -r1.309 ChangeLog
--- ChangeLog	3 Nov 2004 22:59:35 -0000	1.309
+++ ChangeLog	5 Nov 2004 22:39:08 -0000
@@ -1,3 +1,14 @@
+2004-11-06  Fernando Herrera  <fherrera@onirica.com>
+
+	* nautilus-cd-burner.c: (show_error_dialog), (ask_for_cd),
+	(insert_cd_request_cb), (show_error_message),
+	(overwrite_existing_file), (burn_cd), (ask_cancel),
+	(help_activate), (main): Ask the user to replace the in-drive media
+	if data size is bigger than media size (and he hasn't the gconf overburn
+	set). If difference is only 5 MiBs show a button to overburn it.
+	Also show the required size in the insert disc dialog. Finally
+	remove ncb_hig_dialog and use gtk_message_dialog.
+
 === 2.8.5 ===
 
 2004-11-03  Bastien Nocera  <hadess@hadess.net>
Index: nautilus-cd-burner.c
===================================================================
RCS file: /cvs/gnome/nautilus-cd-burner/nautilus-cd-burner.c,v
retrieving revision 1.85
diff -u -u -r1.85 nautilus-cd-burner.c
--- nautilus-cd-burner.c	22 Oct 2004 15:43:22 -0000	1.85
+++ nautilus-cd-burner.c	5 Nov 2004 22:39:13 -0000
@@ -41,6 +41,8 @@
 #include "make-iso.h"
 
 #define MAX_ISO_NAME_LEN 32
+#define RESPONSE_OVERBURN 1
+#define SUGGEST_OVERBURN 5 * 1024 * 1024
 
 enum {
 	CANCEL_NONE,
@@ -57,47 +59,14 @@
 /* For the image spinning */
 static GList *image_list;
 
-static GtkWidget *
-ncb_hig_dialog (GtkMessageType type, char *title, char *reason,
-		GtkWindow *parent)
-{
-	GtkWidget *error_dialog;
-	char *title_esc, *reason_esc;
-
-	if (reason == NULL)
-		g_warning ("ncb_hig_dialog called with reason == NULL");
-
-	title_esc = g_markup_escape_text (title, -1);
-	reason_esc = g_markup_escape_text (reason, -1);
-
-	error_dialog =
-		gtk_message_dialog_new (parent,
-				GTK_DIALOG_DESTROY_WITH_PARENT,
-				type,
-				GTK_BUTTONS_NONE,
-				"<b>%s</b>\n%s", title_esc, reason_esc);
-	gtk_window_set_title (GTK_WINDOW (error_dialog), title_esc);
-	g_free (title_esc);
-	g_free (reason_esc);
-
-	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
-	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
-			GTK_RESPONSE_OK);
-	gtk_label_set_use_markup (GTK_LABEL (GTK_MESSAGE_DIALOG (error_dialog)->label), TRUE);
-	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
-
-	return error_dialog;
-}
-
 static void
-ncb_hig_show_error_dialog (char *title, char *reason, GtkWindow *parent)
+show_error_dialog (char *title, char *reason, GtkWindow *parent)
 {
 	GtkWidget *dialog;
 
-	dialog = ncb_hig_dialog (GTK_MESSAGE_ERROR, title, reason, parent);
-	gtk_dialog_add_button (GTK_DIALOG (dialog),
-			GTK_STOCK_OK, GTK_RESPONSE_OK);
-	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+	dialog = gtk_message_dialog_new (parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
+					 GTK_BUTTONS_OK, reason);
+	gtk_window_set_title (GTK_WINDOW (dialog), title);
 	gtk_dialog_run (GTK_DIALOG (dialog));
 	gtk_widget_destroy (dialog);
 }
@@ -320,46 +289,64 @@
 	cd_progress_set_fraction (fraction);
 }
 
-static gboolean
-insert_cd_request_cb (CDRecorder *cdrecorder,
-		      gboolean is_reload, gboolean can_rewrite,
-		      gboolean busy_cd, gpointer data)
+static int  
+ask_for_cd (gboolean is_reload, gboolean can_rewrite,
+	    gboolean busy_cd, gboolean ask_overburn,
+	    int mibs)
 {
 	GtkWidget *dialog, *parent;
-	const char *msg, *title;
+	const char *title;
+	char *msg;
 	int res;
 
 	if (busy_cd) {
-		msg = N_("Please make sure another application is not using the disc.");
-		title = N_("Disc is busy");
+		msg = g_strdup (_("Please make sure another application is not using the disc."));
+		title = _("Disc is busy");
 	} else if (!is_reload && can_rewrite) {
-		msg = N_("Please insert a rewritable or blank media in the drive tray.");
+		msg = g_strdup_printf (_("Please insert a rewritable or blank media with at least %d MiBs free in the drive tray."),
+				       mibs);
 		title = N_("Insert rewritable or blank media");
 	} else if (!is_reload && !can_rewrite) {
-		msg = N_("Please insert a blank media in the drive tray.");
+		msg = g_strdup_printf (_("Please insert a blank media with at least %d MiBs in the drive tray."), mibs);
 		title = N_("Insert blank media");
 	} else if (can_rewrite) {
-			msg = N_("Please replace the in-drive media by a rewritable or blank media.");
-			title = N_("Reload rewritable or blank media");
+		msg = g_strdup_printf (_("Please replace the in-drive media by a rewritable or blank media with at least %d MiBs free."),
+				       mibs);
+		title = N_("Reload rewritable or blank media");
 	} else {
-		msg = N_("Please replace the in-drive media by a blank media.");
+		msg = g_strdup_printf (_("Please replace the in-drive media by a blank media with at least %d MiBs."), mibs);
 		title = N_("Reload blank media");
 	}
 
 	parent = glade_xml_get_widget (xml, "cdr_dialog");
-	dialog = ncb_hig_dialog (GTK_MESSAGE_INFO,
-			_(title), _(msg), GTK_WINDOW (parent));
-	gtk_dialog_add_buttons (GTK_DIALOG (dialog),
-			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-			GTK_STOCK_OK, GTK_RESPONSE_OK,
-			NULL);
+	dialog = gtk_message_dialog_new (GTK_WINDOW (parent), GTK_DIALOG_DESTROY_WITH_PARENT,
+					 GTK_MESSAGE_INFO, GTK_BUTTONS_OK_CANCEL, msg);
+	if (ask_overburn)
+		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+					_("Overburn"), RESPONSE_OVERBURN,
+					NULL);
+	gtk_window_set_title (GTK_WINDOW (dialog), title);
 	gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 			GTK_RESPONSE_OK);
 	res = gtk_dialog_run (GTK_DIALOG (dialog));
 	gtk_widget_destroy (dialog);
-	if (res == GTK_RESPONSE_CANCEL) {
+	g_free (msg);
+
+	return res;
+}
+
+static gboolean
+insert_cd_request_cb (CDRecorder *cdrecorder,
+		      gboolean is_reload, gboolean can_rewrite,
+		      gboolean busy_cd, gpointer data)
+{
+	int res;
+	int mibs = *(int*)data;
+
+	res = ask_for_cd (is_reload, can_rewrite, busy_cd, FALSE, mibs);
+
+	if (res == GTK_RESPONSE_CANCEL)
 		return FALSE;
-	}
 
 	return TRUE;
 }
@@ -419,11 +406,10 @@
 	msg = cd_recorder_get_error_message (cdrecorder) ?
 		g_strdup_printf (_("There was an error writing to the CD:\n%s"), cd_recorder_get_error_message (cdrecorder))
 		: g_strdup (_("There was an error writing to the CD"));
-	dialog = ncb_hig_dialog (GTK_MESSAGE_ERROR, _("Error writing to CD"),
-			msg, cd_progress_get_window ());
+	dialog = gtk_message_dialog_new (cd_progress_get_window (), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, 
+					 GTK_BUTTONS_OK, msg);
+	gtk_window_set_title (GTK_WINDOW (dialog), _("Error writing to CD"));
 	g_free (msg);
-	gtk_dialog_add_button (GTK_DIALOG (dialog),
-			GTK_STOCK_OK, GTK_RESPONSE_OK);
 
 	button = gtk_button_new_with_mnemonic (_("_Details"));
 	gtk_widget_show (button);
@@ -500,12 +486,10 @@
 
 	msg = g_strdup_printf (_("A file named \"%s\" already exists.\nDo you want to overwrite it?"),
 			filename);
-	dialog = ncb_hig_dialog (GTK_MESSAGE_QUESTION, _("_Overwrite"),
-			msg, filesel);
-
-	/* Add Cancel button */
-	gtk_dialog_add_button (GTK_DIALOG (dialog),
-			       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+	dialog = gtk_message_dialog_new (filesel, GTK_DIALOG_DESTROY_WITH_PARENT,
+					 GTK_MESSAGE_QUESTION,
+					 GTK_BUTTONS_CANCEL, msg);
+	gtk_window_set_title (GTK_WINDOW (dialog), _("_Overwrite"));
 
 	/* Add Overwrite button */
 	gtk_dialog_add_button (GTK_DIALOG (dialog),
@@ -556,13 +540,14 @@
 }
 
 static int
-burn_cd (const CDDrive *rec, const char *source_iso, const char *label, gboolean eject_cd, int speed, gboolean dummy, gboolean debug, gboolean overburn, gboolean burnproof)
+burn_cd (const CDDrive *rec, const char *source_iso, GnomeVFSFileSize size, const char *label, gboolean eject_cd, int speed, gboolean dummy, gboolean debug, gboolean overburn, gboolean burnproof)
 {
 	CDRecorderWriteFlags flags;
 	GList *tracks;
 	char *filename, *str;
 	int fd;
 	int res = RESULT_ERROR;
+	int mibs = (size + 1024 * 1024 - 1)/ (1024 * 1024);
 
 	tracks = NULL;
 	filename = NULL;
@@ -583,7 +568,7 @@
 					char *msg;
 
 					msg = g_strdup_printf (_("You do not have permissions to overwrite that file (%s)."), filename);
-					ncb_hig_show_error_dialog (_("File image creation failed"), msg, NULL);
+					show_error_dialog (_("File image creation failed"), msg, NULL);
 					g_free (msg);
 					g_free (filename);
 					return RESULT_ERROR;
@@ -596,7 +581,7 @@
 					char *msg;
 
 					msg = g_strdup_printf (_("You do not have permissions to create that file (%s)."), filename);
-					ncb_hig_show_error_dialog (_("File image creation failed"), msg, NULL);
+					show_error_dialog (_("File image creation failed"), msg, NULL);
 					g_free (filename);
 					g_free (dir_name);
 					g_free (msg);
@@ -664,8 +649,10 @@
 		setup_close_button ();
 		gtk_main ();
 	} else {
+		gint64 media_size;
 		Track *track;
 
+
 		cdrecorder = cd_recorder_new ();
 		cancel = CANCEL_CD_RECORD;
 
@@ -684,7 +671,7 @@
 		g_signal_connect (G_OBJECT (cdrecorder),
 				  "insert-cd-request",
 				  G_CALLBACK (insert_cd_request_cb),
-				  NULL);
+				  &mibs);
 
 		track = g_new0 (Track, 1);
 		track->type = TRACK_TYPE_DATA;
@@ -708,6 +695,33 @@
 			flags |= CDRECORDER_BURNPROOF;
 		}
 
+		if (!overburn) {
+			do {
+				int res;
+
+				media_size = cd_drive_get_media_size ((CDDrive *)rec);
+				if (media_size >= (gint64) size)
+					break;
+				if (media_size == CD_MEDIA_SIZE_UNKNOWN)
+					break; 
+				if (media_size == CD_MEDIA_SIZE_NA)
+					break;
+				if (media_size == CD_MEDIA_SIZE_BUSY)
+					continue;
+
+				res = ask_for_cd ((media_size > 0) , (rec->type & CDDRIVE_TYPE_CDRW_RECORDER),
+						  FALSE, (((gint64) size - media_size) <= SUGGEST_OVERBURN),
+						  mibs);
+
+				if (res == GTK_RESPONSE_CANCEL)
+					return 1;
+				if (res == RESPONSE_OVERBURN) {
+					flags |= CDRECORDER_OVERBURN;
+					break;
+				}
+			} while (media_size < 0 || (gint64) size > media_size);
+		}
+	
 		res = cd_recorder_write_tracks (cdrecorder, (CDDrive *)rec,
 				tracks, speed, flags);
 
@@ -917,11 +931,11 @@
 	GtkWidget *warning_dialog;
 	int res;
 
-	warning_dialog = ncb_hig_dialog (GTK_MESSAGE_WARNING,
-			_("Cancel write"),
-			_("Are you sure you want to cancel the disc write operation?\n"
-			"Some optical media drives may require that you restart the machine to get it working again."),
-			cd_progress_get_window ());
+	warning_dialog = gtk_message_dialog_new (cd_progress_get_window (), GTK_DIALOG_DESTROY_WITH_PARENT,
+						 GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
+						 _("Are you sure you want to cancel the disc write operation?\n"
+						 "Some optical media drives may require that you restart the machine to get it working again."));
+	gtk_window_set_title (GTK_WINDOW (warning_dialog), _("Cancel write"));
 	gtk_dialog_add_buttons (GTK_DIALOG (warning_dialog),
 			_("Continue"), GTK_RESPONSE_NO,
 			GTK_STOCK_CANCEL, GTK_RESPONSE_YES,
@@ -976,8 +990,7 @@
 		char *msg;
 
 		msg = g_strdup_printf (_("There was a problem displaying the help contents: %s."), err->message);
-		ncb_hig_show_error_dialog (_("Cannot display help"),
-				msg, parent);
+		show_error_dialog (_("Cannot display help"), msg, parent);
 		g_error_free (err);
 		g_free (msg);
 	}
@@ -1090,12 +1103,10 @@
 	gnome_vfs_init ();
 
 	if (argc > 2) {
-		dialog = ncb_hig_dialog (GTK_MESSAGE_ERROR,
-				_("Too many parameters"),
-				_("Too many parameters were passed to the application."),
-				NULL);
-		gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK,
-				GTK_RESPONSE_OK);
+		dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
+						 GTK_BUTTONS_OK,
+						 _("Too many parameters were passed to the application."));
+		gtk_window_set_title (GTK_WINDOW (dialog), _("Too many parameters"));
 		res = gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);
 		return 1;
@@ -1116,9 +1127,9 @@
 			msg = g_strdup_printf
 				(_("The file '%s' is not a valid CD image."),
 				 source_iso);
-			dialog = ncb_hig_dialog (GTK_MESSAGE_ERROR,
-					_("Not a valid CD image"),
-					msg, NULL);
+			dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK, msg);
+			gtk_window_set_title (GTK_WINDOW (dialog), _("Not a valid CD image"));
 			g_free (msg);
 			res = gtk_dialog_run (GTK_DIALOG (dialog));
 			gtk_widget_destroy (dialog);
@@ -1131,11 +1142,11 @@
 		size = estimate_size ("burn:///");
 
 		if (size == 0) {
-			dialog = ncb_hig_dialog (GTK_MESSAGE_ERROR,
-					_("No files selected"),
-					_("You need to copy the files you want to write to disc to the CD/DVD Creator window. Would you like to open it now?"),
-					NULL);
-			gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, _("Open CD/DVD Creator"), GTK_RESPONSE_YES, NULL);
+			dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
+							 GTK_BUTTONS_CLOSE, 
+							 _("You need to copy the files you want to write to disc to the CD/DVD Creator window. Would you like to open it now?"));
+			gtk_window_set_title (GTK_WINDOW (dialog), _("No files selected"));
+			gtk_dialog_add_buttons (GTK_DIALOG (dialog), _("Open CD/DVD Creator"), GTK_RESPONSE_YES, NULL);
 			gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
 			res = gtk_dialog_run (GTK_DIALOG (dialog));
 			gtk_widget_destroy (dialog);
@@ -1220,7 +1231,7 @@
 		gconf_client_set_int (gc, "/apps/nautilus-cd-burner/default_speed", speed, NULL);
 		g_object_unref (G_OBJECT (gc));
 
-		res = burn_cd (rec, source_iso, label, eject, speed, dummy, debug, overburn, burnproof);
+		res = burn_cd (rec, source_iso, size, label, eject, speed, dummy, debug, overburn, burnproof);
 
 		reuse_check = glade_xml_get_widget (xml, "reuse_check");
 		reuse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (reuse_check));
