gthumb r2465 - in trunk: . libgthumb



Author: mjc
Date: Tue Dec 23 16:29:50 2008
New Revision: 2465
URL: http://svn.gnome.org/viewvc/gthumb?rev=2465&view=rev

Log:
2008-12-23  Michael J. Chudobiak  <mjc svn gnome org>

        * libgthumb/file-data.c: (load_info):
        Load the fast mime_type initially.

        * libgthumb/file-utils.c: (path_list_new),
        (visit_rc_directory_sync), (free_cache), (check_cache_free_space):
        Use the new gfile_path_list_new, and fix a small memory leak.

        * libgthumb/gfile-utils.c: (gfile_path_list_new):
        * libgthumb/gfile-utils.h:
        Add a gfile version of path_list_new, as part of the gio porting.



Modified:
   trunk/ChangeLog
   trunk/libgthumb/file-data.c
   trunk/libgthumb/file-utils.c
   trunk/libgthumb/gfile-utils.c
   trunk/libgthumb/gfile-utils.h

Modified: trunk/libgthumb/file-data.c
==============================================================================
--- trunk/libgthumb/file-data.c	(original)
+++ trunk/libgthumb/file-data.c	Tue Dec 23 16:29:50 2008
@@ -73,7 +73,8 @@
 				  G_FILE_ATTRIBUTE_STANDARD_SIZE ","
 				  G_FILE_ATTRIBUTE_TIME_CHANGED ","
 				  G_FILE_ATTRIBUTE_TIME_MODIFIED ","
-				  G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
+				  G_FILE_ATTRIBUTE_ACCESS_CAN_READ ","
+				  G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
                                   G_FILE_QUERY_INFO_NONE,
                                   NULL,
                                   &error);
@@ -85,6 +86,7 @@
 		fd->mtime = tv.tv_sec;
 		fd->display_name = g_strdup (g_file_info_get_display_name (info));
 		fd->can_read = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
+		fd->mime_type = get_static_string (g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE));
         } else {
                 gfile_warning ("Failed to get file information", gfile, error);
                 g_error_free (error);

Modified: trunk/libgthumb/file-utils.c
==============================================================================
--- trunk/libgthumb/file-utils.c	(original)
+++ trunk/libgthumb/file-utils.c	Tue Dec 23 16:29:50 2008
@@ -269,54 +269,14 @@
 	       GList      **files,
 	       GList      **dirs)
 {
-	GnomeVFSResult  r;
-	GnomeVFSURI    *dir_uri;
-	GList          *info_list = NULL;
-	GList          *scan;
-	GList          *f_list = NULL;
-	GList          *d_list = NULL;
-
-	if (files) *files = NULL;
-	if (dirs) *dirs = NULL;
-
-	r = gnome_vfs_directory_list_load (&info_list,
-					   uri,
-					   GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
-
-	if (r != GNOME_VFS_OK)
-		return FALSE;
-
-	dir_uri = new_uri_from_path (uri);
-	for (scan = info_list; scan; scan = scan->next) {
-		GnomeVFSFileInfo *info = scan->data;
-		GnomeVFSURI      *full_uri = NULL;
-		char             *s_uri;
-
-		full_uri = gnome_vfs_uri_append_file_name (dir_uri, info->name);
-		s_uri = gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE);
-
-		if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
-			if (! SPECIAL_DIR (info->name))
-				d_list = g_list_prepend (d_list, s_uri);
-		} 
-		else if (info->type == GNOME_VFS_FILE_TYPE_REGULAR)
-			f_list = g_list_prepend (f_list, file_data_new (s_uri));
-		else
-			g_free (s_uri);
-	}
-	gnome_vfs_file_info_list_free (info_list);
-
-	if (dirs)
-		*dirs = g_list_reverse (d_list);
-	else
-		path_list_free (d_list);
+        GFile    *gfile;
+	gboolean  result;
 
-	if (files)
-		*files = g_list_reverse (f_list);
-	else
-		file_data_list_free (f_list);
+        gfile = gfile_new (uri);
+	result = gfile_path_list_new (gfile, files, dirs);
+	g_object_unref (gfile);
 
-	return TRUE;
+        return result;
 }
 
 
@@ -552,6 +512,7 @@
 	}
 
 	path_list_new (rc_dir_full_path, &files, &dirs);
