Blame SOURCES/0013-Move-from-GtkMenuBar-to-GMenu.patch

f5c53a
From bc5046d9917fe9cf84dd899f90aef5b90b7d4b04 Mon Sep 17 00:00:00 2001
f5c53a
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
f5c53a
Date: Wed, 15 Jul 2020 16:54:27 +0200
f5c53a
Subject: [PATCH 13/18] Move from GtkMenuBar to GMenu
f5c53a
f5c53a
This moves forward with gtk4 support, while also allowing a global menu
f5c53a
for environments which use one, such as GNOME.
f5c53a
f5c53a
I also added shortcuts so that users can press ^Q, ^R and ^S to quit,
f5c53a
refresh and save.
f5c53a
f5c53a
---
f5c53a
 src/gui/gtk-lshw.c  |   2 +-
f5c53a
 src/gui/gtk-lshw.ui | 138 ++++++++++++--------------------------------
f5c53a
 src/gui/stock.c     |   6 +-
f5c53a
 src/gui/stock.h     |   4 +-
f5c53a
 4 files changed, 47 insertions(+), 103 deletions(-)
f5c53a
f5c53a
diff --git a/src/gui/gtk-lshw.c b/src/gui/gtk-lshw.c
f5c53a
index 7b91ec5e4f01..d3e531c4ceb3 100644
f5c53a
--- a/src/gui/gtk-lshw.c
f5c53a
+++ b/src/gui/gtk-lshw.c
f5c53a
@@ -57,7 +57,7 @@ activate (GApplication *app,
f5c53a
   g_simple_action_set_enabled(save_action, FALSE);
f5c53a
 
f5c53a
   lshw_gtk_stock_init();
f5c53a
-  lshw_ui_init();
f5c53a
+  lshw_ui_init(GTK_APPLICATION(app));
f5c53a
 
f5c53a
   if(!mainwindow)
f5c53a
     return;
f5c53a
diff --git a/src/gui/gtk-lshw.ui b/src/gui/gtk-lshw.ui
f5c53a
index 76fcd19379f2..cf9d678f00d9 100644
f5c53a
--- a/src/gui/gtk-lshw.ui
f5c53a
+++ b/src/gui/gtk-lshw.ui
f5c53a
@@ -103,7 +103,6 @@
f5c53a
     </action-widgets>
f5c53a
   </object>
f5c53a
   <object class="GtkApplicationWindow" id="mainwindow">
f5c53a
-    <property name="visible">True</property>
f5c53a
     <property name="can_focus">False</property>
f5c53a
     <property name="title" translatable="yes">lshw</property>
f5c53a
     <property name="default_width">700</property>
f5c53a
@@ -115,105 +114,6 @@
f5c53a
         <property name="visible">True</property>
f5c53a
         <property name="can_focus">False</property>
f5c53a
         <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
f5c53a
-        <child>
f5c53a
-          <object class="GtkMenuBar" id="menubar1">
f5c53a
-            <property name="visible">True</property>
f5c53a
-            <property name="can_focus">False</property>
f5c53a
-            <child>
f5c53a
-              <object class="GtkMenuItem" id="menuitem1">
f5c53a
-                <property name="visible">True</property>
f5c53a
-                <property name="can_focus">False</property>
f5c53a
-                <property name="label" translatable="yes">_File</property>
f5c53a
-                <property name="use_underline">True</property>
f5c53a
-                <child type="submenu">
f5c53a
-                  <object class="GtkMenu" id="menu1">
f5c53a
-                    <property name="visible">True</property>
f5c53a
-                    <property name="can_focus">False</property>
f5c53a
-                    <child>
f5c53a
-                      <object class="GtkImageMenuItem" id="savemenu">
f5c53a
-                        <property name="label">gtk-save</property>
f5c53a
-                        <property name="visible">True</property>
f5c53a
-                        <property name="can_focus">False</property>
f5c53a
-                        <property name="use_underline">True</property>
f5c53a
-                        <property name="use_stock">True</property>
f5c53a
-                        <property name="action_name">app.save</property>
f5c53a
-                      </object>
f5c53a
-                    </child>
f5c53a
-                    <child>
f5c53a
-                      <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
f5c53a
-                        <property name="visible">True</property>
f5c53a
-                        <property name="can_focus">False</property>
f5c53a
-                      </object>
f5c53a
-                    </child>
f5c53a
-                    <child>
f5c53a
-                      <object class="GtkImageMenuItem" id="imagemenuitem5">
f5c53a
-                        <property name="label">gtk-quit</property>
f5c53a
-                        <property name="visible">True</property>
f5c53a
-                        <property name="can_focus">False</property>
f5c53a
-                        <property name="use_underline">True</property>
f5c53a
-                        <property name="use_stock">True</property>
f5c53a
-                        <property name="action_name">app.quit</property>
f5c53a
-                      </object>
f5c53a
-                    </child>
f5c53a
-                  </object>
f5c53a
-                </child>
f5c53a
-              </object>
f5c53a
-            </child>
f5c53a
-            <child>
f5c53a
-              <object class="GtkMenuItem" id="menuitem3">
f5c53a
-                <property name="visible">True</property>
f5c53a
-                <property name="can_focus">False</property>
f5c53a
-                <property name="label" translatable="yes">_View</property>
f5c53a
-                <property name="use_underline">True</property>
f5c53a
-                <child type="submenu">
f5c53a
-                  <object class="GtkMenu" id="menu2">
f5c53a
-                    <property name="visible">True</property>
f5c53a
-                    <property name="can_focus">False</property>
f5c53a
-                    <child>
f5c53a
-                      <object class="GtkImageMenuItem" id="refresh1">
f5c53a
-                        <property name="label">gtk-refresh</property>
f5c53a
-                        <property name="visible">True</property>
f5c53a
-                        <property name="can_focus">False</property>
f5c53a
-                        <property name="use_underline">True</property>
f5c53a
-                        <property name="use_stock">True</property>
f5c53a
-                        <property name="action_name">app.refresh</property>
f5c53a
-                      </object>
f5c53a
-                    </child>
f5c53a
-                  </object>
f5c53a
-                </child>
f5c53a
-              </object>
f5c53a
-            </child>
f5c53a
-            <child>
f5c53a
-              <object class="GtkMenuItem" id="menuitem4">
f5c53a
-                <property name="visible">True</property>
f5c53a
-                <property name="can_focus">False</property>
f5c53a
-                <property name="label" translatable="yes">_Help</property>
f5c53a
-                <property name="use_underline">True</property>
f5c53a
-                <child type="submenu">
f5c53a
-                  <object class="GtkMenu" id="menu3">
f5c53a
-                    <property name="visible">True</property>
f5c53a
-                    <property name="can_focus">False</property>
f5c53a
-                    <child>
f5c53a
-                      <object class="GtkImageMenuItem" id="imagemenuitem10">
f5c53a
-                        <property name="label">gtk-about</property>
f5c53a
-                        <property name="visible">True</property>
f5c53a
-                        <property name="can_focus">False</property>
f5c53a
-                        <property name="use_underline">True</property>
f5c53a
-                        <property name="use_stock">True</property>
f5c53a
-                        <property name="action_name">app.about</property>
f5c53a
-                      </object>
f5c53a
-                    </child>
f5c53a
-                  </object>
f5c53a
-                </child>
f5c53a
-              </object>
f5c53a
-            </child>
f5c53a
-          </object>
f5c53a
-          <packing>
f5c53a
-            <property name="expand">False</property>
f5c53a
-            <property name="fill">True</property>
f5c53a
-            <property name="position">0</property>
f5c53a
-          </packing>
f5c53a
-        </child>
f5c53a
         <child>
f5c53a
           <object class="GtkToolbar" id="toolbar1">
f5c53a
             <property name="visible">True</property>
f5c53a
@@ -423,4 +323,42 @@
f5c53a
       </object>
f5c53a
     </child>
f5c53a
   </object>
f5c53a
+  <menu id="menubar">
f5c53a
+    <submenu>
f5c53a
+      <attribute name="label" translatable="yes">_File</attribute>
f5c53a
+      <section>
f5c53a
+        <item>
f5c53a
+          <attribute name="label" translatable="yes">_Save</attribute>
f5c53a
+          <attribute name="action">app.save</attribute>
f5c53a
+          <attribute name="accel"><Control>s</attribute>
f5c53a
+        </item>
f5c53a
+      </section>
f5c53a
+      <section>
f5c53a
+        <item>
f5c53a
+          <attribute name="label" translatable="yes">_Quit</attribute>
f5c53a
+          <attribute name="action">app.quit</attribute>
f5c53a
+          <attribute name="accel"><Control>q</attribute>
f5c53a
+        </item>
f5c53a
+      </section>
f5c53a
+    </submenu>
f5c53a
+    <submenu>
f5c53a
+      <attribute name="label" translatable="yes">_View</attribute>
f5c53a
+      <section>
f5c53a
+        <item>
f5c53a
+          <attribute name="label" translatable="yes">_Refresh</attribute>
f5c53a
+          <attribute name="action">app.refresh</attribute>
f5c53a
+          <attribute name="accel"><Control>r</attribute>
f5c53a
+        </item>
f5c53a
+      </section>
f5c53a
+    </submenu>
f5c53a
+    <submenu>
f5c53a
+      <attribute name="label" translatable="yes">_Help</attribute>
f5c53a
+      <section>
f5c53a
+        <item>
f5c53a
+          <attribute name="label" translatable="yes">_About</attribute>
f5c53a
+          <attribute name="action">app.about</attribute>
f5c53a
+        </item>
f5c53a
+      </section>
f5c53a
+    </submenu>
f5c53a
+  </menu>
f5c53a
 </interface>
f5c53a
diff --git a/src/gui/stock.c b/src/gui/stock.c
f5c53a
index fa18f9ed7f85..ce0b42abea58 100644
f5c53a
--- a/src/gui/stock.c
f5c53a
+++ b/src/gui/stock.c
f5c53a
@@ -14,6 +14,7 @@ GtkWidget *list2 = NULL;
f5c53a
 GtkWidget *list3 = NULL;
f5c53a
 GtkWidget *description = NULL;
f5c53a
 GtkWidget *statusbar = NULL;
f5c53a
+GMenuModel *menubar = NULL;
f5c53a
 GHashTable *pixbufs = NULL;
f5c53a
 
f5c53a
 static struct StockIcon
f5c53a
@@ -118,7 +119,7 @@ lshw_gtk_stock_init(void)
f5c53a
   (void) &id;                                     /* avoid "id defined but not used" warning */
f5c53a
 }
