file-roller r2452 - in trunk: . src



Author: paobac
Date: Sun Aug 31 07:49:51 2008
New Revision: 2452
URL: http://svn.gnome.org/viewvc/file-roller?rev=2452&view=rev

Log:
2008-08-31  Paolo Bacchilega  <paobac svn gnome org>

	* src/dlg-open-with.c: 
	* src/fr-window.c: 
	* src/file-utils.c: 
	
	Set the application selected in the "open with" dialog as the 
	default	for the mime type.  Allow to remove the registered 
	applications as well.
	
	Fixes bug #544766 â file-roller doesn't remember open-with 
	application.


Modified:
   trunk/ChangeLog
   trunk/src/dlg-open-with.c
   trunk/src/file-utils.c
   trunk/src/fr-window.c

Modified: trunk/src/dlg-open-with.c
==============================================================================
--- trunk/src/dlg-open-with.c	(original)
+++ trunk/src/dlg-open-with.c	Sun Aug 31 07:49:51 2008
@@ -54,6 +54,8 @@
 
 	GtkTreeModel *app_model;
 	GtkTreeModel *recent_model;
+	
+	GtkWidget    *last_clicked_list;
 } DialogData;
 
 
@@ -146,6 +148,7 @@
 			    DATA_COLUMN, &app,
 			    -1);
 	_gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), g_app_info_get_executable (app));
+	data->last_clicked_list = data->o_app_tree_view;
 }
 
 
@@ -192,6 +195,7 @@
 			    -1);
 	_gtk_entry_set_locale_text (GTK_ENTRY (data->o_app_entry), editor);
 	g_free (editor);
+	data->last_clicked_list = data->o_recent_tree_view;
 }
 
 
@@ -237,34 +241,55 @@
 	DialogData       *data = callback_data;
 	GtkTreeSelection *selection;
 	GtkTreeIter       iter;
-	char             *editor;
-	GSList           *editors, *link;
+	
 
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_recent_tree_view));
-	if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
-		return;
+	if (data->last_clicked_list == data->o_recent_tree_view) {
+		char   *editor;
+		GSList *editors, *link;
+	
+		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_recent_tree_view));
+		if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
+			return;
 
-	gtk_tree_model_get (data->recent_model, &iter,
-			    0, &editor,
-			    -1);
-	gtk_list_store_remove (GTK_LIST_STORE (data->recent_model), &iter);
+		gtk_tree_model_get (data->recent_model, &iter,
+				    0, &editor,
+				    -1);
+		gtk_list_store_remove (GTK_LIST_STORE (data->recent_model), &iter);
 
-	/**/
+		/**/
 
-	editors = eel_gconf_get_string_list (PREF_EDIT_EDITORS);
-	link = g_slist_find_custom (editors, editor, (GCompareFunc) strcmp);
-	if (link != NULL) {
-		editors = g_slist_remove_link (editors, link);
-		eel_gconf_set_string_list (PREF_EDIT_EDITORS, editors);
-		g_free (link->data);
-		g_slist_free (link);
-	}
-	g_slist_foreach (editors, (GFunc) g_free, NULL);
-	g_slist_free (editors);
+		editors = eel_gconf_get_string_list (PREF_EDIT_EDITORS);
+		link = g_slist_find_custom (editors, editor, (GCompareFunc) strcmp);
+		if (link != NULL) {
+			editors = g_slist_remove_link (editors, link);
+			eel_gconf_set_string_list (PREF_EDIT_EDITORS, editors);
+			g_free (link->data);
+			g_slist_free (link);
+		}
+		g_slist_foreach (editors, (GFunc) g_free, NULL);
+		g_slist_free (editors);
 
-	/**/
+		g_free (editor);
+	}
+	else if (data->last_clicked_list == data->o_app_tree_view) {
+		GAppInfo *app;
+		
+		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_app_tree_view));
+		if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
+			return;
 
