Fix the wireless settings button for AirPCap devices in the
[obnox/wireshark/wip.git] / gtk / help_dlg.c
1 /* help_dlg.c
2  *
3  * $Id$
4  *
5  * Laurent Deniel <laurent.deniel@free.fr>
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 2000 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29 #include <string.h>
30 #include <stdio.h>
31 #include <errno.h>
32
33 #include <gtk/gtk.h>
34
35 #include "epan/filesystem.h"
36 #include <epan/prefs.h>
37
38 #include "../simple_dialog.h"
39
40 #include "gtk/help_dlg.h"
41 #include "gtk/text_page_utils.h"
42 #include "gtk/gtkglobals.h"
43 #include "gtk/gui_utils.h"
44 #include "gtk/dlg_utils.h"
45 #include "gtk/webbrowser.h"
46
47 #ifdef HHC_DIR
48 #include <windows.h>
49 #include <htmlhelp.h>
50 #include <wsutil/unicode-utils.h>
51 #endif
52
53
54 #define HELP_DIR        "help"
55
56
57 #define NOTEBOOK_KEY    "notebook_key"
58
59 /*
60  * Keep a static pointer to the current "Help" window, if any, so that
61  * if somebody tries to do "Help->Help" while there's already a
62  * "Help" window up, we just pop up the existing one, rather than
63  * creating a new one.
64 */
65 static GtkWidget *help_w = NULL;
66
67 /*
68  * Keep a list of text widgets and corresponding file names as well
69  * (for text format changes).
70  */
71 typedef struct {
72     char *topic;
73     char *pathname;
74     GtkWidget *page;
75 } help_page_t;
76
77 static GSList *help_text_pages = NULL;
78
79
80 /*
81  * Open the help dialog and show a specific HTML help page.
82  */
83 void help_topic_html(const gchar *topic) {
84     GString *url;
85
86     /* try to open local .chm file */
87 #ifdef HHC_DIR
88     HWND hw;
89
90     url = g_string_new("");
91
92     g_string_append_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help",
93         get_datafile_dir(), topic);
94
95     hw = HtmlHelpW(NULL,
96         utf_8to16(url->str),
97         HH_DISPLAY_TOPIC, 0);
98
99     g_string_free(url, TRUE /* free_segment */);
100
101     /* if the .chm file could be opened, stop here */
102     if(hw != NULL) {
103         return;
104     }
105 #endif /* HHC_DIR */
106
107     url = g_string_new("");
108
109 #ifdef DOC_DIR
110     if (g_file_test(DOC_DIR "/guides/wsug_html_chunked", G_FILE_TEST_IS_DIR)) {
111         /* try to open the HTML page from wireshark.org instead */
112         g_string_append_printf(url, "file://" DOC_DIR "/guides/wsug_html_chunked/%s", topic);
113     } else {
114 #endif /* ifdef DOC_DIR */
115        /* try to open the HTML page from wireshark.org instead */
116         g_string_append_printf(url, "http://www.wireshark.org/docs/wsug_html_chunked/%s", topic);
117 #ifdef DOC_DIR
118     }
119 #endif /* ifdef DOC_DIR */
120
121     browser_open_url(url->str);
122
123     g_string_free(url, TRUE /* free_segment */);
124 }
125
126
127 /**
128  * Redraw all help pages, to use a new font.
129  */
130 void help_redraw(void)
131 {
132     GSList *help_page_ent;
133     help_page_t *help_page;
134
135     if (help_w != NULL) {
136         for (help_page_ent = help_text_pages; help_page_ent != NULL;
137              help_page_ent = g_slist_next(help_page_ent))
138         {
139             help_page = (help_page_t *)help_page_ent->data;
140             text_page_redraw(help_page->page, help_page->pathname);
141         }
142     }
143 }
144
145
146 const char *
147 topic_online_url(topic_action_e action)
148 {
149     switch(action) {
150     case(ONLINEPAGE_HOME):
151         return "http://www.wireshark.org";
152         break;
153     case(ONLINEPAGE_WIKI):
154         return "http://wiki.wireshark.org";
155         break;
156     case(ONLINEPAGE_DOWNLOAD):
157         return "http://www.wireshark.org/download.html";
158         break;
159     case(ONLINEPAGE_USERGUIDE):
160         return "http://www.wireshark.org/docs/wsug_html_chunked/";
161         break;
162     case(ONLINEPAGE_FAQ):
163         return "http://www.wireshark.org/faq.html";
164         break;
165     case(ONLINEPAGE_SAMPLE_FILES):
166         return "http://wiki.wireshark.org/SampleCaptures";
167         break;
168     case(ONLINEPAGE_CAPTURE_SETUP):
169         return "http://wiki.wireshark.org/CaptureSetup";
170         break;
171     case(ONLINEPAGE_NETWORK_MEDIA):
172         return "http://wiki.wireshark.org/CaptureSetup/NetworkMedia";
173         break;
174     case(ONLINEPAGE_SAMPLE_CAPTURES):
175         return "http://wiki.wireshark.org/SampleCaptures";
176         break;
177     case(ONLINEPAGE_SECURITY):
178         return "http://wiki.wireshark.org/Security";
179         break;
180     case(ONLINEPAGE_CHIMNEY):
181         return "http://wiki.wireshark.org/CaptureSetup/Offloading#chimney";
182         break;
183     default:
184         return NULL;
185     }
186 }
187
188
189 static void
190 topic_action(topic_action_e action)
191 {
192     const char *online_url;
193
194
195     /* pages online at www.wireshark.org */
196     online_url = topic_online_url(action);
197     if(online_url != NULL) {
198         browser_open_url (online_url);
199         return;
200     }
201
202     switch(action) {
203     /* local manual pages */
204     case(LOCALPAGE_MAN_WIRESHARK):
205         browser_open_data_file("wireshark.html");
206         break;
207     case(LOCALPAGE_MAN_WIRESHARK_FILTER):
208         browser_open_data_file("wireshark-filter.html");
209         break;
210     case(LOCALPAGE_MAN_TSHARK):
211         browser_open_data_file("tshark.html");
212         break;
213     case(LOCALPAGE_MAN_RAWSHARK):
214         browser_open_data_file("rawshark.html");
215         break;
216     case(LOCALPAGE_MAN_DUMPCAP):
217         browser_open_data_file("dumpcap.html");
218         break;
219     case(LOCALPAGE_MAN_MERGECAP):
220         browser_open_data_file("mergecap.html");
221         break;
222     case(LOCALPAGE_MAN_EDITCAP):
223         browser_open_data_file("editcap.html");
224         break;
225     case(LOCALPAGE_MAN_TEXT2PCAP):
226         browser_open_data_file("text2pcap.html");
227         break;
228
229     /* local help pages (User's Guide) */
230     case(HELP_CONTENT):
231         help_topic_html( "index.html");
232         break;
233     case(HELP_CAPTURE_OPTIONS_DIALOG):
234         help_topic_html("ChCapCaptureOptions.html");
235         break;
236     case(HELP_CAPTURE_FILTERS_DIALOG):
237         help_topic_html("ChWorkDefineFilterSection.html");
238         break;
239     case(HELP_DISPLAY_FILTERS_DIALOG):
240         help_topic_html("ChWorkDefineFilterSection.html");
241         break;
242     case(HELP_COLORING_RULES_DIALOG):
243         help_topic_html("ChCustColorizationSection.html");
244         break;
245     case(HELP_CONFIG_PROFILES_DIALOG):
246         help_topic_html("ChCustConfigProfilesSection.html");
247         break;
248     case (HELP_MANUAL_ADDR_RESOLVE_DIALOG):
249         help_topic_html("ChManualAddressResolveSection.html");
250         break;
251     case(HELP_PRINT_DIALOG):
252         help_topic_html("ChIOPrintSection.html");
253         break;
254     case(HELP_FIND_DIALOG):
255         help_topic_html("ChWorkFindPacketSection.html");
256         break;
257     case(HELP_FIREWALL_DIALOG):
258         help_topic_html("ChUseToolsMenuSection.html");
259         break;
260     case(HELP_GOTO_DIALOG):
261         help_topic_html("ChWorkGoToPacketSection.html");
262         break;
263     case(HELP_CAPTURE_INTERFACES_DIALOG):
264         help_topic_html("ChCapInterfaceSection.html");
265         break;
266     case(HELP_CAPTURE_INFO_DIALOG):
267         help_topic_html("ChCapRunningSection.html");
268         break;
269     case(HELP_ENABLED_PROTOCOLS_DIALOG):
270         help_topic_html("ChCustProtocolDissectionSection.html");
271         break;
272     case(HELP_DECODE_AS_DIALOG):
273         help_topic_html("ChCustProtocolDissectionSection.html");
274         break;
275     case(HELP_DECODE_AS_SHOW_DIALOG):
276         help_topic_html("ChCustProtocolDissectionSection.html");
277         break;
278     case(HELP_FOLLOW_STREAM_DIALOG):
279         help_topic_html("ChAdvFollowTCPSection.html");
280         break;
281     case(HELP_EXPERT_INFO_DIALOG):
282         help_topic_html("ChAdvExpert.html");
283         break;
284     case(HELP_STATS_SUMMARY_DIALOG):
285         help_topic_html("ChStatSummary.html");
286         break;
287     case(HELP_STATS_PROTO_HIERARCHY_DIALOG):
288         help_topic_html("ChStatHierarchy.html");
289         break;
290     case(HELP_STATS_ENDPOINTS_DIALOG):
291         help_topic_html("ChStatEndpoints.html");
292         break;
293     case(HELP_STATS_CONVERSATIONS_DIALOG):
294         help_topic_html("ChStatConversations.html");
295         break;
296     case(HELP_STATS_IO_GRAPH_DIALOG):
297         help_topic_html("ChStatIOGraphs.html");
298         break;
299     case(HELP_STATS_COMPARE_FILES_DIALOG):
300         help_topic_html("ChStatCompareCaptureFiles.html");
301         break;
302     case(HELP_STATS_LTE_MAC_TRAFFIC_DIALOG):
303         help_topic_html("ChTelLTEMACTraffic.html");
304         break;
305     case(HELP_STATS_LTE_RLC_TRAFFIC_DIALOG):
306         help_topic_html("ChTelLTERLCTraffic.html");
307         break;
308     case(HELP_STATS_WLAN_TRAFFIC_DIALOG):
309         help_topic_html("ChStatWLANTraffic.html");
310         break;
311     case(HELP_FILESET_DIALOG):
312         help_topic_html("ChIOFileSetSection.html");
313         break;
314     case(HELP_CAPTURE_INTERFACE_OPTIONS_DIALOG):
315         help_topic_html("ChCustPreferencesSection.html#ChCustInterfaceOptionsSection");
316         break;
317     case(HELP_CAPTURE_INTERFACES_DETAILS_DIALOG):
318         help_topic_html("ChCapInterfaceDetailsSection.html");
319         break;
320     case(HELP_PREFERENCES_DIALOG):
321         help_topic_html("ChCustPreferencesSection.html");
322         break;
323     case(HELP_EXPORT_FILE_DIALOG):
324     case(HELP_EXPORT_FILE_WIN32_DIALOG):
325         help_topic_html("ChIOExportSection.html");
326         break;
327     case(HELP_EXPORT_BYTES_DIALOG):
328     case(HELP_EXPORT_BYTES_WIN32_DIALOG):
329         help_topic_html("ChIOExportSection.html#ChIOExportSelectedDialog");
330         break;
331     case(HELP_EXPORT_OBJECT_LIST):
332         help_topic_html("ChIOExportSection.html#ChIOExportObjectsDialog");
333         break;
334     case(HELP_OPEN_DIALOG):
335     case(HELP_OPEN_WIN32_DIALOG):
336         help_topic_html("ChIOOpenSection.html");
337         break;
338     case(HELP_MERGE_DIALOG):
339     case(HELP_MERGE_WIN32_DIALOG):
340         help_topic_html("ChIOMergeSection.html");
341         break;
342     case(HELP_IMPORT_DIALOG):
343         help_topic_html("ChIOImportSection.html");
344         break;
345     case(HELP_SAVE_DIALOG):
346     case(HELP_SAVE_WIN32_DIALOG):
347         help_topic_html("ChIOSaveSection.html");
348         break;
349     case(HELP_TIME_SHIFT_DIALOG):
350         help_topic_html("ChWorkShiftTimePacketSection.html");
351         break;
352     case(HELP_FILTER_SAVE_DIALOG):
353         help_topic_html("ChWorkFilterSaveSection.html");
354         break;
355
356     default:
357         g_assert_not_reached();
358     }
359 }
360
361
362 void
363 topic_cb(GtkWidget *w _U_, topic_action_e action)
364 {
365     topic_action(action);
366 }
367
368
369 gboolean
370 topic_menu_cb(GtkWidget *w _U_, GdkEventButton *event _U_, gpointer user_data)
371 {
372     topic_action((topic_action_e)GPOINTER_TO_INT(user_data));
373     return TRUE;
374 }
375