aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2004-01-22 18:13:57 +0000
committerUlf Lamping <ulf.lamping@web.de>2004-01-22 18:13:57 +0000
commita0f78e3b8f42ccacd4ece05e90d7126e9a8e9777 (patch)
tree6ed76bb965eb7a0eb524931a1bbbf576510f0da5 /gtk
parentf799c98aa5eecf0d2d6c6149d25fa823e34af6df (diff)
moved GTK specific parts from capture.c to ui_util.c,
implemented Win32 "Capture Stop" when using "update list of packets in realtime" while capturing svn path=/trunk/; revision=9777
Diffstat (limited to 'gtk')
-rw-r--r--gtk/menu.c20
-rw-r--r--gtk/toolbar.c16
-rw-r--r--gtk/ui_util.c150
3 files changed, 155 insertions, 31 deletions
diff --git a/gtk/menu.c b/gtk/menu.c
index a38cbe4cad..947031d18a 100644
--- a/gtk/menu.c
+++ b/gtk/menu.c
@@ -1,7 +1,7 @@
/* menu.c
* Menu routines
*
- * $Id: menu.c,v 1.143 2004/01/21 19:21:28 ulfl Exp $
+ * $Id: menu.c,v 1.144 2004/01/22 18:13:56 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -194,9 +194,6 @@ static GtkItemFactoryEntry menu_items[] =
ITEM_FACTORY_ENTRY("/View/Show/Packet Data", NULL, byte_view_show_cb, 0, "<CheckItem>", NULL),
ITEM_FACTORY_ENTRY("/View/Show/<separator>", NULL, NULL, 0, "<Separator>", NULL),
ITEM_FACTORY_ENTRY("/View/Show/Status Bar", NULL, statusbar_show_cb, 0, "<CheckItem>", NULL),
- /* XXX: the settings in the "Options" dialog could be seperated into the following menu items. */
- /* before this, some effort must be taken to transfer the functionality of this dialog to the menu items */
- /* (getting the current values, handling the radioitems, ...) */
ITEM_FACTORY_ENTRY("/View/_Time Display Format", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/View/Time Display Format/Time of day", NULL, timestamp_absolute_cb,
0, "<RadioItem>", NULL),
@@ -211,8 +208,6 @@ static GtkItemFactoryEntry menu_items[] =
ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Network layer", NULL, name_resolution_mac_cb, 0, "<CheckItem>", NULL),
ITEM_FACTORY_ENTRY("/View/Name Resolution/Enable for _Transport layer", NULL, name_resolution_transport_cb, 0, "<CheckItem>", NULL),
ITEM_FACTORY_ENTRY("/View/Auto scroll in live capture", NULL, auto_scroll_live_cb, 0, "<CheckItem>", NULL),
-/* ITEM_FACTORY_ENTRY("/View/_Options...", NULL, display_opt_cb,
- 0, NULL, NULL),*/
ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
ITEM_FACTORY_STOCK_ENTRY("/View/Zoom In", "<control>plus", view_zoom_in_cb,
0, GTK_STOCK_ZOOM_IN),
@@ -237,13 +232,8 @@ static GtkItemFactoryEntry menu_items[] =
ITEM_FACTORY_ENTRY("/_Capture", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_STOCK_ENTRY("/Capture/_Start...", "<control>K",
capture_prep_cb, 0, ETHEREAL_STOCK_CAPTURE_START),
- /*
- * XXX - this doesn't yet work in Win32.
- */
-#ifndef _WIN32
ITEM_FACTORY_STOCK_ENTRY("/Capture/S_top", "<control>E", capture_stop_cb,
0, GTK_STOCK_STOP),
-#endif /* _WIN32 */
ITEM_FACTORY_STOCK_ENTRY("/Capture/_Capture Filters...", NULL, cfilter_dialog_cb,
0, ETHEREAL_STOCK_CAPTURE_FILTER),
#endif /* HAVE_LIBPCAP */
@@ -1201,6 +1191,7 @@ void
set_menus_for_capture_file(gboolean have_capture_file)
{
set_menu_sensitivity(main_menu_factory, "/File/Open...", have_capture_file);
+ set_menu_sensitivity(main_menu_factory, "/File/Open Recent", have_capture_file);
set_menu_sensitivity(main_menu_factory, "/File/Save As...",
have_capture_file);
set_menu_sensitivity(main_menu_factory, "/File/Close", have_capture_file);
@@ -1225,16 +1216,13 @@ set_menus_for_capture_in_progress(gboolean capture_in_progress)
{
set_menu_sensitivity(main_menu_factory, "/File/Open...",
!capture_in_progress);
+ set_menu_sensitivity(main_menu_factory, "/File/Open Recent",
+ !capture_in_progress);
#ifdef HAVE_LIBPCAP
set_menu_sensitivity(main_menu_factory, "/Capture/Start...",
!capture_in_progress);
- /*
- * XXX - this doesn't yet work in Win32.
- */
-#ifndef _WIN32
set_menu_sensitivity(main_menu_factory, "/Capture/Stop",
capture_in_progress);
-#endif
#endif /* HAVE_LIBPCAP */
set_toolbar_for_capture_in_progress(capture_in_progress);
}
diff --git a/gtk/toolbar.c b/gtk/toolbar.c
index bf4da78a5b..c5c2f938c1 100644
--- a/gtk/toolbar.c
+++ b/gtk/toolbar.c
@@ -2,7 +2,7 @@
* The main toolbar
* Copyright 2003, Ulf Lamping <ulf.lamping@web.de>
*
- * $Id: toolbar.c,v 1.25 2004/01/21 09:02:09 guy Exp $
+ * $Id: toolbar.c,v 1.26 2004/01/22 18:13:57 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -257,14 +257,6 @@ void set_toolbar_for_capture_in_progress(gboolean capture_in_progress) {
if (toolbar_init) {
#ifdef HAVE_LIBPCAP
gtk_widget_set_sensitive(new_button, !capture_in_progress);
-#endif
- gtk_widget_set_sensitive(open_button, !capture_in_progress);
-
-#ifdef HAVE_LIBPCAP
- /*
- * XXX - this doesn't yet work in Win32, as in the menus :-(
- */
-#ifndef _WIN32
if (capture_in_progress) {
gtk_widget_hide(new_button);
gtk_widget_show(stop_button);
@@ -272,10 +264,8 @@ void set_toolbar_for_capture_in_progress(gboolean capture_in_progress) {
gtk_widget_show(new_button);
gtk_widget_hide(stop_button);
}
-#else /* _WIN32 */
- gtk_widget_set_sensitive(new_button, !capture_in_progress);
-#endif /* _WIN32 */
#endif /* HAVE_LIBPCAP */
+ gtk_widget_set_sensitive(open_button, !capture_in_progress);
}
}
@@ -380,10 +370,8 @@ toolbar_new(void)
toolbar_item(new_button, window, main_tb,
ETHEREAL_STOCK_CAPTURE_START, "Start a new live capture...", capture_24_xpm, capture_prep_cb);
-#ifndef _WIN32
toolbar_item(stop_button, window, main_tb,
GTK_STOCK_STOP, "Stop the running live capture", stock_stop_24_xpm, capture_stop_cb);
-#endif /* _WIN32 */
toolbar_append_separator(main_tb);
#endif /* HAVE_LIBPCAP */
diff --git a/gtk/ui_util.c b/gtk/ui_util.c
index 332222acd7..1f7ddf3173 100644
--- a/gtk/ui_util.c
+++ b/gtk/ui_util.c
@@ -1,7 +1,7 @@
/* ui_util.c
* UI utility routines
*
- * $Id: ui_util.c,v 1.14 2002/11/11 15:39:06 oabad Exp $
+ * $Id: ui_util.c,v 1.15 2004/01/22 18:13:57 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -26,6 +26,14 @@
# include "config.h"
#endif
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#ifdef HAVE_IO_H
+# include <io.h>
+#endif
+
#include <gtk/gtk.h>
#include "gtkglobals.h"
@@ -47,6 +55,146 @@ set_main_window_name(gchar *window_name)
gdk_window_set_icon_name(top_level->window, window_name);
}
+
+#ifdef HAVE_LIBPCAP
+
+/* update the main window */
+void main_window_update(void)
+{
+ while (gtk_events_pending()) gtk_main_iteration();
+}
+
+/* exit the main window */
+void main_window_exit(void)
+{
+ gtk_exit(0);
+}
+
+/* quit a nested main window */
+void main_window_nested_quit(void)
+{
+ if (gtk_main_level() > 0)
+ gtk_main_quit();
+}
+
+/* quit the main window */
+void main_window_quit(void)
+{
+ gtk_main_quit();
+}
+
+
+
+
+typedef struct pipe_input_tag {
+ gint source;
+ gpointer user_data;
+ HANDLE *child_process;
+ pipe_input_cb_t input_cb;
+ guint pipe_input_id;
+} pipe_input_t;
+
+
+#ifdef _WIN32
+/* The timer has expired, see if there's stuff to read from the pipe,
+ if so, do the callback */
+static gint
+pipe_timer_cb(gpointer data)
+{
+ HANDLE handle;
+ DWORD avail = 0;
+ gboolean result, result1;
+ DWORD childstatus;
+ pipe_input_t *pipe_input = data;
+
+
+ /* Oddly enough although Named pipes don't work on win9x,
+ PeekNamedPipe does !!! */
+ handle = (HANDLE) _get_osfhandle (pipe_input->source);
+ result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
+
+ /* Get the child process exit status */
+ result1 = GetExitCodeProcess(*(pipe_input->child_process), &childstatus);
+
+ /* If the Peek returned an error, or there are bytes to be read
+ or the childwatcher thread has terminated then call the normal
+ callback */
+ if (!result || avail > 0 || childstatus != STILL_ACTIVE) {
+
+ /* avoid reentrancy problems and stack overflow */
+ gtk_timeout_remove(pipe_input->pipe_input_id);
+
+ /* And call the real handler */
+ if (pipe_input->input_cb(pipe_input->source, pipe_input->user_data)) {
+ /* restore pipe handler */
+ pipe_input->pipe_input_id = gtk_timeout_add(1000, pipe_timer_cb, data);
+ }
+
+ /* Return false so that this timer is not run again */
+ return FALSE;
+ }
+ else {
+ /* No data so let timer run again */
+ return TRUE;
+ }
+}
+
+#else /* _WIN32 */
+
+/* There's stuff to read from the sync pipe, meaning the child has sent
+ us a message, or the sync pipe has closed, meaning the child has
+ closed it (perhaps because it exited). */
+static void
+pipe_input_cb(gpointer data, gint source _U_,
+ GdkInputCondition condition _U_)
+{
+ pipe_input_t *pipe_input = data;
+
+
+ /* avoid reentrancy problems and stack overflow */
+ gtk_input_remove(pipe_input->pipe_input_id);
+
+ if (pipe_input->input_cb(source, pipe_input->user_data)) {
+ /* restore pipe handler */
+ pipe_input->pipe_input_id = gtk_input_add_full (source,
+ GDK_INPUT_READ|GDK_INPUT_EXCEPTION,
+ pipe_input_cb,
+ NULL,
+ data,
+ NULL);
+ }
+}
+#endif
+
+void pipe_input_set_handler(gint source, gpointer user_data, int *child_process, pipe_input_cb_t input_cb)
+{
+ static pipe_input_t pipe_input;
+
+ pipe_input.source = source;
+ pipe_input.child_process = (HANDLE *)child_process;
+ pipe_input.user_data = user_data;
+ pipe_input.input_cb = input_cb;
+
+#ifdef _WIN32
+ /* Tricky to use pipes in win9x, as no concept of wait. NT can
+ do this but that doesn't cover all win32 platforms. GTK can do
+ this but doesn't seem to work over processes. Attempt to do
+ something similar here, start a timer and check for data on every
+ timeout. */
+ pipe_input.pipe_input_id = gtk_timeout_add(1000, pipe_timer_cb, &pipe_input);
+#else
+ pipe_input.pipe_input_id = gtk_input_add_full(source,
+ GDK_INPUT_READ|GDK_INPUT_EXCEPTION,
+ pipe_input_cb,
+ NULL,
+ &pipe_input,
+ NULL);
+#endif
+}
+
+
+#endif /* HAVE_LIBPCAP */
+
/* Given a pointer to a GtkWidget for a top-level window, raise it and
de-iconify it. This routine is used if the user has done something to
ask that a window of a certain type be popped up when there can be only