[PATCH] Show potential apps first on 'Open with...' dialog
- From: Rodrigo Moya <rodrigo gnome-db org>
- To: nautilus-list gnome org
- Subject: [PATCH] Show potential apps first on 'Open with...' dialog
- Date: Wed, 20 Feb 2008 18:58:00 +0100
Hi
The openSUSE eel package had a patch that stopped applying with latest
update to 2.21.x, to make eel-open-with-dialog show first the apps
associated to the given mime type.
I've tried adapting the patch to Nautilus, but can't find why, it seems,
g_app_info_get_all_for_type always returns NULL.
Find attached the patch and please let me know if this would acceptable
(for 2.23.x of course, in which case I'll file a bug with the patch)
--
Rodrigo Moya <rodrigo gnome-db org>
Index: libnautilus-private/nautilus-open-with-dialog.c
===================================================================
--- libnautilus-private/nautilus-open-with-dialog.c (revision 13784)
+++ libnautilus-private/nautilus-open-with-dialog.c (working copy)
@@ -50,6 +50,7 @@
#include <gtk/gtktreeselection.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkcellrendererpixbuf.h>
+#include <gtk/gtktreestore.h>
#include <gtk/gtkvbox.h>
#include <gio/gio.h>
@@ -72,7 +73,7 @@
GtkWidget *open_label;
GtkWidget *program_list;
- GtkListStore *program_list_store;
+ GtkTreeStore *program_tree_store;
GSList *add_icon_paths;
gint add_items_idle_id;
gint add_icons_idle_id;
@@ -485,7 +486,7 @@
dialog->details->add_icon_paths = g_slist_delete_link (dialog->details->add_icon_paths,
dialog->details->add_icon_paths);
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (dialog->details->program_list_store),
+ if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (dialog->details->program_tree_store),
&iter, path)) {
gtk_tree_path_free (path);
continue;
@@ -493,7 +494,7 @@
gtk_tree_path_free (path);
- gtk_tree_model_get (GTK_TREE_MODEL (dialog->details->program_list_store), &iter,
+ gtk_tree_model_get (GTK_TREE_MODEL (dialog->details->program_tree_store), &iter,
COLUMN_GICON, &icon, -1);
if (icon == NULL) {
@@ -503,7 +504,7 @@
pixbuf = get_pixbuf_for_icon (icon);
if (pixbuf) {
long_operation = TRUE;
- gtk_list_store_set (dialog->details->program_list_store, &iter, COLUMN_ICON, pixbuf, -1);
+ gtk_tree_store_set (dialog->details->program_tree_store, &iter, COLUMN_ICON, pixbuf, -1);
g_object_unref (pixbuf);
}
@@ -579,19 +580,62 @@
}
}
+static const char *
+add_app_to_list (NautilusOpenWithDialog *dialog,
+ GAppInfo *entry,
+ const char *prev_name,
+ GtkTreeIter *parent,
+ GList *mime_supporters)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ const char *target_desktop = g_app_info_get_id (entry);
+ if (target_desktop != NULL && mime_supporters != NULL) {
+ for ( ; mime_supporters != NULL ; mime_supporters = mime_supporters->next) {
+ const char *desktop =
+ g_app_info_get_id (mime_supporters->data);
+ if (desktop != NULL && 0 == strcmp (desktop, target_desktop))
+ break;
+ }
+ if (mime_supporters == NULL)
+ return prev_name;
+ }
+
+ if (prev_name && strcmp (g_app_info_get_name (entry), prev_name) == 0)
+ return prev_name;
+ gtk_tree_store_append (dialog->details->program_tree_store, &iter, parent);
+ gtk_tree_store_set (dialog->details->program_tree_store, &iter,
+ COLUMN_ICON, NULL,
+ COLUMN_GICON, g_app_info_get_icon (entry),
+ COLUMN_NAME, g_app_info_get_name (entry),
+ COLUMN_COMMENT, g_app_info_get_description (entry),
+ COLUMN_EXEC, g_app_info_get_executable (entry),
+ -1);
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->details->program_tree_store), &iter);
+ if (path != NULL) {
+ dialog->details->add_icon_paths = g_slist_prepend (dialog->details->add_icon_paths, path);
+ }
+
+ return g_app_info_get_name (entry);
+}
+
static gboolean
nautilus_open_with_dialog_add_items_idle (NautilusOpenWithDialog *dialog)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
- GList *all_applications;
- GList *l;
+ GtkTreeIter parent;
+ GList *all_applications;
+ GList *l;
+ GList *mime_supporters;
const char *prev_name;
+ GtkTreePath *recommended_path = NULL;
/* create list store */
- dialog->details->program_list_store = gtk_list_store_new (NUM_COLUMNS,
+ dialog->details->program_tree_store = gtk_tree_store_new (NUM_COLUMNS,
G_TYPE_APP_INFO,
GDK_TYPE_PIXBUF,
G_TYPE_ICON,
@@ -601,35 +645,42 @@
all_applications = g_app_info_get_all ();
+ mime_supporters = dialog->details->content_type
+ ? g_app_info_get_all_for_type (dialog->details->content_type)
+ : NULL;
+
prev_name = NULL;
- for (l = all_applications; l; l = l->next) {
- GAppInfo *app = l->data;
- GtkTreeIter iter;
- GtkTreePath *path;
+ if (mime_supporters != NULL) {
+ /* The known handlers */
+ gtk_tree_store_append (dialog->details->program_tree_store, &parent, NULL);
+ recommended_path = gtk_tree_model_get_path (
+ GTK_TREE_MODEL (dialog->details->program_tree_store), &parent);
+ gtk_tree_store_set (dialog->details->program_tree_store, &parent,
+ COLUMN_NAME, _("Potential Applications "),
+ -1);
+ for (l = mime_supporters; l; l = l->next) {
+ prev_name = add_app_to_list (dialog, l->data,
+ prev_name, &parent, NULL);
+ }
- if (!g_app_info_supports_uris (app) &&
- !g_app_info_supports_files (app))
- continue;
+ /* Everything else */
+ prev_name = NULL;
+ gtk_tree_store_append (dialog->details->program_tree_store, &parent, NULL);
+ gtk_tree_store_set (dialog->details->program_tree_store, &parent,
+ COLUMN_NAME, _("All Applications"),
+ -1);
+ for (l = all_applications; l; l = l->next)
+ prev_name = add_app_to_list (dialog, l->data,
+ prev_name, &parent, mime_supporters);
+ } else
+ for (l = all_applications; l; l = l->next)
+ prev_name = add_app_to_list (dialog, l->data, prev_name, NULL, NULL);
- gtk_list_store_append (dialog->details->program_list_store, &iter);
- gtk_list_store_set (dialog->details->program_list_store, &iter,
- COLUMN_APP_INFO, app,
- COLUMN_ICON, NULL,
- COLUMN_GICON, g_app_info_get_icon (app),
- COLUMN_NAME, g_app_info_get_name (app),
- COLUMN_COMMENT, g_app_info_get_description (app),
- COLUMN_EXEC, g_app_info_get_executable,
- -1);
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->details->program_list_store), &iter);
- if (path != NULL) {
- dialog->details->add_icon_paths = g_slist_prepend (dialog->details->add_icon_paths, path);
- }
- }
+ g_list_free (mime_supporters);
g_list_free (all_applications);
gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->details->program_list),
- GTK_TREE_MODEL (dialog->details->program_list_store));
+ GTK_TREE_MODEL (dialog->details->program_tree_store));
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (dialog->details->program_list),
nautilus_open_with_search_equal_func,
NULL, NULL);
@@ -649,6 +700,10 @@
gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->details->program_list), column);
+ gtk_tree_view_expand_row (GTK_TREE_VIEW (dialog->details->program_list),
+ recommended_path, TRUE);
+ gtk_tree_path_free (recommended_path);
+
dialog->details->add_icon_paths = g_slist_reverse (dialog->details->add_icon_paths);
if (!dialog->details->add_icons_idle_id) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]