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

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