From: Christian Dywan Date: Sat, 28 Nov 2009 22:47:29 +0000 (+0100) Subject: Use icon names for search engines directly instead of pixbufs X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=565e32599e362056cb8cd8be960d1c60aa258487;p=midori Use icon names for search engines directly instead of pixbufs --- diff --git a/midori/gtkiconentry.h b/midori/gtkiconentry.h index d34ff962..c2145684 100644 --- a/midori/gtkiconentry.h +++ b/midori/gtkiconentry.h @@ -39,6 +39,7 @@ G_BEGIN_DECLS #define GTK_TYPE_ICON_ENTRY GTK_TYPE_ENTRY #define gtk_icon_entry_new gtk_entry_new #define gtk_icon_entry_set_icon_from_stock gtk_entry_set_icon_from_stock + #define gtk_icon_entry_set_icon_from_icon_name gtk_entry_set_icon_from_icon_name void gtk_icon_entry_set_icon_from_pixbuf (GtkEntry* entry, diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c index ba062c4d..e324b198 100644 --- a/midori/midori-searchaction.c +++ b/midori/midori-searchaction.c @@ -407,9 +407,9 @@ midori_search_action_manage_activate_cb (GtkWidget* menuitem, /* Private function, used by MidoriView */ /* static */ GdkPixbuf* -midori_search_action_get_icon (KatzeNet* net, - KatzeItem* item, - GtkWidget* widget) +midori_search_action_get_icon (KatzeItem* item, + GtkWidget* widget, + const gchar** icon_name) { const gchar* icon; @@ -417,25 +417,21 @@ midori_search_action_get_icon (KatzeNet* net, { GdkScreen* screen; GtkIconTheme* icon_theme; - gint width, height; - GdkPixbuf* pixbuf; - if (G_UNLIKELY (!(screen = gtk_widget_get_screen (widget)))) - return gtk_widget_render_icon (widget, GTK_STOCK_FILE, - GTK_ICON_SIZE_MENU, NULL); + screen = gtk_widget_get_screen (widget); icon_theme = gtk_icon_theme_get_for_screen (screen); - gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget), - GTK_ICON_SIZE_MENU, &width, &height); - if ((pixbuf = gtk_icon_theme_load_icon (icon_theme, icon, MAX (width, height), - GTK_ICON_LOOKUP_USE_BUILTIN, NULL))) - return pixbuf; + if (gtk_icon_theme_has_icon (icon_theme, icon)) + *icon_name = icon; + else + *icon_name = GTK_STOCK_FILE; + return NULL; } if ((icon = katze_item_get_uri (item)) && (g_strstr_len (icon, 8, "://"))) return katze_load_cached_icon (icon, widget); - return gtk_widget_render_icon (widget, GTK_STOCK_FILE, - GTK_ICON_SIZE_MENU, NULL); + *icon_name = GTK_STOCK_FILE; + return NULL; } static void @@ -463,13 +459,20 @@ midori_search_action_icon_released_cb (GtkWidget* entry, { do { + const gchar* icon_name; + menuitem = gtk_image_menu_item_new_with_label ( katze_item_get_name (item)); image = gtk_image_new (); - icon = midori_search_action_get_icon ( - MIDORI_SEARCH_ACTION (action)->net, item, entry); - gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon); - g_object_unref (icon); + icon = midori_search_action_get_icon (item, entry, &icon_name); + if (icon) + { + gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon); + g_object_unref (icon); + } + else + gtk_image_set_from_icon_name (GTK_IMAGE (image), icon_name, + GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); #if GTK_CHECK_VERSION (2, 16, 0) gtk_image_menu_item_set_always_show_image ( @@ -524,11 +527,19 @@ midori_search_action_set_entry_icon (MidoriSearchAction* search_action, if (search_action->current_item) { - icon = midori_search_action_get_icon (search_action->net, - search_action->current_item, entry); - gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry), - GTK_ICON_ENTRY_PRIMARY, icon); - g_object_unref (icon); + const gchar* icon_name; + + icon = midori_search_action_get_icon (search_action->current_item, + entry, &icon_name); + if (icon) + { + gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry), + GTK_ICON_ENTRY_PRIMARY, icon); + g_object_unref (icon); + } + else + gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry), + GTK_ICON_ENTRY_PRIMARY, icon_name); sokoke_entry_set_default_text (GTK_ENTRY (entry), katze_item_get_name (search_action->current_item)); } @@ -818,13 +829,18 @@ midori_search_action_dialog_render_icon_cb (GtkTreeViewColumn* column, KatzeItem* item; MidoriSearchAction* search_action; GdkPixbuf* icon; + const gchar* icon_name; gtk_tree_model_get (model, iter, 0, &item, -1); search_action = g_object_get_data (G_OBJECT (treeview), "search-action"); - icon = midori_search_action_get_icon (search_action->net, item, treeview); - g_object_set (renderer, "pixbuf", icon, "yalign", 0.25, NULL); - g_object_unref (icon); + if ((icon = midori_search_action_get_icon (item, treeview, &icon_name))) + { + g_object_set (renderer, "pixbuf", icon, "yalign", 0.25, NULL); + g_object_unref (icon); + } + else + g_object_set (renderer, "icon-name", icon_name, "yalign", 0.25, NULL); g_object_unref (item); } diff --git a/midori/midori-view.c b/midori/midori-view.c index d4a89e3d..c2cbf8c1 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -40,9 +40,9 @@ webkit_web_frame_print (WebKitWebFrame* web_frame); #endif GdkPixbuf* -midori_search_action_get_icon (KatzeNet* net, - KatzeItem* item, - GtkWidget* widget); +midori_search_action_get_icon (KatzeItem* item, + GtkWidget* widget, + const gchar** icon_name); static void midori_view_construct_web_view (MidoriView* view); @@ -1850,11 +1850,18 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view, while ((item = katze_array_get_nth_item (search_engines, i++))) { GdkPixbuf* pixbuf; + const gchar* icon_name; + menuitem = gtk_image_menu_item_new_with_mnemonic (katze_item_get_name (item)); - pixbuf = midori_search_action_get_icon (view->net, item, - GTK_WIDGET (web_view)); - icon = gtk_image_new_from_pixbuf (pixbuf); - g_object_unref (pixbuf); + pixbuf = midori_search_action_get_icon (item, + GTK_WIDGET (web_view), &icon_name); + if (pixbuf) + { + icon = gtk_image_new_from_pixbuf (pixbuf); + g_object_unref (pixbuf); + } + else + icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), icon); #if GTK_CHECK_VERSION (2, 16, 0) gtk_image_menu_item_set_always_show_image (