changeset 1418:1817f5178db3

Fix bug when adding a new collection through sort manager. Tidy up.
author zas_
date Wed, 11 Mar 2009 23:35:31 +0000
parents 8036c5b779ca
children c520cfd40aef
files src/bar_sort.c
diffstat 1 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_sort.c	Wed Mar 11 23:04:30 2009 +0000
+++ b/src/bar_sort.c	Wed Mar 11 23:35:31 2009 +0000
@@ -131,7 +131,7 @@
 
 static void bar_sort_mode_sync(SortData *sd, SortModeType mode)
 {
-	gint folder_mode;
+	gboolean folder_mode;
 
 	if (sd->mode == mode) return;
 	sd->mode = mode;
@@ -416,12 +416,13 @@
 static void bar_sort_add_ok_cb(FileDialog *fd, gpointer data)
 {
 	SortData *sd = data;
-	const gchar *name;
+	const gchar *name = gtk_entry_get_text(GTK_ENTRY(sd->dialog_name_entry));
+	gboolean empty_name = (name[0] == '\0');
 
 	name = gtk_entry_get_text(GTK_ENTRY(sd->dialog_name_entry));
 	if (sd->mode == BAR_SORT_MODE_FOLDER)
 		{
-		if (strlen(name) == 0)
+		if (empty_name)
 			{
 			name = filename_from_path(fd->dest_path);
 			}
@@ -431,20 +432,21 @@
 	else
 		{
 		gchar *path;
-	
-		if (strlen(name) == 0) return;
+		gboolean has_extension;
+		gchar *filename = (gchar *) name;
+
+		if (empty_name) return;
 
-		if (!file_extension_match(name, GQ_COLLECTION_EXT))
+		has_extension = file_extension_match(name, GQ_COLLECTION_EXT);
+		if (!has_extension)
 			{
-			gchar *tmp = g_strconcat(name, GQ_COLLECTION_EXT, NULL);
-			g_free((gpointer) name);
-			name = tmp;
+			filename = g_strconcat(name, GQ_COLLECTION_EXT, NULL);
 			}
 
-		path = g_build_filename(get_collections_dir(), name, NULL);
+		path = g_build_filename(get_collections_dir(), filename, NULL);
 		if (isfile(path))
 			{
-			gchar *text = g_strdup_printf(_("The collection:\n%s\nalready exists."), name);
+			gchar *text = g_strdup_printf(_("The collection:\n%s\nalready exists."), filename);
 			file_util_warning_dialog(_("Collection exists"), text, GTK_STOCK_DIALOG_INFO, NULL);
 			g_free(text);
 			}
@@ -467,6 +469,7 @@
 			collection_unref(cd);
 			}
 
+		if (!has_extension) g_free(filename);
 		g_free(path);
 		}
 
@@ -557,7 +560,9 @@
 	g_free(data);
 }
 
-static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action, SortModeType mode, SortSelectionType selection, const gchar *filter_key)
+static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action,
+			       SortModeType mode, SortSelectionType selection,
+			       const gchar *filter_key)
 {
 	SortData *sd;
 	GtkWidget *buttongrp;