Blame SOURCES/0011-Replace-signals-with-GSimpleActions.patch

f5c53a
From d1690196a9007568bfce3847841ea2b509eb3150 Mon Sep 17 00:00:00 2001
f5c53a
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
f5c53a
Date: Fri, 10 Jul 2020 06:28:06 +0200
f5c53a
Subject: [PATCH 11/18] Replace signals with GSimpleActions
f5c53a
f5c53a
This unifies actions pertaining to the application.
f5c53a
f5c53a
---
f5c53a
 src/gui/callbacks.c | 62 ++++++++++++++++++++++-----------------------
f5c53a
 src/gui/callbacks.h | 35 ++++++++++++++++---------
f5c53a
 src/gui/gtk-lshw.c  | 14 ++++++++++
f5c53a
 src/gui/gtk-lshw.ui | 16 ++++++------
f5c53a
 4 files changed, 76 insertions(+), 51 deletions(-)
f5c53a
f5c53a
diff --git a/src/gui/callbacks.c b/src/gui/callbacks.c
f5c53a
index f8aa0cb0f968..eec3e5571741 100644
f5c53a
--- a/src/gui/callbacks.c
f5c53a
+++ b/src/gui/callbacks.c
f5c53a
@@ -17,17 +17,36 @@ static char *id = "@(#) $Id$";
f5c53a
 
f5c53a
 G_MODULE_EXPORT
f5c53a
 void
f5c53a
-refresh_display                        (GtkMenuItem     *menuitem,
f5c53a
-gpointer         user_data)
f5c53a
+on_go_up_activated                     (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app)
f5c53a
+{
f5c53a
+  go_back(mainwindow);
f5c53a
+}
f5c53a
+
f5c53a
+G_MODULE_EXPORT
f5c53a
+void
f5c53a
+on_refresh_activated                   (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app)
f5c53a
 {
f5c53a
   refresh(mainwindow);
f5c53a
 }
f5c53a
 
f5c53a
+G_MODULE_EXPORT
f5c53a
+void
f5c53a
+on_save_activated                      (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app)
f5c53a
+{
f5c53a
+  save_as(mainwindow);
f5c53a
+}
f5c53a
 
f5c53a
 G_MODULE_EXPORT
f5c53a
 void
f5c53a
-on_about1_activate                     (GtkMenuItem     *menuitem,
f5c53a
-gpointer         user_data)
f5c53a
+on_about_activated                     (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app)
f5c53a
 {
f5c53a
   if(GTK_IS_WIDGET(about))
f5c53a
   {
f5c53a
@@ -35,6 +54,14 @@ gpointer         user_data)
f5c53a
   }
f5c53a
 }
f5c53a
 
f5c53a
+G_MODULE_EXPORT
f5c53a
+void
f5c53a
+on_quit_activated                      (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app)
f5c53a
+{
f5c53a
+  g_application_quit(G_APPLICATION(app));
f5c53a
+}
f5c53a
 
f5c53a
 G_MODULE_EXPORT
f5c53a
 void
f5c53a
@@ -147,15 +174,6 @@ gpointer         user_data)
f5c53a
 }
f5c53a
 
f5c53a
 
f5c53a
-G_MODULE_EXPORT
f5c53a
-void
f5c53a
-go_up                                  (GtkToolButton   *toolbutton,
f5c53a
-gpointer         user_data)
f5c53a
-{
f5c53a
-  go_back(mainwindow);
f5c53a
-}
f5c53a
-
f5c53a
-
f5c53a
 G_MODULE_EXPORT
f5c53a
 void
f5c53a
 on_lshw_map                            (GtkWidget       *widget,
f5c53a
@@ -163,21 +181,3 @@ gpointer         user_data)
f5c53a
 {
f5c53a
   refresh(mainwindow);
f5c53a
 }
