[gssdp] sniffer: Modernize UI



commit 2b2f3788090d7a5e6960812878a8c4a8802c6de5
Author: Jens Georg <mail jensge org>
Date:   Fri Oct 26 23:25:22 2018 +0200

    sniffer: Modernize UI

 tools/gssdp-device-sniffer.c             | 102 ++++++++++----
 tools/gssdp-device-sniffer.gresource.xml |   1 +
 tools/gssdp-device-sniffer.ui            | 222 +++++++++++++------------------
 tools/window-menu.ui                     |  24 ++++
 4 files changed, 190 insertions(+), 159 deletions(-)
---
diff --git a/tools/gssdp-device-sniffer.c b/tools/gssdp-device-sniffer.c
index 55bd76c..966c132 100644
--- a/tools/gssdp-device-sniffer.c
+++ b/tools/gssdp-device-sniffer.c
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 
 #define UI_RESOURCE "/org/gupnp/GSSDP/DeviceSniffer.ui"
+#define MENU_RESOURCE "/org/gupnp/GSSDP/WindowMenu.ui"
 #define MAX_IP_LEN 16
 
 static char *interface = NULL;
@@ -42,19 +43,10 @@ GOptionEntry entries[] =
 };
 
 void
-on_enable_packet_capture_activate (GtkCheckMenuItem *menuitem,
+on_enable_packet_capture_activate (GtkToggleButton  *menuitem,
                                    gpointer          user_data);
-void
-on_details_activate (GtkWidget *scrolled_window, GtkCheckMenuItem *menuitem);
-
-void
-on_clear_packet_capture_activate (GtkMenuItem *menuitem,
-                                  gpointer     user_data);
 
 void
-on_use_filter_radiobutton_toggled (GtkToggleButton *togglebutton,
-                                   gpointer         user_data);
-void
 on_address_filter_dialog_response (GtkDialog *dialog,
                                    gint       response,
                                    gpointer   user_data);
@@ -63,10 +55,19 @@ gboolean
 on_delete_event (GtkWidget *widget, GdkEvent  *event, gpointer   user_data);
 
 G_MODULE_EXPORT void
-on_enable_packet_capture_activate (GtkCheckMenuItem      *menuitem,
-                                   G_GNUC_UNUSED gpointer user_data)
+on_enable_packet_capture_activate (GtkToggleButton *menuitem,
+                                   gpointer         user_data)
 {
-        capture_packets = gtk_check_menu_item_get_active (menuitem);
+        const gchar *icon_name = NULL;
+
+        capture_packets = gtk_toggle_button_get_active (menuitem);
+        icon_name = capture_packets
+                ? "media-playback-stop-symbolic"
+                : "media-playback-start-symbolic";
+
+        gtk_image_set_from_icon_name (GTK_IMAGE (user_data),
+                                      icon_name,
+                                      GTK_ICON_SIZE_BUTTON);
 }
 
 static void
@@ -92,14 +93,21 @@ clear_packet_treeview (void)
         }
 }
 
-G_MODULE_EXPORT
-void
-on_details_activate (GtkWidget *scrolled_window, GtkCheckMenuItem *menuitem)
+static void
+on_details_activate (GSimpleAction *action,
+                     GVariant *parameter,
+                     gpointer user_data)
 {
-        gboolean active;
+        GtkWidget *scrolled_window = NULL;
+        GtkBuilder *builder = NULL;
+
+        builder = GTK_BUILDER (user_data);
+
+        scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                              "packet-details-scrolledwindow"));
 
-        active = gtk_check_menu_item_get_active (menuitem);
-        g_object_set (G_OBJECT (scrolled_window), "visible", active, NULL);
+        g_object_set (G_OBJECT (scrolled_window), "visible", g_variant_get_boolean (parameter), NULL);
+        g_simple_action_set_state (action, parameter);
 }
 
 static void
@@ -176,14 +184,6 @@ on_packet_selected (GtkTreeSelection      *selection,
                 update_packet_details ("", 0);
 }
 
-G_MODULE_EXPORT
-void
-on_clear_packet_capture_activate (G_GNUC_UNUSED GtkMenuItem *menuitem,
-                                  G_GNUC_UNUSED gpointer     user_data)
-{
-        clear_packet_treeview ();
-}
-
 static const char *message_types[] = {"M-SEARCH", "RESPONSE", "NOTIFY"};
 
 static char **
@@ -576,6 +576,43 @@ on_delete_event (G_GNUC_UNUSED GtkWidget *widget,
         return TRUE;
 }
 
