[gthumb] Bug 584931 – Old dir name doesn't disappear from list if renaming



commit 7fb669d357e1ce3f81ba67a8c0fe0110e309fc8a
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Mon Jun 15 19:15:25 2009 -0400

    Bug 584931 â?? Old dir name doesn't disappear from list if renaming

 libgthumb/file-utils.c              |   57 ++++++++++-------
 libgthumb/file-utils.h              |    4 +-
 libgthumb/gfile-utils.c             |   20 +-----
 libgthumb/gfile-utils.h             |    3 +-
 src/catalog-web-exporter.c          |   21 ++----
 src/dlg-photo-importer.c            |    2 +-
 src/gth-browser-actions-callbacks.c |   41 ++++++++----
 src/gth-browser.c                   |   66 +++++++++++--------
 src/gth-dir-list.c                  |  119 +++++++++++++++++++----------------
 src/gth-dir-list.h                  |    8 +-
 src/gth-location.c                  |    6 +-
 11 files changed, 185 insertions(+), 162 deletions(-)
---
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index 0664266..576db4c 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -115,7 +115,7 @@ path_list_data_free (PathListData *pli)
 	}
 
 	if (pli->dirs != NULL) {
-		g_list_foreach (pli->dirs, (GFunc) g_free, NULL);
+		g_list_foreach (pli->dirs, (GFunc) g_object_unref, NULL);
 		g_list_free (pli->dirs);
 	}
 