f5c53a
-
f5c53a
-G_MODULE_EXPORT
f5c53a
-void
f5c53a
-on_save_activate                       (GtkMenuItem     *menuitem,
f5c53a
-                                        gpointer         user_data)
f5c53a
-{
f5c53a
-  save_as(mainwindow);
f5c53a
-}
f5c53a
-
f5c53a
-
f5c53a
-G_MODULE_EXPORT
f5c53a
-void
f5c53a
-on_savebutton_clicked                  (GtkToolButton   *toolbutton,
f5c53a
-                                        gpointer         user_data)
f5c53a
-{
f5c53a
-  on_save_activate(NULL, NULL);
f5c53a
-}
f5c53a
-
f5c53a
diff --git a/src/gui/callbacks.h b/src/gui/callbacks.h
f5c53a
index cc856e45ddb4..b9b9141c0eb7 100644
f5c53a
--- a/src/gui/callbacks.h
f5c53a
+++ b/src/gui/callbacks.h
f5c53a
@@ -1,8 +1,29 @@
f5c53a
 #include <gtk/gtk.h>
f5c53a
 
f5c53a
-void refresh_display (GtkMenuItem * menuitem, gpointer user_data);
f5c53a
+void
f5c53a
+on_go_up_activated                     (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app);
f5c53a
+
f5c53a
+void
f5c53a
+on_refresh_activated                   (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app);
f5c53a
 
f5c53a
-void on_about1_activate (GtkMenuItem * menuitem, gpointer user_data);
f5c53a
+void
f5c53a
+on_save_activated                      (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app);
f5c53a
+
f5c53a
+void
f5c53a
+on_about_activated                     (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app);
f5c53a
+
f5c53a
+void
f5c53a
+on_quit_activated                      (GSimpleAction   *action,
f5c53a
+                                        GVariant        *parameter,
f5c53a
+                                        gpointer         app);
f5c53a
 
f5c53a
 void on_aboutclose_activate (GtkButton * button, gpointer user_data);
f5c53a
 
f5c53a
@@ -35,14 +56,4 @@ void on_treeview2_cursor_changed (GtkTreeView * treeview, gpointer user_data);
f5c53a
 
f5c53a
 void on_treeview3_cursor_changed (GtkTreeView * treeview, gpointer user_data);
f5c53a
 
f5c53a
-void go_up (GtkToolButton * toolbutton, gpointer user_data);
f5c53a
-
f5c53a
 void on_lshw_map (GtkWidget * widget, gpointer user_data);
f5c53a
-
f5c53a
-void
f5c53a
-on_save_activate                       (GtkMenuItem     *menuitem,
f5c53a
-                                        gpointer         user_data);
f5c53a
-
f5c53a
-void
f5c53a
-on_savebutton_clicked                  (GtkToolButton   *toolbutton,
f5c53a
-                                        gpointer         user_data);
f5c53a
diff --git a/src/gui/gtk-lshw.c b/src/gui/gtk-lshw.c
f5c53a
index 6c0f0bbdf77f..0dc3aff6d322 100644
f5c53a
--- a/src/gui/gtk-lshw.c
f5c53a
+++ b/src/gui/gtk-lshw.c
f5c53a
@@ -6,11 +6,21 @@
f5c53a
 #include "config.h"
f5c53a
 #include "stock.h"
f5c53a
 #include "engine.h"
f5c53a
+#include "callbacks.h"
f5c53a
 
f5c53a
 static char *id = "@(#) $Id$";
f5c53a
 
f5c53a
 extern GtkWidget *mainwindow;
f5c53a
 
f5c53a
+static GActionEntry app_entries[] =
f5c53a
+{
f5c53a
+  { "go_up",   on_go_up_activated,   NULL, NULL, NULL },
f5c53a
+  { "refresh", on_refresh_activated, NULL, NULL, NULL },
f5c53a
+  { "save",    on_save_activated,    NULL, NULL, NULL },
f5c53a
+  { "about",   on_about_activated,   NULL, NULL, NULL },
f5c53a
+  { "quit",    on_quit_activated,    NULL, NULL, NULL }
f5c53a
+};
f5c53a
+
f5c53a
 static void
f5c53a
 activate (GApplication *app,
f5c53a
           gpointer      user_data)
f5c53a
@@ -35,6 +45,10 @@ activate (GApplication *app,
f5c53a
       return;
f5c53a
   }
f5c53a
 
f5c53a
+  g_action_map_add_action_entries (G_ACTION_MAP (app),
f5c53a
+                                   app_entries, G_N_ELEMENTS (app_entries),
f5c53a
+                                   app);
f5c53a
+
f5c53a
   lshw_gtk_stock_init();
f5c53a
   lshw_ui_init();
f5c53a
 