+static void
+on_show_address_filter (GSimpleAction *action,
+                        GVariant *parameter,
+                        gpointer user_data)
+{
+        GtkWidget *dialog = NULL;
+
+        dialog = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (user_data),
+                                                     "address-filter-dialog"));
+        gtk_widget_show (dialog);
+}
+
+static void
+on_about (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+        GtkWidget *dialog = NULL;
+
+        dialog = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (user_data),
+                                                     "about-dialog"));
+        gtk_widget_show (dialog);
+}
+
+
+G_MODULE_EXPORT
+void
+on_clear_packet_capture_activate (G_GNUC_UNUSED GtkMenuItem *menuitem,
+                                  G_GNUC_UNUSED gpointer     user_data)
+{
+        clear_packet_treeview ();
+}
+
+static GActionEntry actions[] = {
+        { "show-packet-details", NULL, NULL, "true", on_details_activate },
+        { "show-address-filter", on_show_address_filter },
+        { "about", on_about }
+};
+
 static gboolean
 init_ui (gint *argc, gchar **argv[])
 {
@@ -584,6 +621,7 @@ init_ui (gint *argc, gchar **argv[])
         GError *error = NULL;
         GOptionContext *context;
         double w, h;
+        GSimpleActionGroup *group = NULL;
 
         context = g_option_context_new ("- graphical SSDP debug tool");
         g_option_context_add_main_entries (context, entries, NULL);
@@ -599,9 +637,19 @@ init_ui (gint *argc, gchar **argv[])
         if (gtk_builder_add_from_resource(builder, UI_RESOURCE, NULL) == 0)
                 return FALSE;
 
+        if (gtk_builder_add_from_resource (builder, MENU_RESOURCE, NULL) == 0)
+                return FALSE;
+
+        gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (gtk_builder_get_object (builder, "window-menu")),
+                        G_MENU_MODEL (gtk_builder_get_object (builder, "sniffer-window-menu")));
+
         main_window = GTK_WIDGET(gtk_builder_get_object (builder, "main-window"));
         g_assert (main_window != NULL);
 
+        group = g_simple_action_group_new ();
+        gtk_widget_insert_action_group (GTK_WIDGET (main_window), "win", G_ACTION_GROUP (group));
+        g_action_map_add_action_entries (G_ACTION_MAP (group), actions, G_N_ELEMENTS (actions), builder);
+
 
 #if GTK_CHECK_VERSION(3,22,0)
         gtk_widget_realize (main_window);
diff --git a/tools/gssdp-device-sniffer.gresource.xml b/tools/gssdp-device-sniffer.gresource.xml
index dd36bc0..ec8dc93 100644
--- a/tools/gssdp-device-sniffer.gresource.xml
+++ b/tools/gssdp-device-sniffer.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gupnp/GSSDP">
     <file preprocess="xml-stripblanks" alias="DeviceSniffer.ui">gssdp-device-sniffer.ui</file>
+    <file alias="WindowMenu.ui">window-menu.ui</file>
   </gresource>
 </gresources>
diff --git a/tools/gssdp-device-sniffer.ui b/tools/gssdp-device-sniffer.ui
index d5efb72..fe3a97c 100644
--- a/tools/gssdp-device-sniffer.ui
+++ b/tools/gssdp-device-sniffer.ui
@@ -1,151 +1,101 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
+<!-- Generated with glade 3.22.1 -->
 <interface>
-  <requires lib="gtk+" version="3.12"/>
+  <requires lib="gtk+" version="3.20"/>
   <object class="GtkWindow" id="main-window">
     <property name="can_focus">False</property>
-    <property name="title" translatable="yes">GSSDP Device Sniffer</property>
     <signal name="delete-event" handler="on_delete_event" swapped="no"/>
-    <child>
-      <object class="GtkBox" id="vbox2">
+    <child type="titlebar">
+      <object class="GtkHeaderBar">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
+        <property name="show_close_button">True</property>
         <child>
-          <object class="GtkMenuBar" id="menubar">
+          <object class="GtkBox">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="spacing">6</property>
             <child>
-              <object class="GtkMenuItem" id="menu_file">
+              <object class="GtkButton">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">_File</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="menu1">
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="tooltip_text" translatable="yes">Clear packet capture</property>
+                <signal name="clicked" handler="on_clear_packet_capture_activate" swapped="no"/>
+                <child>
+                  <object class="GtkImage">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <child>
-                      <object class="GtkImageMenuItem" id="item_clear_packet_capture">
-                        <property name="label">gtk-clear</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                        <signal name="activate" handler="on_clear_packet_capture_activate" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="separator1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="item_show_packet_details">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Show Packet Details</property>
-                        <property name="use_underline">True</property>
-                        <property name="active">True</property>
-                        <signal name="toggled" handler="on_details_activate" 
object="packet-details-scrolledwindow" swapped="yes"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="item_show_device_tracking">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Show Device Tracking</property>
-                        <property name="use_underline">True</property>
-                        <property name="active">True</property>
-                        <signal name="toggled" handler="on_details_activate" 
object="device-details-scrolledwindow" swapped="yes"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="separator2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkImageMenuItem" id="item_quit">
-                        <property name="label">gtk-quit</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                        <signal name="activate" handler="gtk_main_quit" swapped="no"/>
-                        <accelerator key="q" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                      </object>
-                    </child>
+                    <property name="icon_name">edit-clear-all-symbolic</property>
                   </object>
                 </child>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
             </child>
             <child>
