5 * 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.
35 #include "epan/filesystem.h"
37 #include "text_page.h"
38 #include <epan/prefs.h>
39 #include "gtkglobals.h"
40 #include "gui_utils.h"
41 #include "compat_macros.h"
42 #include "dlg_utils.h"
43 #include "simple_dialog.h"
44 #include "webbrowser.h"
45 #include "file_util.h"
50 #include "epan/strutil.h"
54 #define HELP_DIR "help"
57 #define NOTEBOOK_KEY "notebook_key"
59 static void help_destroy_cb(GtkWidget *w, gpointer data);
62 * Keep a static pointer to the current "Help" window, if any, so that
63 * if somebody tries to do "Help->Help" while there's already a
64 * "Help" window up, we just pop up the existing one, rather than
67 static GtkWidget *help_w = NULL;
70 * Keep a list of text widgets and corresponding file names as well
71 * (for text format changes).
79 static GSList *help_text_pages = NULL;
83 * Helper function to show a simple help text page.
85 static GtkWidget * help_page(const char *topic, const char *filename)
88 char *relative_path, *absolute_path;
91 relative_path = g_strconcat(HELP_DIR, G_DIR_SEPARATOR_S, filename, NULL);
92 absolute_path = get_datafile_path(relative_path);
93 text_page = text_page_new(absolute_path);
94 g_free(relative_path);
95 gtk_widget_show(text_page);
97 page = g_malloc(sizeof (help_page_t));
98 page->topic = g_strdup(topic);
99 page->pathname = absolute_path;
100 page->page = text_page;
101 help_text_pages = g_slist_append(help_text_pages, page);
108 * Create and show help dialog.
111 void help_dialog(void)
113 GtkWidget *main_vb, *bbox, *help_nb, *close_bt, *label, *topic_vb;
114 char line[4096+1]; /* XXX - size? */
117 char *help_toc_file_path;
120 if (help_w != NULL) {
121 /* There's already a "Help" dialog box; reactivate it. */
122 reactivate_window(help_w);
126 help_toc_file_path = get_datafile_path(HELP_DIR G_DIR_SEPARATOR_S "toc");
127 help_toc_file = eth_fopen(help_toc_file_path, "r");
128 if (help_toc_file == NULL) {
129 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open file \"%s\": %s",
130 help_toc_file_path, strerror(errno));
131 g_free(help_toc_file_path);
135 help_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, "Wireshark: Help", "help");
136 gtk_window_set_default_size(GTK_WINDOW(help_w), DEF_WIDTH, DEF_HEIGHT);
137 gtk_container_border_width(GTK_CONTAINER(help_w), 2);
139 /* Container for each row of widgets */
140 main_vb = gtk_vbox_new(FALSE, 1);
141 gtk_container_border_width(GTK_CONTAINER(main_vb), 1);
142 gtk_container_add(GTK_CONTAINER(help_w), main_vb);
144 /* help topics container */
145 help_nb = gtk_notebook_new();
146 gtk_container_add(GTK_CONTAINER(main_vb), help_nb);
147 OBJECT_SET_DATA(help_w, NOTEBOOK_KEY, help_nb);
150 while (fgets(line, sizeof line, help_toc_file) != NULL) {
151 /* Strip off line ending. */
152 p = strpbrk(line, "\r\n");
154 break; /* last line has no line ending */
156 /* {Topic title}:{filename of help file} */
157 p = strchr(line, ':');
163 * "line" refers to the topic now, and "filename" refers to the
166 topic_vb = help_page(line, filename);
167 label = gtk_label_new(line);
168 gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), topic_vb, label);
171 if(ferror(help_toc_file)) {
172 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Error reading file \"%s\": %s",
173 help_toc_file_path, strerror(errno));
175 fclose(help_toc_file);
179 bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
180 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
182 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
183 window_set_cancel_button(help_w, close_bt, window_cancel_button_cb);
185 SIGNAL_CONNECT(help_w, "delete_event", window_delete_event_cb, NULL);
186 SIGNAL_CONNECT(help_w, "destroy", help_destroy_cb, NULL);
188 gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(help_w));
190 gtk_widget_show_all(help_w);
191 window_present(help_w);
195 gboolean topic_available(topic_action_e action) {
197 #ifdef WIRESHARK_EUG_DIR
198 if(action == HELP_CAPTURE_INTERFACES_DETAILS_DIALOG) {
199 /* page currently not existing in user's guide */
202 /* online: we have almost all possible pages available */
205 /* offline: we have only some pages available */
210 case(HELP_GETTING_STARTED):
213 case(HELP_CAPTURE_OPTIONS_DIALOG):
216 case(HELP_CAPTURE_FILTERS_DIALOG):
219 case(HELP_DISPLAY_FILTERS_DIALOG):
229 * Open the help dialog and show a specific help page.
231 static void help_topic(const gchar *topic) {
235 GString *url = g_string_new("");
237 g_string_append_printf(url, "%s\\user-guide.chm::/%s>Wireshark Help",
238 get_datafile_dir(), topic);
242 HH_DISPLAY_TOPIC, 0);
245 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open help file: %s\\user-guide.chm",
249 g_string_free(url, TRUE /* free_segment */);
255 GSList *help_page_ent;
260 /* show help dialog, if not already opened */
263 help_nb = OBJECT_GET_DATA(help_w, NOTEBOOK_KEY);
265 /* find page to display */
266 for (help_page_ent = help_text_pages; help_page_ent != NULL;
267 help_page_ent = g_slist_next(help_page_ent))
269 page = (help_page_t *)help_page_ent->data;
270 page_topic = page->topic;
271 if (strcmp (page_topic, topic) == 0) {
272 /* topic page found, switch to notebook page */
273 gtk_notebook_set_page(GTK_NOTEBOOK(help_nb), page_num);
280 /* topic page not found, default (first page) will be shown */
285 * Help dialog is closed now.
287 static void help_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
289 GSList *help_page_ent;
292 /* Free up the list of help pages. */
293 for (help_page_ent = help_text_pages; help_page_ent != NULL;
294 help_page_ent = g_slist_next(help_page_ent)) {
295 page = (help_page_t *)help_page_ent->data;
297 g_free(page->pathname);
300 g_slist_free(help_text_pages);
301 help_text_pages = NULL;
303 /* Note that we no longer have a Help window. */
309 * Redraw all help pages, to use a new font.
311 void help_redraw(void)
313 GSList *help_page_ent;
314 help_page_t *help_page;
316 if (help_w != NULL) {
317 for (help_page_ent = help_text_pages; help_page_ent != NULL;
318 help_page_ent = g_slist_next(help_page_ent))
320 help_page = (help_page_t *)help_page_ent->data;
321 text_page_redraw(help_page->page, help_page->pathname);
328 #define ONLINE_HELP_CALL help_topic
329 #define ONLINE_HELP_PREFIX "wsug_chm/"
331 #define ONLINE_HELP_CALL browser_open_data_file
332 #define ONLINE_HELP_PREFIX "wsug_html_chunked/"
336 topic_action(topic_action_e action)
338 /* pages online at www.wireshark.org */
340 case(ONLINEPAGE_HOME):
341 browser_open_url ("http://www.wireshark.org");
343 case(ONLINEPAGE_WIKI):
344 browser_open_url ("http://wiki.wireshark.org");
346 case(ONLINEPAGE_DOWNLOAD):
347 browser_open_url ("http://www.wireshark.org/download.html");
349 case(ONLINEPAGE_USERGUIDE):
350 browser_open_url ("http://www.wireshark.org/docs/wsug_html_chunked");
352 case(ONLINEPAGE_FAQ):
353 browser_open_url ("http://www.wireshark.org/faq.html");
355 case(ONLINEPAGE_SAMPLE_FILES):
356 browser_open_url ("http://wiki.wireshark.org/SampleCaptures");
359 /* local manual pages */
360 case(LOCALPAGE_MAN_WIRESHARK):
361 browser_open_data_file("wireshark.html");
363 case(LOCALPAGE_MAN_WIRESHARK_FILTER):
364 browser_open_data_file("wireshark-filter.html");
366 case(LOCALPAGE_MAN_TSHARK):
367 browser_open_data_file("tshark.html");
369 case(LOCALPAGE_MAN_DUMPCAP):
370 browser_open_data_file("dumpcap.html");
372 case(LOCALPAGE_MAN_MERGECAP):
373 browser_open_data_file("mergecap.html");
375 case(LOCALPAGE_MAN_EDITCAP):
376 browser_open_data_file("editcap.html");
378 case(LOCALPAGE_MAN_TEXT2PCAP):
379 browser_open_data_file("text2pcap.html");
382 #ifdef WIRESHARK_EUG_DIR
383 /* local help pages (User's Guide) */
385 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "index.html");
387 case(HELP_CAPTURE_OPTIONS_DIALOG):
388 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCapCaptureOptions.html");
390 case(HELP_CAPTURE_FILTERS_DIALOG):
391 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChWorkDefineFilterSection.html");
393 case(HELP_DISPLAY_FILTERS_DIALOG):
394 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChWorkDefineFilterSection.html");
396 case(HELP_COLORING_RULES_DIALOG):
397 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCustColorizationSection.html");
399 case(HELP_PRINT_DIALOG):
400 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChIOPrintSection.html");
402 case(HELP_FIND_DIALOG):
403 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChWorkFindPacketSection.html");
405 case(HELP_GOTO_DIALOG):
406 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChWorkGoToPacketSection.html");
408 case(HELP_CAPTURE_INTERFACES_DIALOG):
409 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCapInterfaceSection.html");
411 case(HELP_ENABLED_PROTOCOLS_DIALOG):
412 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCustProtocolDissectionSection.html");
414 case(HELP_DECODE_AS_DIALOG):
415 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCustProtocolDissectionSection.html");
417 case(HELP_DECODE_AS_SHOW_DIALOG):
418 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCustProtocolDissectionSection.html");
420 case(HELP_FOLLOW_TCP_STREAM_DIALOG):
421 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChAdvFollowTCPSection.html");
423 case(HELP_STATS_SUMMARY_DIALOG):
424 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChStatSummary.html");
426 case(HELP_STATS_PROTO_HIERARCHY_DIALOG):
427 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChStatHierarchy.html");
429 case(HELP_STATS_ENDPOINTS_DIALOG):
430 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChStatEndpoints.html");
432 case(HELP_STATS_CONVERSATIONS_DIALOG):
433 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChStatConversations.html");
435 case(HELP_STATS_IO_GRAPH_DIALOG):
436 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChStatIOGraphs.html");
438 case(HELP_FILESET_DIALOG):
439 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChIOFileSetSection.html");
441 case(HELP_CAPTURE_INTERFACES_DETAILS_DIALOG):
442 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCapInterfaceDetailsSection.html");
444 case(HELP_PREFERENCES_DIALOG):
445 ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCustPreferencesSection.html");
448 /* only some help pages are available for offline reading */
450 help_topic("Overview");
452 case(HELP_GETTING_STARTED):
453 help_topic("Getting Started");
455 case(HELP_CAPTURE_OPTIONS_DIALOG):
456 help_topic("Capturing");
458 case(HELP_CAPTURE_FILTERS_DIALOG):
459 help_topic("Capture Filters");
461 case(HELP_DISPLAY_FILTERS_DIALOG):
462 help_topic("Display Filters");
467 g_assert_not_reached();
473 topic_cb(GtkWidget *w _U_, topic_action_e action)
475 topic_action(action);
479 topic_menu_cb(GtkWidget *w _U_, gpointer data _U_, topic_action_e action) {
480 topic_action(action);