file-roller r2207 - in trunk: . src



Author: paobac
Date: Thu Apr  3 11:22:46 2008
New Revision: 2207
URL: http://svn.gnome.org/viewvc/file-roller?rev=2207&view=rev

Log:
2008-04-03  Paolo Bacchilega  <paobac svn gnome org>

	* src/open-file.h: 
	* src/open-file.c: 
	* src/main.c: 
	* src/fr-window.h: 
	* src/fr-window.c: 
	* src/fr-command-jar.c: 
	* src/fr-command-iso.c: 
	* src/fr-archive.c: 
	* src/file-utils.h: 
	* src/file-utils.c: 
	* src/file-data.c: 
	* src/dlg-open-with.c: 
	* src/dlg-add-folder.c: 

	Continuing GIO port.

Modified:
   trunk/ChangeLog
   trunk/src/dlg-add-folder.c
   trunk/src/dlg-open-with.c
   trunk/src/file-data.c
   trunk/src/file-utils.c
   trunk/src/file-utils.h
   trunk/src/fr-archive.c
   trunk/src/fr-command-iso.c
   trunk/src/fr-command-jar.c
   trunk/src/fr-window.c
   trunk/src/fr-window.h
   trunk/src/main.c
   trunk/src/open-file.c
   trunk/src/open-file.h

Modified: trunk/src/dlg-add-folder.c
==============================================================================
--- trunk/src/dlg-add-folder.c	(original)
+++ trunk/src/dlg-add-folder.c	Thu Apr  3 11:22:46 2008
@@ -531,7 +531,7 @@
 	gtk_list_store_clear (list_store);
 
 	options_dir = get_home_relative_dir (RC_OPTIONS_DIR);
-	ensure_dir_exists (options_dir, 0700);
+	ensure_dir_exists (options_dir, 0700, NULL);
 
 	file = g_file_new_for_path (options_dir);
 	fileenum = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &err);
@@ -736,7 +736,7 @@
 	const char *exclude_files;
 
 	options_dir = get_home_relative_dir (RC_OPTIONS_DIR);
-	ensure_dir_exists (options_dir, 0700);
+	ensure_dir_exists (options_dir, 0700, NULL);
 
 	opt_filename = _gtk_request_dialog_run (
 			GTK_WINDOW (data->dialog),

Modified: trunk/src/dlg-open-with.c
==============================================================================
--- trunk/src/dlg-open-with.c	(original)
+++ trunk/src/dlg-open-with.c	Thu Apr  3 11:22:46 2008
@@ -66,8 +66,10 @@
 {
 	g_object_unref (G_OBJECT (data->gui));
 
-	if (data->app_list)
-		gnome_vfs_mime_application_list_free (data->app_list);
+	if (data->app_list != NULL) {
+		g_list_foreach (data->app_list, (GFunc) g_object_unref, NULL);
+		g_list_free (data->app_list);
+	}
 
 	if (data->file_list != NULL)
 		path_list_free (data->file_list);
@@ -90,8 +92,8 @@
 	application = gtk_entry_get_text (GTK_ENTRY (data->o_app_entry));
 
 	for (scan = data->app_list; scan; scan = scan->next) {
-		GnomeVFSMimeApplication *app = scan->data;
-		if (strcmp (gnome_vfs_mime_application_get_exec (app), application) == 0) {
+		GAppInfo *app = scan->data;
+		if (strcmp (g_app_info_get_executable (app), application) == 0) {
 			fr_window_open_files_with_application (data->window, data->file_list, app);
 			gtk_widget_destroy (data->dialog);
 			return;
@@ -147,7 +149,7 @@
 	gtk_tree_model_get (data->app_model, &iter,
 			    DATA_COLUMN, &app,
 			    -1);
-	_gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), gnome_vfs_mime_application_get_exec (app));
+	_gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), g_app_info_get_executable (app));
 }
 
 
