Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
authorJohn Ellis <johne@verizon.net>
Wed, 18 May 2005 23:52:16 +0000 (23:52 +0000)
committerJohn Ellis <johne@verizon.net>
Wed, 18 May 2005 23:52:16 +0000 (23:52 +0000)
        * utilops.[ch] (file_util_rename_dir): New utility to rename a folder,
        does proper checking for existing folder to avoid clobbering an
        existing folder.
        * view_dir_list.c, view_dir_tree.c: Use new utility above when renaming
        a folder to fix possible clobbering of an existing folder with the
        same name as the requested name.

##### Note: GQview CVS on sourceforge is not always up to date, please use #####
##### an offical release when making enhancements and translation updates. #####

ChangeLog
src/utilops.c
src/utilops.h
src/view_dir_list.c
src/view_dir_tree.c

index 56e78d6..4efde9d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed May 18 19:36:49 2005  John Ellis  <johne@verizon.net>
+
+       * utilops.[ch] (file_util_rename_dir): New utility to rename a folder,
+       does proper checking for existing folder to avoid clobbering an
+       existing folder.
+       * view_dir_list.c, view_dir_tree.c: Use new utility above when renaming
+       a folder to fix possible clobbering of an existing folder with the
+       same name as the requested name.
+
 Sun May 15 21:40:26 2005  John Ellis  <johne@verizon.net>
 
        * format_raw.[ch]: New files to parse image data and exif offsets for
index d31900c..23ac2b9 100644 (file)
@@ -2453,3 +2453,43 @@ void file_util_create_dir(const gchar *path, GtkWidget *parent)
        gtk_widget_show(GENERIC_DIALOG(fd)->dialog);
 }
 
+gint file_util_rename_dir(const gchar *old_path, const gchar *new_path, GtkWidget *parent)
+{
+       const gchar *old_name;
+       const gchar *new_name;
+
+       if (!old_path || !new_path || !isdir(old_path)) return FALSE;
+
+       old_name = filename_from_path(old_path);
+       new_name = filename_from_path(new_path);
+
+       if (isdir(new_path))
+               {
+               gchar *text = g_strdup_printf(_("The folder:\n%s\nalready exists."), new_name);
+               file_util_warning_dialog(_("Folder exists"), text, GTK_STOCK_DIALOG_INFO, parent);
+               g_free(text);
+
+               return FALSE;
+               }
+
+       if (isname(new_path))
+               {
+               gchar *text = g_strdup_printf(_("The path:\n%s\nalready exists as a file."), new_name);
+               file_util_warning_dialog(_("Rename failed"), text, GTK_STOCK_DIALOG_INFO,parent);
+               g_free(text);
+
+               return FALSE;
+               }
+
+       if (!rename_file(old_path, new_path))
+               {
+               gchar *text = g_strdup_printf(_("Failed to rename %s to %s."), old_name, new_name);
+               file_util_warning_dialog("Rename failed", text, GTK_STOCK_DIALOG_ERROR, parent);
+               g_free(text);
+
+               return FALSE;
+               }
+
+       return TRUE;
+}
+
index 1671265..9b33fcf 100644 (file)
@@ -39,7 +39,9 @@ void file_util_delete(const gchar *source_path, GList *source_list, GtkWidget *p
 void file_util_move(const gchar *source_path, GList *source_list, const gchar *dest_path, GtkWidget *parent);
 void file_util_copy(const gchar *source_path, GList *source_list, const gchar *dest_path, GtkWidget *parent);
 void file_util_rename(const gchar *source_path, GList *source_list, GtkWidget *parent);
+
 void file_util_create_dir(const gchar *path, GtkWidget *parent);
+gint file_util_rename_dir(const gchar *old_path, const gchar *new_path, GtkWidget *parent);
 
 /* these avoid the location entry dialog, list must be files only and
  * dest_path must be a valid directory path
index e083405..e771da1 100644 (file)
@@ -90,15 +90,7 @@ static gint vdlist_rename_row_cb(TreeEditData *td, const gchar *old, const gchar
        new_path = concat_dir_and_file(base, new);
        g_free(base);
 
-       if (!rename_file(old_path, new_path))
-               {
-               gchar *buf;
-
-               buf = g_strdup_printf(_("Failed to rename %s to %s."), old, new);
-               file_util_warning_dialog("Rename failed", buf, GTK_STOCK_DIALOG_ERROR, vdl->listview);
-               g_free(buf);
-               }
-       else
+       if (file_util_rename_dir(old_path, new_path, vdl->listview))
                {
                if (vdl->layout && strcmp(vdl->path, old_path) == 0)
                        {
index 9c8d9d5..c9a35d6 100644 (file)
@@ -197,15 +197,7 @@ static gint vdtree_rename_row_cb(TreeEditData *td, const gchar *old, const gchar
        new_path = concat_dir_and_file(base, new);
        g_free(base);
 
-       if (!rename_file(old_path, new_path))
-               {
-               gchar *buf;
-
-               buf = g_strdup_printf(_("Failed to rename %s to %s."), old, new);
-               file_util_warning_dialog("Rename failed", buf, GTK_STOCK_DIALOG_ERROR, vdt->treeview);
-               g_free(buf);
-               }
-       else
+       if (file_util_rename_dir(old_path, new_path, vdt->treeview))
                {
                vdtree_populate_path(vdt, new_path, TRUE, TRUE);