1 /* supported_protos_dlg.c
3 * Laurent Deniel <laurent.deniel@free.fr>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 2000 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/prefs.h>
35 #include "../globals.h"
37 #include "gtk/supported_protos_dlg.h"
38 #include "gtk/gtkglobals.h"
39 #include "gtk/gui_utils.h"
40 #include "gtk/dlg_utils.h"
41 #include "gtk/font_utils.h"
45 static const char *proto_supported =
46 "The following %d protocols (and packet types) are currently\n"
47 "supported by Wireshark:\n\n";
49 static const char *dfilter_supported =
50 "The following per-protocol fields are currently supported by\n"
51 "Wireshark and can be used in display filters:\n";
60 static void supported_destroy_cb(GtkWidget *w, gpointer data);
61 static void insert_text(GtkWidget *w, const char *buffer, int nchars);
62 static void set_supported_text(GtkWidget *w, supported_type_t type);
65 * Keep a static pointer to the current "Supported" window, if any, so that
66 * if somebody tries to do "Help->Supported" while there's already a
67 * "Supported" window up, we just pop up the existing one, rather than
70 static GtkWidget *supported_w = NULL;
73 * Keep static pointers to the text widgets as well (for text format changes).
75 static GtkWidget *proto_text, *dfilter_text;
79 void supported_cb(GtkWidget *w _U_, gpointer data _U_)
82 GtkWidget *main_vb, *bbox, *supported_nb, *ok_bt, *label, *txt_scrollw,
86 if (supported_w != NULL) {
87 /* There's already a "Supported" dialog box; reactivate it. */
88 reactivate_window(supported_w);
92 supported_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Supported Protocols");
93 gtk_window_set_default_size(GTK_WINDOW(supported_w), DEF_WIDTH * 2/3, DEF_HEIGHT * 2/3);
94 gtk_container_set_border_width(GTK_CONTAINER(supported_w), 2);
96 /* Container for each row of widgets */
97 main_vb = gtk_vbox_new(FALSE, 1);
98 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 1);
99 gtk_container_add(GTK_CONTAINER(supported_w), main_vb);
100 gtk_widget_show(main_vb);
102 /* supported topics container */
103 supported_nb = gtk_notebook_new();
104 gtk_container_add(GTK_CONTAINER(main_vb), supported_nb);
107 /* humm, gtk 1.2 does not support horizontal scrollbar for text widgets */
110 proto_vb = gtk_vbox_new(FALSE, 0);
111 gtk_container_set_border_width(GTK_CONTAINER(proto_vb), 1);
113 txt_scrollw = scrolled_window_new(NULL, NULL);
114 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
116 gtk_box_pack_start(GTK_BOX(proto_vb), txt_scrollw, TRUE, TRUE, 0);
117 proto_text = gtk_text_view_new();
118 gtk_text_view_set_editable(GTK_TEXT_VIEW(proto_text), FALSE);
119 set_supported_text(proto_text, PROTOCOL_SUPPORTED);
120 gtk_container_add(GTK_CONTAINER(txt_scrollw), proto_text);
121 gtk_widget_show(txt_scrollw);
122 gtk_widget_show(proto_text);
123 gtk_widget_show(proto_vb);
124 label = gtk_label_new("Protocols");
125 gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), proto_vb, label);
127 /* display filter fields */
128 dfilter_vb = gtk_vbox_new(FALSE, 0);
129 gtk_container_set_border_width(GTK_CONTAINER(dfilter_vb), 1);
131 txt_scrollw = scrolled_window_new(NULL, NULL);
132 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
134 gtk_box_pack_start(GTK_BOX(dfilter_vb), txt_scrollw, TRUE, TRUE, 0);
135 dfilter_text = gtk_text_view_new();
136 if (prefs.gui_scrollbar_on_right) {
137 gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
138 GTK_CORNER_TOP_LEFT);
141 gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
142 GTK_CORNER_TOP_RIGHT);
144 gtk_text_view_set_editable(GTK_TEXT_VIEW(dfilter_text), FALSE);
145 set_supported_text(dfilter_text, DFILTER_SUPPORTED);
146 gtk_container_add(GTK_CONTAINER(txt_scrollw), dfilter_text);
147 gtk_widget_show(txt_scrollw);
148 gtk_widget_show(dfilter_text);
149 gtk_widget_show(dfilter_vb);
150 label = gtk_label_new("Display Filter Fields");
151 gtk_notebook_append_page(GTK_NOTEBOOK(supported_nb), dfilter_vb, label);
153 /* XXX add other panels here ... */
155 gtk_widget_show(supported_nb);
158 bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
159 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
160 gtk_widget_show(bbox);
162 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
163 window_set_cancel_button(supported_w, ok_bt, window_cancel_button_cb);
165 gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(supported_w));
167 g_signal_connect(supported_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
168 g_signal_connect(supported_w, "destroy", G_CALLBACK(supported_destroy_cb), NULL);
170 gtk_widget_show(supported_w);
171 window_present(supported_w);
174 static void supported_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
176 /* Note that we no longer have a Help window. */
180 static void insert_text(GtkWidget *w, const char *buffer, int nchars)
182 GtkTextBuffer *buf= gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
185 gtk_text_buffer_get_end_iter(buf, &iter);
186 gtk_widget_modify_font(w, user_font_get_regular());
187 if (!g_utf8_validate(buffer, -1, NULL))
188 printf("Invalid utf8 encoding: %s\n", buffer);
189 gtk_text_buffer_insert(buf, &iter, buffer, nchars);
193 static void set_supported_text(GtkWidget *w, supported_type_t type)
196 #define BUFF_LEN 4096
198 char buffer[BUFF_LEN];
199 header_field_info *hfinfo;
200 int i, len, maxlen = 0, maxlen2 = 0, maxlen4 = 0;
201 const char *type_name;
202 void *cookie, *cookie2;
203 protocol_t *protocol;
204 const char *name, *short_name, *filter_name;
205 int namel = 0, short_namel = 0, filter_namel = 0;
211 * the width and height computations are performed to make the
212 * horizontal scrollbar work in gtk1.2. This is only necessary for the
213 * PROTOCOL_SUPPORTED and DFILTER_SUPPORTED windows since all others should
214 * not have any horizontal scrollbar (line wrapping enabled).
220 case PROTOCOL_SUPPORTED :
221 /* first pass to know the maximum length of first field */
223 for (i = proto_get_first_protocol(&cookie); i != -1;
224 i = proto_get_next_protocol(&cookie)) {
226 protocol = find_protocol_by_id(i);
227 name = proto_get_protocol_name(i);
228 short_name = proto_get_protocol_short_name(protocol);
229 filter_name = proto_get_protocol_filter_name(i);
230 if ((len = (int) strlen(name)) > namel)
232 if ((len = (int) strlen(short_name)) > short_namel)
234 if ((len = (int) strlen(filter_name)) > filter_namel)
237 maxlen = namel + short_namel + filter_namel;
239 len = g_snprintf(buffer, BUFF_LEN, proto_supported, count);
240 insert_text(w, buffer, len);
242 /* ok, display the correctly aligned strings */
243 for (i = proto_get_first_protocol(&cookie); i != -1;
244 i = proto_get_next_protocol(&cookie)) {
245 protocol = find_protocol_by_id(i);
246 name = proto_get_protocol_name(i);
247 short_name = proto_get_protocol_short_name(protocol);
248 filter_name = proto_get_protocol_filter_name(i);
250 /* the name used for sorting in the left column */
251 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s\n",
252 -short_namel, short_name,
254 -filter_namel, filter_name);
255 insert_text(w, buffer, (int) strlen(buffer));
260 case DFILTER_SUPPORTED :
262 /* XXX we should display hinfo->blurb instead of name (if not empty) */
264 /* first pass to know the maximum length of first and second fields */
265 for (i = proto_get_first_protocol(&cookie); i != -1;
266 i = proto_get_next_protocol(&cookie)) {
268 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
269 hfinfo = proto_get_next_protocol_field(&cookie2)) {
271 if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
274 if ((len = (int) strlen(hfinfo->abbrev)) > maxlen)
276 if ((len = (int) strlen(hfinfo->name)) > maxlen2)
278 if (hfinfo->blurb != NULL) {
279 if ((len = (int) strlen(hfinfo->blurb)) > maxlen4)
285 insert_text(w, dfilter_supported, (int) strlen(dfilter_supported));
288 for (i = proto_get_first_protocol(&cookie); i != -1;
289 i = proto_get_next_protocol(&cookie)) {
290 protocol = find_protocol_by_id(i);
291 name = proto_get_protocol_name(i);
292 short_name = proto_get_protocol_short_name(protocol);
293 filter_name = proto_get_protocol_filter_name(i);
296 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
297 hfinfo = proto_get_next_protocol_field(&cookie2)) {
299 if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
305 len = g_snprintf(buffer, BUFF_LEN, "\n%s - %s (%s) [%d fields]:\n",
306 short_name, name, filter_name, count);
307 insert_text(w, buffer, len);
309 for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL;
310 hfinfo = proto_get_next_protocol_field(&cookie2)) {
312 if (hfinfo->same_name_prev != NULL) /* ignore duplicate names */
315 type_name = ftype_pretty_name(hfinfo->type);
316 if (hfinfo->blurb != NULL && hfinfo->blurb[0] != '\0') {
317 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s %*s (%s)\n",
318 -maxlen, hfinfo->abbrev,
319 -maxlen2, hfinfo->name,
320 -maxlen4, hfinfo->blurb,
323 len = g_snprintf(buffer, BUFF_LEN, "%*s %*s (%s)\n",
324 -maxlen, hfinfo->abbrev,
325 -maxlen2, hfinfo->name,
328 insert_text(w, buffer, (int) strlen(buffer));
331 len = g_snprintf(buffer, BUFF_LEN, "\n-- Total %d fields\n", fcount);
332 insert_text(w, buffer, len);
336 g_assert_not_reached();
339 } /* set_supported_text */
342 static void clear_supported_text(GtkWidget *w)
344 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
346 gtk_text_buffer_set_text(buf, "", 0);
350 /* Redraw all the text widgets, to use a new font. */
351 void supported_redraw(void)
353 if (supported_w != NULL) {
354 clear_supported_text(proto_text);
355 set_supported_text(proto_text, PROTOCOL_SUPPORTED);
356 clear_supported_text(dfilter_text);
357 set_supported_text(dfilter_text, DFILTER_SUPPORTED);