[gthumb] use a custom _g_file_has_prefix that works has expected.



commit 5cb353448c17d0a5f8c121aeea9810ff29ac7cc6
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Jul 2 19:38:35 2010 +0200

    use a custom _g_file_has_prefix that works has expected.
    
    This function simply operates on uris and always works as expected.

 gthumb/glib-utils.c  |   26 ++++++++++++++++++++++++++
 gthumb/glib-utils.h  |    2 ++
 gthumb/gth-browser.c |    5 +++--
 3 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index eb5c88a..18a0689 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -2349,6 +2349,32 @@ _g_file_resolve_all_symlinks (GFile   *file,
 }
 
 
+gboolean
+_g_file_has_prefix (GFile *file,
+		    GFile *prefix)
+{
+	char     *file_uri;
+	char     *prefix_uri;
+	gboolean  result;
+
+	file_uri = g_file_get_uri (file);
+	prefix_uri = g_file_get_uri (prefix);
+	if (! g_str_has_suffix (prefix_uri, "/")) {
+		char *tmp;
+
+		tmp = g_strconcat (prefix_uri, "/", NULL);
+		g_free (prefix_uri);
+		prefix_uri = tmp;
+	}
+	result = g_str_has_prefix (file_uri, prefix_uri);
+
+	g_free (prefix_uri);
+	g_free (file_uri);
+
+	return result;
+}
+
+
 GFile *
 _g_file_append_prefix (GFile      *file,
 		       const char *prefix)
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index b62833c..680525f 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -265,6 +265,8 @@ int             _g_file_cmp_modification_time    (GFile      *a,
 goffset         _g_file_get_size                 (GFile      *info);
 GFile *         _g_file_resolve_all_symlinks     (GFile      *file,
 						  GError    **error);
+gboolean        _g_file_has_prefix               (GFile      *file,
+						  GFile      *prefix);
 GFile *         _g_file_append_prefix            (GFile      *file,
 						  const char *prefix);
 GFile *         _g_file_append_path              (GFile      *file,
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 6e67aa6..8202324 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -1610,7 +1610,7 @@ get_nearest_entry_point (GFile *file)
 	for (scan = list; scan; scan = scan->next) {
 		GthFileData *entry_point = scan->data;
 
-		if (g_file_equal (file, entry_point->file) || g_file_has_prefix (file, entry_point->file))
+		if (g_file_equal (file, entry_point->file) || _g_file_has_prefix (file, entry_point->file))
 			entries = g_list_prepend (entries, g_file_get_uri (entry_point->file));
 	}
 
@@ -1620,9 +1620,10 @@ get_nearest_entry_point (GFile *file)
 	min_diff = 0;
 	for (scan = entries; scan; scan = scan->next) {
 		char *entry_uri = scan->data;
-		int   entry_len = strlen (entry_uri);
+		int   entry_len;
 		int   diff;
 
+		entry_len = strlen (entry_uri);
 		diff = abs (entry_len - file_uri_len);
 		if ((scan == entries) || (diff < min_diff)) {
 			min_diff = diff;



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