Redesigned the menu structure of the former statistics stuff,
[obnox/wireshark/wip.git] / gtk / rtp_analysis.c
index c549a96b2824f09061d0063e6cb981bacd56651c..7ee792692f954f21fbd4652e524f46e447bdb82d 100644 (file)
@@ -1,7 +1,7 @@
 /* rtp_analysis.c
  * RTP analysis addition for ethereal
  *
- * $Id: rtp_analysis.c,v 1.31 2004/01/31 09:48:26 guy Exp $
+ * $Id: rtp_analysis.c,v 1.38 2004/02/22 18:44:03 ulfl Exp $
  *
  * Copyright 2003, Alcatel Business Systems
  * By Lars Ruoff <lars.ruoff@gmx.net>
 #include "../graph/graph.h"
 #endif
 
+#include <epan/epan_dissect.h>
+#include <epan/filesystem.h>
+
 #include "util.h"
-#include "epan/epan_dissect.h"
-#include "epan/filesystem.h"
 #include "tap.h"
 #include "register.h"
 #include "packet-rtp.h"
@@ -60,8 +61,9 @@
 /* in /gtk ... */
 #include "dlg_utils.h"
 #include "ui_util.h"
+#include "alert_box.h"
 #include "simple_dialog.h"
-#include "menu.h"
+#include "tap_menu.h"
 #include "main.h"
 #include "progress_dlg.h"
 #include "compat_macros.h"
@@ -874,7 +876,7 @@ static void on_refresh_bt_clicked(GtkWidget *bt _U_, user_data_t *user_data _U_)
        /* try to compile the filter. */
        strcpy(filter_text,"rtp && ip");
        if (!dfilter_compile(filter_text, &sfcode)) {
-               simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK, dfilter_error_msg);
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
                return;
        }
 
@@ -893,7 +895,7 @@ static void on_refresh_bt_clicked(GtkWidget *bt _U_, user_data_t *user_data _U_)
        error_string = register_tap_listener("rtp", user_data, filter_text,
                rtp_reset, rtp_packet, rtp_draw);
        if (error_string != NULL) {
-               simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK, error_string->str);
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
                        g_string_free(error_string, TRUE);
                return;
        }
@@ -986,16 +988,14 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
        if (GTK_TOGGLE_BUTTON(forw)->active || GTK_TOGGLE_BUTTON(both)->active) {
                fp = fopen(g_dest, "w");
                if (fp == NULL) {
-                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                           file_open_error_message(errno, TRUE), g_dest);
+                       open_failure_alert_box(g_dest, errno, TRUE);
                        return;
                }
                
                if (GTK_TOGGLE_BUTTON(both)->active) {
                        fprintf(fp, "Forward\n");
                        if (ferror(fp)) {
-                               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                                   file_write_error_message(errno), g_dest);
+                               write_failure_alert_box(g_dest, errno);
                                fclose(fp);
                                return;
                        }
@@ -1010,8 +1010,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
                }
                fprintf(fp,"\n");
                if (ferror(fp)) {
-                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                           file_write_error_message(errno), g_dest);
+                       write_failure_alert_box(g_dest, errno);
                        fclose(fp);
                        return;
                }
@@ -1026,16 +1025,14 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
                        }
                        fprintf(fp,"\n");
                        if (ferror(fp)) {
-                               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                                   file_write_error_message(errno), g_dest);
+                               write_failure_alert_box(g_dest, errno);
                                fclose(fp);
                                return;
                        }
                }
                
                if (fclose(fp) == EOF) {
-                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                           file_write_error_message(errno), g_dest);
+                       write_failure_alert_box(g_dest, errno);
                        return;
                }
        }
@@ -1045,24 +1042,19 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
                if (GTK_TOGGLE_BUTTON(both)->active) {
                        fp = fopen(g_dest, "a");
                        if (fp == NULL) {
-                               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                                   file_open_error_message(errno, TRUE),
-                                   g_dest);
+                               open_failure_alert_box(g_dest, errno, TRUE);
                                return;
                        }
                        fprintf(fp, "\nReverse\n");
                        if (ferror(fp)) {
-                               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                                   file_write_error_message(errno), g_dest);
+                               write_failure_alert_box(g_dest, errno);
                                fclose(fp);
                                return;
                        }
                } else {
                        fp = fopen(g_dest, "w");
                        if (fp == NULL) {
-                               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                                   file_open_error_message(errno, TRUE),
-                                   g_dest);
+                               open_failure_alert_box(g_dest, errno, TRUE);
                                return;
                        }
                }
