quick-lounge-applet r228 - in trunk: . data data/ui src



Author: paobac
Date: Fri Jan 30 19:30:52 2009
New Revision: 228
URL: http://svn.gnome.org/viewvc/quick-lounge-applet?rev=228&view=rev

Log:
2009-01-30  Paolo Bacchilega  <paobac svn gnome org>

	* configure.in: 
	* src/typedefs.h: 
	* src/quick-lounge.h: 
	* src/quick-lounge.c: 
	* src/quick-box.c: 
	* src/file-utils.h: 
	* src/file-utils.c: 
	* src/dlg-properties.c: 
	* src/dlg-pick-applications.c: 

	started port to gio.


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/data/   (props changed)
   trunk/data/ui/   (props changed)
   trunk/src/dlg-pick-applications.c
   trunk/src/dlg-properties.c
   trunk/src/file-utils.c
   trunk/src/file-utils.h
   trunk/src/quick-box.c
   trunk/src/quick-lounge.c
   trunk/src/quick-lounge.h
   trunk/src/typedefs.h

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri Jan 30 19:30:52 2009
@@ -21,7 +21,6 @@
 LIBGNOME_REQUIRED=2.4.0
 LIBGNOMEUI_REQUIRED=2.4.0
 LIBGNOME_DESKTOP_REQUIRED=2.4.0
-GNOME_VFS_REQUIRED=2.4.0
 LIBPANEL_REQUIRED=2.4.0
 LIBGNOME_MENU_REQUIRED=2.12.0
 
@@ -30,7 +29,6 @@
 AC_SUBST(LIBGNOME_REQUIRED)
 AC_SUBST(LIBGNOMEUI_REQUIRED)
 AC_SUBST(LIBGNOME_DESKTOP_REQUIRED)
-AC_SUBST(GNOME_VFS_REQUIRED)
 AC_SUBST(LIBPANEL_REQUIRED)
 AC_SUBST(LIBGNOME_MENU_REQUIRED)
 
@@ -46,8 +44,6 @@
 	gtk+-2.0 >= $GTK_REQUIRED			\
 	libgnome-2.0 >= $LIBGNOME_REQUIRED 		\
 	libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED		\
-	gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED		\
-	gnome-vfs-module-2.0				\
 	gnome-desktop-2.0 >= $LIBGNOME_DESKTOP_REQUIRED \
 	libpanelapplet-2.0 >= $LIBPANEL_REQUIRED	\
 	libgnome-menu >= $LIBGNOME_MENU_REQUIRED)

Modified: trunk/src/dlg-pick-applications.c
==============================================================================
--- trunk/src/dlg-pick-applications.c	(original)
+++ trunk/src/dlg-pick-applications.c	Fri Jan 30 19:30:52 2009
@@ -23,9 +23,6 @@
 #include <config.h>
 #include <string.h>
 #include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-directory.h>
 #include <libgnome/gnome-desktop-item.h>
 #include <libgnomeui/gnome-help.h>
 #include <libgnomeui/gnome-window-icon.h>

Modified: trunk/src/dlg-properties.c
==============================================================================
--- trunk/src/dlg-properties.c	(original)
+++ trunk/src/dlg-properties.c	Fri Jan 30 19:30:52 2009
@@ -28,7 +28,6 @@
 #include <libgnome/libgnome.h>
 #include <libgnomeui/gnome-help.h>
 #include <libgnomeui/gnome-window-icon.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
 #include "file-utils.h"
 #include "gtk-utils.h"
 #include "quick-lounge.h"
@@ -633,8 +632,13 @@
 			    -1);
 
 	uri = g_object_get_data (G_OBJECT (button), "uri");
-	if (uri != NULL)
-		gnome_vfs_unlink (uri);
+	if (uri != NULL) {
+		GFile *file;
+		
+		file = g_file_new_for_uri (uri);
+		g_file_delete (file, NULL, NULL);
+		g_object_unref (file);
+	}
 
 	gtk_container_remove (GTK_CONTAINER (data->quick_box), button);
 	gtk_list_store_remove (GTK_LIST_STORE (data->model), &iter);

Modified: trunk/src/file-utils.c
==============================================================================
--- trunk/src/file-utils.c	(original)
+++ trunk/src/file-utils.c	Fri Jan 30 19:30:52 2009
@@ -20,487 +20,316 @@
  *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
  */
 
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <dirent.h>
-
-#include <glib.h>
+#include <config.h>
 #include <glib/gi18n.h>
-#include <libgnome/libgnome.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <libgnomevfs/gnome-vfs-handle.h>
-#include <libgnomevfs/gnome-vfs-mime.h>
-#include <libgnomevfs/gnome-vfs-result.h>
-#include <gconf/gconf-client.h>
 #include "file-utils.h"
 
 
-#define BUF_SIZE 4096
-
 /* -- path_list_async_new implementation -- */
 
-PathListData * 
-path_list_data_new ()
-{
-	PathListData *pli;
 
-	pli = g_new0 (PathListData, 1);
-
-	pli->uri = NULL;
-	pli->result = GNOME_VFS_OK;
-	pli->files = NULL;
-	pli->dirs = NULL;
-	pli->done_func = NULL;
-	pli->data = NULL;
-
-	return pli;
-}
+typedef struct {
+	GFile            *directory;
+	GCancellable     *cancellable;
+	PathListDoneFunc  done_func;
+	gpointer          done_data;
+	GList            *dirs;
+	GList            *files;
+	GError           *error;
+} PathListData;
 
 
 void 
 path_list_data_free (PathListData *pli)
 {
-	g_return_if_fail (pli != NULL);
-
-	if (pli->uri != NULL)
-		gnome_vfs_uri_unref (pli->uri);
-
-	if (pli->files != NULL) {
-		g_list_foreach (pli->files, (GFunc) g_free, NULL);
-		g_list_free (pli->files);
-	}
-
-	if (pli->dirs != NULL) {
-		g_list_foreach (pli->dirs, (GFunc) g_free, NULL);
-		g_list_free (pli->dirs);
-	}
-
+	g_object_unref (pli->directory);
+	path_list_free (pli->dirs);
+	path_list_free (pli->files);
 	g_free (pli);
 }
 
 
-void
-path_list_handle_free (PathListHandle *handle)
+void 
+path_list_async_done (PathListData *pli)
 {
-	if (handle->pli_data != NULL)
-		path_list_data_free (handle->pli_data);
-	g_free (handle);
+	if (pli->done_func != NULL)	
+		pli->done_func (pli->dirs, pli->files, pli->error, pli->done_data);
+	path_list_data_free (pli);
 }
 
 
 static void
