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

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