Rename "register_ethereal_tap()" to "register_tap_listener_cmd_arg()" as
[obnox/wireshark/wip.git] / gtk / ldap_stat.c
index 6e9c0e891d7694a00624ce47b9ecefe9d67f45e9..da6149ef4bf82007049186336d888e8048c13b56 100644 (file)
@@ -1,7 +1,7 @@
 /* ldap_stat.c
  * ldap_stat   2003 Ronnie Sahlberg
  *
- * $Id: ldap_stat.c,v 1.9 2004/01/21 21:19:33 ulfl Exp $
+ * $Id$
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 # include "config.h"
 #endif
 
-#include <stdio.h>
-
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 #endif
 
-#include <gtk/gtk.h>
 #include <string.h>
-#include "../epan/packet_info.h"
-#include "../epan/epan.h"
-#include "menu.h"
-#include "../tap.h"
-#include "../epan/value_string.h"
-#include "../packet-ldap.h"
+
+#include <gtk/gtk.h>
+
+#include <epan/packet_info.h>
+#include <epan/epan.h>
+#include <epan/value_string.h>
+
+#include "tap_menu.h"
+#include <epan/tap.h>
+#include <epan/dissectors/packet-ldap.h>
 #include "../register.h"
 #include "../timestats.h"
 #include "compat_macros.h"
 #include "../simple_dialog.h"
+#include "ui_util.h"
 #include "dlg_utils.h"
 #include "../file.h"
 #include "../globals.h"
-#include "filter_prefs.h"
+#include "filter_dlg.h"
 #include "service_response_time_table.h"
+#include "gtkglobals.h"
 
-extern GtkWidget   *main_display_filter_widget;
 
 /* used to keep track of the statistics for an entire program interface */
 typedef struct _ldapstat_t {
@@ -79,9 +81,9 @@ ldapstat_reset(void *pldap)
 }
 
 static int
-ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, void *psi)
+ldapstat_packet(void *pldap, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
 {
-       ldap_call_response_t *ldap=(ldap_call_response_t *)psi;
+       const ldap_call_response_t *ldap=psi;
        ldapstat_t *fs=(ldapstat_t *)pldap;
 
        /* we are only interested in reply packets */
@@ -149,6 +151,8 @@ gtk_ldapstat_init(char *optarg)
        char filter_string[256];
        GString *error_string;
        GtkWidget *vbox;
+    GtkWidget *bbox;
+    GtkWidget *close_bt;
 
        if(!strncmp(optarg,"ldap,srt,",9)){
                filter=optarg+9;
@@ -158,32 +162,26 @@ gtk_ldapstat_init(char *optarg)
 
        ldap=g_malloc(sizeof(ldapstat_t));
 
-       ldap->win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       ldap->win=window_new(GTK_WINDOW_TOPLEVEL, "ldap-stat");
        gtk_window_set_default_size(GTK_WINDOW(ldap->win), 550, 400);
        ldapstat_set_title(ldap);
-       SIGNAL_CONNECT(ldap->win, "destroy", win_destroy_cb, ldap);
 
-       vbox=gtk_vbox_new(FALSE, 0);
+       vbox=gtk_vbox_new(FALSE, 3);
        gtk_container_add(GTK_CONTAINER(ldap->win), vbox);
-       gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
-       gtk_widget_show(vbox);
+       gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
 
        label=gtk_label_new("LDAP Service Response Time statistics");
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
-       gtk_widget_show(label);
 
-       snprintf(filter_string,255,"Filter:%s",filter?filter:"");
+       g_snprintf(filter_string,255,"Filter:%s",filter?filter:"");
        label=gtk_label_new(filter_string);
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
-       gtk_widget_show(label);
-
 
        label=gtk_label_new("LDAP Commands");
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
-       gtk_widget_show(label);
 
        /* We must display TOP LEVEL Widget before calling init_srt_table() */
-       gtk_widget_show(ldap->win);
+       gtk_widget_show_all(ldap->win);
 
        init_srt_table(&ldap->ldap_srt_table, 24, vbox, NULL);
        init_srt_table_row(&ldap->ldap_srt_table, 0, "Bind");
@@ -214,14 +212,26 @@ gtk_ldapstat_init(char *optarg)
 
        error_string=register_tap_listener("ldap", ldap, filter, ldapstat_reset, ldapstat_packet, ldapstat_draw);
        if(error_string){
-               simple_dialog(ESD_TYPE_WARN, NULL, error_string->str);
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
                g_string_free(error_string, TRUE);
                g_free(ldap);
                return;
        }
 
-       gtk_widget_show_all(ldap->win);
-       retap_packets(&cfile);
+       /* Button row. */
+       bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
+       gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
+
+       close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
+    window_set_cancel_button(ldap->win, close_bt, window_cancel_button_cb);
+
+    SIGNAL_CONNECT(ldap->win, "delete_event", window_delete_event_cb, NULL);
+       SIGNAL_CONNECT(ldap->win, "destroy", win_destroy_cb, ldap);
+
+    gtk_widget_show_all(ldap->win);
+    window_present(ldap->win);
+       
+    cf_retap_packets(&cfile);
 }
 
 
@@ -235,20 +245,14 @@ dlg_destroy_cb(void)
        dlg=NULL;
 }
 
-static void
-dlg_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
-{
-       gtk_widget_destroy(GTK_WIDGET(parent_w));
-}
-
 static void
 ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
 {
        GString *str;
-       char *filter;
+       const char *filter;
 
        str = g_string_new("ldap,srt");
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
+       filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
        if(filter[0]!=0){
                g_string_sprintfa(str,",%s", filter);
        }
@@ -276,7 +280,7 @@ gtk_ldapstat_cb(GtkWidget *w _U_, gpointer d _U_)
        }
 
        dlg=dlg_window_new("Ethereal: Compute LDAP Service Response Time statistics");
-       SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
+       gtk_window_set_default_size(GTK_WINDOW(dlg), 300, -1);
 
        dlg_box=gtk_vbox_new(FALSE, 10);
        gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
@@ -294,7 +298,7 @@ gtk_ldapstat_cb(GtkWidget *w _U_, gpointer d _U_)
 
        /* Filter entry */
        filter_entry=gtk_entry_new();
-       WIDGET_SET_SIZE(filter_entry, 300, -2);
+    SIGNAL_CONNECT(filter_entry, "changed", filter_te_syntax_check_cb, NULL);
 
        /* filter prefs dialog */
        OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_entry);
