update expert info LED also while doing live capturing
[obnox/wireshark/wip.git] / gtk / goto_dlg.c
1 /* goto_dlg.c
2  * Routines for "go to packet" window
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <gtk/gtk.h>
31
32 #include <epan/proto.h>
33 #include "globals.h"
34
35 #include "goto_dlg.h"
36 #include "simple_dialog.h"
37 #include "dlg_utils.h"
38 #include "compat_macros.h"
39 #include "gui_utils.h"
40 #include "help_dlg.h"
41
42 /* Capture callback data keys */
43 #define E_GOTO_FNUMBER_KEY     "goto_fnumber_te"
44
45 static void
46 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
47
48 void
49 goto_frame_cb(GtkWidget *w _U_, gpointer d _U_)
50 {
51   GtkWidget     *goto_frame_w, *main_vb, *fnumber_hb, *fnumber_lb, *fnumber_te,
52                 *bbox, *ok_bt, *cancel_bt, *help_bt;
53
54   goto_frame_w = dlg_window_new("Wireshark: Go To Packet");
55
56   /* Container for each row of widgets */
57   main_vb = gtk_vbox_new(FALSE, 3);
58   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
59   gtk_container_add(GTK_CONTAINER(goto_frame_w), main_vb);
60   gtk_widget_show(main_vb);
61
62   /* Frame number row */
63   fnumber_hb = gtk_hbox_new(FALSE, 3);
64   gtk_container_add(GTK_CONTAINER(main_vb), fnumber_hb);
65   gtk_widget_show(fnumber_hb);
66
67   fnumber_lb = gtk_label_new("Packet number:");
68   gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_lb, FALSE, FALSE, 0);
69   gtk_widget_show(fnumber_lb);
70
71   fnumber_te = gtk_entry_new();
72   gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_te, FALSE, FALSE, 0);
73   gtk_widget_show(fnumber_te);
74
75   /* Button row: OK and cancel buttons */
76   if(topic_available(HELP_GOTO_DIALOG)) {
77     bbox = dlg_button_row_new(GTK_STOCK_JUMP_TO, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
78   } else {
79     bbox = dlg_button_row_new(GTK_STOCK_JUMP_TO, GTK_STOCK_CANCEL, NULL);
80   }
81   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
82   gtk_widget_show(bbox);
83
84   ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_JUMP_TO);
85   SIGNAL_CONNECT(ok_bt, "clicked", goto_frame_ok_cb, goto_frame_w);
86
87   cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
88   window_set_cancel_button(goto_frame_w, cancel_bt, window_cancel_button_cb);
89
90   if(topic_available(HELP_GOTO_DIALOG)) {
91       help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
92       SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_GOTO_DIALOG);
93   }
94
95   gtk_widget_grab_default(ok_bt);
96
97   /* Catch the "activate" signal on the frame number text entry, so that
98      if the user types Return there, we act as if the "OK" button
99      had been selected, as happens if Return is typed if some widget
100      that *doesn't* handle the Return key has the input focus. */
101   dlg_set_activate(fnumber_te, ok_bt);
102
103   /* Give the initial focus to the "Packet number" entry box. */
104   gtk_widget_grab_focus(fnumber_te);
105
106   /* Attach pointers to needed widgets to the capture prefs window/object */
107   OBJECT_SET_DATA(goto_frame_w, E_GOTO_FNUMBER_KEY, fnumber_te);
108
109   SIGNAL_CONNECT(goto_frame_w, "delete_event", window_delete_event_cb, NULL);
110
111   gtk_widget_show(goto_frame_w);
112   window_present(goto_frame_w);
113 }
114
115 static void
116 goto_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
117 {
118   GtkWidget   *fnumber_te;
119   const gchar *fnumber_text;
120   guint        fnumber;
121   char        *p;
122
123   fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_GOTO_FNUMBER_KEY);
124
125   fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
126   fnumber = strtoul(fnumber_text, &p, 10);
127   if (p == fnumber_text || *p != '\0') {
128     /* Illegal number.
129        XXX - what about negative numbers (which "strtoul()" allows)?
130        Can we hack up signal handlers for the widget to make it
131        reject attempts to type in characters other than digits? */
132     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
133                 "The packet number you entered isn't a valid number.");
134     return;
135   }
136
137   if (cf_goto_frame(&cfile, fnumber)) {
138     /* We succeeded in going to that frame; we're done. */
139     window_destroy(GTK_WIDGET(parent_w));
140   }
141 }
142
143 /*
144  * Go to frame specified by currently selected protocol tree item.
145  */
146 void
147 goto_framenum_cb(GtkWidget *w _U_, gpointer data _U_)
148 {
149     cf_goto_framenum(&cfile);
150 }
151
152 void
153 goto_top_frame_cb(GtkWidget *w _U_, gpointer d _U_)
154 {
155     cf_goto_top_frame(&cfile);
156 }
157
158 void
159 goto_bottom_frame_cb(GtkWidget *w _U_, gpointer d _U_)
160 {
161     cf_goto_bottom_frame(&cfile);
162 }
163
164