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