Do case insensitive search for lua scripts to load.
[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
34 #include "../globals.h"
35 #include "../simple_dialog.h"
36 #include "../ui_util.h"
37
38 #include "gtk/goto_dlg.h"
39 #include "gtk/dlg_utils.h"
40 #include "gtk/gui_utils.h"
41 #include "gtk/help_dlg.h"
42
43
44 /* Capture callback data keys */
45 #define E_GOTO_FNUMBER_KEY     "goto_fnumber_te"
46
47 static void
48 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
49
50 void
51 goto_frame_cb(GtkWidget *w _U_, gpointer d _U_)
52 {
53   GtkWidget     *goto_frame_w, *main_vb, *fnumber_hb, *fnumber_lb, *fnumber_te,
54                 *bbox, *ok_bt, *cancel_bt, *help_bt;
55
56   goto_frame_w = dlg_window_new("Wireshark: Go To Packet");
57
58   /* Container for each row of widgets */
59   main_vb = gtk_vbox_new(FALSE, 3);
60   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
61   gtk_container_add(GTK_CONTAINER(goto_frame_w), main_vb);
62   gtk_widget_show(main_vb);
63
64   /* Frame number row */
65   fnumber_hb = gtk_hbox_new(FALSE, 3);
66   gtk_container_add(GTK_CONTAINER(main_vb), fnumber_hb);
67   gtk_widget_show(fnumber_hb);
68
69   fnumber_lb = gtk_label_new("Packet number:");
70   gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_lb, FALSE, FALSE, 0);
71   gtk_widget_show(fnumber_lb);
72
73   fnumber_te = gtk_entry_new();
74   gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_te, FALSE, FALSE, 0);
75   gtk_widget_show(fnumber_te);
76
77   /* Button row: OK and cancel buttons */
78   bbox = dlg_button_row_new(GTK_STOCK_JUMP_TO, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
79   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
80   gtk_widget_show(bbox);
81
82   ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_JUMP_TO);
83   g_signal_connect(ok_bt, "clicked", G_CALLBACK(goto_frame_ok_cb), goto_frame_w);
84
85   cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
86   window_set_cancel_button(goto_frame_w, cancel_bt, window_cancel_button_cb);
87
88   help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
89   g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_GOTO_DIALOG);
90
91   gtk_widget_grab_default(ok_bt);
92
93   /* Catch the "activate" signal on the frame number text entry, so that
94      if the user types Return there, we act as if the "OK" button
95      had been selected, as happens if Return is typed if some widget
96      that *doesn't* handle the Return key has the input focus. */
97   dlg_set_activate(fnumber_te, ok_bt);
98
99   /* Give the initial focus to the "Packet number" entry box. */
100   gtk_widget_grab_focus(fnumber_te);
101
102   /* Attach pointers to needed widgets to the capture prefs window/object */
103   g_object_set_data(G_OBJECT(goto_frame_w), E_GOTO_FNUMBER_KEY, fnumber_te);
104
105   g_signal_connect(goto_frame_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
106
107   gtk_widget_show(goto_frame_w);
108   window_present(goto_frame_w);
109 }
110
111 static void
112 goto_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
113 {
114   GtkWidget   *fnumber_te;
115   const gchar *fnumber_text;
116   guint        fnumber;
117   char        *p;
118
119   fnumber_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_GOTO_FNUMBER_KEY);
120
121   fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
122   fnumber = strtoul(fnumber_text, &p, 10);
123   if (p == fnumber_text || *p != '\0') {
124     /* Illegal number.
125        XXX - what about negative numbers (which "strtoul()" allows)?
126        Can we hack up signal handlers for the widget to make it
127        reject attempts to type in characters other than digits? */
128     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
129                 "The packet number you entered isn't a valid number.");
130     return;
131   }
132
133   if (cf_goto_frame(&cfile, fnumber)) {
134     /* We succeeded in going to that frame; we're done. */
135     window_destroy(GTK_WIDGET(parent_w));
136   }
137 }
138
139 /*
140  * Go to frame specified by currently selected protocol tree item.
141  */
142 void
143 goto_framenum_cb(GtkWidget *w _U_, gpointer data _U_)
144 {
145     cf_goto_framenum(&cfile);
146 }
147
148 void
149 goto_top_frame_cb(GtkWidget *w _U_, gpointer d _U_)
150 {
151     cf_goto_top_frame();
152 }
153
154 void
155 goto_bottom_frame_cb(GtkWidget *w _U_, gpointer d _U_)
156 {
157     cf_goto_bottom_frame();
158 }
159
160 void
161 goto_next_frame_cb(GtkWidget *w _U_, gpointer d _U_)
162 {
163     new_packet_list_next();
164 }
165
166 void
167 goto_previous_frame_cb(GtkWidget *w _U_, gpointer d _U_)
168 {
169     new_packet_list_prev();
170 }
171