-directory_load_cb (GnomeVFSAsyncHandle *handle,
-		   GnomeVFSResult result,
-		   GList *list,
-		   guint entries_read,
-		   gpointer data)
-{
-	PathListData *pli;
-	GList *node;
+path_list_close_enumerator_cb (GObject      *source_object,
+	              	       GAsyncResult *result,
+		      	       gpointer      user_data)
+{
+	GFileEnumerator *enumerator = (GFileEnumerator *) source_object;
+	PathListData    *pli = user_data;
+	GError          *error = NULL;
+
+	if (! g_file_enumerator_close_finish (enumerator, result, &error)) {
+		if (pli->error == NULL)
+			pli->error = g_error_copy (error);
+		else
+			g_clear_error (&error);
+	}
 
-	pli = (PathListData *) data;
-	pli->result = result;
+	path_list_async_done (pli);
+}
 
-	for (node = list; node != NULL; node = node->next) {
-		GnomeVFSFileInfo * info     = node->data;
-		GnomeVFSURI *      full_uri = NULL;
-		gchar *            str_uri;
-		gchar *            unesc_uri;
-
-		switch (info->type) {
-		case GNOME_VFS_FILE_TYPE_REGULAR:
-			full_uri = gnome_vfs_uri_append_file_name (pli->uri, info->name);
-			str_uri = gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE);
-			unesc_uri = gnome_vfs_unescape_string (str_uri, NULL);
 
-			pli->files = g_list_prepend (pli->files, unesc_uri);
-			g_free (str_uri);
-			break;
-
-		case GNOME_VFS_FILE_TYPE_DIRECTORY:
-			if (SPECIAL_DIR (info->name))
-				break;
-
-			full_uri = gnome_vfs_uri_append_path (pli->uri, info->name);
-			str_uri = gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE);
-			unesc_uri = gnome_vfs_unescape_string (str_uri, NULL);
+static void
+path_list_files_ready_cb (GObject      *source_object,
+			  GAsyncResult *result,
+			  gpointer      user_data)
+{
+	GFileEnumerator *enumerator = (GFileEnumerator *) source_object;
+	PathListData    *pli = user_data;
+	GList           *children, *scan;
+
+	pli->error = NULL;
+	children = g_file_enumerator_next_files_finish (enumerator,
+                                                        result,
+                                                        &(pli->error));
+
+	if (children == NULL) {
+		g_file_enumerator_close_async (enumerator,
+					       G_PRIORITY_DEFAULT,
+					       pli->cancellable,
+					       path_list_close_enumerator_cb,
+					       pli);
+		return;
+	}
 
-			pli->dirs = g_list_prepend (pli->dirs,  unesc_uri);
-			g_free (str_uri);
+	for (scan = children; scan; scan = scan->next) {
+		GFileInfo *info = scan->data;
+		GFile     *file;
+		
+		file = g_file_get_child (pli->directory, g_file_info_get_name (info));
+		if (file == NULL)
+			continue;
+			
+		switch (g_file_info_get_file_type (info)) {
+		case G_FILE_TYPE_DIRECTORY:
+			pli->dirs = g_list_prepend (pli->dirs, g_file_get_uri (file));
+			break;
+		case G_FILE_TYPE_REGULAR:
+			pli->files = g_list_prepend (pli->files, g_file_get_uri (file));
 			break;
-
 		default:
 			break;
 		}
-
-		if (full_uri)
-			gnome_vfs_uri_unref (full_uri);
+		
+		g_object_unref (file);
 	}
 
-	if ((result == GNOME_VFS_ERROR_EOF) 
-	    || (result != GNOME_VFS_OK)) {
-		if (pli->done_func) 
-			/* pli is deallocated in pli->done_func */
-			pli->done_func (pli, pli->data);
-		else
-			path_list_data_free (pli);
+	g_file_enumerator_next_files_async (enumerator,
+                                            128,
+                                            G_PRIORITY_DEFAULT,
+                                            pli->cancellable,
+                                            path_list_files_ready_cb,
+                                            pli);
+}
 
+
+static void
+path_list_ready_cb (GObject      *source_object,
+		    GAsyncResult *result,
+		    gpointer      user_data)
+{
+	PathListData    *pli = user_data;
+	GFileEnumerator *enumerator;
+
+	enumerator = g_file_enumerate_children_finish (G_FILE (source_object), result, &(pli->error));
+	if (enumerator == NULL) {
+		path_list_async_done (pli);
 		return;
-	} 
+	}
+
+	g_file_enumerator_next_files_async (enumerator,
+                                            128,
+                                            G_PRIORITY_DEFAULT,
+                                            pli->cancellable,
+                                            path_list_files_ready_cb,
+                                            pli);
 }
 
 
-PathListHandle *
+void
 path_list_async_new (const gchar      *uri, 
+		     GCancellable     *cancellable,
 		     PathListDoneFunc  f,
 		     gpointer         data)
 {
-	GnomeVFSAsyncHandle *handle;
 	PathListData *pli;
-	PathListHandle *pl_handle;
-
-	pli = path_list_data_new ();
-
-	pli->uri = gnome_vfs_uri_new (uri);
-
+	
+	pli = g_new0 (PathListData, 1);
+	pli->directory = g_file_new_for_uri (uri);
+	pli->cancellable = cancellable;
 	pli->done_func = f;
-	pli->data = data;
-
-	gnome_vfs_async_load_directory_uri (
-		&handle,
-		pli->uri,
-		GNOME_VFS_FILE_INFO_FOLLOW_LINKS,
-		128 /* items_per_notification FIXME */,
-		GNOME_VFS_PRIORITY_DEFAULT,
-		directory_load_cb,
-		pli);
-
-	pl_handle = g_new (PathListHandle, 1);
-	pl_handle->vfs_handle = handle;
-	pl_handle->pli_data = pli;
-
-	return pl_handle;
-}
-
-
-void
-path_list_async_interrupt (PathListHandle *handle)
-{
-	gnome_vfs_async_cancel (handle->vfs_handle);
-	path_list_data_free (handle->pli_data);
-	g_free (handle);
-}
-
-
-gboolean
-path_is_file (const gchar *path)
-{
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult result;
-	gboolean is_file;
-	gchar *escaped;
-
-	if (! path || ! *path) return FALSE; 
-
-	info = gnome_vfs_file_info_new ();
-	escaped = gnome_vfs_escape_path_string (path);
-	result = gnome_vfs_get_file_info (escaped, 
-					  info, 
-					  (GNOME_VFS_FILE_INFO_DEFAULT 
-					   | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
-	is_file = FALSE;
-	if (result == GNOME_VFS_OK)		
-		is_file = (info->type == GNOME_VFS_FILE_TYPE_REGULAR);
+	pli->done_data = data;
 	
-	g_free (escaped);
-	gnome_vfs_file_info_unref (info);
-
-	return is_file;
+	g_file_enumerate_children_async (pli->directory,
+					 "standard::*", 
+					 G_FILE_QUERY_INFO_NONE,
+					 G_PRIORITY_DEFAULT,
+                                         pli->cancellable,
+					 path_list_ready_cb,
+					 pli);	
 }
 
 
-gboolean
-path_is_dir (const gchar *path)
+static gboolean
+uri_is_filetype (const char *uri,
+		 GFileType   file_type)
 {
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult result;
-	gboolean is_dir;
-	gchar *escaped;
-
-	if (! path || ! *path) return FALSE; 
-
-	info = gnome_vfs_file_info_new ();
-	escaped = gnome_vfs_escape_path_string (path);
-	result = gnome_vfs_get_file_info (escaped, 
-					  info, 
-					  (GNOME_VFS_FILE_INFO_DEFAULT 
-					   | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
-	is_dir = FALSE;
-	if (result == GNOME_VFS_OK)
-		is_dir = (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY);
-	
-	g_free (escaped);
-	gnome_vfs_file_info_unref (info);
+	gboolean   result = FALSE;
+	GFile     *file;
+	GFileInfo *info;
+	GError    *error = NULL;
 
-	return is_dir;
-}
-
-
-gboolean
-dir_is_empty (const gchar *path)
-{
-	DIR *dp;
-	int n;
+	file = g_file_new_for_uri (uri);
 
-	if (strcmp (path, "/") == 0)
+	if (! g_file_query_exists (file, NULL)) {
+		g_object_unref (file);
 		return FALSE;
-
-	dp = opendir (path);
-	n = 0;
-	while (readdir (dp) != NULL) {
-		n++;
-		if (n > 2) {
-			closedir (dp);
-			return FALSE;
-		}
 	}
-	closedir (dp);
 
-	return TRUE;
-}
-
-
-GnomeVFSFileSize 
-get_file_size (const gchar *path)
-{
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult result;
-	GnomeVFSFileSize size;
-	gchar *escaped;
-
-	if (! path || ! *path) return 0; 
-
-	info = gnome_vfs_file_info_new ();
-	escaped = gnome_vfs_escape_path_string (path);
-	result = gnome_vfs_get_file_info (escaped, 
-					  info,
-					  (GNOME_VFS_FILE_INFO_DEFAULT 
-					   | GNOME_VFS_FILE_INFO_FOLLOW_LINKS)); 
-	size = 0;
-	if (result == GNOME_VFS_OK)
-		size = info->size;
+	info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, NULL, &error);
+	if (error == NULL) {
+		result = (g_file_info_get_file_type (info) == file_type);
+	}
+	else {
+		g_warning ("Failed to get file type for uri %s: %s", uri, error->message);
+		g_error_free (error);
+	}
 
-	g_free (escaped);
-	gnome_vfs_file_info_unref (info);
+	g_object_unref (info);
+	g_object_unref (file);
 
-	return size;
+	return result;
 }
 
 
-time_t 
-get_file_mtime (const gchar *path)
+gboolean
+uri_is_file (const char *uri)
 {
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult result;
-	gchar *escaped;
-	time_t mtime;
-
-	if (! path || ! *path) return 0; 
-
-	info = gnome_vfs_file_info_new ();
-	escaped = gnome_vfs_escape_path_string (path);
-	result = gnome_vfs_get_file_info (escaped, 
-					  info, 
-					  (GNOME_VFS_FILE_INFO_DEFAULT 
-					   | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
-	mtime = 0;
-	if (result == GNOME_VFS_OK)
-		mtime = info->mtime;
-
-	g_free (escaped);
-	gnome_vfs_file_info_unref (info);
-
-	return mtime;
+	return uri_is_filetype (uri, G_FILE_TYPE_REGULAR);
 }
 
 
-time_t 
-get_file_ctime (const gchar *path)
+gboolean
+uri_is_dir (const char *uri)
 {
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult result;
-	gchar *escaped;
-	time_t ctime;
-
-	if (! path || ! *path) return 0; 
-
-	info = gnome_vfs_file_info_new ();
-	escaped = gnome_vfs_escape_path_string (path);
-	result = gnome_vfs_get_file_info (escaped, 
-					  info, 
-					  (GNOME_VFS_FILE_INFO_DEFAULT 
-					   | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
-	ctime = 0;
-	if (result == GNOME_VFS_OK)
-		ctime = info->ctime;
-
-	g_free (escaped);
-	gnome_vfs_file_info_unref (info);
-
-	return ctime;
+	return uri_is_filetype (uri, G_FILE_TYPE_DIRECTORY);
 }
 
 
-void
-set_file_mtime (const gchar *path,
-		time_t       mtime)
+gboolean
+path_is_dir (const char *path)
 {
-	GnomeVFSFileInfo *file_info;
-	char             *escaped_path;
+	char     *uri;
+	gboolean  result;
+
+	uri = g_filename_to_uri (path, NULL, NULL);
+	result = uri_is_dir (uri);
+	g_free (uri);
 
-	file_info = gnome_vfs_file_info_new ();
-	file_info->mtime = mtime;
-	file_info->atime = mtime;
-
-	escaped_path = gnome_vfs_escape_path_string (path);
-	gnome_vfs_set_file_info (escaped_path,
-				 file_info,
-				 GNOME_VFS_SET_FILE_INFO_TIME);
-	gnome_vfs_file_info_unref (file_info);
-	g_free (escaped_path);
+	return result;
 }
 
 
 gboolean 
-file_copy (const char *from, 
-	   const char *to)
-{
-	GnomeVFSURI      *src_uri, *dest_uri;
-	GnomeVFSResult    result;
-
-	src_uri = gnome_vfs_uri_new (from);
-	dest_uri = gnome_vfs_uri_new (to);
-
-	result = gnome_vfs_xfer_uri (src_uri, dest_uri,
-				     (GNOME_VFS_XFER_RECURSIVE 
-				      | GNOME_VFS_XFER_FOLLOW_LINKS),
-				     GNOME_VFS_XFER_ERROR_MODE_ABORT,
-				     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
-				     NULL,
-				     NULL);
-
-	if (result != GNOME_VFS_OK) {
-#ifdef DEBUG
-		g_print ("ERROR : %s\n", gnome_vfs_result_to_string (result));
-#endif
-	}
+file_copy (const char *source_uri, 
+	   const char *destination_uri)
+{	
+	GFile    *source;
+	GFile    *destination;
+	gboolean  result;
 	
-	return (result == GNOME_VFS_OK);
-}
-
-
-gboolean
-file_move (const gchar *from, 
-	   const gchar *to)
-{
-	if (file_copy (from, to) && ! unlink (from))
-		return TRUE;
-
-	return FALSE;
+	source = g_file_new_for_uri (source_uri);
+	destination = g_file_new_for_uri (destination_uri);
+	
+	result = g_file_copy (source, destination, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
+	
+	g_object_unref (source);
+	g_object_unref (destination);
+	
+	return result;
 }
 
 
 gboolean 
-path_list_new (const char  *text_uri, 
+path_list_new (const char  *uri, 
 	       GList      **files, 
 	       GList      **dirs)
 {
-	GnomeVFSResult  result;
-	GList          *list;
-	GnomeVFSURI    *uri;
-	GList          *node;	
-	GList          *file_list = NULL, *dir_list = NULL;
-
-	result = gnome_vfs_directory_list_load (&list, text_uri, GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
-
-	if (result != GNOME_VFS_OK) {
-		if (files)
-			*files = NULL;
-		if (dirs)
-			*dirs = NULL;
+	GFile           *directory;
+	GFileEnumerator *enumerator;
+	GFileInfo       *info;
+	
+	directory = g_file_new_for_uri (uri);
+	enumerator = g_file_enumerate_children (directory, 
+						"standard::*", 
+						G_FILE_QUERY_INFO_NONE,
+						NULL,
+						NULL);
+	
+	if (enumerator == NULL) {
+		g_object_unref (directory);
 		return FALSE;
-	}
+	} 
+			
+	while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
+		GFile *file;
 		
-	uri = gnome_vfs_uri_new (text_uri);
-
-	for (node = list; node != NULL; node = node->next) {
-		GnomeVFSFileInfo * info     = node->data;
-		GnomeVFSURI *      full_uri = NULL;
-		char *             str_uri;
-		char *             unesc_uri;
-
-#ifdef DEBUG
-		g_print ("--> %s\n", info->name);
-#endif
-
-		switch (info->type) {
-		case GNOME_VFS_FILE_TYPE_REGULAR:
-			full_uri = gnome_vfs_uri_append_file_name (uri, info->name);
-			str_uri = gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE);
-			unesc_uri = gnome_vfs_unescape_string (str_uri, NULL);
-
-#ifdef DEBUG
-			g_print ("--> %s\n", unesc_uri);
-#endif
-
-			file_list = g_list_prepend (file_list, unesc_uri);
-			g_free (str_uri);
+		file = g_file_get_child (directory, g_file_info_get_name (info));
+		if (file == NULL)
+			continue;
+			
+		switch (g_file_info_get_file_type (info)) {
+		case G_FILE_TYPE_DIRECTORY:
+			if (dirs != NULL)
+				*dirs = g_list_prepend (*dirs, g_file_get_uri (file));
 			break;
-
-		case GNOME_VFS_FILE_TYPE_DIRECTORY:
-			if (SPECIAL_DIR (info->name))
-				break;
-
-			full_uri = gnome_vfs_uri_append_path (uri, info->name);
-			str_uri = gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE);
-			unesc_uri = gnome_vfs_unescape_string (str_uri, NULL);
-
-			dir_list = g_list_prepend (dir_list, unesc_uri);
-			g_free (str_uri);
+		case G_FILE_TYPE_REGULAR:
+			if (files != NULL)
+				*files = g_list_prepend (*files, g_file_get_uri (file));
 			break;
-
 		default:
 			break;
 		}
-
-		if (full_uri)
-			gnome_vfs_uri_unref (full_uri);
+		
+		g_object_unref (file);
+		g_object_unref (info);
 	}
 	
-	gnome_vfs_uri_unref (uri);
+	if (dirs != NULL) 
+		*dirs = g_list_reverse (*dirs);
 
-	if (dirs) 
-		*dirs = g_list_reverse (dir_list);
-	else
-		path_list_free (dir_list);
-
-	if (files) 
-		*files = g_list_reverse (file_list);
-	else
-		path_list_free (file_list);
+	if (files != NULL) 
+		*files = g_list_reverse (*files);
+	
+	g_object_unref (enumerator);
+	g_object_unref (directory);
 
 	return TRUE;
 }
 
 
+GList *
+path_list_dup (GList *list)
+{
+	GList *new_list = NULL;
+	GList *scan;
+	
+	for (scan = list; scan; scan = scan->next)
+		new_list = g_list_prepend (new_list, g_strdup ((char *) scan->data));
+		
+	return g_list_reverse (new_list);
+}
+
+
 void 
 path_list_free (GList *list)
 {
@@ -511,71 +340,8 @@
 }
 
 
-gboolean 
-file_is_hidden (const gchar *name)
-{
-	if (name[0] != '.') return FALSE;
-	if (name[1] == '\0') return FALSE;
-	if ((name[1] == '.') && (name[2] == '\0')) return FALSE;
-
-	return TRUE;
-}
-
-
-gboolean
-file_is_image (const gchar *name,
-	       gboolean     fast_file_type)
-{
-	const char *result;
-	gboolean    is_an_image;
-
-	if (fast_file_type)
-		result = gnome_vfs_mime_type_from_name_or_default (name, NULL);
-	else 
-		result = gnome_vfs_get_file_mime_type (name, NULL, FALSE);
-
-	/* Unknown file type. */
-	if (result == NULL)
-		return FALSE;
-
-	/* If the description contains the word 'image' than we suppose 
-	 * it is an image that gdk-pixbuf can load. */
-	is_an_image = strstr (result, "image") != NULL;
-
-	return is_an_image;
-}
-
-
-gboolean
-file_extension_is (const char *filename, 
-		   const char *ext)
-{
-	return ! strcasecmp (filename + strlen (filename) - strlen (ext), ext);
-}
-
-
-long 
-checksum_simple (const gchar *path)
-{
-	FILE *f;
-	long sum = 0;
-	gint c;
-
-	f = fopen (path, "r");
-	if (!f) return -1;
-
-	while ((c = fgetc (f)) != EOF)
-		sum += c;
-	fclose (f);
-
-	return sum;
-}
-
-
-/* like g_basename but does not warns about NULL and does not
- * alloc a new string. */
-G_CONST_RETURN gchar *
-file_name_from_path (const gchar *file_name)
+const char *
+file_name_from_path (const char *file_name)
 {
 	register gssize base;
         register gssize last_char;
@@ -599,440 +365,171 @@
 }
 
 
-gchar *
-remove_level_from_path (const gchar *path)
+gboolean
+make_directory_tree (GFile    *dir,
+		     mode_t    mode,
+		     GError  **error)
 {
-	gchar *new_path;
-	const gchar *ptr = path;
-	gint p;
-
-	if (! path) 
-		return NULL;
-
-	p = strlen (path) - 1;
-	if (p < 0) 
-		return NULL;
-
-	while ((p > 0) && (ptr[p] != '/')) 
-		p--;
-	if ((p == 0) && (ptr[p] == '/')) 
-		p++;
-	new_path = g_strndup (path, (guint)p);
-
-	return new_path;
-}
+	gboolean  success = TRUE;
+	GFile    *parent;
 
+	if ((dir == NULL) || g_file_query_exists (dir, NULL))
+		return TRUE;
 
-gchar *
-remove_extension_from_path (const gchar *path)
-{
-	gchar *new_path;
-	gint len;
-	const gchar *ptr = path;
-	gint p;
+	parent = g_file_get_parent (dir);
+	if (parent != NULL) {
+		success = make_directory_tree (parent, mode, error);
+		g_object_unref (parent);
+		if (! success)
+			return FALSE;
+	}
 
-	if (! path) 
-		return NULL;
-	len = strlen (path);
-	if (len == 1) 
-		return g_strdup (path);
+	success = g_file_make_directory (dir, NULL, error);
+	if ((error != NULL) && (*error != NULL) && g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+		g_clear_error (error);
+		success = TRUE;
+	}
 
-	p = len - 1;
-	while ((ptr[p] != '.') && (p > 0)) p--;
-	if (p == 0) 
-		p = len;
-	new_path = g_strndup (path, (guint) p);
+	if (success)
+		g_file_set_attribute_uint32 (dir,
+					     G_FILE_ATTRIBUTE_UNIX_MODE,
+					     mode,
+					     0,
+					     NULL,
+					     NULL);
 
-	return new_path;
+	return success;
 }
 
 
-gchar * 
-remove_ending_separator (const gchar *path)
+gboolean
+ensure_dir_exists (const char  *uri,
+		   mode_t       mode,
+		   GError     **error)
 {
-	gint len, copy_len;
-
-	if (path == NULL)
-		return NULL;
+	GFile  *dir;
+	GError *priv_error = NULL;
 
-	copy_len = len = strlen (path);
-	if ((len > 1) && (path[len - 1] == '/')) 
-		copy_len--;
-
-	return g_strndup (path, copy_len);
-}
-
-
-gboolean 
-ensure_dir_exists (const gchar *a_path, 
-		   mode_t mode)
-{
-	if (! a_path) return FALSE;
+	if (uri == NULL)
+		return FALSE;
 
-	if (! path_is_dir (a_path)) {
-		char *path = g_strdup (a_path);
-		char *p    = path;
-
-		while (*p != '\0') {
-			p++;
-			if ((*p == '/') || (*p == '\0')) {
-				gboolean end;
-				
-				if (*p != '\0') {
-					*p = '\0';
-					end = FALSE;
-				} else
-					end = TRUE;
-			
-				if (! path_is_dir (path)) {
-					if (mkdir (path, mode) < 0) {
-						g_warning ("directory creation failed: %s.", path);
-						g_free (path);
-						return FALSE;
-					}
-				}
+	if (error == NULL)
+		error = &priv_error;
 
-				if (! end) *p = '/';
-			}
-		}
-		
-		g_free (path);
+	dir = g_file_new_for_uri (uri);
+	if (! make_directory_tree (dir, mode, error)) {
+		g_warning ("could create directory %s: %s", uri, (*error)->message);
+		if (priv_error != NULL)
+			g_clear_error (&priv_error);
+		return FALSE;
 	}
 
 	return TRUE;
 }
 
 
-GList *
-dir_list_filter_and_sort (GList *dir_list, 
-			  gboolean names_only,
-			  gboolean show_dot_files)
-{
-	GList *filtered;
-	GList *scan;
-
-	/* Apply filters on dir list. */
-	filtered = NULL;
-	scan = dir_list;
-	while (scan) {
-		const gchar *name_only = file_name_from_path (scan->data);
-
-		if (! (file_is_hidden (name_only) && ! show_dot_files)) {
-			gchar *s;
-			gchar *path = (gchar*) scan->data;
-			
-			s = g_strdup (names_only ? name_only : path);
-			filtered = g_list_prepend (filtered, s);
-		}
-		scan = scan->next;
-	}
-	filtered = g_list_sort (filtered, (GCompareFunc) strcasecmp);
-
-	return filtered;
-}
-
-
-/* characters to escape */
-static gchar bad_char[] = { '$', '\'', '`', '"', '\\', '!', '?', '*',
-			    ' ', '(', ')', '[', ']', '&', '|', '@' , '#',
-			    ';' };
-
-/* the size of bad_char */
-static const gint bad_chars = sizeof (bad_char) / sizeof (gchar);
-
-
-/* counts how many characters to escape in @str. */
-static gint
-count_chars_to_escape (const gchar *str)
-{
-	const gchar *s;
-	gint i, n;
-
-	n = 0;
-	for (s = str; *s != 0; s++)
-		for (i = 0; i < bad_chars; i++)
-			if (*s == bad_char[i]) {
-				n++;
-				break;
-			}
-	return n;
-}
-
-
-/* escape with backslash the file name. */
-gchar*
-shell_escape (const gchar *filename)
-{
-	gchar *escaped;
-	gint i, new_l;
-	const gchar *s;
-	gchar *t;
-
-	if (filename == NULL) 
-		return NULL;
-
-	new_l = strlen (filename) + count_chars_to_escape (filename);
-	escaped = g_malloc (new_l + 1);
-
-	s = filename;
-	t = escaped;
-	while (*s) {
-		gboolean is_bad;
-	
-		is_bad = FALSE;
-		for (i = 0; (i < bad_chars) && !is_bad; i++)
-			is_bad = (*s == bad_char[i]);
-
-		if (is_bad)
-			*t++ = '\\';
-		*t++ = *s++;
-	}
-	*t = 0;
+gboolean
+make_directory_tree_from_path (const char  *path,
+		   	       mode_t       mode,
+		   	       GError     **error)
+{
+	char     *uri;
+	gboolean  result;
+
+	uri = g_filename_to_uri (path, NULL, NULL);
+	result = ensure_dir_exists (uri, mode, error);
+	g_free (uri);
 
-	return escaped;
+	return result;
 }
 
 
-static gchar *
-get_terminal ()
+char *
+get_unique_desktop_file (const char *base_dir)
 {
-	GConfClient *client;
-	gchar *result;
-	gchar *terminal = NULL;
-	gchar *exec_flag = NULL;
-
-	client = gconf_client_get_default ();
-	terminal = gconf_client_get_string (client, "/desktop/gnome/applications/terminal/exec", NULL);
-	g_object_unref (G_OBJECT (client));
+	static int n = 0;
 	
-	if (terminal) 
-		exec_flag = gconf_client_get_string (client, "/desktop/gnome/applications/terminal/exec_arg", NULL);
+	while (TRUE) {
+		char  *path;
+		char  *name;
 
-	if (terminal == NULL) {
-		char *check;
+		name = g_strdup_printf ("QL.%d.%d.desktop", getpid (), n++);
+		path = g_build_filename (base_dir, name, NULL);
+		g_free (name);
 
-		check = g_find_program_in_path ("gnome-terminal");
-		if (check != NULL) {
-			terminal = check;
-			/* Note that gnome-terminal takes -x and
-			 * as -e in gnome-terminal is broken we use that. */
-			exec_flag = g_strdup ("-x");
-		} else {
-			if (check == NULL)
-				check = g_find_program_in_path ("nxterm");
-			if (check == NULL)
-				check = g_find_program_in_path ("color-xterm");
-			if (check == NULL)
-				check = g_find_program_in_path ("rxvt");
-			if (check == NULL)
-				check = g_find_program_in_path ("xterm");
-			if (check == NULL)
-				check = g_find_program_in_path ("dtterm");
-			if (check == NULL) {
-				g_warning (_("Cannot find a terminal, using "
-					     "xterm, even if it may not work"));
-				check = g_strdup ("xterm");
-			}
-			terminal = check;
-			exec_flag = g_strdup ("-e");
-		}
+		if (! g_file_test (path, G_FILE_TEST_EXISTS))
+			return path;
+		g_free (path);
 	}
-
-	if (terminal == NULL)
-		return NULL;
-
-	result = g_strconcat (terminal, " ", exec_flag, NULL);
-	return result;
 }
 
 
-gchar *
-application_get_command (const GnomeVFSMimeApplication *app)
-{
-	char *command;
-
-	if (app->requires_terminal) {
-		char *terminal;
-		char *command_to_exec;
-
-		terminal = get_terminal ();
-		if (terminal == NULL)
-			return NULL;
-
-		command_to_exec = shell_escape (app->command);
-		command = g_strconcat (terminal,
-				       " ",
-				       command_to_exec,
-				       NULL);
-		g_free (terminal);
-		g_free (command_to_exec);
-	} else
-		command = shell_escape (app->command);
-
-	return command;
-}
+GHashTable *static_strings = NULL;
 
 
-/* example 1 : filename = /xxx/yyy/zzz/foo 
- *             destdir  = /xxx/www 
- *             return   : ../yyy/zzz/foo
- *
- * example 2 : filename = /xxx/yyy/foo
- *             destdir  = /xxx
- *             return   : yyy/foo
- */
-char *
-get_path_relative_to_dir (const char *filename, 
-			  const char *destdir)
+const char *
+get_static_string (const char *s)
 {
-	char     *sourcedir;
-	char    **sourcedir_v;
-	char    **destdir_v;
-	int       i, j;
-	char     *result;
-	GString  *relpath;
-
-	sourcedir = remove_level_from_path (filename);
-	sourcedir_v = g_strsplit (sourcedir, "/", 0);
-	destdir_v = g_strsplit (destdir, "/", 0);
-
-	relpath = g_string_new (NULL);
-
-	i = 0;
-	while ((sourcedir_v[i] != NULL)
-	       && (destdir_v[i] != NULL)
-	       && (strcmp (sourcedir_v[i], destdir_v[i]) == 0))
-		i++;
-	
-	j = i;
-
-	while (destdir_v[i++] != NULL) 
-		g_string_append (relpath, "../");
-
-	while (sourcedir_v[j] != NULL) {
-		g_string_append (relpath, sourcedir_v[j]);
-		g_string_append_c (relpath, '/');
-		j++;
-	}
+        const char *result;
 
-	g_string_append (relpath, file_name_from_path (filename));
+        if (s == NULL)
+                return NULL;
 
-	g_strfreev (sourcedir_v);
-	g_strfreev (destdir_v);
-	g_free (sourcedir);
+        if (static_strings == NULL)
+                static_strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
-	result = relpath->str;
-	g_string_free (relpath, FALSE);
+        if (! g_hash_table_lookup_extended (static_strings, s, (gpointer*) &result, NULL)) {
+                result = g_strdup (s);
+                g_hash_table_insert (static_strings,
+                                     (gpointer) result,
+                                     GINT_TO_POINTER (1));
+        }
 
-	return result;
+        return result;
 }
 
 
-/*
- * example 1) input : "/xxx/yyy/.."         output : "/xxx"
- * example 2) input : "/xxx/yyy/../www"     output : "/xxx/www"
- * example 3) input : "/xxx/../yyy/../www"  output : "/www"
- * example 4) input : "/xxx/../yyy/../"     output : "/"
- * example 5) input : "/xxx/./"             output : "/xxx"
- * example 6) input : "/xxx/./yyy"          output : "/xxx/yyy"
- *
- * Note : PATH must be absolute.
- */
-char *
-remove_special_dirs_from_path (const char *path)
-{
-	char    **pathv;
-	GList    *list = NULL, *scan;
-	int       i;
-	GString  *result_s;
-	char     *result;
-
-	if ((path == NULL) || (*path != '/'))
-		return NULL;
-
-	if (strstr (path, ".") == NULL)
-		return g_strdup (path);
-
-	pathv = g_strsplit (path, "/", 0);
-
-	/* start from 1 to remove the first / that will be readded later. */
-	for (i = 1; pathv[i] != NULL; i++) {
-		if (strcmp (pathv[i], ".") == 0) {
-			/* nothing to do. */
-		} else if (strcmp (pathv[i], "..") == 0) {
-			if (list == NULL) {
-				/* path error. */
-				g_strfreev (pathv);
-				return NULL;
-			}
-			list = g_list_delete_link (list, list);
-		} else 
-			list = g_list_prepend (list, pathv[i]);
+const char*
+get_file_mime_type (const char *uri,
+                    gboolean    fast_file_type)
+{
+	GFile      *file;
+	GFileInfo  *info;
+	GError     *err = NULL;
+ 	const char *result = NULL;
+
+ 	file = g_file_new_for_uri (uri);
+	info = g_file_query_info (file,
+				  fast_file_type ?
+				  G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE :
+				  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+				  0, NULL, &err);
+	if (info == NULL) {
+		g_warning ("could not get content type for %s: %s", uri, err->message);
+		g_clear_error (&err);
 	}
-
-	result_s = g_string_new (NULL);
-	if (list == NULL)
-		g_string_append_c (result_s, '/');
 	else {
-		list = g_list_reverse (list);
-		for (scan = list; scan; scan = scan->next) {
-			g_string_append_c (result_s, '/');
-			g_string_append (result_s, scan->data);
-		}
+		result = get_static_string (g_file_info_get_content_type (info));
+		g_object_unref (info);
 	}
-	result = result_s->str;
-	g_string_free (result_s, FALSE);
-	g_strfreev (pathv);
 
-	return result;
-}
+	g_object_unref (file);
 
-
-char *
-get_unique_desktop_file (const char *base_dir)
-{
-	static int n = 0;
-	
-	while (TRUE) {
-		char  *path;
-		char  *name;
-
-		name = g_strdup_printf ("QL.%d.%d.desktop", getpid (), n++);
-		path = g_build_filename (base_dir, name, NULL);
-		g_free (name);
-
-		if (! g_file_test (path, G_FILE_TEST_EXISTS))
-			return path;
-		g_free (path);
-	}
+	return result;
 }
 
 
 gboolean
 is_desktop_file (const char *uri)
 {
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult    result;
-	gboolean          is_desktop = TRUE;
-
-	g_return_val_if_fail (uri != NULL, FALSE);
-
-	info = gnome_vfs_file_info_new ();
-
-	result = gnome_vfs_get_file_info (uri, info,
-                                          (GNOME_VFS_FILE_INFO_FOLLOW_LINKS 
-					   | GNOME_VFS_FILE_INFO_GET_MIME_TYPE
-					   | GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE));
-
-	if (result != GNOME_VFS_OK) 
-		is_desktop = FALSE;
-	else if ((strcmp (info->mime_type, "application/x-gnome-app-info") != 0)
-		 && (strcmp (info->mime_type, "application/x-desktop") != 0)) 
-		is_desktop = FALSE;
-	
-	gnome_vfs_file_info_unref (info);
+	const char *mime_type;
 	
-	return is_desktop;
+	mime_type = get_file_mime_type (uri, FALSE);
+	if (mime_type == NULL)
+		return FALSE;
+
+	return ((strcmp (mime_type, "application/x-gnome-app-info") == 0)
+		|| (strcmp (mime_type, "application/x-desktop") == 0)); 
 }
 
 

Modified: trunk/src/file-utils.h
==============================================================================
--- trunk/src/file-utils.h	(original)
+++ trunk/src/file-utils.h	Fri Jan 30 19:30:52 2009
@@ -3,7 +3,7 @@
 /*
  *  Quick Lounge Applet
  *
- *  Copyright (C) 2001 The Free Software Foundation, Inc.
+ *  Copyright (C) 2001-2009 The Free Software Foundation, Inc.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -25,123 +25,38 @@
 
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <time.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-result.h>
-#include <libgnomevfs/gnome-vfs-file-size.h>
-#include <libgnomevfs/gnome-vfs-async-ops.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
+#include <glib.h>
+#include <gio/gio.h>
 #include "typedefs.h"
 
-#define SPECIAL_DIR(x) (! strcmp (x, "..") || ! strcmp (x, "."))
-
-typedef struct _PathListData PathListData;
-
-typedef void (*PathListDoneFunc) (PathListData *dld, gpointer data);
-
-struct _PathListData {
-	GnomeVFSURI *uri;
-	GnomeVFSResult result;
-	GList *files;               /* gchar* items. */
-	GList *dirs;                /* gchar* items. */
-	PathListDoneFunc done_func;
-	gpointer data;
-};
-
-
-typedef struct {
-	GnomeVFSAsyncHandle *vfs_handle;
-	PathListData *pli_data;
-} PathListHandle;
-
-
-PathListData *      path_list_data_new           ();
-
-void                path_list_data_free          (PathListData *dli);
-
-void                path_list_handle_free        (PathListHandle *handle);
-
-gboolean            path_is_file                 (const gchar *s);
-
-gboolean            path_is_dir                  (const gchar *s);
-
-gboolean            dir_is_empty                 (const gchar *s);
-
-GnomeVFSFileSize    get_file_size                (const gchar *s);
-
-time_t              get_file_mtime               (const gchar *s);
-
-time_t              get_file_ctime               (const gchar *s);
-
-void                set_file_mtime               (const gchar *s,
-						  time_t       mtime);
-
-gboolean            file_copy                    (const gchar *from, 
-						  const gchar *to);
-
-gboolean            file_move                    (const gchar *from, 
-						  const gchar *to);
-
-gint                file_in_path                 (const gchar *name);
-
-gboolean            ensure_dir_exists            (const gchar *a_path,
-						  mode_t mode);
-
-gboolean            file_is_hidden               (const gchar *name);
-
-G_CONST_RETURN gchar * file_name_from_path       (const gchar *path);
-
-gchar *             remove_level_from_path       (const gchar *path);
-
-gchar *             remove_extension_from_path   (const gchar *path);
-
-gchar *             remove_ending_separator      (const gchar *path);
-
-
-/* Return TRUE on success, it is up to you to free
- * the lists with path_list_free()
- */
-gboolean            path_list_new                (const gchar *path, 
-						  GList **files, 
-						  GList **dirs);
-
-void                path_list_free               (GList *list);
-
-PathListHandle *    path_list_async_new          (const gchar *uri, 
-						  PathListDoneFunc f,
-						  gpointer  data);
-
-void                path_list_async_interrupt    (PathListHandle *handle);
-
-gboolean            file_is_image                (const gchar *name,
-						  gboolean fast_file_type);
-
-gboolean            file_extension_is            (const char *filename, 
-						  const char *ext);
-
-long                checksum_simple              (const gchar *path);
-
-GList *             dir_list_filter_and_sort     (GList *dir_list, 
-						  gboolean names_only,
-						  gboolean show_dot_files);
-
-gchar*              shell_escape                 (const gchar *filename);
-
-gchar *             application_get_command      (const GnomeVFSMimeApplication *app);
-
-char *              get_path_relative_to_dir     (const char *filename, 
-						  const char *destdir);
-
-char *              remove_special_dirs_from_path (const char *path);
-     
-char *              get_unique_desktop_file (const char *base_dir);
-
-gboolean            is_desktop_file (const char *uri);
-
-GList *             get_file_list_from_url_list (char *url_list);
-
-
-#define errno_to_string() (gnome_vfs_result_to_string (gnome_vfs_result_from_errno ()))
+typedef void (*PathListDoneFunc) (GList *files, GList *dirs, GError *error, gpointer data);
 
+gboolean            uri_is_file                   (const char        *uri);
+gboolean            uri_is_dir                    (const char        *uri);
+gboolean            path_is_dir                   (const char        *path);
+gboolean            file_copy                     (const char        *source_uri, 
+						   const char        *destination_uri);
+gboolean            make_directory_tree           (GFile             *dir,
+		     				   mode_t             mode,
+		     				   GError           **error);
+gboolean            ensure_dir_exists             (const char        *uri,
+						   mode_t             mode,
+						   GError           **error);
+gboolean            make_directory_tree_from_path (const char        *path,
+		   	                           mode_t             mode,
+		   	                           GError           **error);
+const char *        file_name_from_path           (const char        *path);
+gboolean            path_list_new                 (const char        *path, 
+						   GList            **files, 
+						   GList            **dirs);
+GList *             path_list_dup                 (GList             *list);						   
+void                path_list_free                (GList             *list);
+void                path_list_async_new           (const gchar       *uri, 
+						   GCancellable      *cancellable,
+						   PathListDoneFunc   f,
+						   gpointer           data);
+char *              get_unique_desktop_file       (const char        *base_dir);
+gboolean            is_desktop_file               (const char        *uri);
+GList *             get_file_list_from_url_list   (char              *url_list);
 
 #endif /* FILE_UTILS_H */

Modified: trunk/src/quick-box.c
==============================================================================
--- trunk/src/quick-box.c	(original)
+++ trunk/src/quick-box.c	Fri Jan 30 19:30:52 2009
@@ -27,8 +27,6 @@
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
 #include <libgnome/gnome-desktop-item.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
 #include "dlg-properties.h"
 #include "quick-box.h"
 #include "quick-button.h"

Modified: trunk/src/quick-lounge.c
==============================================================================
--- trunk/src/quick-lounge.c	(original)
+++ trunk/src/quick-lounge.c	Fri Jan 30 19:30:52 2009
@@ -31,9 +31,6 @@
 #include <libgnomeui/libgnomeui.h>
 #include <libgnomeui/gnome-window-icon.h>
 #include <libgnome/gnome-desktop-item.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-directory.h>
 #include "dlg-pick-applications.h"
 #include "dlg-properties.h"
 #include "file-utils.h"
@@ -177,37 +174,6 @@
 };
 
 
-#if 0
-
-static void
-remove_directory (const char *uri)
-{
-	GnomeVFSDirectoryHandle *h;
-	GnomeVFSFileInfo        *file_info;
-	GnomeVFSResult           r;
-
-	/* this directory does not contain sub-directories so let's keep the
-	 * function simple. */
-
-	r = gnome_vfs_directory_open (&h, uri, GNOME_VFS_FILE_INFO_DEFAULT);
-	if (r != GNOME_VFS_OK)
-		return;
-
-	file_info = gnome_vfs_file_info_new ();
-	while (gnome_vfs_directory_read_next (h, file_info) == GNOME_VFS_OK) {
-		char *file_uri;
-		file_uri = g_build_filename (uri, file_info->name, NULL);
-		gnome_vfs_unlink (file_uri);
-		g_free (file_uri);
-	}
-	gnome_vfs_file_info_unref (file_info);
-	gnome_vfs_directory_close (h);
-
-	gnome_vfs_remove_directory (uri);
-}
-
-#endif
-
 static void
 gh_desktop_item_unref  (gpointer  key,
 			gpointer  value,
@@ -605,8 +571,13 @@
 					  "quick_lounge");
 
 	uri = g_object_get_data (G_OBJECT (button), "uri");
-	if (uri != NULL)
-		gnome_vfs_unlink (uri);
+	if (uri != NULL) {
+		GFile *file;
+		
+		file = g_file_new_for_uri (uri);
+		g_file_delete (file, NULL, NULL);
+		g_object_unref (file);
+	}
 
 	gtk_container_remove (GTK_CONTAINER (quick_box), button);
 	quick_lounge_save_order (quick_lounge);
@@ -719,28 +690,30 @@
 			gtk_dialog_run (GTK_DIALOG (message_dialog));
 			gtk_widget_destroy (message_dialog);
 		}
-		
-	} else if (response == GTK_RESPONSE_OK) { 
+	} 
+	else if (response == GTK_RESPONSE_OK) { 
 		GnomeDesktopItem *ditem;
 		char             *uri, *path;
-		GnomeVFSURI      *vfs_uri;
-
+		GFile            *file;
+		GError           *error = NULL;
+		
 		uri = quick_lounge_util__get_unique_uri (quick_lounge);
 
-		vfs_uri = gnome_vfs_uri_new (uri);
-		path = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD);
-		gnome_vfs_uri_unref (vfs_uri);
+		file = g_file_new_for_uri (uri);
+		path = g_file_get_path (file);
+		g_object_unref (file);		
 
 		ditem = gnome_ditem_edit_get_ditem (dedit);
 		gnome_desktop_item_set_location_file (ditem, path);
 		g_free (path);
 
-		if (! gnome_desktop_item_save (ditem, NULL, TRUE, NULL)) {
+		if (! gnome_desktop_item_save (ditem, NULL, TRUE, &error)) {
 			_gtk_error_dialog_run (NULL, 
 					       ERROR_FORMAT, 
 					       _("Could not create the new launcher"),
-					       errno_to_string ());
+					       error->message);
 			g_free (uri);
+			g_clear_error (&error);
 			gtk_widget_destroy (dialog);
 			return;
 		}
@@ -752,8 +725,8 @@
 		dlg_properties_update (quick_lounge->prop_dialog);
 
 		gtk_widget_destroy (dialog);
-
-	} else if (response == GTK_RESPONSE_CANCEL) 
+	} 
+	else if (response == GTK_RESPONSE_CANCEL) 
 		gtk_widget_destroy (dialog);
 }
 
@@ -1121,7 +1094,15 @@
 char *
 quick_lounge_get_path (QuickLounge *quick_lounge)
 {
-	return gnome_vfs_get_local_path_from_uri (quick_lounge->location);
+	GFile *file;
+	char  *path;
+	
+	file = g_file_new_for_uri (quick_lounge->location);
+	path = g_file_get_path (file);
+	
+	g_object_unref (file);
+	
+	return path;
 }
 
 
@@ -1183,17 +1164,21 @@
 
 
 static void
-load_uri__step2 (PathListData *pld, 
-		 gpointer      data)
+load_uri__step2 (GList    *files, 
+		 GList    *dirs, 
+		 GError   *error, 
+		 gpointer  data)
 {
 	QuickLounge *quick_lounge = data;
 	QuickBox    *quick_box = quick_lounge->quick_box;
 	GList       *folder_list = NULL;
 	GList       *order_list = NULL;
-	GList       *files, *scan;
+	GList       *scan;
+	
+	quick_lounge->loading = FALSE;
 
-	if (pld->result != GNOME_VFS_ERROR_EOF) {
-		path_list_data_free (pld);
+	if (error != NULL) {
+		g_error_free (error);
 		return;
 	}
 
@@ -1201,9 +1186,7 @@
 
 	order_list = get_order_list (quick_lounge);
 
-	folder_list = pld->files;
-	pld->files = NULL;
-
+	folder_list = path_list_dup (files);
 	for (scan = folder_list; order_list && scan;) {
 		char *path = scan->data;
 		
@@ -1213,15 +1196,16 @@
 			g_free (path);
 			
 			scan = folder_list;
-		} else
+		} 
+		else
 			scan = scan->next;
 	}
 
-	files = g_list_concat (order_list, folder_list);
+	folder_list = g_list_concat (order_list, folder_list);
 
 	gtk_widget_hide (GTK_WIDGET (quick_lounge->quick_box));
 
-	for (scan = files; scan; scan = scan->next) {
+	for (scan = folder_list; scan; scan = scan->next) {
 		char *uri = scan->data;
 
 		if (*uri == 0)  
@@ -1230,9 +1214,7 @@
 			quick_box_add_button (quick_box, uri, -1);
 	}
 
-	path_list_free (files);
-	path_list_handle_free (quick_lounge->handle);
-	quick_lounge->handle = NULL;
+	path_list_free (folder_list);
 
 	gtk_widget_show (GTK_WIDGET (quick_lounge->quick_box));
 
@@ -1248,16 +1230,14 @@
 	QuickBox     *quick_box = quick_lounge->quick_box;
 	GList        *children, *scan;
 
+	if (quick_lounge->loading)
+		return;
+
 	if (quick_lounge->location != uri) {
 		g_free (quick_lounge->location);
 		quick_lounge->location = g_strdup (uri);
 	}
 
-	if (quick_lounge->handle != NULL) {
-		path_list_async_interrupt (quick_lounge->handle);
-		path_list_handle_free (quick_lounge->handle);
-	}
-
 	children = gtk_container_get_children (GTK_CONTAINER (quick_box));
 	for (scan = children; scan; scan = scan->next) {
 		GtkWidget *child_widget = scan->data;
@@ -1265,9 +1245,11 @@
 	}
 	g_list_free (children);
 
-	quick_lounge->handle = path_list_async_new (quick_lounge->location,
-						    load_uri__step2,
-						    quick_lounge);
+	quick_lounge->loading = TRUE;
+	path_list_async_new (quick_lounge->location,
+			     NULL,
+			     load_uri__step2,
+			     quick_lounge);
 }
 
 
@@ -1406,7 +1388,7 @@
 	char       *unique_dir = NULL;
         
 	base_dir = g_build_filename (g_get_home_dir (), BASE_DIR, NULL);
-	ensure_dir_exists (base_dir, 0700);
+	ensure_dir_exists (base_dir, 0700, NULL);
 
         while (unique_dir == NULL) {
 		char     *path;
@@ -1426,7 +1408,7 @@
 	}
 
 	g_free (base_dir);
-	ensure_dir_exists (unique_dir, 0700);
+	ensure_dir_exists (unique_dir, 0700, NULL);
 
 	return unique_dir;
 }

Modified: trunk/src/quick-lounge.h
==============================================================================
--- trunk/src/quick-lounge.h	(original)
+++ trunk/src/quick-lounge.h	Fri Jan 30 19:30:52 2009
@@ -34,7 +34,7 @@
 	GtkWidget         *prop_dialog;
 	QuickBox          *quick_box;
 
-	PathListHandle    *handle;
+	gboolean           loading;
 	char              *location;
 	int                size;
 	PanelAppletOrient  orientation;

Modified: trunk/src/typedefs.h
==============================================================================
--- trunk/src/typedefs.h	(original)
+++ trunk/src/typedefs.h	Fri Jan 30 19:30:52 2009
@@ -25,20 +25,10 @@
 
 #include <glib.h>
 
-
 typedef void (*ErrorFunc)      (gpointer data);
-
 typedef void (*DoneFunc)       (gpointer data);
-
 typedef void (*ProgressFunc)   (gfloat percent, 
 				gpointer data);
 
-typedef void (*AreaReadyFunc)  (guint x,
-				guint y, 
-				guint w, 
-				guint h, 
-				gpointer data);
-
-
 #endif /* TYPEDEFS_H */
 



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