Add some conversion checks to GtkFileSelection (bug 50298)
- From: Alexander Larsson <alla lysator liu se>
- To: gtk-devel-list gnome org
- Subject: Add some conversion checks to GtkFileSelection (bug 50298)
- Date: Fri, 23 Feb 2001 15:03:38 +0100 (CET)
This patch adds conversion checks to all "user" operations in the
GtkFileSelection dialog. It also changes the error dialog to use
GtkMessageDialog.
Comments?
/ Alex
Index: gtk/gtkfilesel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesel.c,v
retrieving revision 1.72
diff -u -p -r1.72 gtkfilesel.c
--- gtk/gtkfilesel.c 2001/02/02 17:53:29 1.72
+++ gtk/gtkfilesel.c 2001/02/23 13:37:27
@@ -66,6 +66,7 @@
#include "gtkoptionmenu.h"
#include "gtkclist.h"
#include "gtkdialog.h"
+#include "gtkmessagedialog.h"
#include "gtkintl.h"
#if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN)
@@ -819,52 +820,28 @@ static void
gtk_file_selection_fileop_error (GtkFileSelection *fs,
gchar *error_message)
{
- GtkWidget *label;
- GtkWidget *vbox;
- GtkWidget *button;
GtkWidget *dialog;
-
+
g_return_if_fail (error_message != NULL);
-
+
/* main dialog */
- dialog = gtk_dialog_new ();
- /*
- gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
- (GtkSignalFunc) gtk_file_selection_fileop_destroy,
- (gpointer) fs);
- */
- gtk_window_set_title (GTK_WINDOW (dialog), _("Error"));
- gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
-
+ dialog = gtk_message_dialog_new (GTK_WINDOW (fs),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", error_message);
+
+ /* yes, we free it */
+ g_free (error_message);
+
/* If file dialog is grabbed, make this dialog modal too */
/* When error dialog is closed, file dialog will be grabbed again */
if (GTK_WINDOW (fs)->modal)
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- vbox = gtk_vbox_new (FALSE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox,
- FALSE, FALSE, 0);
- gtk_widget_show (vbox);
-
- label = gtk_label_new (error_message);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 5);
- gtk_widget_show (label);
- /* yes, we free it */
- g_free (error_message);
-
- /* close button */
- button = gtk_button_new_with_label (_("Close"));
- gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
+ gtk_signal_connect_object (GTK_OBJECT (dialog), "response",
(GtkSignalFunc) gtk_widget_destroy,
(gpointer) dialog);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
- button, TRUE, TRUE, 0);
- GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
- gtk_widget_grab_default (button);
- gtk_widget_show (button);
gtk_widget_show (dialog);
}
@@ -892,6 +869,7 @@ gtk_file_selection_create_dir_confirmed
gchar *full_path;
gchar *sys_full_path;
gchar *buf;
+ GError *error = NULL;
CompletionState *cmpl_state;
g_return_if_fail (fs != NULL);
@@ -902,10 +880,17 @@ gtk_file_selection_create_dir_confirmed
path = cmpl_reference_position (cmpl_state);
full_path = g_strconcat (path, G_DIR_SEPARATOR_S, dirname, NULL);
- sys_full_path = g_filename_from_utf8 (full_path, -1, NULL, NULL, NULL);
- if (mkdir (sys_full_path, 0755) < 0)
+ sys_full_path = g_filename_from_utf8 (full_path, -1, NULL, NULL, &error);
+ if (error)
+ {
+ buf = g_strconcat (_("Error creating directory")," \"", dirname, "\": ",
+ error->message, "\n", _("You probably used symbols not allowed in filenames."), NULL);
+ gtk_file_selection_fileop_error (fs, buf);
+ g_error_free (error);
+ }
+ else if (mkdir (sys_full_path, 0755) < 0)
{
- buf = g_strconcat ("Error creating directory \"", dirname, "\": ",
+ buf = g_strconcat (_("Error creating directory"), " \"", dirname, "\": ",
g_strerror (errno), NULL);
gtk_file_selection_fileop_error (fs, buf);
}
@@ -996,6 +981,7 @@ gtk_file_selection_delete_file_confirmed
gchar *path;
gchar *full_path;
gchar *sys_full_path;
+ GError *error = NULL;
gchar *buf;
g_return_if_fail (fs != NULL);
@@ -1005,10 +991,17 @@ gtk_file_selection_delete_file_confirmed
path = cmpl_reference_position (cmpl_state);
full_path = g_strconcat (path, G_DIR_SEPARATOR_S, fs->fileop_file, NULL);
- sys_full_path = g_filename_from_utf8 (full_path, -1, NULL, NULL, NULL);
- if (unlink (sys_full_path) < 0)
+ sys_full_path = g_filename_from_utf8 (full_path, -1, NULL, NULL, &error);
+ if (error)
+ {
+ buf = g_strconcat (_("Error deleting file")," \"", fs->fileop_file, "\": ",
+ error->message, NULL);
+ gtk_file_selection_fileop_error (fs, buf);
+ g_error_free (error);
+ }
+ else if (unlink (sys_full_path) < 0)
{
- buf = g_strconcat ("Error deleting file \"", fs->fileop_file, "\": ",
+ buf = g_strconcat (_("Error deleting file")," \"", fs->fileop_file, "\": ",
g_strerror (errno), NULL);
gtk_file_selection_fileop_error (fs, buf);
}
@@ -1110,6 +1103,7 @@ gtk_file_selection_rename_file_confirmed
gchar *sys_new_filename;
gchar *sys_old_filename;
CompletionState *cmpl_state;
+ GError *error = NULL;
g_return_if_fail (fs != NULL);
g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
@@ -1121,19 +1115,35 @@ gtk_file_selection_rename_file_confirmed
new_filename = g_strconcat (path, G_DIR_SEPARATOR_S, file, NULL);
old_filename = g_strconcat (path, G_DIR_SEPARATOR_S, fs->fileop_file, NULL);
- sys_new_filename = g_filename_from_utf8 (new_filename, -1, NULL, NULL, NULL);
- sys_old_filename = g_filename_from_utf8 (old_filename, -1, NULL, NULL, NULL);
-
- if (rename (sys_old_filename, sys_new_filename) < 0)
+ sys_new_filename = g_filename_from_utf8 (new_filename, -1, NULL, NULL, &error);
+ if (error)
{
- buf = g_strconcat ("Error renaming file \"", file, "\": ",
- g_strerror (errno), NULL);
+ buf = g_strconcat (_("Error renaming file to")," \"", new_filename, "\": ",
+ error->message, "\n", _("You probably used symbols not allowed in filenames."), NULL);
gtk_file_selection_fileop_error (fs, buf);
+ g_error_free (error);
+ }
+ else
+ {
+ sys_old_filename = g_filename_from_utf8 (old_filename, -1, NULL, NULL, &error);
+ if (error)
+ {
+ buf = g_strconcat (_("Error renaming file")," \"", old_filename, "\": ",
+ error->message, NULL);
+ gtk_file_selection_fileop_error (fs, buf);
+ g_error_free (error);
+ }
+ else if (rename (sys_old_filename, sys_new_filename) < 0)
+ {
+ buf = g_strconcat ("Error renaming file \"", file, "\": ",
+ g_strerror (errno), NULL);
+ gtk_file_selection_fileop_error (fs, buf);
+ }
+ g_free (sys_old_filename);
}
g_free (new_filename);
g_free (old_filename);
g_free (sys_new_filename);
- g_free (sys_old_filename);
gtk_widget_destroy (fs->fileop_dialog);
gtk_file_selection_populate (fs, "", FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]