@@ -157,9 +159,9 @@
 		  GtkTreeViewColumn *column,
 		  gpointer           callback_data)
 {
-	DialogData              *data = callback_data;
-	GtkTreeIter              iter;
-	GnomeVFSMimeApplication *app;
+	DialogData   *data = callback_data;
+	GtkTreeIter   iter;
+	GAppInfo     *app;
 
 	if (! gtk_tree_model_get_iter (data->app_model, &iter, path))
 		return;
@@ -168,7 +170,7 @@
 			    DATA_COLUMN, &app,
 			    -1);
 
-	_gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), gnome_vfs_mime_application_get_exec (app));
+	_gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), g_app_info_get_executable (app));
 
 	open_cb (NULL, data);
 }
@@ -275,16 +277,16 @@
 dlg_open_with (FrWindow *window,
 	       GList    *file_list)
 {
-	DialogData              *data;
-	GnomeVFSMimeApplication *app;
-	GList                   *scan, *app_names = NULL;
-	GSList                  *sscan, *editors;
-	GtkWidget               *cancel_button;
-	GtkTreeIter              iter;
-	GtkCellRenderer         *renderer;
-	GtkTreeViewColumn       *column;
-	GtkIconTheme            *theme;
-	int                      icon_size;
+	DialogData        *data;
+	GAppInfo          *app;
+	GList             *scan, *app_names = NULL;
+	GSList            *sscan, *editors;
+	GtkWidget         *cancel_button;
+	GtkTreeIter        iter;
+	GtkCellRenderer   *renderer;
+	GtkTreeViewColumn *column;
+	GtkIconTheme      *theme;
+	int                icon_size;
 
 	if (file_list == NULL)
 		return;
@@ -365,7 +367,7 @@
 
 		mime_type = get_file_mime_type (name, FALSE);
 		if ((mime_type != NULL) && (strcmp (mime_type, GNOME_VFS_MIME_TYPE_UNKNOWN) != 0))
-			data->app_list = g_list_concat (data->app_list, gnome_vfs_mime_get_all_applications (mime_type));
+			data->app_list = g_list_concat (data->app_list, g_app_info_get_all_for_type (mime_type));
 	}
 
 	data->app_model = GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS,
@@ -395,23 +397,23 @@
 		if (app_names != NULL) {
 			GList *p;
 			for (p = app_names; p && !found; p = p->next)
-				if (strcmp ((char*)p->data, gnome_vfs_mime_application_get_exec (app)) == 0)
+				if (strcmp ((char*)p->data, g_app_info_get_executable (app)) == 0)
 					found = TRUE;
 		}
 
 		if (found)
 			continue;
 
-		app_names = g_list_prepend (app_names, (char*) gnome_vfs_mime_application_get_exec (app));
+		app_names = g_list_prepend (app_names, (char*) g_app_info_get_executable (app));
 
 		utf8_name = g_locale_to_utf8 (app->name, -1, NULL, NULL, NULL);
-		icon = create_pixbuf (theme, gnome_vfs_mime_application_get_icon (app), icon_size);
+		/*icon = create_pixbuf (theme, gnome_vfs_mime_application_get_icon (app), icon_size);*/
 
 		gtk_list_store_append (GTK_LIST_STORE (data->app_model),
 				       &iter);
 		gtk_list_store_set (GTK_LIST_STORE (data->app_model),
 				    &iter,
-				    ICON_COLUMN, icon,
+				    /*ICON_COLUMN, icon,*/
 				    TEXT_COLUMN, utf8_name,
 				    DATA_COLUMN, app,
 				    -1);

Modified: trunk/src/file-data.c
==============================================================================
--- trunk/src/file-data.c	(original)
+++ trunk/src/file-data.c	Thu Apr  3 11:22:46 2008
@@ -161,7 +161,7 @@
 	if (fdata->link != NULL)
 		return DESCRIPTION_SYMLINK;
 
-	desc = gnome_vfs_mime_get_description (file_data_get_mime_type (fdata));
+	desc = g_content_type_get_description (file_data_get_mime_type (fdata));
 	if (desc == NULL)
 		desc = DESCRIPTION_UNKNOWN;
 

Modified: trunk/src/file-utils.c
==============================================================================
--- trunk/src/file-utils.c	(original)
+++ trunk/src/file-utils.c	Thu Apr  3 11:22:46 2008
@@ -522,19 +522,24 @@
 
 
 gboolean
