Fix Windows builds broken by previous commit
[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
87     /* try to open local .chm file */
88 #ifdef HHC_DIR
89     HWND hw;
90
91     url = g_string_new("");
92
93     g_string_append_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help",
94         get_datafile_dir(), topic);
95
96     hw = HtmlHelpW(NULL,
97         utf_8to16(url->str),
98         HH_DISPLAY_TOPIC, 0);
99
100     g_string_free(url, TRUE /* free_segment */);
101
102     /* if the .chm file could be opened, stop here */
103     if(hw != NULL) {
104         return;
105     }
106 #endif /* HHC_DIR */
107
108     url = g_string_new("");
109
110 #ifdef DOC_DIR
111     if (g_file_test(DOC_DIR "/wsug_html_chunked", G_FILE_TEST_IS_DIR)) {
112         /* try to open the HTML page from wireshark.org instead */
113         g_string_append_printf(url, "file://" DOC_DIR "/wsug_html_chunked/%s", topic);
114     } else {
115 #endif /* ifdef DOC_DIR */ 
116        /* try to open the HTML page from wireshark.org instead */
117         g_string_append_printf(url, "http://www.wireshark.org/docs/wsug_html_chunked/%s", topic);
118 #ifdef DOC_DIR
119     }
120 #endif /* ifdef DOC_DIR */ 
121
122     browser_open_url(url->str);
123
124     g_string_free(url, TRUE /* free_segment */);
125 }
126
127
128
129 /**
130  * Redraw all help pages, to use a new font.
131  */
132 void help_redraw(void)
133 {
134   GSList *help_page_ent;
135   help_page_t *help_page;
136
137   if (help_w != NULL) {
138     for (help_page_ent = help_text_pages; help_page_ent != NULL;
139         help_page_ent = g_slist_next(help_page_ent))
140     {
141       help_page = (help_page_t *)help_page_ent->data;
142       text_page_redraw(help_page->page, help_page->pathname);
143     }
144   }
145 }
146
147
148 const char *
149 topic_online_url(topic_action_e action)
150 {
151     switch(action) {
152     case(ONLINEPAGE_HOME):
153         return "http://www.wireshark.org";
154         break;
155     case(ONLINEPAGE_WIKI):
156         return "http://wiki.wireshark.org";
157         break;
158     case(ONLINEPAGE_DOWNLOAD):
159         return "http://www.wireshark.org/download.html";
160         break;
161     case(ONLINEPAGE_USERGUIDE):
162         return "http://www.wireshark.org/docs/wsug_html_chunked/";
163         break;
164     case(ONLINEPAGE_FAQ):
165         return "http://www.wireshark.org/faq.html";
166         break;
167     case(ONLINEPAGE_SAMPLE_FILES):
168         return "http://wiki.wireshark.org/SampleCaptures";
169         break;
170     case(ONLINEPAGE_CAPTURE_SETUP):
171         return "http://wiki.wireshark.org/CaptureSetup";
172         break;
173     case(ONLINEPAGE_NETWORK_MEDIA):
174         return "http://wiki.wireshark.org/CaptureSetup/NetworkMedia";
175         break;
176     case(ONLINEPAGE_SAMPLE_CAPTURES):
177         return "http://wiki.wireshark.org/SampleCaptures";
178         break;
179     case(ONLINEPAGE_SECURITY):
180         return "http://wiki.wireshark.org/Security";
181         break;
182     case(ONLINEPAGE_CHIMNEY):
183         return "http://wiki.wireshark.org/CaptureSetup/Offloading#chimney";
184         break;
185     default:
186         return NULL;
187     }
188 }
189
190
191 static void
192 topic_action(topic_action_e action)
193 {
194     const char *online_url;
195
196
197     /* pages online at www.wireshark.org */
198     online_url = topic_online_url(action);
199     if(online_url != NULL) {
200         browser_open_url (online_url);
201         return;
202     }
203
204     switch(action) {
205     /* local manual pages */
206     case(LOCALPAGE_MAN_WIRESHARK):
207         browser_open_data_file("wireshark.html");
208         break;
209     case(LOCALPAGE_MAN_WIRESHARK_FILTER):
210         browser_open_data_file("wireshark-filter.html");
211         break;
212     case(LOCALPAGE_MAN_TSHARK):
213         browser_open_data_file("tshark.html");
214         break;
215     case(LOCALPAGE_MAN_RAWSHARK):
216         browser_open_data_file("rawshark.html");
217         break;
218     case(LOCALPAGE_MAN_DUMPCAP):
219         browser_open_data_file("dumpcap.html");
220         break;
221     case(LOCALPAGE_MAN_MERGECAP):
222         browser_open_data_file("mergecap.html");
223         break;
224     case(LOCALPAGE_MAN_EDITCAP):
225         browser_open_data_file("editcap.html");
226         break;
227     case(LOCALPAGE_MAN_TEXT2PCAP):
228         browser_open_data_file("text2pcap.html");
229         break;
230
231     /* local help pages (User's Guide) */
232     case(HELP_CONTENT):
233         help_topic_html( "index.html");
234         break;
235     case(HELP_CAPTURE_OPTIONS_DIALOG):
236         help_topic_html("ChCapCaptureOptions.html");
237         break;
238     case(HELP_CAPTURE_FILTERS_DIALOG):
239         help_topic_html("ChWorkDefineFilterSection.html");
240         break;
241     case(HELP_DISPLAY_FILTERS_DIALOG):
242         help_topic_html("ChWorkDefineFilterSection.html");
243         break;
244     case(HELP_COLORING_RULES_DIALOG):
245         help_topic_html("ChCustColorizationSection.html");
246         break;
247     case(HELP_CONFIG_PROFILES_DIALOG):
248         help_topic_html("ChCustConfigProfilesSection.html");
249         break;
250     case (HELP_MANUAL_ADDR_RESOLVE_DIALOG):
251         help_topic_html("ChManualAddressResolveSection.html");
252         break;
253     case(HELP_PRINT_DIALOG):
254         help_topic_html("ChIOPrintSection.html");
255         break;
256     case(HELP_FIND_DIALOG):
257         help_topic_html("ChWorkFindPacketSection.html");
258         break;
259     case(HELP_FIREWALL_DIALOG):
260         help_topic_html("ChUseToolsMenuSection.html");
261         break;
262     case(HELP_GOTO_DIALOG):
263         help_topic_html("ChWorkGoToPacketSection.html");
264         break;
265     case(HELP_CAPTURE_INTERFACES_DIALOG):
266         help_topic_html("ChCapInterfaceSection.html");
267         break;
268     case(HELP_CAPTURE_INFO_DIALOG):
269         help_topic_html("ChCapRunningSection.html");
270         break;
271     case(HELP_ENABLED_PROTOCOLS_DIALOG):
272         help_topic_html("ChCustProtocolDissectionSection.html");
273         break;
274     case(HELP_DECODE_AS_DIALOG):
275         help_topic_html("ChCustProtocolDissectionSection.html");
276         break;
277     case(HELP_DECODE_AS_SHOW_DIALOG):
278         help_topic_html("ChCustProtocolDissectionSection.html");
279         break;
280     case(HELP_FOLLOW_STREAM_DIALOG):
281         help_topic_html("ChAdvFollowTCPSection.html");
282         break;
283     case(HELP_EXPERT_INFO_DIALOG):
284         help_topic_html("ChAdvExpert.html");
285         break;
286     case(HELP_STATS_SUMMARY_DIALOG):
287         help_topic_html("ChStatSummary.html");
288         break;
289     case(HELP_STATS_PROTO_HIERARCHY_DIALOG):
290         help_topic_html("ChStatHierarchy.html");
291         break;
292     case(HELP_STATS_ENDPOINTS_DIALOG):
293         help_topic_html("ChStatEndpoints.html");
294         break;
295     case(HELP_STATS_CONVERSATIONS_DIALOG):
296         help_topic_html("ChStatConversations.html");
297         break;
298     case(HELP_STATS_IO_GRAPH_DIALOG):
299         help_topic_html("ChStatIOGraphs.html");
300         break;
301     case(HELP_STATS_COMPARE_FILES_DIALOG):
302         help_topic_html("ChStatCompareCaptureFiles.html");
303         break;
304     case(HELP_STATS_LTE_MAC_TRAFFIC_DIALOG):
305         help_topic_html("ChTelLTEMACTraffic.html");
306         break;
307     case(HELP_STATS_LTE_RLC_TRAFFIC_DIALOG):
308         help_topic_html("ChTelLTERLCTraffic.html");
309         break;
310     case(HELP_STATS_WLAN_TRAFFIC_DIALOG):
311         help_topic_html("ChStatWLANTraffic.html");
312         break;
313     case(HELP_FILESET_DIALOG):
314         help_topic_html("ChIOFileSetSection.html");
315         break;
316     case(HELP_CAPTURE_INTERFACE_OPTIONS_DIALOG):
317         help_topic_html("ChCustInterfaceOptionsSection.html");
318         break;
319     case(HELP_CAPTURE_INTERFACES_DETAILS_DIALOG):
320         help_topic_html("ChCapInterfaceDetailsSection.html");
321         break;
322     case(HELP_PREFERENCES_DIALOG):
323         help_topic_html("ChCustPreferencesSection.html");
324         break;
325     case(HELP_EXPORT_FILE_DIALOG):
326     case(HELP_EXPORT_FILE_WIN32_DIALOG):
327         help_topic_html("ChIOExportSection.html");
328         break;
329     case(HELP_EXPORT_BYTES_DIALOG):
330     case(HELP_EXPORT_BYTES_WIN32_DIALOG):
331         help_topic_html("ChIOExportSection.html#ChIOExportSelectedDialog");
332         break;
333     case(HELP_EXPORT_OBJECT_LIST):
334         help_topic_html("ChIOExportSection.html#ChIOExportObjectsDialog");
335         break;
336     case(HELP_OPEN_DIALOG):
337     case(HELP_OPEN_WIN32_DIALOG):
338         help_topic_html("ChIOOpenSection.html");
339         break;
340     case(HELP_MERGE_DIALOG):
341     case(HELP_MERGE_WIN32_DIALOG):
342         help_topic_html("ChIOMergeSection.html");
343         break;
344     case(HELP_SAVE_DIALOG):
345     case(HELP_SAVE_WIN32_DIALOG):
346         help_topic_html("ChIOSaveSection.html");
347         break;
348
349     default:
350         g_assert_not_reached();
351     }
352 }
353
354
355 void
356 topic_cb(GtkWidget *w _U_, topic_action_e action)
357 {
358     topic_action(action);
359 }
360
361 gboolean
362 topic_menu_cb(GtkWidget *w _U_, gpointer data _U_, topic_action_e action)
363 {
364     topic_action(action);
365     return TRUE;
366 }
367