brasero r1599 - in trunk: . src



Author: philippr
Date: Wed Dec  3 15:40:17 2008
New Revision: 1599
URL: http://svn.gnome.org/viewvc/brasero?rev=1599&view=rev

Log:
	Rework previous change:
	Now only show alert dialog when the user clicked OK

	* src/brasero-drive-properties.c
	(brasero_drive_properties_set_tmpdir_info),
	(brasero_drive_properties_tmpdir_changed),
	(brasero_drive_properties_set_tmpdir),
	(brasero_drive_properties_check_tmpdir),
	(brasero_drive_properties_response),
	(brasero_drive_properties_init),
	(brasero_drive_properties_finalize),
	(brasero_drive_properties_class_init):


Modified:
   trunk/ChangeLog
   trunk/src/brasero-drive-properties.c

Modified: trunk/src/brasero-drive-properties.c
==============================================================================
--- trunk/src/brasero-drive-properties.c	(original)
+++ trunk/src/brasero-drive-properties.c	Wed Dec  3 15:40:17 2008
@@ -54,10 +54,6 @@
 
 	GtkWidget *tmpdir;
 	GtkWidget *tmpdir_size;
-
-	gchar *previous_path;
-
-	guint check_filesystem:1;
 };
 
 #define BRASERO_DRIVE_PROPERTIES_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_DRIVE_PROPERTIES, BraseroDrivePropertiesPrivate))
@@ -68,7 +64,6 @@
 	PROP_NUM
 };
 
-static GtkDialogClass* parent_class = NULL;
 
 G_DEFINE_TYPE (BraseroDriveProperties, brasero_drive_properties, GTK_TYPE_DIALOG);
 
@@ -129,54 +124,140 @@
 	return gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->tmpdir));
 }
 
-static gboolean
+static void
 brasero_drive_properties_set_tmpdir_info (BraseroDriveProperties *self,
-					  const gchar *path,
-					  gboolean warn)
+					  const gchar *path)
 {
 	GFile *file;
 	gchar *string;
 	GFileInfo *info;
-	gboolean noalert;
-	GError *error = NULL;
 	guint64 vol_size = 0;
-	const gchar *filesystem;
 	BraseroDrivePropertiesPrivate *priv;
 
 	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
 
-	/* This is to avoid showing an alert right before window is shown */
-	if (!GTK_WIDGET_VISIBLE (self))
-		noalert = TRUE;
-	else
-		noalert = FALSE;
-
 	/* get the volume free space */
 	file = g_file_new_for_commandline_arg (path);
 	if (!file) {
-		BRASERO_BURN_LOG ("impossible to retrieve size for %s", path);
+		BRASERO_BURN_LOG ("Impossible to retrieve size for %s", path);
 		gtk_label_set_text (GTK_LABEL (priv->tmpdir_size), _("Unknown"));
-		return FALSE;
+		return;
 	}
 
+	info = g_file_query_filesystem_info (file,
+					     G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
+					     NULL,
+					     NULL);
+	g_object_unref (file);
+
+	if (!info) {
+		BRASERO_BURN_LOG ("Impossible to retrieve size for %s", path);
+		gtk_label_set_text (GTK_LABEL (priv->tmpdir_size), _("Unknown"));
+		return;
+	}
+
+	vol_size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+	g_object_unref (info);
+
+	string = brasero_utils_get_size_string (vol_size, TRUE, TRUE);
+	gtk_label_set_text (GTK_LABEL (priv->tmpdir_size), string);
+	g_free (string);
+}
+
+static void
+brasero_drive_properties_tmpdir_changed (GtkFileChooser *chooser,
+					 BraseroDriveProperties *self)
+{
+	gchar *path;
+	BraseroDrivePropertiesPrivate *priv;
+
+	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
+
+	path = gtk_file_chooser_get_filename (chooser);
+	if (!path)
+		return;
+
+	brasero_drive_properties_set_tmpdir_info (self, path);
+	g_free (path);
+}
+
+void
+brasero_drive_properties_set_tmpdir (BraseroDriveProperties *self,
+				     const gchar *path)
+{
+	BraseroDrivePropertiesPrivate *priv;
+
+	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
+
+	if (!path)
+		path = g_get_tmp_dir ();
+
+	gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (priv->tmpdir), path);
+	brasero_drive_properties_set_tmpdir_info (self, path);
+}
+
+static gboolean
+brasero_drive_properties_check_tmpdir (BraseroDriveProperties *self,
+				       const gchar *path)
+{
+	GFile *file;
+	GFileInfo *info;
+	GError *error = NULL;
+	const gchar *filesystem;
+	BraseroDrivePropertiesPrivate *priv;
+
+	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
+
+	file = g_file_new_for_commandline_arg (path);
+	if (!file)
+		return TRUE;
+
 	info = g_file_query_info (file,
 				  G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
 				  G_FILE_QUERY_INFO_NONE,
 				  NULL,
 				  &error);
 	if (error) {
-		g_object_unref (info);
-		g_object_unref (file);
+		gint answer;
+		gchar *string;
+		GtkWidget *dialog;
+		GtkWidget *toplevel;
 
-		BRASERO_BURN_LOG ("impossible to retrieve size for %s (%s)", path, error->message);
+		if (error)
+			return TRUE;
+
+		/* Tell the user what went wrong */
+		toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
+		dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
+						 GTK_DIALOG_DESTROY_WITH_PARENT |
+						 GTK_DIALOG_MODAL,
+						 GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_NONE,
+						 _("Do you really want to choose this location?"));
+
+		string = g_strdup_printf ("%s.", error->message);
+		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), string);
 		g_error_free (error);