-ensure_dir_exists (const char *uri,
-		   mode_t      mode)
+ensure_dir_exists (const char  *uri,
+		   mode_t       mode.
+		   GError     **error)
 {
 	GFile  *dir;
-	GError *error;
+	GError *priv_error = NULL;
 	
 	if (uri == NULL)
 		return FALSE;
 	
+	if (error == NULL)
+		error = &priv_error;
+	
 	dir = g_file_new_for_uri (uri);
-	if (! make_directory_tree (dir, mode, &error)) {
-		g_warning ("could create directory %s: %s", uri, error->message);
-		g_clear_error (&error);
+	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;
 	}
 	

Modified: trunk/src/file-utils.h
==============================================================================
--- trunk/src/file-utils.h	(original)
+++ trunk/src/file-utils.h	Thu Apr  3 11:22:46 2008
@@ -46,26 +46,27 @@
 char *              get_directory_content_if_unique (const char  *uri);
 gboolean            path_in_path                 (const char  *path_src,
 						  const char  *path_dest);
-goffset             get_file_size                (const char *uri);
-time_t              get_file_mtime               (const char *s);
-time_t              get_file_ctime               (const char *s);
-gint                file_in_path                 (const char *name);
-gboolean            ensure_dir_exists            (const char *uri,
-						  mode_t      mode);
-gboolean            file_is_hidden               (const char *name);
-G_CONST_RETURN char*file_name_from_path          (const char *path);
-char *              dir_name_from_path           (const char *path);
-char *              remove_level_from_path       (const char *path);
-char *              remove_extension_from_path   (const char *path);
-char *              remove_ending_separator      (const char *path);
-gboolean            file_extension_is            (const char *filename,
-						  const char *ext);
-void                path_list_free               (GList *path_list);
-GList *             path_list_dup                (GList *path_list);
-gboolean            is_mime_type                 (const char* type,
-						  const char* pattern);
-const char*         get_file_mime_type           (const char *filename,
-                    				  gboolean    fast_file_type);
+goffset             get_file_size                (const char  *uri);
+time_t              get_file_mtime               (const char  *s);
+time_t              get_file_ctime               (const char  *s);
+gint                file_in_path                 (const char  *name);
+gboolean            ensure_dir_exists            (const char  *uri,
+						  mode_t       mode,
+						  GError     **error);
+gboolean            file_is_hidden               (const char  *name);
+G_CONST_RETURN char*file_name_from_path          (const char  *path);
+char *              dir_name_from_path           (const char  *path);
+char *              remove_level_from_path       (const char  *path);
+char *              remove_extension_from_path   (const char  *path);
+char *              remove_ending_separator      (const char  *path);
+gboolean            file_extension_is            (const char  *filename,
+						  const char  *ext);
+void                path_list_free               (GList       *path_list);
+GList *             path_list_dup                (GList       *path_list);
+gboolean            is_mime_type                 (const char  *type,
+						  const char  *pattern);
+const char*         get_file_mime_type           (const char  *filename,
+                    				  gboolean     fast_file_type);
 guint64             get_dest_free_space          (const char  *path);
 gboolean            remove_directory             (const char  *uri);
 gboolean            remove_local_directory       (const char  *directory);

Modified: trunk/src/fr-archive.c
==============================================================================
--- trunk/src/fr-archive.c	(original)
+++ trunk/src/fr-archive.c	Thu Apr  3 11:22:46 2008
@@ -1470,7 +1470,7 @@
 	parent_dir =  g_build_filename (temp_dir, tmp, NULL);
 	g_free (tmp);
 
-	ensure_dir_exists (parent_dir, 0700);
+	ensure_dir_exists (parent_dir, 0700, NULL);
 
 	debug (DEBUG_INFO, "mkdir %s\n", parent_dir);
 

Modified: trunk/src/fr-command-iso.c
==============================================================================
--- trunk/src/fr-command-iso.c	(original)
+++ trunk/src/fr-command-iso.c	Thu Apr  3 11:22:46 2008
@@ -192,7 +192,7 @@
 
 		temp_dest_dir = unescape_str (e_temp_dest_dir);
 		temp_dest_dir_uri = get_uri_from_local_path (temp_dest_dir);
-		ensure_dir_exists (temp_dest_dir_uri, 0700);
+		ensure_dir_exists (temp_dest_dir_uri, 0700, NULL);
 
 		fr_process_begin_command (comm->process, "sh " PRIVEXECDIR "isoinfo.sh");
 		fr_process_set_working_dir (comm->process, temp_dest_dir);

Modified: trunk/src/fr-command-jar.c
==============================================================================
--- trunk/src/fr-command-jar.c	(original)
+++ trunk/src/fr-command-jar.c	Thu Apr  3 11:22:46 2008
@@ -100,7 +100,7 @@
 					  jdata->package_minus_one_level,
 					  NULL);
 		
