[nautilus-actions] Fix icon display for non standard themes



commit b46253e5eb7827d9e4b94b4be4a5ffcf5f9fe16d
Author: Pierre <pwieser trychlos org>
Date:   Wed Apr 7 22:54:20 2010 +0200

    Fix icon display for non standard themes

 ChangeLog                      |   11 ++++++++++
 src/nact/nact-gtk-utils.c      |   41 ++++++++++++++++++++++++++-------------
 src/nact/nact-gtk-utils.h      |    5 ++-
 src/nact/nact-iaction-tab.c    |   11 +--------
 src/nact/nact-main-statusbar.c |    3 +-
 src/nact/nact-tree-model.c     |    3 +-
 6 files changed, 46 insertions(+), 28 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 26ea7fe..d05c8f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-04-07 Pierre Wieser <pwieser trychlos org>
+
+	* src/nact/nact-gtk-utils.c:
+	* src/nact/nact-gtk-utils.h
+	(nact_gtk_utils_get_pixbuf): Render an icon for a given widget.
+	(nact_utils_render): New function.
+
+	* src/nact/nact-iaction-tab.c (on_icon_changed):
+	* src/nact/nact-main-statusbar.c (nact_main_statusbar_set_locked):
+	* src/nact/nact-tree-model.c (display_item): Updated accordingly.
+
 2009-04-02 Pierre Wieser <pwieser trychlos org>
 
 	* configure.ac:
diff --git a/src/nact/nact-gtk-utils.c b/src/nact/nact-gtk-utils.c
index e76f26d..c35f140 100644
--- a/src/nact/nact-gtk-utils.c
+++ b/src/nact/nact-gtk-utils.c
@@ -88,17 +88,16 @@ nact_gtk_utils_set_editable( GtkObject *widget, gboolean editable )
 /**
  * nact_utils_get_pixbuf:
  * @name: the name of the file or an icon.
- * @size: the desired size (width=height).
+ * widget: the widget on which the imagecshould be rendered.
+ * size: the desired size.
  *
- * Returns a #GdkPixbuf of the given size.
+ * Returns a pixbuf for the given widget.
  */
 GdkPixbuf *
-nact_gtk_utils_get_pixbuf( const gchar *name, gint size )
+nact_gtk_utils_get_pixbuf( const gchar *name, GtkWidget *widget, gint size )
 {
 	static const gchar *thisfn = "nact_gtk_utils_get_pixbuf";
 	GdkPixbuf* pixbuf;
-	GIcon *icon;
-	GtkIconTheme *theme;
 	GError *error;
 
 	error = NULL;
@@ -115,21 +114,35 @@ nact_gtk_utils_get_pixbuf( const gchar *name, gint size )
 			}
 
 		} else {
-			icon = g_themed_icon_new( name );
-			theme = gtk_icon_theme_get_default();
-			pixbuf = gtk_icon_theme_load_icon( theme, name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK, &error );
-			if( error ){
-				g_warning( "%s: gtk_icon_theme_load_icon: name=%s, error=%s", thisfn, name, error->message );
-				g_error_free( error );
-				error = NULL;
-				pixbuf = NULL;
-			}
+			pixbuf = gtk_widget_render_icon( widget, name, size, NULL );
 		}
 	}
 
 	if( !pixbuf ){
+		g_debug( "%s: null pixbuf, loading transparent image", thisfn );
 		pixbuf = gdk_pixbuf_new_from_file_at_size( PKGDATADIR "/transparent.png", size, size, NULL );
 	}
 
 	return( pixbuf );
 }
+
+/**
+ * nact_utils_render:
+ * @name: the name of the file or an icon.
+ * widget: the widget on which the image should be rendered.
+ * size: the desired size.
+ *
+ * Displays the (maybe themed) image on the given widget.
+ */
+void
+nact_gtk_utils_render( const gchar *name, GtkImage *widget, gint size )
+{
+	GdkPixbuf* pixbuf;
+
+	pixbuf = nact_gtk_utils_get_pixbuf( name, GTK_WIDGET( widget ), size );
+
+	if( pixbuf ){
+		gtk_image_set_from_pixbuf( widget, pixbuf );
+		g_object_unref( pixbuf );
+	}
+}
diff --git a/src/nact/nact-gtk-utils.h b/src/nact/nact-gtk-utils.h
index 12ae243..4e5fc77 100644
--- a/src/nact/nact-gtk-utils.h
+++ b/src/nact/nact-gtk-utils.h
@@ -43,9 +43,10 @@ G_BEGIN_DECLS
 
 void       nact_gtk_utils_set_editable( GtkObject *widget, gboolean editable );
 