-              <object class="GtkMenuItem" id="menu_filter">
+              <object class="GtkToggleButton">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Filter</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="menu2">
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="tooltip_text" translatable="yes">Toggle packet capture</property>
+                <property name="active">True</property>
+                <signal name="toggled" handler="on_enable_packet_capture_activate" object="capture-image" 
swapped="no"/>
+                <child>
+                  <object class="GtkImage" id="capture-image">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="item_toggle_capture">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Enable Packet Capture</property>
-                        <property name="use_underline">True</property>
-                        <property name="active">True</property>
-                        <signal name="toggled" handler="on_enable_packet_capture_activate" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="item_address_filter">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Address Filter</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="gtk_widget_show" object="address-filter-dialog" 
swapped="yes"/>
-                      </object>
-                    </child>
+                    <property name="icon_name">media-playback-stop-symbolic</property>
                   </object>
                 </child>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
             </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child type="title">
+          <object class="GtkStackSwitcher">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">center</property>
+            <property name="icon_size">0</property>
+            <property name="stack">stack1</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkMenuButton" id="window-menu">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
             <child>
-              <object class="GtkMenuItem" id="menu_help">
+              <object class="GtkImage">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">_Help</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="menu3">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <child>
-                      <object class="GtkImageMenuItem" id="item_about">
-                        <property name="label">gtk-about</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                        <signal name="activate" handler="gtk_widget_show" object="about-dialog" 
swapped="yes"/>
-                      </object>
-                    </child>
-                  </object>
-                </child>
+                <property name="icon_name">open-menu-symbolic</property>
               </object>
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">0</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
           </packing>
         </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkStack" id="stack1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <child>
           <object class="GtkBox" id="vbox">
             <property name="visible">True</property>
@@ -163,7 +113,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <child internal-child="selection">
-                      <object class="GtkTreeSelection" id="treeview-selection1"/>
+                      <object class="GtkTreeSelection"/>
                     </child>
                   </object>
                 </child>
@@ -184,6 +134,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="editable">False</property>
+                    <property name="monospace">True</property>
                   </object>
                 </child>
               </object>
@@ -193,31 +144,33 @@
                 <property name="position">1</property>
               </packing>
             </child>
+          </object>
+          <packing>
+            <property name="name">page0</property>
+            <property name="title" translatable="yes">Packets</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="device-details-scrolledwindow">
+            <property name="name">Bar</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="margin_top">6</property>
+            <property name="margin_bottom">6</property>
+            <property name="shadow_type">in</property>
             <child>
-              <object class="GtkScrolledWindow" id="device-details-scrolledwindow">
+              <object class="GtkTreeView" id="device-details-treeview">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="shadow_type">in</property>
-                <child>
-                  <object class="GtkTreeView" id="device-details-treeview">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <child internal-child="selection">
-                      <object class="GtkTreeSelection" id="treeview-selection2"/>
-                    </child>
-                  </object>
+                <child internal-child="selection">
+                  <object class="GtkTreeSelection"/>
                 </child>
               </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
             </child>
           </object>
           <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
+            <property name="name">page1</property>
+            <property name="title" translatable="yes">Device history</property>
             <property name="position">1</property>
           </packing>
         </child>
@@ -238,6 +191,9 @@ Inspired by Intel Tools for UPnP.</property>
     <property name="license_type">lgpl-2-1</property>
     <signal name="delete-event" handler="gtk_widget_hide" object="about-dialog" swapped="yes"/>
     <signal name="response" handler="gtk_widget_hide" object="about-dialog" swapped="yes"/>
+    <child>
+      <placeholder/>
+    </child>
     <child internal-child="vbox">
       <object class="GtkBox" id="aboutdialog-vbox1">
         <property name="can_focus">False</property>
@@ -259,11 +215,13 @@ Inspired by Intel Tools for UPnP.</property>
   <object class="GtkDialog" id="address-filter-dialog">
     <property name="can_focus">False</property>
     <property name="border_width">7</property>
-    <property name="title" translatable="yes">Address Filter</property>
     <property name="resizable">False</property>
     <property name="type_hint">dialog</property>
     <property name="transient_for">main-window</property>
     <signal name="response" handler="on_address_filter_dialog_response" swapped="no"/>
+    <child type="titlebar">
+      <placeholder/>
+    </child>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
         <property name="visible">True</property>
diff --git a/tools/window-menu.ui b/tools/window-menu.ui
new file mode 100644
index 0000000..05c0a04
--- /dev/null
+++ b/tools/window-menu.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <menu id="sniffer-window-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Show packet details</attribute>
+        <attribute name="action">win.show-packet-details</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Address Filter…</attribute>
+        <attribute name="action">win.show-address-filter</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">win.about</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]