-		if (! ensure_dir_exists (pack_path, 0755 )) { 
+		if (! ensure_dir_exists (pack_path, 0755, NULL)) { 
 			g_free (pack_path);
 			continue;
 		}

Modified: trunk/src/fr-window.c
==============================================================================
--- trunk/src/fr-window.c	(original)
+++ trunk/src/fr-window.c	Thu Apr  3 11:22:46 2008
@@ -480,7 +480,7 @@
 		OpenFile *file = scan->data;
 		
 		if (file->monitor != NULL) 
-			gnome_vfs_monitor_cancel (file->monitor);
+			g_file_monitor_cancel (file->monitor);
 		open_file_free (file);
 	}
 	g_list_free (window->priv->open_files);
@@ -3328,18 +3328,17 @@
 static GList *
 get_uri_list_from_selection_data (char *uri_list)
 {
-	GList *uris = NULL, *scan;
-	GList *list = NULL;
+	GList  *list = NULL;
+	char  **uris;
+	int     i;
 
 	if (uri_list == NULL)
 		return NULL;
 
-	uris = gnome_vfs_uri_list_parse (uri_list);
-	for (scan = uris; scan; scan = g_list_next (scan)) {
-		char *uri = gnome_vfs_uri_to_string (scan->data, GNOME_VFS_URI_HIDE_NONE);
-		list = g_list_prepend (list, uri);
-	}
-	gnome_vfs_uri_list_free (uris);
+	uris = g_uri_list_extract_uris (uri_list);
+	for (i = 0; uris[i] != NULL; i++) 
+		list = g_list_prepend (list, g_strdup (uris[i]));
+	g_strfreev (uris);
 
 	return g_list_reverse (list);
 }
@@ -3746,7 +3745,7 @@
 
 	if (window->priv->drag_error == NULL) {
 		g_free (window->priv->drag_destination_folder);
-		window->priv->drag_destination_folder = gnome_vfs_get_local_path_from_uri (destination_folder);
+		window->priv->drag_destination_folder = g_filename_from_uri (destination_folder, NULL, NULL);
 		path_list_free (window->priv->drag_file_list);
 		window->priv->drag_file_list = fr_window_get_file_list_from_path_list (window, path_list, NULL);
 	}