-/* pixbuf utilities
+/* image utilities
  */
-GdkPixbuf *nact_gtk_utils_get_pixbuf( const gchar *name, gint size );
+GdkPixbuf *nact_gtk_utils_get_pixbuf( const gchar *name, GtkWidget *widget, gint size );
+void       nact_gtk_utils_render( const gchar *name, GtkImage *widget, gint size );
 
 G_END_DECLS
 
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index f46aba8..7de8ecd 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -879,7 +879,6 @@ create_stock_icon_model( void )
 	model = gtk_list_store_new( ICON_N_COLUMN, G_TYPE_STRING, G_TYPE_STRING );
 
 	gtk_list_store_append( model, &row );
-
 	/* i18n notes: when no icon is selected in the drop-down list */
 	gtk_list_store_set( model, &row, ICON_STOCK_COLUMN, "", ICON_LABEL_COLUMN, _( "None" ), -1 );
 
@@ -962,7 +961,6 @@ on_icon_changed( GtkEntry *icon_entry, NactIActionTab *instance )
 {
 	static const gchar *thisfn = "nact_iaction_tab_on_icon_changed";
 	GtkImage *image;
-	GdkPixbuf *pixbuf;
 	NAObjectItem *edited;
 	const gchar *icon_name;
 
@@ -981,13 +979,8 @@ on_icon_changed( GtkEntry *icon_entry, NactIActionTab *instance )
 		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, TRUE );
 	}
 
-	pixbuf = nact_gtk_utils_get_pixbuf( icon_name, GTK_ICON_SIZE_MENU );
-
-	if( pixbuf ){
-		image = GTK_IMAGE( base_window_get_widget( BASE_WINDOW( instance ), "ActionIconImage" ));
-		g_assert( GTK_IS_WIDGET( image ));
-		gtk_image_set_from_pixbuf( image, pixbuf );
-	}
+	image = GTK_IMAGE( base_window_get_widget( BASE_WINDOW( instance ), "ActionIconImage" ));
+	nact_gtk_utils_render( icon_name, image, GTK_ICON_SIZE_MENU );
 }
 
 static gint
diff --git a/src/nact/nact-main-statusbar.c b/src/nact/nact-main-statusbar.c
index 12f77fa..885d7a4 100644
--- a/src/nact/nact-main-statusbar.c
+++ b/src/nact/nact-main-statusbar.c
@@ -215,8 +215,7 @@ nact_main_statusbar_set_locked( NactMainWindow *window, gboolean readonly, gint
 	}
 
 	if( set_pixbuf ){
-		pixbuf = nact_gtk_utils_get_pixbuf( NULL, GTK_ICON_SIZE_MENU );
-		gtk_image_set_from_pixbuf( image, pixbuf );
+		nact_gtk_utils_render( NULL, image, GTK_ICON_SIZE_MENU );
 	}
 }
 
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index f55b855..692e407 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -879,8 +879,9 @@ display_item( GtkTreeStore *model, GtkTreeView *treeview, GtkTreeIter *iter, con
 
 	if( NA_IS_OBJECT_ITEM( object )){
 		gchar *icon_name = na_object_get_icon( object );
-		GdkPixbuf *icon = nact_gtk_utils_get_pixbuf( icon_name, GTK_ICON_SIZE_MENU );
+		GdkPixbuf *icon = nact_gtk_utils_get_pixbuf( icon_name, GTK_WIDGET( treeview ), GTK_ICON_SIZE_MENU );
 		gtk_tree_store_set( model, iter, IACTIONS_LIST_ICON_COLUMN, icon, -1 );
+		g_object_unref( icon );
 	}
 }
 



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