[PATCH]: Show icon on Open with page



Hello

   Attached patch changes eel to show the application icon in the Open
With selector.
   Notice that it's getting the icon from the .desktop file, and only
applications added after with recent eel are creating a full .dekstop
file (with the icon field).

Salu2

? eel-2.0-uninstalled.pc
? mkinstalldirs
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/eel/ChangeLog,v
retrieving revision 1.668
diff -u -r1.668 ChangeLog
--- ChangeLog	21 Jan 2005 09:59:22 -0000	1.668
+++ ChangeLog	21 Jan 2005 13:38:11 -0000
@@ -1,3 +1,8 @@
+2005-01-21  Fernando Herrera  <fernando herrera tecsidel es>
+
+	* eel/eel-mime-application-chooser.c: (create_tree_view),
+	(refresh_model): Show application icon in the selector.
+
 2005-01-21  Alexander Larsson  <alexl redhat com>
 
 	* configure.in:
Index: eel/eel-mime-application-chooser.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-mime-application-chooser.c,v
retrieving revision 1.5
diff -u -r1.5 eel-mime-application-chooser.c
--- eel/eel-mime-application-chooser.c	25 Nov 2004 17:07:56 -0000	1.5
+++ eel/eel-mime-application-chooser.c	21 Jan 2005 13:38:11 -0000
@@ -31,14 +31,17 @@
 
 #include <string.h>
 #include <glib/gi18n-lib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gtk/gtkalignment.h> 
 #include <gtk/gtkbox.h> 
 #include <gtk/gtkbutton.h>
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtkcellrenderertoggle.h>
+#include <gtk/gtkcellrendererpixbuf.h>
 #include <gtk/gtkentry.h>
 #include <gtk/gtkhbbox.h>
 #include <gtk/gtkimage.h>
+#include <gtk/gtkicontheme.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtkliststore.h>
 #include <gtk/gtkscrolledwindow.h>
@@ -68,6 +71,7 @@
 
 enum {
 	COLUMN_DEFAULT,
+	COLUMN_ICON,
 	COLUMN_NAME,
 	COLUMN_ID,
 	NUM_COLUMNS
@@ -208,6 +212,7 @@
 	
 	store = gtk_list_store_new (NUM_COLUMNS,
 				    G_TYPE_BOOLEAN,
+				    GDK_TYPE_PIXBUF,
 				    G_TYPE_STRING,
 				    G_TYPE_STRING);
 	gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
@@ -228,6 +233,14 @@
 							   NULL);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
+	renderer = gtk_cell_renderer_pixbuf_new ();
+	column = gtk_tree_view_column_new_with_attributes (_("Icon"),
+							   renderer,
+							   "pixbuf",
+							   COLUMN_ICON,
+							   NULL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
 	chooser->details->toggle_renderer = renderer;
 	renderer = gtk_cell_renderer_text_new ();
 	column = gtk_tree_view_column_new_with_attributes (_("Name"),
@@ -391,6 +404,10 @@
 		gboolean is_default;
 		GnomeVFSMimeApplication *application;
 		char *escaped;
+		const char *icon;
+		GdkPixbuf *pixbuf;
+
+		pixbuf = NULL;
 
 		application = l->data;
 		
@@ -399,14 +416,41 @@
 
 		escaped = g_markup_escape_text (application->name, -1);
 
+		icon = gnome_vfs_mime_application_get_icon (application);
+
+		if (g_path_is_absolute (icon)) {
+			pixbuf = gdk_pixbuf_new_from_file_at_size (icon, 24, 24, NULL);
+		}
+		if (pixbuf == NULL) {
+			pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+							   icon, 24, 0, NULL);
+		}
+		if (pixbuf == NULL && strrchr (icon, '.') != NULL) {
+			char *name;
+			name = g_strndup (icon, strlen (icon) - strlen (strrchr (icon, '.')));
+			pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+							   name, 24, 0, NULL);
+			g_free (name);
+		}
+
+		if (pixbuf == NULL) {
+			char *filename;
+			filename = g_strdup_printf (DATADIR"/pixmaps/%s", icon);
+			pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 24, 24, NULL);
+			g_free (filename);
+		}
+
 		gtk_list_store_append (chooser->details->model, &iter);
 		gtk_list_store_set (chooser->details->model, &iter,
 				    COLUMN_DEFAULT, is_default,
+				    COLUMN_ICON, pixbuf,
 				    COLUMN_NAME, escaped,
 				    COLUMN_ID,
 				    gnome_vfs_mime_application_get_desktop_id (application), 
 				    -1);
 		g_free (escaped);
+		if (pixbuf != NULL)
+			g_object_unref(pixbuf);
 	}
 
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chooser->details->treeview));


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