summaryrefslogtreecommitdiff
path: root/gtk/bootp_stat.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-09-26 02:09:44 +0000
committerGuy Harris <guy@alum.mit.edu>2003-09-26 02:09:44 +0000
commit59938a45fe143d4b4f862cf2dcebe66d727de44e (patch)
tree468c708281c137b584bb51d0f4df8c353c74a948 /gtk/bootp_stat.c
parent87d87ace4e628c8826391817f67a373af1712a4f (diff)
downloadwireshark-59938a45fe143d4b4f862cf2dcebe66d727de44e.tar.gz
Assorted GUI cleanups.
svn path=/trunk/; revision=8544
Diffstat (limited to 'gtk/bootp_stat.c')
-rw-r--r--gtk/bootp_stat.c94
1 files changed, 68 insertions, 26 deletions
diff --git a/gtk/bootp_stat.c b/gtk/bootp_stat.c
index b72bfd4178..eeabe1be3f 100644
--- a/gtk/bootp_stat.c
+++ b/gtk/bootp_stat.c
@@ -1,7 +1,7 @@
/* bootp_stat.c
* boop_stat 2003 Jean-Michel FAYARD
*
- * $Id: bootp_stat.c,v 1.4 2003/09/24 02:36:34 guy Exp $
+ * $Id: bootp_stat.c,v 1.5 2003/09/26 02:09:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -32,6 +32,7 @@
#include "epan/epan.h"
#include "menu.h"
#include "simple_dialog.h"
+#include "dlg_utils.h"
#include "tap.h"
#include "../register.h"
#include "../globals.h"
@@ -57,10 +58,8 @@ typedef struct _dhcp_message_type_t {
dhcpstat_t *sp; /* entire program interface */
} dhcp_message_type_t;
-static GtkWidget *dlg=NULL, *dlg_box;
-static GtkWidget *filter_box;
-static GtkWidget *filter_label, *filter_entry;
-static GtkWidget *start_button;
+static GtkWidget *dlg=NULL;
+static GtkWidget *filter_entry;
static void
dhcp_free_hash( gpointer key _U_ , gpointer value, gpointer user_data _U_ )
@@ -197,7 +196,7 @@ gtk_dhcpstat_init(char *optarg)
char *filter=NULL;
char *title=NULL;
GString *error_string;
- GtkWidget *message_type_fr ;
+ GtkWidget *message_type_fr;
if (!strncmp (optarg, "bootp,stat,", 11)){
filter=optarg+11;
@@ -210,18 +209,18 @@ gtk_dhcpstat_init(char *optarg)
if(filter){
sp->filter=g_malloc(strlen(filter)+1);
strcpy(sp->filter,filter);
- title=g_strdup_printf("DHCP Stats with filter: %s", filter);
+ title=g_strdup_printf("DHCP statistics with filter: %s", filter);
} else {
sp->filter=NULL;
- title=g_strdup("DHCP Stats");
+ title=g_strdup("DHCP statistics");
}
+ /* top level window */
sp->win = gtk_window_new( GTK_WINDOW_TOPLEVEL);
gtk_window_set_title( GTK_WINDOW(sp->win), title );
g_free(title);
SIGNAL_CONNECT( sp->win, "destroy", win_destroy_cb, sp);
-
/* Status Codes frame */
message_type_fr = gtk_frame_new("DHCP Message Type");
gtk_container_add(GTK_CONTAINER(sp->win), message_type_fr);
@@ -261,16 +260,14 @@ gtk_dhcpstat_init(char *optarg)
static void
dhcp_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{
+ GString *str;
char *filter;
- char str[256];
+ str = g_string_new("dhcp,stat,");
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
- if(filter[0]==0){
- gtk_dhcpstat_init("dhcp,stat,");
- } else {
- sprintf(str, "dhcp,stat,%s", filter);
- gtk_dhcpstat_init(str);
- }
+ str = g_string_append(str, filter);
+ gtk_dhcpstat_init(str->str);
+ g_string_free(str, TRUE);
}
static void
@@ -280,45 +277,90 @@ dlg_destroy_cb(void)
}
static void
+dlg_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
+{
+ gtk_widget_destroy(GTK_WIDGET(parent_w));
+}
+
+static void
gtk_dhcpstat_cb(GtkWidget *w _U_, gpointer d _U_)
{
+ GtkWidget *dlg_box;
+ GtkWidget *filter_box, *filter_label;
+ GtkWidget *bbox, *start_button, *cancel_button;
+
/* if the window is already open, bring it to front */
if(dlg){
gdk_window_raise(dlg->window);
return;
}
- dlg=gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(dlg), "WSP Statistics");
+ dlg=dlg_window_new("Ethereal: Compute DHCP statistics");
SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
- dlg_box=gtk_vbox_new(FALSE, 0);
+
+ dlg_box=gtk_vbox_new(FALSE, 10);
+ gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
gtk_widget_show(dlg_box);
+ /* Filter box */
+ filter_box=gtk_hbox_new(FALSE, 3);
- /* filter box */
- filter_box=gtk_hbox_new(FALSE, 10);
/* Filter label */
- gtk_container_set_border_width(GTK_CONTAINER(filter_box), 10);
filter_label=gtk_label_new("Filter:");
gtk_box_pack_start(GTK_BOX(filter_box), filter_label, FALSE, FALSE, 0);
gtk_widget_show(filter_label);
- filter_entry=gtk_entry_new_with_max_length(250);
- gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, FALSE, FALSE, 0);
+ /* Filter entry */
+ filter_entry=gtk_entry_new();
+ gtk_widget_set_usize(filter_entry, 300, -2);
+ gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
gtk_widget_show(filter_entry);
gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
gtk_widget_show(filter_box);
+ /* button box */
+ bbox = gtk_hbutton_box_new();
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_DEFAULT_STYLE);
+ gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
+ gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
+ gtk_widget_show(bbox);
/* the start button */
start_button=gtk_button_new_with_label("Create Stat");
SIGNAL_CONNECT_OBJECT(start_button, "clicked",
dhcp_start_button_clicked, NULL);
- gtk_box_pack_start(GTK_BOX(dlg_box), start_button, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(bbox), start_button, TRUE, TRUE, 0);
+ GTK_WIDGET_SET_FLAGS(start_button, GTK_CAN_DEFAULT);
+ gtk_widget_grab_default(start_button);
gtk_widget_show(start_button);
+#if GTK_MAJOR_VERSION < 2
+ cancel_button=gtk_button_new_with_label("Cancel");
+#else
+ cancel_button=gtk_button_new_from_stock(GTK_STOCK_CANCEL);
+#endif
+ SIGNAL_CONNECT(cancel_button, "clicked", dlg_cancel_cb, dlg);
+ GTK_WIDGET_SET_FLAGS(cancel_button, GTK_CAN_DEFAULT);
+ gtk_box_pack_start(GTK_BOX(bbox), cancel_button, TRUE, TRUE, 0);
+ gtk_widget_show(cancel_button);
+
+ /* Catch the "activate" signal on the filter text entry, so that
+ if the user types Return there, we act as if the "Create Stat"
+ button had been selected, as happens if Return is typed if
+ some widget that *doesn't* handle the Return key has the input
+ focus. */
+ dlg_set_activate(filter_entry, start_button);
+
+ /* Catch the "key_press_event" signal in the window, so that we can
+ catch the ESC key being pressed and act as if the "Cancel" button
+ had been selected. */
+ dlg_set_cancel(dlg, cancel_button);
+
+ /* Give the initial focus to the "Filter" entry box. */
+ gtk_widget_grab_focus(filter_entry);
+
gtk_widget_show_all(dlg);
}
@@ -332,6 +374,6 @@ register_tap_listener_gtkdhcpstat(void)
void
register_tap_menu_gtkdhcpstat(void)
{
- register_tap_menu_item("Statistics/Watch protocol/BOOTP-DHCP",
+ register_tap_menu_item("Statistics/Watch protocol/BOOTP-DHCP...",
gtk_dhcpstat_cb, NULL, NULL);
}