[nautilus] all: use nautilus_bookmark_get_gicon()



commit 3aa0396da2014b35f0ef21dffd29e4953667ceb2
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Jan 12 19:29:25 2011 +0100

    all: use nautilus_bookmark_get_gicon()

 libnautilus-private/nautilus-ui-utilities.c |   43 ++++++--------------------
 src/nautilus-bookmarks-window.c             |   33 +++++++++-----------
 src/nautilus-window-menus.c                 |   15 ++++-----
 3 files changed, 32 insertions(+), 59 deletions(-)
---
diff --git a/libnautilus-private/nautilus-ui-utilities.c b/libnautilus-private/nautilus-ui-utilities.c
index 311ada9..e60f1e3 100644
--- a/libnautilus-private/nautilus-ui-utilities.c
+++ b/libnautilus-private/nautilus-ui-utilities.c
@@ -128,30 +128,13 @@ extension_action_sensitive_callback (NautilusMenuItem *item,
 	gtk_action_set_sensitive (GTK_ACTION (user_data), value);
 }
 
-static GdkPixbuf *
-get_action_icon (const char *icon_name, int size)
-{
-	NautilusIconInfo *info;
-	GdkPixbuf *pixbuf;
-
-	if (g_path_is_absolute (icon_name)) {
-		info = nautilus_icon_info_lookup_from_path (icon_name, size);
-	} else {
-		info = nautilus_icon_info_lookup_from_name (icon_name, size);
-	}
-	pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size);
-	g_object_unref (info);
-
-	return pixbuf;
-}
-
 GtkAction *
 nautilus_action_from_menu_item (NautilusMenuItem *item)
 {
 	char *name, *label, *tip, *icon_name;
 	gboolean sensitive, priority;
 	GtkAction *action;
-	GdkPixbuf *pixbuf;
+	GIcon *icon;
 
 	g_object_get (G_OBJECT (item),
 		      "name", &name, "label", &label,
@@ -166,13 +149,10 @@ nautilus_action_from_menu_item (NautilusMenuItem *item)
 				 icon_name);
 
 	if (icon_name != NULL) {
-		pixbuf = get_action_icon (icon_name,
-								nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU));
-		if (pixbuf != NULL) {
-			g_object_set_data_full (G_OBJECT (action), "menu-icon",
-						pixbuf,
-						g_object_unref);
-		}
+		icon = g_themed_icon_new_with_default_fallbacks (icon_name);
+		g_object_set_data_full (G_OBJECT (action), "menu-icon",
+					icon,
+					g_object_unref);
 	}
 
 	gtk_action_set_sensitive (action, sensitive);
@@ -197,7 +177,7 @@ nautilus_toolbar_action_from_menu_item (NautilusMenuItem *item)
 	char *name, *label, *tip, *icon_name;
 	gboolean sensitive, priority;
 	GtkAction *action;
-	GdkPixbuf *pixbuf;
+	GIcon *icon;
 
 	g_object_get (G_OBJECT (item),
 		      "name", &name, "label", &label,
@@ -212,13 +192,10 @@ nautilus_toolbar_action_from_menu_item (NautilusMenuItem *item)
 				 icon_name);
 
 	if (icon_name != NULL) {
-		pixbuf = get_action_icon (icon_name,
-								nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_LARGE_TOOLBAR));
-		if (pixbuf != NULL) {
-			g_object_set_data_full (G_OBJECT (action), "toolbar-icon",
-						pixbuf,
-						g_object_unref);
-		}
+		icon = g_themed_icon_new_with_default_fallbacks (icon_name);
+		g_object_set_data_full (G_OBJECT (action), "toolbar-icon",
+					icon,
+					g_object_unref);
 	}
 
 	gtk_action_set_sensitive (action, sensitive);
