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

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