f5c53a
 
f5c53a
-void lshw_ui_init(void)
f5c53a
+void lshw_ui_init(GtkApplication *app)
f5c53a
 {
f5c53a
   GError *error = NULL;
f5c53a
   GtkBuilder *builder = NULL;
f5c53a
@@ -151,6 +152,9 @@ void lshw_ui_init(void)
f5c53a
   description = GTK_WIDGET(gtk_builder_get_object( builder, "description"));
f5c53a
   statusbar = GTK_WIDGET(gtk_builder_get_object( builder, "statusbar"));
f5c53a
   gtk_builder_connect_signals( builder, mainwindow );
f5c53a
+  menubar = G_MENU_MODEL( gtk_builder_get_object( builder, "menubar"));
f5c53a
+  gtk_window_set_application( GTK_WINDOW( mainwindow ), app );
f5c53a
+  gtk_application_set_menubar( app, menubar );
f5c53a
   g_object_unref( G_OBJECT( builder ) );
f5c53a
 
f5c53a
   icon = g_hash_table_lookup(pixbufs, LSHW_STOCK_LOGO);
f5c53a
diff --git a/src/gui/stock.h b/src/gui/stock.h
f5c53a
index 58f788e5b573..1c732dfb541e 100644
f5c53a
--- a/src/gui/stock.h
f5c53a
+++ b/src/gui/stock.h
f5c53a
@@ -45,6 +45,8 @@
f5c53a
  */
f5c53a
 #define LSHW_DEFAULT_ICON_SIZE        40
f5c53a
 
f5c53a
+typedef struct _GtkApplication GtkApplication;
f5c53a
+
f5c53a
 void lshw_gtk_stock_init(void);
f5c53a
-void lshw_ui_init(void);
f5c53a
+void lshw_ui_init(GtkApplication *);
f5c53a
 #endif                                            /* _STOCK_H_ */
f5c53a
-- 
f5c53a
2.17.1
f5c53a