diff --git a/src/nautilus-bookmarks-window.c b/src/nautilus-bookmarks-window.c
index 713fa5c..b249f98 100644
--- a/src/nautilus-bookmarks-window.c
+++ b/src/nautilus-bookmarks-window.c
@@ -174,7 +174,7 @@ static GtkListStore *
 create_bookmark_store (void)
 {
 	return gtk_list_store_new (BOOKMARK_LIST_COLUMN_COUNT,
-				   GDK_TYPE_PIXBUF,
+				   G_TYPE_ICON,
 				   G_TYPE_STRING,
 				   G_TYPE_OBJECT,
 				   PANGO_TYPE_STYLE);
@@ -287,14 +287,14 @@ create_bookmarks_window (NautilusBookmarkList *list, GObject *undo_manager_sourc
 	rend = gtk_cell_renderer_pixbuf_new ();
 	col = gtk_tree_view_column_new_with_attributes ("Icon", 
 							rend,
-							"pixbuf", 
+							"gicon", 
 							BOOKMARK_LIST_COLUMN_ICON,
 							NULL);
 	gtk_tree_view_append_column (bookmark_list_widget,
 				     GTK_TREE_VIEW_COLUMN (col));
 	gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (col),
 					      NAUTILUS_ICON_SIZE_SMALLER);
-	
+
 	rend = gtk_cell_renderer_text_new ();
 	g_object_set (rend,
 		      "ellipsize", PANGO_ELLIPSIZE_END,
@@ -811,8 +811,8 @@ update_bookmark_from_text (void)
 {
 	if (text_changed) {
 		NautilusBookmark *bookmark, *bookmark_in_list;
-		char *name;
-		GdkPixbuf *pixbuf;
+		const char *name;
+		GIcon *icon;
 		guint selected_row;
 		GtkTreeIter iter;
 		GFile *location;
@@ -856,19 +856,17 @@ update_bookmark_from_text (void)
 								   selected_row);
 
 		name = nautilus_bookmark_get_name (bookmark_in_list);
-
-		pixbuf = nautilus_bookmark_get_pixbuf (bookmark_in_list, GTK_ICON_SIZE_MENU);
+		icon = nautilus_bookmark_get_icon (bookmark_in_list);
 
 		gtk_list_store_set (bookmark_list_store, &iter,
 				    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark_in_list,
 				    BOOKMARK_LIST_COLUMN_NAME, name,
-				    BOOKMARK_LIST_COLUMN_ICON, pixbuf,
+				    BOOKMARK_LIST_COLUMN_ICON, icon,
 				    -1);
 		g_signal_handler_unblock (bookmark_list_store,
 					  row_changed_signal_id);
 
-		g_object_unref (pixbuf);
-		g_free (name);
+		g_object_unref (icon);
 	}
 }
 
@@ -993,17 +991,17 @@ repopulate (void)
 
 	for (index = 0; index < nautilus_bookmark_list_length (bookmarks); ++index) {
 		NautilusBookmark *bookmark;
-		char             *bookmark_name;
-		GdkPixbuf        *bookmark_pixbuf;
+		const char       *bookmark_name;
+		GIcon            *bookmark_icon;
 		GtkTreeIter       iter;
 
 		bookmark = nautilus_bookmark_list_item_at (bookmarks, index);
 		bookmark_name = nautilus_bookmark_get_name (bookmark);
-		bookmark_pixbuf = nautilus_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU);
-		
+		bookmark_icon = nautilus_bookmark_get_icon (bookmark);
+
 		gtk_list_store_append (store, &iter);
 		gtk_list_store_set (store, &iter, 
-				    BOOKMARK_LIST_COLUMN_ICON, bookmark_pixbuf,
+				    BOOKMARK_LIST_COLUMN_ICON, bookmark_icon,
 				    BOOKMARK_LIST_COLUMN_NAME, bookmark_name,
 				    BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark,
 				    BOOKMARK_LIST_COLUMN_STYLE, PANGO_STYLE_NORMAL,
@@ -1018,10 +1016,9 @@ repopulate (void)
 			gtk_tree_path_free (path);
 		}
 
-		g_free (bookmark_name);
-		g_object_unref (bookmark_pixbuf);
-		
+		g_object_unref (bookmark_icon);
 	}
+
 	g_signal_handler_unblock (store, row_changed_signal_id);
 
 	if (reference != NULL) {
diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c
index 0574a2e..d437e08 100644
--- a/src/nautilus-window-menus.c
+++ b/src/nautilus-window-menus.c
@@ -167,7 +167,7 @@ nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
 	char action_name[128];
 	char *name;
 	char *path;
-	GdkPixbuf *pixbuf;
+	GIcon *icon;
 	GtkAction *action;
 	GtkWidget *menuitem;
 
@@ -178,7 +178,7 @@ nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
 	name = nautilus_bookmark_get_name (bookmark);
 
 	/* Create menu item with pixbuf */
-	pixbuf = nautilus_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU);
+	icon = nautilus_bookmark_get_icon (bookmark);
 
 	g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent);
 
@@ -188,7 +188,7 @@ nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
 				 NULL);
 	
 	g_object_set_data_full (G_OBJECT (action), "menu-icon",
-				g_object_ref (pixbuf),
+				icon,
 				g_object_unref);
 
 	g_signal_connect_data (action, "activate",
@@ -215,7 +215,6 @@ nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
 	gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem),
 						   TRUE);
 
-	g_object_unref (pixbuf);
 	g_free (path);
 	g_free (name);
 }
@@ -693,7 +692,7 @@ connect_proxy_cb (GtkUIManager *manager,
 		  GtkWidget *proxy,
 		  NautilusWindow *window)
 {
-	GdkPixbuf *icon;
+	GIcon *icon;
 	GtkWidget *widget;
 	
 	if (GTK_IS_MENU_ITEM (proxy)) {
@@ -707,19 +706,19 @@ connect_proxy_cb (GtkUIManager *manager,
 		icon = g_object_get_data (G_OBJECT (action), "menu-icon");
 		if (icon != NULL) {
 			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy),
-						       gtk_image_new_from_pixbuf (icon));
+						       gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU));
 		}
 	}
 	if (GTK_IS_TOOL_BUTTON (proxy)) {
 		icon = g_object_get_data (G_OBJECT (action), "toolbar-icon");
 		if (icon != NULL) {
-			widget = gtk_image_new_from_pixbuf (icon);
+			widget = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
 			gtk_widget_show (widget);
 			gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (proxy),
 							 widget);
 		}
 	}
-	
+
 	widget = get_event_widget (proxy);
 	if (widget) {
 		g_signal_connect (widget, "button-press-event",



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