Blame SOURCES/0006-Replace-deprecated-GtkIconFactory-with-GHashTable.patch

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