From fe400023ef6e29a74a2709f42a02b232bdd034c6 Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Fri, 1 May 2009 16:12:36 +0200 Subject: [PATCH] Port gssdp-device-sniffer to GtkBuilder --- Makefile.am | 2 +- configure.ac | 40 +-- tools/Makefile.am | 6 +- tools/gssdp-device-sniffer.c | 64 +++-- tools/gssdp-device-sniffer.glade | 587 --------------------------------------- tools/gssdp-device-sniffer.ui | 526 +++++++++++++++++++++++++++++++++++ 6 files changed, 584 insertions(+), 641 deletions(-) delete mode 100644 tools/gssdp-device-sniffer.glade create mode 100644 tools/gssdp-device-sniffer.ui diff --git a/Makefile.am b/Makefile.am index bc5d602..f830c30 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -if USE_LIBGLADE +if USE_LIBGTK TOOLS_DIR = tools else TOOLS_DIR = diff --git a/configure.ac b/configure.ac index aef6978..1e002cc 100644 --- a/configure.ac +++ b/configure.ac @@ -14,38 +14,38 @@ PKG_CHECK_MODULES(LIBGSSDP, glib-2.0 >= 2.18 \ gobject-2.0 >= 2.18 \ libsoup-2.4) -LIBGLADE_REQUIRED=2.6.0 +LIBGTK_REQUIRED=2.12.0 -AC_ARG_WITH( libglade, - AC_HELP_STRING([--without-libglade],[compile without libglade support]), - try_libglade=$withval, try_libglade=yes ) +AC_ARG_WITH( gtk, + AC_HELP_STRING([--without-gtk],[compile without gtk+ support]), + try_gtk=$withval, try_gtk=yes ) -HAVE_LIBGLADE=no -if test x$try_libglade = xyes ; then - dnl check for libglade - PKG_CHECK_MODULES(LIBGLADE, libglade-2.0 >= $LIBGLADE_REQUIRED , +HAVE_LIBGGTK=no +if test x$try_gtk = xyes ; then + dnl check for gtk+ + PKG_CHECK_MODULES(LIBGTK, gtk+-2.0 >= $LIBGTK_REQUIRED , [ - HAVE_LIBGLADE=yes - AC_SUBST(LIBGLADE_CFLAGS) - AC_SUBST(LIBGLADE_LIBS) + HAVE_LIBGTK=yes + AC_SUBST(LIBGTK_CFLAGS) + AC_SUBST(LIBGTK_LIBS) ], [ - HAVE_LIBGLADE=no - AC_MSG_WARN([libglade $LIBGLADE_REQUIRED or greater not found, some tools will not build.]) + HAVE_LIBGTK=no + AC_MSG_WARN([gtk+ $LIBGTK_REQUIRED or greater not found, some tools will not build.]) ]) else - AC_MSG_NOTICE([libglade usage disabled, some tools may not build.]) + AC_MSG_NOTICE([gtk+ usage disabled, some tools may not build.]) fi -if test x$HAVE_LIBGLADE = xno; then - USE_LIBGLADE=no +if test x$HAVE_LIBGTK = xno; then + USE_LIBGTK=no else - USE_LIBGLADE=yes - AC_DEFINE(HAVE_LIBGLADE, , [Use libglade]) + USE_LIBGTK=yes + AC_DEFINE(HAVE_LIBGTK, , [Use gtk+]) fi -AC_SUBST(HAVE_LIBGLADE) -AM_CONDITIONAL(USE_LIBGLADE, test x$USE_LIBGLADE = xyes) +AC_SUBST(HAVE_LIBGTK) +AM_CONDITIONAL(USE_LIBGTK, test x$USE_LIBGTK = xyes) # glib-genmarshal GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0` diff --git a/tools/Makefile.am b/tools/Makefile.am index fad500e..565e556 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,12 +1,12 @@ uidir = $(datadir)/gssdp -dist_ui_DATA = $(srcdir)/gssdp-device-sniffer.glade +dist_ui_DATA = $(srcdir)/gssdp-device-sniffer.ui -AM_CFLAGS = $(LIBGSSDP_CFLAGS) $(LIBGLADE_CFLAGS) -I$(top_srcdir) -DUI_DIR='"$(uidir)"' +AM_CFLAGS = $(LIBGSSDP_CFLAGS) $(LIBGTK_CFLAGS) -I$(top_srcdir) -DUI_DIR='"$(uidir)"' bin_PROGRAMS = gssdp-device-sniffer gssdp_device_sniffer_SOURCES = gssdp-device-sniffer.c -gssdp_device_sniffer_LDADD = $(LIBGLADE_LIBS) $(LIBGSSDP_LIBS) $(top_builddir)/libgssdp/libgssdp-1.0.la +gssdp_device_sniffer_LDADD = $(LIBGSSDP_LIBS) $(LIBGTK_LIBS) $(top_builddir)/libgssdp/libgssdp-1.0.la gssdp_device_sniffer_LDFLAGS = -export-dynamic MAINTAINERCLEANFILES = Makefile.in diff --git a/tools/gssdp-device-sniffer.c b/tools/gssdp-device-sniffer.c index b22c93b..2ca44c5 100644 --- a/tools/gssdp-device-sniffer.c +++ b/tools/gssdp-device-sniffer.c @@ -21,19 +21,19 @@ #include #include #include -#include #include #include -#define GLADE_FILE "gssdp-device-sniffer.glade" +#define UI_FILE "gssdp-device-sniffer.ui" #define MAX_IP_LEN 16 -GladeXML *glade_xml; +GtkBuilder *builder; GSSDPResourceBrowser *resource_browser; GSSDPClient *client; char *ip_filter = NULL; gboolean capture_packets = TRUE; +G_MODULE_EXPORT void on_enable_packet_capture_activate (GtkCheckMenuItem *menuitem, gpointer user_data) { @@ -49,7 +49,7 @@ clear_packet_treeview () gboolean more; time_t *arrival_time; - treeview = glade_xml_get_widget (glade_xml, "packet-treeview"); + treeview = GTK_WIDGET(gtk_builder_get_object (builder, "packet-treeview")); g_assert (treeview != NULL); model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); more = gtk_tree_model_get_iter_first (model, &iter); @@ -63,6 +63,7 @@ clear_packet_treeview () } } +G_MODULE_EXPORT void on_details_activate (GtkWidget *scrolled_window, GtkCheckMenuItem *menuitem) { @@ -97,7 +98,7 @@ update_packet_details (char *text, unsigned int len) GtkWidget *textview; GtkTextBuffer *textbuffer; - textview = glade_xml_get_widget (glade_xml, "packet-details-textview"); + textview = GTK_WIDGET(gtk_builder_get_object (builder, "packet-details-textview")); g_assert (textview != NULL); textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); @@ -145,6 +146,7 @@ on_packet_selected (GtkTreeSelection *selection, gpointer user_data) update_packet_details ("", 0); } +G_MODULE_EXPORT void on_clear_packet_capture_activate (GtkMenuItem *menuitem, gpointer user_data) { @@ -198,7 +200,7 @@ append_packet (const gchar *from_ip, GtkTreeIter iter; char **packet_data; - treeview = glade_xml_get_widget (glade_xml, "packet-treeview"); + treeview = GTK_WIDGET(gtk_builder_get_object (builder, "packet-treeview")); g_assert (treeview != NULL); liststore = GTK_LIST_STORE ( gtk_tree_view_get_model (GTK_TREE_VIEW (treeview))); @@ -275,7 +277,7 @@ append_device (const char *uuid, GtkTreeModel *model; GtkTreeIter iter; - treeview = glade_xml_get_widget (glade_xml, "device-details-treeview"); + treeview = GTK_WIDGET(gtk_builder_get_object (builder, "device-details-treeview")); g_assert (treeview != NULL); model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); g_assert (model != NULL); @@ -346,7 +348,7 @@ remove_device (const char *uuid) GtkTreeModel *model; GtkTreeIter iter; - treeview = glade_xml_get_widget (glade_xml, "device-details-treeview"); + treeview = GTK_WIDGET(gtk_builder_get_object (builder, "device-details-treeview")); g_assert (treeview != NULL); model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); g_assert (model != NULL); @@ -372,6 +374,7 @@ resource_unavailable_cb (GSSDPResourceBrowser *resource_browser, g_strfreev (usn_tokens); } +G_MODULE_EXPORT void on_use_filter_radiobutton_toggled (GtkToggleButton *togglebutton, gpointer user_data) @@ -379,7 +382,7 @@ on_use_filter_radiobutton_toggled (GtkToggleButton *togglebutton, GtkWidget *filter_hbox; gboolean use_filter; - filter_hbox = glade_xml_get_widget (glade_xml, "address-filter-hbox"); + filter_hbox = GTK_WIDGET(gtk_builder_get_object (builder, "address-filter-hbox")); g_assert (filter_hbox != NULL); use_filter = gtk_toggle_button_get_active (togglebutton); @@ -400,7 +403,7 @@ get_ip_filter () gint val; sprintf (entry_name, "address-entry%d", i); - entry = glade_xml_get_widget (glade_xml, entry_name); + entry = GTK_WIDGET(gtk_builder_get_object (builder, entry_name)); g_assert (entry != NULL); val = atoi (gtk_entry_get_text (GTK_ENTRY (entry))); @@ -411,6 +414,7 @@ get_ip_filter () return ip; } +G_MODULE_EXPORT void on_address_filter_dialog_response (GtkDialog *dialog, gint response, @@ -420,7 +424,7 @@ on_address_filter_dialog_response (GtkDialog *dialog, gtk_widget_hide (GTK_WIDGET (dialog)); - use_filter_radio = glade_xml_get_widget (glade_xml, "use-filter-radiobutton"); + use_filter_radio = GTK_WIDGET(gtk_builder_get_object (builder, "use-filter-radiobutton")); g_assert (use_filter_radio != NULL); if (response != GTK_RESPONSE_OK) @@ -507,11 +511,11 @@ setup_treeviews () GtkTreeSelection *selection; int i; - treeviews[0] = glade_xml_get_widget (glade_xml, - "packet-treeview"); + treeviews[0] = GTK_WIDGET(gtk_builder_get_object (builder, + "packet-treeview")); g_assert (treeviews[0] != NULL); - treeviews[1] = glade_xml_get_widget (glade_xml, - "device-details-treeview"); + treeviews[1] = GTK_WIDGET(gtk_builder_get_object (builder, + "device-details-treeview")); g_assert (treeviews[1] != NULL); treemodels[0] = create_packet_treemodel (); @@ -530,6 +534,7 @@ setup_treeviews () (gpointer *) treeviews[0]); } +G_MODULE_EXPORT gboolean on_delete_event (GtkWidget *widget, GdkEvent *event, @@ -544,31 +549,30 @@ init_ui (gint *argc, gchar **argv[]) { GtkWidget *main_window; gint window_width, window_height; - gchar *glade_path = NULL; + gchar *ui_path = NULL; gtk_init (argc, argv); - glade_init (); - /* Try to fetch the glade file from the CWD first */ - glade_path = GLADE_FILE; - if (!g_file_test (glade_path, G_FILE_TEST_EXISTS)) { + /* Try to fetch the ui file from the CWD first */ + ui_path = UI_FILE; + if (!g_file_test (ui_path, G_FILE_TEST_EXISTS)) { /* Then Try to fetch it from the system path */ - glade_path = UI_DIR "/" GLADE_FILE; + ui_path = UI_DIR "/" UI_FILE; - if (!g_file_test (glade_path, G_FILE_TEST_EXISTS)) - glade_path = NULL; + if (!g_file_test (ui_path, G_FILE_TEST_EXISTS)) + ui_path = NULL; } - if (glade_path == NULL) { - g_critical ("Unable to load the GUI file %s", GLADE_FILE); + if (ui_path == NULL) { + g_critical ("Unable to load the GUI file %s", UI_FILE); return FALSE; } - glade_xml = glade_xml_new (glade_path, NULL, NULL); - if (glade_xml == NULL) + builder = gtk_builder_new(); + if (gtk_builder_add_from_file(builder, ui_path, NULL) == 0) return FALSE; - main_window = glade_xml_get_widget (glade_xml, "main-window"); + main_window = GTK_WIDGET(gtk_builder_get_object (builder, "main-window")); g_assert (main_window != NULL); /* 80% of the screen but don't get bigger than 1000x800 */ @@ -578,7 +582,7 @@ init_ui (gint *argc, gchar **argv[]) window_width, window_height); - glade_xml_signal_autoconnect (glade_xml); + gtk_builder_connect_signals (builder, NULL); setup_treeviews (); gtk_widget_show_all (main_window); @@ -588,7 +592,7 @@ init_ui (gint *argc, gchar **argv[]) static void deinit_ui (void) { - g_object_unref (glade_xml); + g_object_unref (builder); } static gboolean diff --git a/tools/gssdp-device-sniffer.glade b/tools/gssdp-device-sniffer.glade deleted file mode 100644 index febba2a..0000000 --- a/tools/gssdp-device-sniffer.glade +++ /dev/null @@ -1,587 +0,0 @@ - - - - - - - GSSDP Device Sniffer - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - False - - - - - True - False - 0 - - - - True - GTK_PACK_DIRECTION_LTR - GTK_PACK_DIRECTION_LTR - - - - True - _File - True - - - - - - - True - Clear Packet Capture - True - - - - - True - gtk-clear - 1 - 0.5 - 0.5 - 0 - 0 - - - - - - - - True - - - - - - True - Show Packet Details - True - True - - - - - - - True - Show Device Tracking - True - True - - - - - - - True - - - - - - True - gtk-quit - True - - - - - - - - - - - True - Filter - True - - - - - - - True - Enable Packet Capture - True - True - - - - - - - True - Address Filter - True - - - - - - - - - - - True - _Help - True - - - - - - - True - gtk-about - True - - - - - - - - - - 0 - False - False - - - - - - 6 - True - False - 6 - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT - - - - True - True - True - False - False - True - False - False - False - - - - - 0 - True - True - - - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT - - - - True - True - False - False - True - GTK_JUSTIFY_LEFT - GTK_WRAP_NONE - True - 0 - 0 - 0 - 0 - 0 - 0 - - - - - - 0 - True - True - - - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT - - - - True - True - True - False - False - True - False - False - False - - - - - 0 - True - True - - - - - 0 - True - True - - - - - - - - False - GSSDP Device Sniffer - Copyright (C) 2007 Zeeshan Ali (Khattak) - A Device Sniffer tool based on GSSDP framework. -Inspired by Intel Tools for UPnP. - LGPL - False - Zeeshan Ali (Khattak) <zeeshanak@gnome.org> - translator-credits - - - - - - 7 - Address Filter - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - False - False - - - - - True - False - 8 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-close - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - 5 - True - False - 4 - - - - True - True - No filter, capture all traffic - True - GTK_RELIEF_NORMAL - True - True - False - True - - - 0 - False - False - - - - - - True - True - Use IP address filter - True - GTK_RELIEF_NORMAL - True - False - False - True - dont-use-filter-radiobutton - - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 50 - 0 - - - - True - False - False - 0 - - - - True - True - True - True - 3 - - True - * - True - 4 - - - 0 - True - True - - - - - - True - . - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - True - 3 - - True - * - True - 4 - - - 0 - True - True - - - - - - True - . - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - True - 3 - - True - * - True - 4 - - - 0 - True - True - - - - - - True - . - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - True - True - True - 3 - - True - * - True - 4 - - - 0 - True - True - - - - - - - 0 - True - True - - - - - 0 - True - True - - - - - - - diff --git a/tools/gssdp-device-sniffer.ui b/tools/gssdp-device-sniffer.ui new file mode 100644 index 0000000..f16b3bc --- /dev/null +++ b/tools/gssdp-device-sniffer.ui @@ -0,0 +1,526 @@ + + + + + + + + + file_menuitem + _File + + + + + gtk-clear + clear_packet_capture + Clear Packet Capture + + + + + + True + show_packet_details + Show Packet Details + + + + + + True + show_device_tracking + Show Device Tracking + + + + + + gtk-quit + quit + + + + + + filter_menuitem + Filter + + + + + True + enable_packet_capture + Enable Packet Capture + + + + + + address_filter + Address Filter + + + + + + help_menuitem + _Help + + + + + gtk-about + about + + + + + + + + + + + + + + + + + + + + + + + + + + + GSSDP Device Sniffer + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + True + False + 0 + + + True + GTK_PACK_DIRECTION_LTR + GTK_PACK_DIRECTION_LTR + + + 0 + False + False + + + + + 6 + True + False + 6 + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + True + True + True + False + False + True + False + False + False + + + + + 0 + True + True + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + True + True + False + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_NONE + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + 0 + True + True + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + True + True + True + False + False + True + False + False + False + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + False + GSSDP Device Sniffer + Copyright (C) 2007 Zeeshan Ali (Khattak) + A Device Sniffer tool based on GSSDP framework. +Inspired by Intel Tools for UPnP. + LGPL + False + Zeeshan Ali (Khattak) <zeeshanak@gnome.org> + translator-credits + + + + + 7 + Address Filter + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + False + + + + True + False + 8 + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + + + + + 0 + False + True + GTK_PACK_END + + + + + 5 + True + False + 4 + + + True + True + No filter, capture all traffic + True + GTK_RELIEF_NORMAL + True + True + False + True + + + 0 + False + False + + + + + True + True + Use IP address filter + True + GTK_RELIEF_NORMAL + True + False + False + True + dont-use-filter-radiobutton + + + + 0 + False + False + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 50 + 0 + + + True + False + False + 0 + + + True + True + True + True + 3 + + True + * + True + 4 + + + 0 + True + True + + + + + True + . + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + True + True + True + True + 3 + + True + * + True + 4 + + + 0 + True + True + + + + + True + . + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + True + True + True + True + 3 + + True + * + True + 4 + + + 0 + True + True + + + + + True + . + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + True + True + True + True + 3 + + True + * + True + 4 + + + 0 + True + True + + + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + closebutton1 + + + -- 2.7.4