@@ -316,12 +320,11 @@ gtk_ldapstat_cb(GtkWidget *w _U_, gpointer d _U_)
     gtk_widget_show(bbox);
 
     start_button = OBJECT_GET_DATA(bbox, ETHEREAL_STOCK_CREATE_STAT);
-    gtk_widget_grab_default(start_button );
     SIGNAL_CONNECT_OBJECT(start_button, "clicked",
                               ldapstat_start_button_clicked, NULL);
 
     cancel_button = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
-       SIGNAL_CONNECT(cancel_button, "clicked", dlg_cancel_cb, dlg);    
+    window_set_cancel_button(dlg, cancel_button, window_cancel_button_cb);
 
        /* Catch the "activate" signal on the filter text entry, so that
           if the user types Return there, we act as if the "Create Stat"
@@ -330,26 +333,22 @@ gtk_ldapstat_cb(GtkWidget *w _U_, gpointer d _U_)
           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);
+    gtk_widget_grab_default(start_button );
 
-       /* Give the initial focus to the "Filter" entry box. */
+    /* Give the initial focus to the "Filter" entry box. */
        gtk_widget_grab_focus(filter_entry);
 
-       gtk_widget_show_all(dlg);
+       SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
+
+    gtk_widget_show_all(dlg);
+    window_present(dlg);
 }
 
 void
 register_tap_listener_gtkldapstat(void)
 {
-       register_ethereal_tap("ldap,srt", gtk_ldapstat_init);
-}
+       register_tap_listener_cmd_arg("ldap,srt", gtk_ldapstat_init);
 
-void
-register_tap_menu_gtkldapstat(void)
-{
-       register_tap_menu_item("_Statistics/Service Response Time/LDAP...",
+       register_tap_menu_item("LDAP...", REGISTER_TAP_GROUP_RESPONSE_TIME,
            gtk_ldapstat_cb, NULL, NULL, NULL);
 }