From e342333d936293e82ff889aa6745b93a8c975543 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 10 Jul 2020 05:04:19 +0200 Subject: [PATCH 06/18] Replace deprecated GtkIconFactory with GHashTable This removes most warnings. A possible further improvement would be to use GtkIconTheme instead, but it will require reorganising the SVG files around. --- src/gui/engine.cc | 3 ++- src/gui/print-gui.cc | 19 ++++++++----------- src/gui/print-gui.h | 2 +- src/gui/stock.c | 26 ++++++-------------------- src/gui/stock.h | 1 - 5 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/gui/engine.cc b/src/gui/engine.cc index 21e446e0359d..c66279e5f498 100644 --- a/src/gui/engine.cc +++ b/src/gui/engine.cc @@ -40,6 +40,7 @@ extern GtkWidget *description; extern GtkWidget *go_up_button; extern GtkWidget *save_button; extern GtkWidget *statusbar; +extern GHashTable *pixbufs; enum { @@ -224,7 +225,7 @@ static void display(GtkWidget * mainwindow) create_tags(buffer); string hwpath = gethwpath(*displayed, container); - printmarkup(*displayed, GTK_TEXT_VIEW(description), hwpath); + printmarkup(*displayed, GTK_TEXT_VIEW(description), hwpath, pixbufs); } } diff --git a/src/gui/print-gui.cc b/src/gui/print-gui.cc index 861ec4c695da..4138424d172e 100644 --- a/src/gui/print-gui.cc +++ b/src/gui/print-gui.cc @@ -66,15 +66,12 @@ static void printsize(long long value, const hwNode & node, const string & name, } -static void inserticon(const string & icon, const string & comment, GtkTextBuffer *buffer, GtkTextIter &iter, GtkTextView * textview) +static void inserticon(const string & icon, const string & comment, GtkTextBuffer *buffer, GtkTextIter &iter, GHashTable *pixbufs) { GdkPixbuf *pixbuf; GtkTextTag *tag; - pixbuf = gtk_widget_render_icon(GTK_WIDGET(textview), - icon.c_str(), - gtk_icon_size_from_name(LSHW_ICON_SIZE_LOGO), /* size */ - NULL); + pixbuf = GDK_PIXBUF(g_hash_table_lookup(pixbufs, icon.c_str())); if(!GDK_IS_PIXBUF(pixbuf)) return; @@ -87,7 +84,7 @@ static void inserticon(const string & icon, const string & comment, GtkTextBuff } -void printmarkup(const hwNode & node, GtkTextView *textview, const string & hwpath) +void printmarkup(const hwNode & node, GtkTextView *textview, const string & hwpath, GHashTable *pixbufs) { vector < string > config; vector < string > resources; @@ -125,13 +122,13 @@ void printmarkup(const hwNode & node, GtkTextView *textview, const string & hwpa gtk_text_buffer_insert (buffer, &iter, "\n", -1); if(node.getHint("icon").defined()) - inserticon(string("lshw-") + node.getHint("icon").asString(), "", buffer, iter, textview); + inserticon(string("lshw-") + node.getHint("icon").asString(), "", buffer, iter, pixbufs); if(node.getHint("bus.icon").defined()) - inserticon(string("lshw-") + node.getHint("bus.icon").asString(), "", buffer, iter, textview); + inserticon(string("lshw-") + node.getHint("bus.icon").asString(), "", buffer, iter, pixbufs); if(node.getHint("logo").defined()) - inserticon(string("lshw-") + node.getHint("logo").asString(), "", buffer, iter, textview); + inserticon(string("lshw-") + node.getHint("logo").asString(), "", buffer, iter, pixbufs); gtk_text_buffer_insert (buffer, &iter, "\n\n", -1); @@ -218,10 +215,10 @@ void printmarkup(const hwNode & node, GtkTextView *textview, const string & hwpa gtk_text_buffer_insert (buffer, &iter, "\n", -1); if(!node.claimed()) - inserticon(LSHW_STOCK_DISABLED, _("this device hasn't been claimed\n"), buffer, iter, textview); + inserticon(LSHW_STOCK_DISABLED, _("this device hasn't been claimed\n"), buffer, iter, pixbufs); if(!node.enabled()) - inserticon(LSHW_STOCK_DISABLED, _("this device has been disabled\n"), buffer, iter, textview); + inserticon(LSHW_STOCK_DISABLED, _("this device has been disabled\n"), buffer, iter, pixbufs); (void) &id; // avoid "id defined but not used" warning } diff --git a/src/gui/print-gui.h b/src/gui/print-gui.h index 055f7cdf3087..d41946161f02 100644 --- a/src/gui/print-gui.h +++ b/src/gui/print-gui.h @@ -4,7 +4,7 @@ #include "hw.h" #include -void printmarkup(const hwNode & node, GtkTextView *textview, const string & hwpath); +void printmarkup(const hwNode & node, GtkTextView *textview, const string & hwpath, GHashTable *pixbufs); string gethwpath(hwNode & node, hwNode & base); #endif diff --git a/src/gui/stock.c b/src/gui/stock.c index 46dfbe7173b5..9e7c3664427a 100644 --- a/src/gui/stock.c +++ b/src/gui/stock.c @@ -16,6 +16,7 @@ GtkWidget *description = NULL; GtkWidget *go_up_button = NULL; GtkWidget *save_button = NULL; GtkWidget *statusbar = NULL; +GHashTable *pixbufs = NULL; static struct StockIcon { @@ -87,7 +88,6 @@ void lshw_gtk_stock_init(void) { static int stock_initted = 0; - GtkIconFactory *icon_factory; int i; if (stock_initted) @@ -95,15 +95,12 @@ lshw_gtk_stock_init(void) stock_initted = 1; -/* Setup the icon factory. */ - icon_factory = gtk_icon_factory_new(); - - gtk_icon_factory_add_default(icon_factory); +/* Setup the icons hash table. */ + pixbufs = g_hash_table_new(g_str_hash, g_str_equal); for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) { GdkPixbuf *pixbuf; - GtkIconSet *iconset; gchar *filename; filename = find_file(stock_icons[i].filename, "artwork"); @@ -111,23 +108,15 @@ lshw_gtk_stock_init(void) if (filename == NULL) continue; - pixbuf = gdk_pixbuf_new_from_file(filename, NULL); + pixbuf = gdk_pixbuf_new_from_file_at_size(filename, LSHW_DEFAULT_ICON_SIZE, LSHW_DEFAULT_ICON_SIZE, NULL); g_free(filename); if(pixbuf) /* we managed to load something */ { - iconset = gtk_icon_set_new_from_pixbuf(pixbuf); - g_object_unref(G_OBJECT(pixbuf)); - gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); - gtk_icon_set_unref(iconset); + g_hash_table_insert(pixbufs, (char*)stock_icons[i].name, pixbuf); } } -/* register logo icon size */ - gtk_icon_size_register(LSHW_ICON_SIZE_LOGO, LSHW_DEFAULT_ICON_SIZE, LSHW_DEFAULT_ICON_SIZE); - - g_object_unref(G_OBJECT(icon_factory)); - (void) &id; /* avoid "id defined but not used" warning */ } @@ -168,10 +157,7 @@ void lshw_ui_init(void) gtk_builder_connect_signals( builder, mainwindow ); g_object_unref( G_OBJECT( builder ) ); - icon = gtk_widget_render_icon(GTK_WIDGET(mainwindow), - "lshw-logo", - GTK_ICON_SIZE_DIALOG, - NULL); + icon = g_hash_table_lookup(pixbufs, LSHW_STOCK_LOGO); if(GDK_IS_PIXBUF(icon)) { gtk_window_set_icon(GTK_WINDOW(mainwindow), icon); diff --git a/src/gui/stock.h b/src/gui/stock.h index a0fef5b882b2..58f788e5b573 100644 --- a/src/gui/stock.h +++ b/src/gui/stock.h @@ -43,7 +43,6 @@ /** * For getting the icon size for the logo */ -#define LSHW_ICON_SIZE_LOGO "lshw-icon-size-logo" #define LSHW_DEFAULT_ICON_SIZE 40 void lshw_gtk_stock_init(void); -- 2.17.1