@@ -5903,6 +5902,7 @@
 {
 	ExtractData *edata;
 	gboolean     do_not_extract = FALSE;
+	GError      *error;
 
 	edata = extract_data_new (file_list,
 				  extract_to_dir,
@@ -5948,7 +5948,7 @@
 				do_not_extract = TRUE;
 		}
 
-		if (! do_not_extract && ! ensure_dir_exists (edata->extract_to_dir, 0755)) {
+		if (! do_not_extract && ! ensure_dir_exists (edata->extract_to_dir, 0755, &error)) {
 			GtkWidget  *d;
 
 			d = _gtk_error_dialog_new (GTK_WINDOW (window),
@@ -5956,7 +5956,8 @@
 						   NULL,
 						   _("Extraction not performed"),
 						   _("Could not create the destination folder: %s."),
-						   gnome_vfs_result_to_string (gnome_vfs_result_from_errno ()));
+						   error->message);
+			g_clear_error (&error);
 			fr_window_show_error_dialog (window, d, GTK_WINDOW (window));		
 			fr_window_stop_batch (window);
 
@@ -7292,7 +7293,7 @@
 
 			debug (DEBUG_INFO, "mktree %s\n", dir_path);
 
-			ensure_dir_exists (dir_path, 0700);
+			ensure_dir_exists (dir_path, 0700, NULL);
 			g_free (dir_path);
 			g_hash_table_replace (created_dirs, g_strdup (dir), "1");
 		}
@@ -7429,24 +7430,25 @@
 
 
 void
-fr_window_open_files_with_application (FrWindow                *window,
-				       GList                   *file_list,
-				       GnomeVFSMimeApplication *app)
+fr_window_open_files_with_application (FrWindow *window,
+				       GList    *file_list,
+				       GAppInfo *app)
 {
-	GList *uris = NULL, *scan;
-	GnomeVFSResult result;
+	GList  *uris = NULL, *scan;
+	GError *error;
 
 	for (scan = file_list; scan; scan = scan->next) {
 		char *filename = g_filename_to_uri (scan->data, NULL, NULL);
 		uris = g_list_prepend (uris, filename);
 	}
 
-	result = gnome_vfs_mime_application_launch (app, uris);
-	if (result != GNOME_VFS_OK)
+	if (! g_app_info_launch_uris (app, uris, NULL, &error)) {
 		_gtk_error_dialog_run (GTK_WINDOW (window),
 				       _("Could not perform the operation"),
 				       "%s",
-				       gnome_vfs_result_to_string (result));
+				       error->messsage);
+		g_clear_error (&error);
+	}
 
 	path_list_free (uris);	
 }
@@ -7575,15 +7577,56 @@
 
 
 static void
+open_file_modified_cb (GFileMonitor     *monitor,
+		       GFile            *file,
+		       GFile            *other_file,
+		       GFileMonitorEvent event_type,
+		       gpointer          user_data)
+{
+	FrWindow *window = user_data;
+	char     *monitor_uri;
+	OpenFile *file;
+	GList    *scan;
+	
+	if ((event_type != G_FILE_MONITOR_EVENT_CHANGED) 
+	    && (event_type != G_FILE_MONITOR_EVENT_CREATED))
+	{
+		return;
+	}
+
+	monitor_uri = g_file_get_uri (file);
+	file = NULL;
+	for (scan = window->priv->open_files; scan; scan = scan->next) {
+		OpenFile *test = scan->data;
+		if (uricmp (test->extracted_uri, monitor_uri) == 0) {
+			file = test;
+			break;
+		}
+	}
+	g_free (monitor_uri);
+
+	g_return_if_fail (file != NULL);
+
+	if (window->priv->update_dialog == NULL)
+		window->priv->update_dialog = dlg_update (window);
+	dlg_update_add_file (window->priv->update_dialog, file);
+}
+
+
+static void
 fr_window_monitor_open_file (FrWindow *window, 
 			     OpenFile *file)
 {	
-	window->priv->open_files = g_list_prepend (window->priv->open_files, file);
-	gnome_vfs_monitor_add (&(file->monitor),
-                               file->extracted_uri,
-			       GNOME_VFS_MONITOR_FILE,
-                               open_file_modified_cb,
-                               window);
+	GFile *f;
+	
+	window->priv->open_files = g_list_prepend (window->priv->open_files, file);                              
+	f = g_file_new_for_uri (file->extracted_uri);  
+	file->monitor = g_file_monitor_file (f, 0, NULL, NULL);
+	g_signal_connect (file->monitor, 
+			  "changed",
+			  open_file_modified_cb,
+			  window);
+	g_object_unref (f);
 }
 
 
@@ -7610,12 +7653,12 @@
 static gboolean
 fr_window_open_extracted_files (OpenFilesData *odata)
 {
-	GList                   *file_list = odata->cdata->file_list;
-        gboolean                 result = FALSE;
-        const char              *first_file;
-        const char              *first_mime_type;
-        GnomeVFSMimeApplication *app;
-        GList                   *files_to_open = NULL;
+	GList      *file_list = odata->cdata->file_list;
+        gboolean    result = FALSE;
+        const char *first_file;
+        const char *first_mime_type;
+        GAppInfo   *app;
+        GList      *files_to_open = NULL;
 
 	g_return_val_if_fail (file_list != NULL, FALSE);
 
@@ -7631,7 +7674,7 @@
         }
 	
 	first_mime_type = get_file_mime_type (first_file, FALSE);
