[gssdp] sniffer: Move list store to ui file
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gssdp] sniffer: Move list store to ui file
- Date: Tue, 18 Aug 2020 19:59:56 +0000 (UTC)
commit 21e4dfe7b96de26cbabd54d4a9dcfc2ffe656ba5
Author: Jens Georg <mail jensge org>
Date: Wed Jul 8 22:31:43 2020 +0200
sniffer: Move list store to ui file
tools/gssdp-device-sniffer.c | 104 +++++----------------------------
tools/gssdp-device-sniffer.ui | 133 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 145 insertions(+), 92 deletions(-)
---
diff --git a/tools/gssdp-device-sniffer.c b/tools/gssdp-device-sniffer.c
index cb0535c..4020130 100644
--- a/tools/gssdp-device-sniffer.c
+++ b/tools/gssdp-device-sniffer.c
@@ -475,62 +475,6 @@ on_address_filter_dialog_response (GtkDialog *dialog,
ip_filter = NULL;
}
-static GtkTreeModel *
-create_packet_treemodel (void)
-{
- GtkListStore *store;
-
- store = gtk_list_store_new (7,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING,
- SOUP_TYPE_MESSAGE_HEADERS,
- G_TYPE_DATE_TIME);
-
- return GTK_TREE_MODEL (store);
-}
-
-static GtkTreeModel *
-create_device_treemodel (void)
-{
- GtkListStore *store;
-
- store = gtk_list_store_new (4,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING);
-
- return GTK_TREE_MODEL (store);
-}
-
-static void
-setup_treeview (GtkWidget *treeview,
- GtkTreeModel *model,
- const char *headers[])
-{
- int i;
-
- /* Set-up columns */
- for (i=0; headers[i] != NULL; i++) {
- GtkCellRenderer *renderer;
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (
- GTK_TREE_VIEW (treeview),
- -1,
- headers[i],
- renderer,
- "text", i,
- NULL);
- }
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
- model);
-}
-
static gboolean
on_treeview_popup_menu (GtkWidget *tv, GdkEventButton *event, gpointer user_data)
{
@@ -544,49 +488,25 @@ on_treeview_popup_menu (GtkWidget *tv, GdkEventButton *event, gpointer user_data
static void
setup_treeviews (void)
{
- GtkWidget *treeviews[2];
- GtkTreeModel *treemodels[2];
- const char *headers[2][7] = { {"Time",
- "Source Address",
- "Interface",
- "Packet Type",
- "Packet Information",
- NULL }, {"Unique Identifier",
- "First Notify",
- "Device Type",
- "Location",
- NULL } };
+ GtkWidget *treeview;
GtkTreeSelection *selection;
GtkWidget *menu = NULL;
- int i;
-
- treeviews[0] = GTK_WIDGET(gtk_builder_get_object (builder,
- "packet-treeview"));
- g_assert (treeviews[0] != NULL);
- treeviews[1] = GTK_WIDGET(gtk_builder_get_object (builder,
- "device-details-treeview"));
- g_assert (treeviews[1] != NULL);
-
- treemodels[0] = create_packet_treemodel ();
- g_assert (treemodels[0] != NULL);
- treemodels[1] = create_device_treemodel ();
- g_assert (treemodels[1] != NULL);
- for (i=0; i<2; i++)
- setup_treeview (treeviews[i], treemodels[i], headers[i]);
+ treeview = GTK_WIDGET(gtk_builder_get_object (builder,
+ "packet-treeview"));
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeviews[0]));
- g_assert (selection != NULL);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
g_signal_connect (selection,
- "changed",
- G_CALLBACK (on_packet_selected),
- (gpointer *) treeviews[0]);
+ "changed",
+ G_CALLBACK (on_packet_selected),
+ (gpointer *) treeview);
menu = gtk_menu_new_from_model (G_MENU_MODEL (gtk_builder_get_object (builder,
"sniffer-context-menu")));
- gtk_menu_attach_to_widget (GTK_MENU (menu), treeviews[0], NULL);
- g_signal_connect (G_OBJECT (treeviews[0]),
+ gtk_menu_attach_to_widget (GTK_MENU (menu), treeview, NULL);
+ g_signal_connect (G_OBJECT (treeview),
"button-press-event",
- G_CALLBACK (on_treeview_popup_menu), menu);
+ G_CALLBACK (on_treeview_popup_menu),
+ menu);
}
G_MODULE_EXPORT
@@ -800,6 +720,8 @@ deinit_upnp (void)
gint
main (gint argc, gchar *argv[])
{
+ g_type_ensure (G_TYPE_DATE_TIME);
+
if (!init_ui (&argc, &argv)) {
return -2;
}
diff --git a/tools/gssdp-device-sniffer.ui b/tools/gssdp-device-sniffer.ui
index f1acc7c..95faf76 100644
--- a/tools/gssdp-device-sniffer.ui
+++ b/tools/gssdp-device-sniffer.ui
@@ -1,7 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.1 -->
+<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
+ <object class="GtkListStore" id="device_store">
+ <columns>
+ <!-- column-name uid -->
+ <column type="gchararray"/>
+ <!-- column-name first-seen -->
+ <column type="gchararray"/>
+ <!-- column-name device-type -->
+ <column type="gchararray"/>
+ <!-- column-name location -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
+ <object class="GtkListStore" id="packet_store">
+ <columns>
+ <!-- column-name time -->
+ <column type="gchararray"/>
+ <!-- column-name source-address -->
+ <column type="gchararray"/>
+ <!-- column-name interface -->
+ <column type="gchararray"/>
+ <!-- column-name type -->
+ <column type="gchararray"/>
+ <!-- column-name information -->
+ <column type="gchararray"/>
+ <!-- column-name SoupMessageHeader1 -->
+ <column type="SoupMessageHeaders"/>
+ <!-- column-name GDateTime1 -->
+ <column type="GDateTime"/>
+ </columns>
+ </object>
<object class="GtkWindow" id="main-window">
<property name="can_focus">False</property>
<signal name="delete-event" handler="on_delete_event" swapped="no"/>
@@ -133,9 +163,65 @@
<object class="GtkTreeView" id="packet-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="model">packet_store</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Time</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="markup">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Source Address</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="markup">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Interface</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="markup">2</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Packet Type</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="markup">3</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Packet Information</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="markup">4</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
@@ -183,9 +269,54 @@
<object class="GtkTreeView" id="device-details-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="model">device_store</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Unique Identifier</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">First Notify</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Device Type</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="text">2</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Location</property>
+ <child>
+ <object class="GtkCellRendererText"/>
+ <attributes>
+ <attribute name="text">3</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]