f5c53a
diff --git a/src/gui/gtk-lshw.ui b/src/gui/gtk-lshw.ui
f5c53a
index 7504c76d1a1b..d24e05c3aa20 100644
f5c53a
--- a/src/gui/gtk-lshw.ui
f5c53a
+++ b/src/gui/gtk-lshw.ui
f5c53a
@@ -136,7 +136,7 @@
f5c53a
                         <property name="can_focus">False</property>
f5c53a
                         <property name="use_underline">True</property>
f5c53a
                         <property name="use_stock">True</property>
f5c53a
-                        <signal name="activate" handler="on_save_activate" swapped="no"/>
f5c53a
+                        <property name="action_name">app.save</property>
f5c53a
                       </object>
f5c53a
                     </child>
f5c53a
                     <child>
f5c53a
@@ -152,7 +152,7 @@
f5c53a
                         <property name="can_focus">False</property>
f5c53a
                         <property name="use_underline">True</property>
f5c53a
                         <property name="use_stock">True</property>
f5c53a
-                        <signal name="activate" handler="gtk_main_quit" swapped="no"/>
f5c53a
+                        <property name="action_name">app.quit</property>
f5c53a
                       </object>
f5c53a
                     </child>
f5c53a
                   </object>
f5c53a
@@ -176,7 +176,7 @@
f5c53a
                         <property name="can_focus">False</property>
f5c53a
                         <property name="use_underline">True</property>
f5c53a
                         <property name="use_stock">True</property>
f5c53a
-                        <signal name="activate" handler="refresh_display" swapped="no"/>
f5c53a
+                        <property name="action_name">app.refresh</property>
f5c53a
                       </object>
f5c53a
                     </child>
f5c53a
                   </object>
f5c53a
@@ -200,7 +200,7 @@
f5c53a
                         <property name="can_focus">False</property>
f5c53a
                         <property name="use_underline">True</property>
f5c53a
                         <property name="use_stock">True</property>
f5c53a
-                        <signal name="activate" handler="on_about1_activate" swapped="no"/>
f5c53a
+                        <property name="action_name">app.about</property>
f5c53a
                       </object>
f5c53a
                     </child>
f5c53a
                   </object>
f5c53a
@@ -225,7 +225,7 @@
f5c53a
                 <property name="sensitive">False</property>
f5c53a
                 <property name="can_focus">False</property>
f5c53a
                 <property name="stock_id">gtk-go-up</property>
f5c53a
-                <signal name="clicked" handler="go_up" swapped="no"/>
f5c53a
+                <property name="action_name">app.go_up</property>
f5c53a
               </object>
f5c53a
               <packing>
f5c53a
                 <property name="expand">False</property>
f5c53a
@@ -238,7 +238,7 @@
f5c53a
                 <property name="can_focus">False</property>
f5c53a
                 <property name="tooltip_text" translatable="yes">Rescan the hardware</property>
f5c53a
                 <property name="stock_id">gtk-refresh</property>
f5c53a
-                <signal name="clicked" handler="refresh_display" swapped="no"/>
f5c53a
+                <property name="action_name">app.refresh</property>
f5c53a
               </object>
f5c53a
               <packing>
f5c53a
                 <property name="expand">False</property>
f5c53a
@@ -251,7 +251,7 @@
f5c53a
                 <property name="sensitive">False</property>
f5c53a
                 <property name="can_focus">False</property>
f5c53a
                 <property name="stock_id">gtk-save</property>
f5c53a
-                <signal name="clicked" handler="on_savebutton_clicked" swapped="no"/>
f5c53a
+                <property name="action_name">app.save</property>
f5c53a
               </object>
f5c53a
               <packing>
f5c53a
                 <property name="expand">False</property>
f5c53a
@@ -263,7 +263,7 @@
f5c53a
                 <property name="visible">True</property>
f5c53a
                 <property name="can_focus">False</property>
f5c53a
                 <property name="stock_id">gtk-quit</property>
f5c53a
-                <signal name="clicked" handler="gtk_main_quit" swapped="no"/>
f5c53a
+                <property name="action_name">app.quit</property>
f5c53a
               </object>
f5c53a
               <packing>
f5c53a
                 <property name="expand">False</property>
f5c53a
-- 
f5c53a
2.17.1
f5c53a