@@ -1075,8 +1067,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
                }
                fprintf(fp,"\n");
                if (ferror(fp)) {
-                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                           file_write_error_message(errno), g_dest);
+                       write_failure_alert_box(g_dest, errno);
                        fclose(fp);
                        return;
                }
@@ -1091,15 +1082,13 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user
                        }
                        fprintf(fp,"\n");
                        if (ferror(fp)) {
-                               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                                   file_write_error_message(errno), g_dest);
+                               write_failure_alert_box(g_dest, errno);
                                fclose(fp);
                                return;
                        }
                }
                if (fclose(fp) == EOF) {
-                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                           file_write_error_message(errno), g_dest);
+                       write_failure_alert_box(g_dest, errno);
                        return;
                }
        }
@@ -1439,22 +1428,22 @@ static void save_voice_as_ok_cb(GtkWidget *ok_bt _U_, gpointer fs _U_)
                /* there are many combinations here, we just exit when first matches */
                if ((user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_CODEC) || 
                        (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_CODEC))
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save in a file: Unsupported codec!");
                else if ((user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_LENGTH) || 
                        (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_LENGTH))
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save in a file: Wrong length of captured packets!");
                else if ((user_data->forward.saveinfo.error_type == TAP_RTP_PADDING_ERROR) || 
                        (user_data->reversed.saveinfo.error_type == TAP_RTP_PADDING_ERROR))
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save in a file: RTP data with padding!");
                else if ((user_data->forward.saveinfo.error_type == TAP_RTP_SHORT_FRAME) || 
                        (user_data->reversed.saveinfo.error_type == TAP_RTP_SHORT_FRAME))
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save in a file: Not all data in all packets was captured!");
                else  
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save in a file: File I/O problem!");
                return;
        }
@@ -1462,19 +1451,19 @@ static void save_voice_as_ok_cb(GtkWidget *ok_bt _U_, gpointer fs _U_)
        else if ((user_data->forward.saveinfo.saved == FALSE) && ((GTK_TOGGLE_BUTTON (forw)->active) ||
                (GTK_TOGGLE_BUTTON (both)->active))) {  
                if (user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_CODEC)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save forward direction in a file: Unsupported codec!");
                else if (user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_LENGTH)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save forward direction in a file: Wrong length of captured packets!");
                else if (user_data->forward.saveinfo.error_type == TAP_RTP_PADDING_ERROR)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save forward direction in a file: RTP data with padding!");
                else if (user_data->forward.saveinfo.error_type == TAP_RTP_SHORT_FRAME)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save forward direction in a file: Not all data in all packets was captured!");
                else
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save forward direction in a file: File I/O problem!");
                return;
        }
@@ -1482,22 +1471,22 @@ static void save_voice_as_ok_cb(GtkWidget *ok_bt _U_, gpointer fs _U_)
        else if ((user_data->reversed.saveinfo.saved == FALSE) && ((GTK_TOGGLE_BUTTON (rev)->active) ||
                (GTK_TOGGLE_BUTTON (both)->active))) {  
                if (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_CODEC)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save reversed direction in a file: Unsupported codec!");
                else if (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_LENGTH)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save reversed direction in a file: Wrong length of captured packets!");
                else if (user_data->reversed.saveinfo.error_type == TAP_RTP_PADDING_ERROR)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save reversed direction in a file: RTP data with padding!");
                else if (user_data->forward.saveinfo.error_type == TAP_RTP_SHORT_FRAME)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save reversed direction in a file: Not all data in all packets was captured!");
                else if (user_data->reversed.saveinfo.error_type == TAP_RTP_NO_DATA)
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save reversed direction in a file: No RTP data!");
                else
-                       simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+                       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't save reversed direction in a file: File I/O problem!");
                return;
        }