+		g_free (string);
 
-		gtk_label_set_text (GTK_LABEL (priv->tmpdir_size), _("Unknown"));
-		return FALSE;
+		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+					_("_Keep Current Location"), GTK_RESPONSE_CANCEL,
+					_("_Change Location"), GTK_RESPONSE_OK,
+					NULL);
+
+		gtk_widget_show_all (dialog);
+		answer = gtk_dialog_run (GTK_DIALOG (dialog));
+		gtk_widget_destroy (dialog);
+
+		g_object_unref (info);
+		g_object_unref (file);
+		if (answer == GTK_RESPONSE_OK)
+			return FALSE;
+
+		return TRUE;
 	}
 
-	if (!noalert
-	&&  !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
+	if (!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
 		gint answer;
 		gchar *string;
 		GtkWidget *dialog;
@@ -203,18 +284,16 @@
 		answer = gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);
 
-		if (answer != GTK_RESPONSE_OK) {
-			g_object_unref (info);
-			g_object_unref (file);
+		g_object_unref (info);
+		g_object_unref (file);
+		if (answer == GTK_RESPONSE_OK)
 			return FALSE;
-		}
 
-		priv->check_filesystem = 1;
+		return TRUE;
 	}
 
 	g_object_unref (info);
 	info = g_file_query_filesystem_info (file,
-					     G_FILE_ATTRIBUTE_FILESYSTEM_FREE ","
 					     G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
 					     NULL,
 					     &error);
@@ -228,10 +307,7 @@
 	 * filesystems have a maximum file size limit of 4 GiB and more than
 	 * often we need a temporary file size of 4 GiB or more. */
 	filesystem = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
-	if (priv->check_filesystem
-	&&  filesystem
-	&& !noalert
-	&& !strcmp (filesystem, "msdos")) {
+	if (filesystem && !strcmp (filesystem, "msdos")) {
 		gint answer;
 		GtkWidget *dialog;
 		GtkWidget *toplevel;
@@ -257,86 +333,32 @@
 		answer = gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);
 
-		if (answer != GTK_RESPONSE_OK) {
-			g_object_unref (info);
+		g_object_unref (info);
+		if (answer == GTK_RESPONSE_OK)
 			return FALSE;
-		}
-
-		priv->check_filesystem = 1;
 	}
-
-	vol_size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
-	g_object_unref (info);
-
-	string = brasero_utils_get_size_string (vol_size, TRUE, TRUE);
-	gtk_label_set_text (GTK_LABEL (priv->tmpdir_size), string);
-	g_free (string);
+	else if (info)
+		g_object_unref (info);
 
 	return TRUE;
 }
 
 static void