-	g_free (editor);
+		gtk_tree_model_get (data->app_model, &iter,
+			    	    DATA_COLUMN, &app,
+			    	    -1);
+		gtk_list_store_remove (GTK_LIST_STORE (data->app_model), &iter);
+		
+		if (g_app_info_can_remove_supports_type (app)) {
+			const char *mime_type;
+			
+			mime_type = get_file_mime_type_for_path ((char*) data->file_list->data, FALSE);
+			g_app_info_remove_supports_type (app, mime_type, NULL);
+		}
+	}
 }
 
 

Modified: trunk/src/file-utils.c
==============================================================================
--- trunk/src/file-utils.c	(original)
+++ trunk/src/file-utils.c	Sun Aug 31 07:49:51 2008
@@ -708,7 +708,7 @@
 
 
 const char*
-get_file_mime_type (const char *filename,
+get_file_mime_type (const char *uri,
                     gboolean    fast_file_type)
 {
 	GFile      *file;
@@ -716,14 +716,14 @@
 	GError     *err = NULL;
  	const char *result = NULL;
 
- 	file = g_file_new_for_uri (filename);
+ 	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", filename, err->message);
+		g_warning ("could not get content type for %s: %s", uri, err->message);
 		g_clear_error (&err);
 	}
 	else {

Modified: trunk/src/fr-window.c
==============================================================================
--- trunk/src/fr-window.c	(original)
+++ trunk/src/fr-window.c	Sun Aug 31 07:49:51 2008
@@ -7728,30 +7728,24 @@
 
 
 void
-fr_window_open_files_with_command (FrWindow   *window,
-				   GList      *file_list,
-				   char       *command)
-{
-	CommandData *cdata;
-	GList       *scan;
-
-	if (window->priv->activity_ref > 0)
+fr_window_open_files_with_command (FrWindow *window,
+				   GList    *file_list,
+				   char     *command)
+{
+	GAppInfo *app;
+	GError   *error = NULL;
+		
+	app = g_app_info_create_from_commandline (command, NULL, G_APP_INFO_CREATE_NONE, &error);
+	if (error != NULL) {
+		_gtk_error_dialog_run (GTK_WINDOW (window),
+				       _("Could not perform the operation"),
+				       "%s",
+				       error->message);
+		g_clear_error (&error);
 		return;
-
-	/* The command data is used to unref the process on exit. */
-
-	cdata = g_new0 (CommandData, 1);
-	cdata->process = fr_process_new ();
-	fr_process_use_standard_locale (cdata->process, FALSE);
-	cdata->process->term_on_stop = FALSE;
-
-	fr_process_begin_command (cdata->process, command);
-	for (scan = file_list; scan; scan = scan->next)
-		fr_process_add_arg (cdata->process, scan->data);
-	fr_process_end_command (cdata->process);
-
-	CommandList = g_list_prepend (CommandList, cdata);
-	fr_process_start (cdata->process);
+	}
+ 
+	fr_window_open_files_with_application (window, file_list, app);
 }
 
 
@@ -7766,10 +7760,8 @@
 	if (window->priv->activity_ref > 0)
 		return;
 
-	for (scan = file_list; scan; scan = scan->next) {
-		char *filename = g_filename_to_uri (scan->data, NULL, NULL);
-		uris = g_list_prepend (uris, filename);
-	}
+	for (scan = file_list; scan; scan = scan->next) 
+		uris = g_list_prepend (uris, g_filename_to_uri (scan->data, NULL, NULL));
 
 	if (! g_app_info_launch_uris (app, uris, NULL, &error)) {
 		_gtk_error_dialog_run (GTK_WINDOW (window),
@@ -7778,6 +7770,16 @@
 				       error->message);
 		g_clear_error (&error);
 	}
+	else {
+		char       *uri;
+		const char *mime_type;
+		
+		uri = g_filename_to_uri (file_list->data, NULL, NULL);
+		mime_type = get_file_mime_type (uri, FALSE);
+		if (mime_type != NULL)
+			g_app_info_set_as_default_for_type (app, mime_type, NULL);
+		g_free (uri);
+	}
 
 	path_list_free (uris);
 }



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