@@ -1518,7 +1507,7 @@ static void save_voice_as_ok_cb(GtkWidget *ok_bt _U_, gpointer fs _U_)
        
        if(!copy_file(g_dest, channels/*, format*/, user_data)) {
                /* XXX - report the error type! */
-               simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "An error occured while saving voice in a file!");
                return;
        }
@@ -1930,8 +1919,7 @@ void create_rtp_dialog(user_data_t* user_data)
        column_arrows *col_arrows_rev;
        
 
-       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-       gtk_window_set_title (GTK_WINDOW (window), "Ethereal: RTP Stream Analysis");
+       window = window_new (GTK_WINDOW_TOPLEVEL, "Ethereal: RTP Stream Analysis");
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
        SIGNAL_CONNECT(window, "destroy", on_destroy, user_data);
 
@@ -1976,10 +1964,8 @@ void create_rtp_dialog(user_data_t* user_data)
        gtk_box_pack_end(GTK_BOX(page), label_stats_fwd, FALSE, FALSE, 0);
 
        /* scrolled window */
-       scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+       scrolled_window = scrolled_window_new(NULL, NULL);
        WIDGET_SET_SIZE(scrolled_window, 560, 200);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), 
-               GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
        /* packet clist */
        clist_fwd = create_clist(user_data);
@@ -2000,10 +1986,8 @@ void create_rtp_dialog(user_data_t* user_data)
        label_stats_rev = gtk_label_new("\n");
        gtk_box_pack_end(GTK_BOX(page_r), label_stats_rev, FALSE, FALSE, 0);
 
-       scrolled_window_r = gtk_scrolled_window_new(NULL, NULL);
+       scrolled_window_r = scrolled_window_new(NULL, NULL);
        WIDGET_SET_SIZE(scrolled_window_r, 560, 200);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window_r), 
-               GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
        clist_rev = create_clist(user_data);
        gtk_widget_show(clist_rev);
@@ -2248,8 +2232,7 @@ void rtp_analysis_cb(GtkWidget *w _U_, gpointer data _U_)
        /* Try to compile the filter. */
        strcpy(filter_text,"rtp && ip");
        if (!dfilter_compile(filter_text, &sfcode)) {
-               simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
-                   dfilter_error_msg);
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
                return;
        }
        /* we load the current file into cf variable */
@@ -2263,7 +2246,7 @@ void rtp_analysis_cb(GtkWidget *w _U_, gpointer data _U_)
        /* dissect the current frame */
        if (!wtap_seek_read(cf->wth, fdata->file_off, &cf->pseudo_header,
            cf->pd, fdata->cap_len, &err, &err_info)) {
-               simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        cf_read_error_message(err, err_info), cf->filename);
                return;
        }
@@ -2276,7 +2259,7 @@ void rtp_analysis_cb(GtkWidget *w _U_, gpointer data _U_)
        frame_matched = dfilter_apply_edt(sfcode, edt);
        if (frame_matched != 1) {
                epan_dissect_free(edt);
-               simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "You didn't choose a RTP packet!");
                return;
        }
@@ -2295,7 +2278,7 @@ void rtp_analysis_cb(GtkWidget *w _U_, gpointer data _U_)
        
        /* now we need the SSRC value of the current frame */
        if (!get_int_value_from_proto_tree(edt->tree, "rtp", "rtp.ssrc", &ssrc_fwd)) {
-               simple_dialog(ESD_TYPE_ERROR | ESD_TYPE_MODAL, ESD_BTN_OK,
+               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "SSRC value couldn't be found!");
                return;
        }
@@ -2361,11 +2344,7 @@ void
 register_tap_listener_rtp_analysis(void)
 {
        register_ethereal_tap("rtp", rtp_analysis_init);
-}
 
-void
-register_tap_menu_rtp_analysis(void)
-{
-       register_tap_menu_item("_Statistics/RTP Streams/Analyse...",
+       register_tap_menu_item("RTP/Stream Analysis...", REGISTER_TAP_LAYER_APPLICATION,
            rtp_analysis_cb, NULL, NULL, NULL);
 }