@@ -139,48 +139,45 @@ path_list_classify_files_cb (gpointer data)
 {
 	GFile     *child=NULL;
 	GFileInfo *info;
-	char      *uri_txt;
 	FileData  *file;
 
 	int count=0;
 	PathListData *pli = (PathListData *) data;
-	while ((!(pli->current_file == NULL)) && !g_cancellable_is_cancelled(pli->cancelled)) {
+	while ((!(pli->current_file == NULL)) && !g_cancellable_is_cancelled (pli->cancelled)) {
 		count++;
 		info = pli->current_file->data;
 		switch (g_file_info_get_file_type (info)) {
 		case G_FILE_TYPE_REGULAR:
 			child = g_file_get_child (pli->gfile, g_file_info_get_name (info));
-			uri_txt = g_file_get_uri (child);
-			file = file_data_new_from_path (uri_txt);
+			file = file_data_new_from_gfile (child);
 			if ((pli->filter_func != NULL) && pli->filter_func (pli, file, pli->filter_data))
 				pli->files = g_list_prepend (pli->files, file);
 			else
 				file_data_unref (file);
-			g_free (uri_txt);
 			g_object_unref (child);
 			break;
 		case G_FILE_TYPE_DIRECTORY:
 			child = g_file_get_child (pli->gfile, g_file_info_get_name (info));
-			uri_txt = g_file_get_uri (child);
-			pli->dirs = g_list_prepend (pli->dirs, uri_txt);
-			g_object_unref (child);
+			pli->dirs = g_list_prepend (pli->dirs, child);
 			break;
 		default:
 			break;
 		}
 
-		g_object_unref(info);
+		g_object_unref (info);
 		pli->current_file=pli->current_file->next;
 		
 		if (count == ITEMS_PER_NOTIFICATION) 
 			return TRUE;
 	}
+
 	if (pli->done_func) {
 		// pli is deallocated in pli->done_func 
-		g_list_free(pli->file_list);
+		g_list_free (pli->file_list);
 		pli->done_func (pli, pli->done_data);
 		return FALSE;
 	}
+
 	path_list_data_free (pli);
 	return FALSE;
 }
@@ -405,7 +402,6 @@ ensure_dir_exists (const char *path)
 
 GList *
 dir_list_filter_and_sort (GList    *dir_list,
-			  gboolean  names_only,
 			  gboolean  show_dot_files)
 {
 	GList *filtered;
@@ -415,19 +411,18 @@ dir_list_filter_and_sort (GList    *dir_list,
 	filtered = NULL;
 	scan = dir_list;
 	while (scan) {
-		const char *name_only = file_name_from_path (scan->data);
-
-		if (! (file_is_hidden (name_only) && ! show_dot_files)
+		char *name_only;
+		name_only = g_file_get_basename (scan->data);
+		GFile *gfile;
+		gfile = (GFile*)scan->data;
+		if (! (gfile_is_hidden(gfile) && ! show_dot_files)
 		    && (strcmp (name_only, CACHE_DIR) != 0)) {
-			char *s;
-			char *path = (char*) scan->data;
-
-			s = g_strdup (names_only ? name_only : path);
-			filtered = g_list_prepend (filtered, s);
+			filtered = g_list_prepend (filtered, g_file_dup(gfile));
 		}
+		g_free(name_only);
 		scan = scan->next;
 	}
-	filtered = g_list_sort (filtered, (GCompareFunc) gth_sort_by_full_path);
+	filtered = g_list_sort (filtered, (GCompareFunc) gth_sort_by_gfile);
 
 	return filtered;
 }
@@ -856,7 +851,7 @@ get_file_size (const char *path)
 
 	file = gfile_new (path);
 
-	result = gfile_get_file_size (file);
+	result = gfile_get_size (file);
 	
 	g_object_unref (file);
 
@@ -1366,6 +1361,20 @@ basename_for_display (const char *uri)
 }
 
 
+char *
+gfile_get_basename_for_uri (const char *uri)
+{
+        char  *basename;
+        GFile *gfile;
+
+        gfile = gfile_new(uri);
+        basename = g_file_get_basename (gfile);
+        g_object_unref (gfile);
+
+        return basename;
+}
+
+
 /* example 1 : uri      = file:///xxx/yyy/zzz/foo
  *             desturi  = file:///xxx/www
  *             return   : ../yyy/zzz/foo
@@ -1513,7 +1522,7 @@ remove_special_dirs_from_path (const char *uri)
 		return NULL;
 
 	file = gfile_new (uri);
-	result = g_file_get_uri (file);
+	result = g_file_get_parse_name (file);
 	g_object_unref (file);
 
 	return result;
@@ -1666,7 +1675,7 @@ char *resolve_all_symlinks (const char *uri)
 		g_object_unref (parent);
 	}
 
-	result = g_file_get_uri (gfile_full);
+	result = g_file_get_parse_name (gfile_full);
 	g_object_unref (gfile_curr);
 	g_object_unref (gfile_full);
 	g_free (child);
diff --git a/libgthumb/file-utils.h b/libgthumb/file-utils.h
index 2058707..38856d6 100644
--- a/libgthumb/file-utils.h
+++ b/libgthumb/file-utils.h
@@ -53,7 +53,7 @@ struct _PathListData {
 	GFile		   *gfile;
 	GFileEnumerator    *gfile_enum;
 	GList              *files;               /* char* items. */
-	GList              *dirs;                /* char* items. */
+	GList              *dirs;                /* GFile* items. */
 	PathListFilterFunc  filter_func;
 	gpointer            filter_data;
 	PathListDoneFunc    done_func;
@@ -93,7 +93,6 @@ gboolean            dir_remove_recursive          (const char       *path);
 
 gboolean            ensure_dir_exists             (const char       *path);
 GList *             dir_list_filter_and_sort      (GList            *dir_list,
-						   gboolean          names_only,
 						   gboolean          show_dot_files);
 gboolean            file_filter                   (FileData         *file,
 	     					   gboolean          show_hidden_files,
@@ -166,6 +165,7 @@ int                 uricmp                        (const char       *uri1,
 gboolean            same_uri                      (const char       *uri1,
 						   const char       *uri2);
 char               *basename_for_display          (const char       *uri);
+char               *gfile_get_basename_for_uri    (const char       *uri);
 
 char *              get_path_relative_to_uri      (const char       *uri,
 						   const char       *desturi);
diff --git a/libgthumb/gfile-utils.c b/libgthumb/gfile-utils.c
index 55e8372..6aadb7f 100644
--- a/libgthumb/gfile-utils.c
+++ b/libgthumb/gfile-utils.c
@@ -42,15 +42,6 @@
 
 
 
-/* GFile to string */
-
-char *
-gfile_get_uri (GFile *file)
-{
-        return g_file_get_uri (file);
-}
-
-
 char *
 gfile_get_path (GFile *file)
 {
@@ -64,7 +55,6 @@ gfile_get_path (GFile *file)
         return unescaped;
 }
 
-
 /* Debug */
 
 void
@@ -99,7 +89,7 @@ gfile_warning (const char *msg,
         char *uri;
         char *warning;
 
-        uri = gfile_get_uri (file);
+        uri = g_file_get_parse_name (file);
 
         if (err == NULL)
                 warning = g_strdup_printf ("%s: file %s", msg, uri);
@@ -420,13 +410,12 @@ gboolean gfile_path_contains (GFile      *file,
 
 
 goffset
-gfile_get_file_size (GFile *file)
+gfile_get_size (GFile *file)
 {
         GFileInfo *info;
         goffset    size = 0;
         GError    *err = NULL;
 
-        //FIXME: shouldn't we get rid of this test and fix the callers instead?
         if (file == NULL)
                 return 0;
 
@@ -749,7 +738,7 @@ gfile_path_list_new (GFile  *gfile,
                 char  *uri;
 
                 child = g_file_get_child (gfile, g_file_info_get_name (info));
-                uri = gfile_get_uri (child);
+                uri = g_file_get_parse_name (child);
 
                 switch (g_file_info_get_file_type (info)) {
                 case G_FILE_TYPE_DIRECTORY:
@@ -759,7 +748,7 @@ gfile_path_list_new (GFile  *gfile,
                         break;
                 case G_FILE_TYPE_REGULAR:
                         if (files) {
-                                f_list = g_list_prepend (f_list, file_data_new_from_path (uri));
+                                f_list = g_list_prepend (f_list, file_data_new_from_gfile (child));
                         }
                         break;
                 default:
@@ -1025,4 +1014,3 @@ gfile_set_mtime (GFile  *gfile,
                 g_error_free (error);
         }
 }
-
diff --git a/libgthumb/gfile-utils.h b/libgthumb/gfile-utils.h
index 063f249..6ad2d2c 100644
--- a/libgthumb/gfile-utils.h
+++ b/libgthumb/gfile-utils.h
@@ -40,7 +40,6 @@
 
 /* GFile to string */
 
-char *        gfile_get_uri                    (GFile *file);
 char *        gfile_get_path                   (GFile *file);
 
 /* Debug */
@@ -75,7 +74,7 @@ gboolean      gfile_is_file                    (GFile      *file);
 gboolean      gfile_is_dir                     (GFile      *file);
 gboolean      gfile_path_contains              (GFile      *file,
 						const char *find_this);
-goffset       gfile_get_file_size              (GFile      *file);
+goffset       gfile_get_size                   (GFile      *file);
 char *        gfile_get_display_name           (GFile      *file);
 void          gfile_set_mtime                  (GFile      *gfile,
                                                 time_t      mtime);
diff --git a/src/catalog-web-exporter.c b/src/catalog-web-exporter.c
index 629b757..444f16d 100644
--- a/src/catalog-web-exporter.c
+++ b/src/catalog-web-exporter.c
@@ -1136,8 +1136,8 @@ gfile_get_relative_uri (GFile *file,
 	char  *relative_uri;
 	char  *result;
 	
-	escaped = gfile_get_uri (file);
-	relative_uri = gfile_get_uri (relative_to);
+	escaped = g_file_get_parse_name (file);
+	relative_uri = g_file_get_parse_name (relative_to);
 	
 	result = get_path_relative_to_uri (escaped, relative_uri);
 	
@@ -2548,7 +2548,6 @@ save_resized_image_cb (gpointer data)
 
 		if (ce->copy_images && (idata->image != NULL)) {
 			GFile *file;
-			char  *image_uri;
 			char  *local_file; 
 
 			exporter_set_info (ce, _("Saving images"));
@@ -2556,7 +2555,6 @@ save_resized_image_cb (gpointer data)
 			file = get_image_file (ce, 
 					       idata, 
 					       ce->target_tmp_dir);
-			image_uri = gfile_get_uri (file);
 			local_file = gfile_get_path (file);
 
 			debug (DEBUG_INFO, "saving image: %s", local_file);
@@ -2566,11 +2564,10 @@ save_resized_image_cb (gpointer data)
 					      idata->src_file->local_path,
 					      "jpeg",
 					      NULL, NULL)) {
-				idata->src_file->size = get_file_size (image_uri);
+				idata->src_file->size = gfile_get_size (file);
 			} 
 			
 			g_free (local_file);
-			g_free (image_uri);
 			g_object_unref (file);
 		}
 	}
@@ -2607,13 +2604,10 @@ export__copy_image (CatalogWebExporter *ce)
 
 	if (copy_done) {
 		if (gfile_image_is_jpeg (dfile)) {
-			char *uri;
-			uri = gfile_get_uri (dfile);
-		
 			GthTransform  transform;
-		
 			FileData *fd;
-			fd = file_data_new_from_path (uri);
+
+			fd = file_data_new_from_gfile (dfile);
 			transform = get_orientation_from_fd (fd);
 			
 			if (transform > 1) {
@@ -2624,7 +2618,6 @@ export__copy_image (CatalogWebExporter *ce)
 			}
 
 			file_data_unref (fd);
-			g_free (uri);
 		}
 	}
 	
@@ -3061,10 +3054,10 @@ catalog_web_exporter_export (CatalogWebExporter *ce)
 	 * since xfer functions have not yet been ported to gio
 	 */
 	g_free (ce->base_tmp_dir);
-	ce->base_tmp_dir = g_file_get_uri (ce->target_tmp_dir);
+	ce->base_tmp_dir = g_file_get_parse_name (ce->target_tmp_dir);
 	
 	g_free (ce->base_dir);
-	ce->base_dir = g_file_get_uri (ce->target_dir);
+	ce->base_dir = g_file_get_parse_name (ce->target_dir);
 
 	
 	if (ce->iloader != NULL)
diff --git a/src/dlg-photo-importer.c b/src/dlg-photo-importer.c
index a3b968e..cfbd9d8 100644
--- a/src/dlg-photo-importer.c
+++ b/src/dlg-photo-importer.c
@@ -1473,7 +1473,7 @@ ok_clicked_cb (GtkButton  *button,
 	file_data_unref (folder_fd);
 
 	for (scan = file_list; scan; scan = scan->next) {
-		total_size += gfile_get_file_size ((GFile *) scan->data);
+		total_size += gfile_get_size ((GFile *) scan->data);
 	}
 
 	debug (DEBUG_INFO, "Prepare to import %ld bytes", total_size);
diff --git a/src/gth-browser-actions-callbacks.c b/src/gth-browser-actions-callbacks.c
index c2f8b28..236ba5f 100644
--- a/src/gth-browser-actions-callbacks.c
+++ b/src/gth-browser-actions-callbacks.c
@@ -940,7 +940,6 @@ folder_rename (GtkWindow  *window,
 	g_free (new_name);
 	g_free (parent_path);
 	new_fd = file_data_new_from_path (new_path);
-	g_free (new_path);
 
 	gth_monitor_pause ();
 
@@ -969,7 +968,7 @@ folder_rename (GtkWindow  *window,
 					       old_fd->utf8_name);
 		}
 	}
-
+	g_free (new_path);
 	gth_monitor_resume ();
 
 	file_data_unref (old_fd);
@@ -1362,7 +1361,7 @@ gth_browser_activate_action_edit_dir_move (GtkAction  *action,
 
 typedef struct {
 	GthBrowser *browser;
-	GList      *file_list;
+	GList      *gfile_list /* GFiles */;
 	GList      *add_list, *remove_list;
 } FolderTagsData;
 
@@ -1373,11 +1372,14 @@ edit_current_folder_tags__done (gpointer data)
 	FolderTagsData *fcdata = data;
 	GList                *scan;
 
-	for (scan = fcdata->file_list; scan; scan = scan->next) {
-		const char  *filename = scan->data;
+	for (scan = fcdata->gfile_list; scan; scan = scan->next) {
+		GFile  *gfile = scan->data;
+		char *filename;
 		CommentData *cdata;
 		GList       *scan2;
 		GthDirList  *dir_list;
+		
+		filename = g_file_get_parse_name (gfile);
 
 		cdata = comments_load_comment (filename, FALSE);
 		if (cdata == NULL)
@@ -1398,12 +1400,12 @@ edit_current_folder_tags__done (gpointer data)
 
 		dir_list = gth_browser_get_dir_list (fcdata->browser);
 		if (path_in_path (dir_list->path, filename)) {
-			gth_dir_list_remove_directory (dir_list, filename);
-			gth_dir_list_add_directory (dir_list, filename);
+			gth_dir_list_remove_directory (dir_list, gfile);
+			gth_dir_list_add_directory (dir_list, gfile);
 		}
 	}
 
-	path_list_free (fcdata->file_list);
+	gfile_list_free (fcdata->gfile_list);
 	path_list_free (fcdata->add_list);
 	path_list_free (fcdata->remove_list);
 	g_free (fcdata);
@@ -1412,21 +1414,23 @@ edit_current_folder_tags__done (gpointer data)
 
 static void
 edit_current_folder_tags (GthBrowser *browser,
-                          const char *path)
+                          GFile *gfile)
 {
 	FolderTagsData *fcdata;
 
-	if (path == NULL)
+	if (gfile == NULL)
 		return;
 
 	fcdata = g_new0 (FolderTagsData, 1);
 	fcdata->browser = browser;
 	fcdata->add_list = NULL;
 	fcdata->remove_list = NULL;
-	fcdata->file_list = g_list_prepend (NULL, g_strdup (path));
+	fcdata->gfile_list = g_list_prepend (NULL, g_file_dup (gfile));
+
+	GList *file_list = g_list_prepend (NULL, g_file_get_parse_name (gfile));
 
 	dlg_choose_tags (GTK_WINDOW (browser),
-                         fcdata->file_list,
+                         file_list,
                          NULL,
                          &(fcdata->add_list),
                          &(fcdata->remove_list),
@@ -1440,12 +1444,17 @@ gth_browser_activate_action_edit_dir_tags (GtkAction  *action,
                                            GthBrowser *browser)
 {
 	char *path;
+	GFile *gfile;
 
 	path = gth_dir_list_get_selected_path (gth_browser_get_dir_list (browser));
+	
 	if (path == NULL)
 		return;
-	edit_current_folder_tags (browser, path);
+
+	gfile = gfile_new (path);
+	edit_current_folder_tags (browser, gfile);
 	g_free (path);
+	g_object_unref (gfile);
 }
 
 
@@ -1493,7 +1502,11 @@ void
 gth_browser_activate_action_edit_current_dir_tags (GtkAction  *action,
                                                    GthBrowser *browser)
 {
-	edit_current_folder_tags (browser, gth_browser_get_dir_list (browser)->path);
+	char *path = gth_browser_get_dir_list (browser)->path;
+	GFile *gfile;
+	gfile = gfile_new(path);
+	edit_current_folder_tags (browser, gfile);
+	g_object_unref(gfile);
 }
 
 
diff --git a/src/gth-browser.c b/src/gth-browser.c
index 79465f1..a9c14f4 100644
--- a/src/gth-browser.c
+++ b/src/gth-browser.c
@@ -5733,46 +5733,50 @@ gth_browser_notify_file_rename (GthBrowser *browser,
 
 static void
 gth_browser_notify_directory_rename (GthBrowser *browser,
-				     const char *old_name,
-				     const char *new_name)
+				     const char *old_parse_name,
+				     const char *new_parse_name)
 {
 	GthBrowserPrivateData *priv = browser->priv;
 
 	if (priv->sidebar_content == GTH_SIDEBAR_DIR_LIST) {
-		if (same_uri (priv->dir_list->path, old_name))
-			gth_browser_go_to_directory (browser, new_name);
+		if (same_uri (priv->dir_list->path, old_parse_name))
+			gth_browser_go_to_directory (browser, new_parse_name);
 		else {
 			const char *current = priv->dir_list->path;
-
+			GFile *old_gfile, *new_gfile;
+			old_gfile = g_file_parse_name(old_parse_name);
+			new_gfile = g_file_parse_name(new_parse_name);
 			/* a sub directory was renamed, refresh. */
-			if (first_level_sub_directory (browser, current, old_name))
-				gth_dir_list_remove_directory (priv->dir_list,
-							       file_name_from_path (old_name));
-
-			if (first_level_sub_directory (browser, current, new_name))
+			if (first_level_sub_directory (browser, current, new_parse_name))
 				gth_dir_list_add_directory (priv->dir_list,
-							    file_name_from_path (new_name));
+							    new_gfile);
+                                
+            		if (first_level_sub_directory (browser, current, old_parse_name))
+                		gth_dir_list_remove_directory (priv->dir_list,
+                                   			    old_gfile);
+			g_object_unref(old_gfile);
+			g_object_unref(new_gfile);
 		}
 	} 
 	else if (priv->sidebar_content == GTH_SIDEBAR_CATALOG_LIST) {
-		if (same_uri (priv->catalog_list->path, old_name))
-			gth_browser_go_to_catalog_directory (browser, new_name);
+		if (same_uri (priv->catalog_list->path, old_parse_name))
+			gth_browser_go_to_catalog_directory (browser, new_parse_name);
 		else {
 			const char *current = priv->catalog_list->path;
-			if (first_level_sub_directory (browser, current, old_name))
+			if (first_level_sub_directory (browser, current, old_parse_name))
 				window_update_catalog_list (browser);
 		}
 	}
 
 	if ((priv->image != NULL)
 	    && (priv->sidebar_content == GTH_SIDEBAR_DIR_LIST)
-	    && path_in_path (old_name, priv->image->utf8_path)) 
+	    && path_in_path (old_parse_name, priv->image->utf8_path)) 
 	{
 		char *new_image_path = g_strdup (priv->image->utf8_path);
 		char *new_image_name;
 
-		new_image_name = g_strconcat (new_name,
-					      priv->image->utf8_path + strlen (old_name),
+		new_image_name = g_strconcat (new_parse_name,
+					      priv->image->utf8_path + strlen (old_parse_name),
 					      NULL);
 		gth_browser_notify_file_rename (browser,
 						new_image_path,
@@ -5785,33 +5789,36 @@ gth_browser_notify_directory_rename (GthBrowser *browser,
 
 static void
 gth_browser_notify_directory_delete (GthBrowser *browser,
-				     const char *path)
+				     const char *parse_name)
 {
 	GthBrowserPrivateData *priv = browser->priv;
 
 	if (priv->sidebar_content == GTH_SIDEBAR_DIR_LIST) {
-		if (same_uri (priv->dir_list->path, path))
+		if (same_uri (priv->dir_list->path, parse_name))
 			gth_browser_go_up (browser);
 		else {
+			GFile *gfile;
+			gfile = g_file_parse_name(parse_name);
 			const char *current = priv->dir_list->path;
-			if (first_level_sub_directory (browser, current, path))
+			if (first_level_sub_directory (browser, current, parse_name))
 				gth_dir_list_remove_directory (priv->dir_list,
-							       file_name_from_path (path));
+							       gfile);
+			g_object_unref(gfile);
 		}
 	} 
 	else if (priv->sidebar_content == GTH_SIDEBAR_CATALOG_LIST) {
-		if (same_uri (priv->catalog_list->path, path))
+		if (same_uri (priv->catalog_list->path, parse_name))
 			gth_browser_go_up (browser);
 		else {
 			const char *current = priv->catalog_list->path;
-			if (path_in_path (current, path))
+			if (path_in_path (current, parse_name))
 				/* a sub directory got deleted, refresh. */
 				window_update_catalog_list (browser);
 		}
 	}
 
 	if ((priv->image != NULL)
-	    && (path_in_path (priv->image->utf8_path, path))) {
+	    && (path_in_path (priv->image->utf8_path, parse_name))) {
 		GList *list;
 
 		list = g_list_append (NULL, priv->image->utf8_path);
@@ -5823,19 +5830,22 @@ gth_browser_notify_directory_delete (GthBrowser *browser,
 
 static void
 gth_browser_notify_directory_new (GthBrowser *browser,
-				  const char *path)
+				  const char *parse_name)
 {
 	GthBrowserPrivateData *priv = browser->priv;
 
 	if (priv->sidebar_content == GTH_SIDEBAR_DIR_LIST) {
 		const char *current = priv->dir_list->path;
-		if (first_level_sub_directory (browser, current, path))
+		GFile *gfile;
+		gfile = g_file_parse_name(parse_name);
+		if (first_level_sub_directory (browser, current, parse_name))
 			gth_dir_list_add_directory (priv->dir_list,
-						    file_name_from_path (path));
+						    gfile);
+		g_object_unref(gfile);
 	} 
 	else if (priv->sidebar_content == GTH_SIDEBAR_CATALOG_LIST) {
 		const char *current = priv->catalog_list->path;
-		if (path_in_path (current, path))
+		if (path_in_path (current, parse_name))
 			/* a sub directory was created, refresh. */
 			window_update_catalog_list (browser);
 	}
diff --git a/src/gth-dir-list.c b/src/gth-dir-list.c
index cc15ea3..9cc4403 100644
--- a/src/gth-dir-list.c
+++ b/src/gth-dir-list.c
@@ -37,6 +37,7 @@
 #include "pixbuf-utils.h"
 #include "icons/pixbufs.h"
 #include "comments.h"
+#include "gfile-utils.h"
 
 #define DEF_SHOW_HIDDEN FALSE
 #define DEF_SHOW_ONLY_IMAGES FALSE
@@ -67,10 +68,11 @@ gth_dir_list_finalize (GObject *object)
 	dir_list = GTH_DIR_LIST (object);
 
 	file_data_list_free (dir_list->file_list);
-	path_list_free (dir_list->list);
+	gfile_list_free (dir_list->list);
 	g_free (dir_list->path);
 	g_free (dir_list->try_path);
-	g_free (dir_list->old_dir);
+	if (dir_list->old_dir != NULL)
+		g_object_unref (dir_list->old_dir);
 	g_free (dir_list->dir_load_handle);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -400,6 +402,8 @@ gth_dir_list_update_view (GthDirList *dir_list)
 	GdkPixbuf *dir_pixbuf;
 	GdkPixbuf *up_pixbuf;
 	GList     *scan;
+	GtkTreeIter  iter;
+	GdkPixbuf   *pixbuf;
 
 	dir_pixbuf = get_folder_pixbuf (get_folder_pixbuf_size_for_list (dir_list->list_view));
 	up_pixbuf = gtk_widget_render_icon (dir_list->list_view,
@@ -409,25 +413,34 @@ gth_dir_list_update_view (GthDirList *dir_list)
 
 	gtk_list_store_clear (dir_list->list_store);
 
+	/* if this isn't a root dir add a '..' item */
+	if (! uri_is_root (dir_list->path)) {
+		gtk_list_store_append (dir_list->list_store, &iter);
+		gtk_list_store_set (dir_list->list_store, &iter,
+				    DIR_LIST_COLUMN_ICON, dir_pixbuf /*up_pixbuf*/,
+				    DIR_LIST_COLUMN_DISPLAY_NAME, "..",
+				    DIR_LIST_COLUMN_NAME, "..",
+				    -1);
+	}
+	
+	pixbuf = dir_pixbuf;
+	
 	for (scan = dir_list->list; scan; scan = scan->next) {
-		char        *name = scan->data;
+		GFile       *gfile = (GFile*)scan->data;
+		char        *name;
 		char        *utf8_name;
-		GtkTreeIter  iter;
-		GdkPixbuf   *pixbuf;
-
-		if (strcmp (name, "..") == 0)
-			pixbuf = dir_pixbuf /*up_pixbuf*/;
-		else
-			pixbuf = dir_pixbuf;
-
+		
+		
+		name = g_file_get_basename (gfile);
 		utf8_name = get_utf8_display_name_from_uri (name);
+
 		gtk_list_store_append (dir_list->list_store, &iter);
 		gtk_list_store_set (dir_list->list_store, &iter,
 				    DIR_LIST_COLUMN_ICON, pixbuf,
 				    DIR_LIST_COLUMN_DISPLAY_NAME, utf8_name,
 				    DIR_LIST_COLUMN_NAME, name,
 				    -1);
-
+		g_free (name);
 		g_free (utf8_name);
 	}
 
@@ -473,7 +486,7 @@ gth_dir_list_change_to__step2 (PathListData *pld,
 	/* Update path data. */
 
 	if (dir_list->old_dir != NULL) {
-		g_free (dir_list->old_dir);
+		g_object_unref (dir_list->old_dir);
 		dir_list->old_dir = NULL;
 	}
 
@@ -483,7 +496,7 @@ gth_dir_list_change_to__step2 (PathListData *pld,
 		char *previous_dir = remove_level_from_path (dir_list->path);
 
 		if (same_uri (previous_dir, dir_list->try_path))
-			dir_list->old_dir = g_strdup (file_name_from_path (dir_list->path));
+			dir_list->old_dir = gfile_new (dir_list->path);
 		else
 			dir_list->old_dir = NULL;
 		g_free (previous_dir);
@@ -506,7 +519,7 @@ gth_dir_list_change_to__step2 (PathListData *pld,
 	/* Delete the old dir list. */
 
 	if (dir_list->list != NULL) {
-		path_list_free (dir_list->list);
+		gfile_list_free (dir_list->list);
 		dir_list->list = NULL;
 	}
 
@@ -518,17 +531,10 @@ gth_dir_list_change_to__step2 (PathListData *pld,
 	/* Set the new dir list */
 
 	filtered = dir_list_filter_and_sort (new_dir_list,
-			         	     TRUE,
-					     dir_list->show_dot_files);
-
-	/* * Add the ".." entry if the current path is not "/".
-	 * path_list_async_new does not include the "." and ".." elements. */
-
-	if (! uri_is_root (dir_list->path))
-		filtered = g_list_prepend (filtered, g_strdup (".."));
+			         	     dir_list->show_dot_files);
 
 	dir_list->list = filtered;
-	path_list_free (new_dir_list);
+	gfile_list_free (new_dir_list);
 
 	/* Update the view. */
 
@@ -540,11 +546,10 @@ gth_dir_list_change_to__step2 (PathListData *pld,
 		GList *scan;
 		int    row;
 		int    found = FALSE;
-
 		row = -1;
 		scan = dir_list->list;
 		while (scan && !found) {
-			if (same_uri (dir_list->old_dir, scan->data))
+			if (g_file_equal (dir_list->old_dir, (GFile*)scan->data))
 				found = TRUE;
 			scan = scan->next;
 			row++;
@@ -553,6 +558,11 @@ gth_dir_list_change_to__step2 (PathListData *pld,
 		if (found) {
 			GtkTreePath *path;
 			path = gtk_tree_path_new ();
+			
+			/* if this isn't a root dir there will be a '..' item */
+			if (! uri_is_root (dir_list->path))
+				row++;
+
 			gtk_tree_path_prepend_index (path, row);
 			gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (dir_list->list_view),
 						      path,
@@ -563,7 +573,7 @@ gth_dir_list_change_to__step2 (PathListData *pld,
 			gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (dir_list->list_view)), path);
 			gtk_tree_path_free (path);
 		}
-		g_free (dir_list->old_dir);
+		g_object_unref (dir_list->old_dir);
 		dir_list->old_dir = NULL;
 	}
 
@@ -620,9 +630,9 @@ gth_dir_list_stop (GthDirList *dir_list)
 
 void
 gth_dir_list_add_directory (GthDirList *dir_list,
-			    const char *path)
+			    GFile      *gfile)
 {
-	const char  *name_only;
+	char 	    *name_only;
 	GList       *scan;
 	GdkPixbuf   *dir_pixbuf;
 	GdkPixbuf   *pixbuf;
@@ -630,33 +640,37 @@ gth_dir_list_add_directory (GthDirList *dir_list,
 	GtkTreeIter  iter;
 	int          pos;
 
-	if (path == NULL)
+	if (gfile == NULL)
 		return;
-	name_only = file_name_from_path (path);
+	name_only = g_file_get_basename (gfile);
 
 	/* check whether dir is already present */
 
 	for (scan = dir_list->list; scan; scan = scan->next)
-		if (same_uri (name_only, (char*)scan->data))
+		if (g_file_equal (gfile, (GFile*)scan->data))
 			return;
 
-	/* insert dir in the list */
-
-	if (! (file_is_hidden (name_only) && ! dir_list->show_dot_files)
-	    && ! same_uri (name_only, CACHE_DIR))
-		dir_list->list = g_list_prepend (dir_list->list, g_strdup (name_only));
-	dir_list->list = g_list_sort (dir_list->list, (GCompareFunc) gth_sort_by_full_path);
-
+	/* Insert dir in the list */    
+	
+	if (! (gfile_is_hidden(gfile) && ! dir_list->show_dot_files)
+	    && ! same_uri (name_only, CACHE_DIR)) 
+		dir_list->list = g_list_prepend (dir_list->list, g_file_dup(gfile));
+	
+	dir_list->list = g_list_sort (dir_list->list, (GCompareFunc) gth_sort_by_gfile);
+        
 	/* get the dir position */
 
 	for (pos = 0, scan = dir_list->list; scan; scan = scan->next) {
-		if (same_uri (name_only, (char*) scan->data))
+		if (g_file_equal (gfile, (GFile*) scan->data))
 			break;
 		pos++;
 	}
-
+	
+	/* if this isn't a root dir there will be a '..' item */
+	if (! uri_is_root (dir_list->path))
+		pos++;
+		
 	/* insert dir in the list view */
-
 	dir_pixbuf = get_folder_pixbuf (get_folder_pixbuf_size_for_list (dir_list->list_view));
 
 	pixbuf = dir_pixbuf;
@@ -669,43 +683,40 @@ gth_dir_list_add_directory (GthDirList *dir_list,
 			    DIR_LIST_COLUMN_NAME, name_only,
 			    -1);
 	g_free (utf8_name);
+	g_free (name_only);
 	g_object_unref (dir_pixbuf);
 }
 
 
 void
 gth_dir_list_remove_directory (GthDirList *dir_list,
-			       const char *path)
+			       GFile *gfile)
 {
 	GList        *scan, *link = NULL;
-	const char   *name_only;
 	int           pos;
 	GtkTreeIter   iter;
 
-	if (path == NULL)
+	if (gfile == NULL)
 		return;
 
-	name_only = file_name_from_path (path);
-
 	for (pos = 0, scan = dir_list->list; scan; scan = scan->next) {
-		if (same_uri (name_only, (char*)scan->data)) {
+		if (g_file_equal (gfile, (GFile*)scan->data)) {
 			link = scan;
 			break;
 		}
 		pos++;
 	}
-
+	
+	if (! uri_is_root (dir_list->path))
+		pos++;
+	
 	if (link == NULL)
 		return;
 
-	/**/
-
 	dir_list->list = g_list_remove_link (dir_list->list, link);
-	g_free (link->data);
+	g_object_unref (link->data);
 	g_list_free (link);
 
-	/**/
-
 	if (! gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (dir_list->list_store),
 					     &iter,
 					     NULL,
diff --git a/src/gth-dir-list.h b/src/gth-dir-list.h
index 1a800fd..a1fe4be 100644
--- a/src/gth-dir-list.h
+++ b/src/gth-dir-list.h
@@ -42,7 +42,7 @@ struct _GthDirList {
 
 	char            *path;           /* The directory we are showing. */
 	char            *try_path;       /* The directory we are loading. */
-	GList           *list;           /* The directory name list (gchar*
+	GList           *list;           /* The directory name list (GFile*
 				          * elements). */
 	GList           *file_list;      /* The file name list (gchar* elements). */
 	GtkListStore    *list_store;
@@ -54,7 +54,7 @@ struct _GthDirList {
 	gboolean         show_only_images;
 	gboolean         single_click;
 	GtkTreePath     *hover_path;
-	char            *old_dir;
+	GFile           *old_dir;
 	PathListHandle  *dir_load_handle;
 };
 
@@ -78,9 +78,9 @@ void           gth_dir_list_change_to               (GthDirList  *dir_list,
 						     const char  *path);
 void           gth_dir_list_stop                    (GthDirList  *dir_list);
 void           gth_dir_list_add_directory           (GthDirList  *dir_list,
-						     const char  *path);
+						     GFile	 *gfile);
 void           gth_dir_list_remove_directory        (GthDirList  *dir_list,
-						     const char  *path);
+						     GFile	 *path);
 char *         gth_dir_list_get_name_from_iter      (GthDirList  *dir_list,
 						     GtkTreeIter *iter);
 char *         gth_dir_list_get_path_from_tree_path (GthDirList  *dir_list,
diff --git a/src/gth-location.c b/src/gth-location.c
index 4c503ea..32f6a72 100644
--- a/src/gth-location.c
+++ b/src/gth-location.c
@@ -617,7 +617,7 @@ update_drives (GthLocation *loc)
                 pixbuf = get_mount_icon ((GtkWidget *) loc, mount);
                 uri_name = g_mount_get_name (mount);
 
-                uri = g_file_get_uri(gfile);
+                uri = g_file_get_parse_name (gfile);
 
                 gtk_list_store_insert (loc->priv->model, &iter, pos++);
                 gtk_list_store_set (loc->priv->model, &iter,
@@ -686,7 +686,7 @@ update_uri (GthLocation *loc,
         while (gfile != NULL) {
                 GFile *parent_gfile;
                 char *uri;
-                uri = g_file_get_uri(gfile);
+                uri = g_file_get_parse_name (gfile);
 
                 if (loc->priv->catalog_uri)
                         pixbuf = gdk_pixbuf_new_from_inline (-1, library_19_rgba, FALSE, NULL);
@@ -707,7 +707,7 @@ update_uri (GthLocation *loc,
                                         if (g_file_has_uri_scheme (gfile, "file"))
                                                 uri_name = g_strdup (_("File System"));
                                         else
-                                                uri_name = g_file_get_uri (gfile);
+                                                uri_name = g_file_get_parse_name (gfile);
                                 }
                         }
                 } else {



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