-brasero_drive_properties_tmpdir_changed_cb (GtkFileChooser *chooser,
-					    BraseroDriveProperties *self)
+brasero_drive_properties_response (GtkDialog *dialog,
+				   gint response,
+				   gpointer NULL_data)
 {
-	gchar *path;
-	gboolean result;
 	BraseroDrivePropertiesPrivate *priv;
+	gchar *path;
 
-	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
-
-	priv->check_filesystem = 1;
-	path = gtk_file_chooser_get_filename (chooser);
-	result = brasero_drive_properties_set_tmpdir_info (self, path, TRUE);
-	g_free (path);
-
-	if (result) {
-		if (priv->previous_path)
-			g_free (priv->previous_path);
-
-		priv->previous_path = gtk_file_chooser_get_filename (chooser);
+	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (dialog);
+	if (response != GTK_RESPONSE_ACCEPT)
 		return;
-	}
-
-	g_signal_handlers_block_by_func (chooser,
-					 brasero_drive_properties_tmpdir_changed_cb,
-					 self);
-	if (priv->previous_path)
-		gtk_file_chooser_set_filename (chooser, priv->previous_path);
-	else
-		gtk_file_chooser_set_filename (chooser, g_get_tmp_dir ());
-
-	g_signal_handlers_unblock_by_func (chooser,
-					   brasero_drive_properties_tmpdir_changed_cb,
-					   self);
-}
-
-void
-brasero_drive_properties_set_tmpdir (BraseroDriveProperties *self,
-				     const gchar *path)
-{
-	BraseroDrivePropertiesPrivate *priv;
-
-	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
 
-	if (!path)
-		path = g_get_tmp_dir ();
-
-	priv->check_filesystem = 0;
-	brasero_drive_properties_set_tmpdir_info (self, path, FALSE);
-
-	g_signal_handlers_block_by_func (GTK_FILE_CHOOSER (priv->tmpdir),
-					 brasero_drive_properties_tmpdir_changed_cb,
-					 self);
-	gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (priv->tmpdir), path);
-	g_signal_handlers_unblock_by_func (GTK_FILE_CHOOSER (priv->tmpdir),
-					   brasero_drive_properties_tmpdir_changed_cb,
-					   self);
-
-	if (priv->previous_path)
-		g_free (priv->previous_path);
-
-	priv->previous_path = g_strdup (path);
+	path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->tmpdir));
+	if (!brasero_drive_properties_check_tmpdir (BRASERO_DRIVE_PROPERTIES (dialog), path))
+		g_signal_stop_emission_by_name (dialog, "response");
+	g_free (path);
 }
 
 static void
@@ -592,34 +614,28 @@
 	gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (priv->tmpdir),
 				       g_get_tmp_dir ());
 
+	gtk_widget_show_all (GTK_DIALOG (object)->vbox);
+
 	g_signal_connect (priv->tmpdir,
-			  "file-set",
-			  G_CALLBACK (brasero_drive_properties_tmpdir_changed_cb),
+			  "selection-changed",
+			  G_CALLBACK (brasero_drive_properties_tmpdir_changed),
 			  object);
-
-	gtk_widget_show_all (GTK_DIALOG (object)->vbox);
+	g_signal_connect (object,
+			  "response",
+			  G_CALLBACK (brasero_drive_properties_response),
+			  NULL);
 }
 
 static void
 brasero_drive_properties_finalize (GObject *object)
 {
-	BraseroDrivePropertiesPrivate *priv;
-
-	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (object);
-
-	if (priv->previous_path) {
-		g_free (priv->previous_path);
-		priv->previous_path = NULL;
-	}
-
-	G_OBJECT_CLASS (parent_class)->finalize (object);
+	G_OBJECT_CLASS (brasero_drive_properties_parent_class)->finalize (object);
 }
 
 static void
 brasero_drive_properties_class_init (BraseroDrivePropertiesClass *klass)
 {
-	GObjectClass* object_class = G_OBJECT_CLASS (klass);
-	parent_class = GTK_DIALOG_CLASS (g_type_class_peek_parent (klass));
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
 	g_type_class_add_private (klass, sizeof (BraseroDrivePropertiesPrivate));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]