+	g_free (rc_dir_full_path);
 
 	for (scan = files; scan; scan = scan->next) {
 		FileData *file = scan->data;
@@ -2683,14 +2644,14 @@
 free_cache (void)
 {
 	char  *cache_dir;
-	char  *cache_uri;
+	GFile *cache_gfile;
 	GList *files = NULL;
 	
 	cache_dir = get_cache_full_path (NULL, NULL);
-	cache_uri = get_uri_from_local_path (cache_dir);
+	cache_gfile = gfile_new (cache_dir);
 	g_free (cache_dir);
 	
-	if (path_list_new (cache_uri, &files, NULL)) {
+	if (gfile_path_list_new (cache_gfile, &files, NULL)) {
 		GList *scan;
 		for (scan = files; scan; scan = scan->next ) {
 			FileData *file = scan->data;
@@ -2698,10 +2659,10 @@
 		}
 	}
 
+	g_object_unref (cache_gfile);
 	file_data_list_free (files);
-	g_free (cache_uri);
-	
 	file_data_list_free (cache_files);
+
 	cache_files = NULL;
 	cache_used_space = 0;
 }
@@ -2724,19 +2685,19 @@
 check_cache_free_space (void)
 {
 	char  *cache_dir;
-	char  *cache_uri;
+	GFile *cache_gfile;
 	GList *scan;
 
 	cache_dir = get_cache_full_path (NULL, NULL);
-	cache_uri = get_uri_from_local_path (cache_dir);
+	cache_gfile = gfile_new (cache_dir);
 	g_free (cache_dir);
 	
 	if (! cache_loaded) {
-		if (! path_list_new (cache_uri, &cache_files, NULL)) {
+		if (! gfile_path_list_new (cache_gfile, &cache_files, NULL)) {
 			file_data_list_free (cache_files);
 			cache_files = NULL;
 			cache_loaded = FALSE;
-			g_free (cache_uri);
+			g_object_unref (cache_gfile);
 			return;
 		}
 		cache_files = g_list_sort (cache_files, comp_func_time);
@@ -2776,7 +2737,7 @@
 		debug (DEBUG_INFO, "deleted %d files, new cache size: %"GNOME_VFS_SIZE_FORMAT_STR".\n", n, cache_used_space);
 	}
 	
-	g_free (cache_uri);
+	g_object_unref (cache_gfile);
 }
 
 

Modified: trunk/libgthumb/gfile-utils.c
==============================================================================
--- trunk/libgthumb/gfile-utils.c	(original)
+++ trunk/libgthumb/gfile-utils.c	Tue Dec 23 16:29:50 2008
@@ -30,6 +30,8 @@
 #include "glib-utils.h"
 #include "gconf-utils.h"
 #include "gfile-utils.h"
+#include "file-data.h"
+#include "file-utils.h"
 
 
 /*
@@ -653,6 +655,72 @@
 }
 
 
+gboolean
+gfile_path_list_new (GFile  *gfile,
+                     GList **files,
+                     GList **dirs)
+{
+        GFileEnumerator *file_enum;
+        GFileInfo       *info;
+        GList           *f_list = NULL;
+        GList           *d_list = NULL;
+	GError		*error = NULL;
+
+        file_enum = g_file_enumerate_children (gfile,
+                                               G_FILE_ATTRIBUTE_STANDARD_NAME ","
+                                               G_FILE_ATTRIBUTE_STANDARD_TYPE,
+                                               0, NULL, &error);
+
+        if (error != NULL) {
+                gfile_warning ("Error while reading catalog folder", gfile, error);
+                g_error_free (error);
+                return FALSE;
+        }
+
+        while ((info = g_file_enumerator_next_file (file_enum, NULL, NULL)) != NULL) {
+                GFile *child;
+                char  *uri;
+
+                child = g_file_get_child (gfile, g_file_info_get_name (info));
+                uri = gfile_get_uri (child);
+
+                switch (g_file_info_get_file_type (info)) {
+                case G_FILE_TYPE_DIRECTORY:
+                        if (dirs) {
+                                d_list = g_list_prepend (d_list, g_strdup (uri));
+                        }
+                        break;
+                case G_FILE_TYPE_REGULAR:
+                        if (files) {
+                                f_list = g_list_prepend (f_list, file_data_new (uri));
+                        }
+                        break;
+                default:
+                        break;
+                }
+
+                g_object_unref (child);
+                g_object_unref (info);
+                g_free (uri);
+        }
+
+        if (dirs)
+                *dirs = g_list_reverse (d_list);
+        else
+                path_list_free (d_list);
+
+        if (files) {
+                *files = g_list_reverse (f_list);
+        }
+        else
+                file_data_list_free (f_list);
+
+        g_object_unref (file_enum);
+
+        return TRUE;
+}
+
+
 /* Xfer */
 
 static void _empty_file_progress_cb  (goffset current_num_bytes,

Modified: trunk/libgthumb/gfile-utils.h
==============================================================================
--- trunk/libgthumb/gfile-utils.h	(original)
+++ trunk/libgthumb/gfile-utils.h	Tue Dec 23 16:29:50 2008
@@ -84,7 +84,9 @@
 GFile *       gfile_get_tmp_dir                (void);
 GFile *       gfile_get_temp_dir_name          (void);
 gboolean      gfile_dir_remove_recursive       (GFile      *dir);
-
+gboolean      gfile_path_list_new              (GFile      *gfile,
+                                                GList     **files,
+                                                GList     **dirs);
 /* Xfer */
 
 gboolean      gfile_xfer                       (GFile      *sfile,



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