-        app = gnome_vfs_mime_get_default_application_for_uri (first_file, first_mime_type);
+        app = g_app_info_get_default_for_type (first_mime_type, FALSE);
         
         if (app == NULL) {
         	dlg_open_with (odata->window, file_list);
@@ -7655,19 +7698,23 @@
 				files_to_open = g_list_append (files_to_open, (char*) path);
 			}
 			else {
-				GnomeVFSMimeApplication *app2;
+				GAppInfo *app2;
 				
-				app2 = gnome_vfs_mime_get_default_application_for_uri (path, mime_type);
-				if (gnome_vfs_mime_application_equal (app, app2))
+				app2 = g_app_info_get_default_for_type (mime_type, FALSE);
+				if (g_app_info_equal (app, app2))
 					files_to_open = g_list_append (files_to_open, (char*) path);
-				gnome_vfs_mime_application_free (app2);
+				g_object_unref (app2);
 			}
 		}
         }
 
-	result = gnome_vfs_mime_application_launch (app, files_to_open) == GNOME_VFS_OK;
+	result = g_app_info_launch_uris (app, files_to_open, NULL, &error);
+        if (! result) {
+        	g_warning ("could not launch '%s': %s", g_app_info_get_executable  (app), error->message);
+        	g_clear_error (&error);
+        }
         
-        gnome_vfs_mime_application_free (app);
+        g_object_unref (app);
         g_list_free (files_to_open);
         
 	return result;

Modified: trunk/src/fr-window.h
==============================================================================
--- trunk/src/fr-window.h	(original)
+++ trunk/src/fr-window.h	Thu Apr  3 11:22:46 2008
@@ -244,7 +244,7 @@
 						   char       *command);
 void        fr_window_open_files_with_application (FrWindow   *window,
 						   GList      *file_list,
-						   GnomeVFSMimeApplication *app);
+						   GAppInfo   *app);
 void        fr_window_update_files                (FrWindow   *window,
 						   GList      *file_list);			   
 void        fr_window_update_columns_visibility   (FrWindow   *window);

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Thu Apr  3 11:22:46 2008
@@ -491,7 +491,7 @@
 	if (path_is_file (path))
 		unlink (path);
 
-	ensure_dir_exists (path, 0700);
+	ensure_dir_exists (path, 0700, NULL);
 	g_free (path);
 
 	if (eel_gconf_get_boolean (PREF_MIGRATE_DIRECTORIES, TRUE))

Modified: trunk/src/open-file.c
==============================================================================
--- trunk/src/open-file.c	(original)
+++ trunk/src/open-file.c	Thu Apr  3 11:22:46 2008
@@ -47,6 +47,8 @@
 {
 	if (ofile == NULL)
 		return;
+	if (ofile->monitor != NULL)
+		g_object_unref (ofile->monitor);
 	g_free (ofile->path);
 	g_free (ofile->extracted_uri);
 	g_free (ofile->temp_dir);

Modified: trunk/src/open-file.h
==============================================================================
--- trunk/src/open-file.h	(original)
+++ trunk/src/open-file.h	Thu Apr  3 11:22:46 2008
@@ -29,11 +29,11 @@
 #include <libgnomevfs/gnome-vfs-monitor.h>
 
 typedef struct {
-	char                  *path;
-	char                  *extracted_uri;
-	char                  *temp_dir;
-	time_t                 last_modified;
-	GnomeVFSMonitorHandle *monitor;
+	char         *path;
+	char         *extracted_uri;
+	char         *temp_dir;
+	time_t        last_modified;
+	GFileMonitor *monitor;
 } OpenFile;
 
 #define FR_TYPE_OPEN_FILE (open_file_get_type ())



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