name change
[metze/wireshark/wip.git] / gtk / help_dlg.c
index 7d1bdc4aac13042d6990ef8786b04c52f27a9ba8..f64898cdf4c801d74f747a548fcef4984eb5e153 100644 (file)
@@ -4,8 +4,8 @@
  *
  * Laurent Deniel <laurent.deniel@free.fr>
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 2000 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
 #include "epan/filesystem.h"
 #include "help_dlg.h"
 #include "text_page.h"
-#include "prefs.h"
+#include <epan/prefs.h>
 #include "gtkglobals.h"
-#include "ui_util.h"
+#include "gui_utils.h"
 #include "compat_macros.h"
 #include "dlg_utils.h"
 #include "simple_dialog.h"
 #include "webbrowser.h"
+#include "file_util.h"
+
+#ifdef HHC_DIR
+#include <windows.h>
+#include <htmlhelp.h>
+#include "epan/strutil.h"
+#endif
+
 
 #define HELP_DIR       "help"
 
@@ -99,7 +107,8 @@ static GtkWidget * help_page(const char *topic, const char *filename)
 /*
  * Create and show help dialog.
  */
-void help_cb(GtkWidget *w _U_, gpointer data _U_)
+static
+void help_dialog(void)
 {
   GtkWidget *main_vb, *bbox, *help_nb, *close_bt, *label, *topic_vb;
   char line[4096+1];   /* XXX - size? */
@@ -115,7 +124,7 @@ void help_cb(GtkWidget *w _U_, gpointer data _U_)
   }
 
   help_toc_file_path = get_datafile_path(HELP_DIR G_DIR_SEPARATOR_S "toc");
-  help_toc_file = fopen(help_toc_file_path, "r");
+  help_toc_file = eth_fopen(help_toc_file_path, "r");
   if (help_toc_file == NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open file \"%s\": %s",
                   help_toc_file_path, strerror(errno));
@@ -180,23 +189,76 @@ void help_cb(GtkWidget *w _U_, gpointer data _U_)
 
   gtk_widget_show_all(help_w);
   window_present(help_w);
-} /* help_cb */
+} /* help_dialog */
+
 
+gboolean topic_available(topic_action_e action) {
+
+#ifdef ETHEREAL_EUG_DIR
+    if(action == HELP_CAPTURE_INTERFACES_DETAILS_DIALOG) {
+        /* page currently not existing in user's guide */
+        return FALSE;
+    }
+    /* online: we have almost all possible pages available */
+    return TRUE;
+#else
+    /* offline: we have only some pages available */
+    switch(action) {
+    case(HELP_CONTENT):
+        return TRUE;
+        break;
+    case(HELP_GETTING_STARTED):
+        return TRUE;
+        break;
+    case(HELP_CAPTURE_OPTIONS_DIALOG):
+        return TRUE;
+        break;
+    case(HELP_CAPTURE_FILTERS_DIALOG):
+        return TRUE;
+        break;
+    case(HELP_DISPLAY_FILTERS_DIALOG):
+        return TRUE;
+        break;
+    default:
+        return FALSE;
+    }
+#endif
+}
 
 /*
  * Open the help dialog and show a specific help page.
  */
+static void help_topic(const gchar *topic) {
+
+#ifdef HHC_DIR
+    HWND hw;
+    GString *url = g_string_new("");
+
+    g_string_append_printf(url, "%s\\user-guide.chm::/%s>Ethereal Help", 
+        get_datafile_dir(), topic);
+
+    hw = HtmlHelpW(NULL, 
+        utf_8to16(url->str), 
+        HH_DISPLAY_TOPIC, 0); 
 
-void help_topic_cb(GtkWidget *w _U_, gpointer data) {
-    gchar       *topic = data;
+    if(hw == NULL) {
+        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open help file: %s\\user-guide.chm",
+            get_datafile_dir());
+    }
+
+    g_string_free(url, TRUE /* free_segment */);
+
+    return;
+#else
     gchar       *page_topic;
     GtkWidget   *help_nb;
     GSList      *help_page_ent;
     gint        page_num = 0;
     help_page_t *page;
 
+
     /* show help dialog, if not already opened */
-    help_cb(NULL, NULL);
+    help_dialog();
 
     help_nb = OBJECT_GET_DATA(help_w, NOTEBOOK_KEY);
 
@@ -213,6 +275,7 @@ void help_topic_cb(GtkWidget *w _U_, gpointer data) {
         }
         page_num++;
     }
+#endif
 
     /* topic page not found, default (first page) will be shown */
 }
@@ -261,8 +324,16 @@ void help_redraw(void)
 }
 
 
-void
-url_page_action(url_page_action_e action)
+#ifdef HHC_DIR
+#define ONLINE_HELP_CALL help_topic
+#define ONLINE_HELP_PREFIX "eug_chm/"
+#else
+#define ONLINE_HELP_CALL browser_open_data_file
+#define ONLINE_HELP_PREFIX "eug_html_chunked/"
+#endif
+
+static void
+topic_action(topic_action_e action)
 {
     /* pages online at www.ethereal.com */
     switch(action) {
@@ -276,13 +347,13 @@ url_page_action(url_page_action_e action)
         browser_open_url ("http://www.ethereal.com/download.html");
         break;
     case(ONLINEPAGE_USERGUIDE):
-        browser_open_url ("http://www.ethereal.com/docs/user-guide");
+        browser_open_url ("http://www.ethereal.com/docs/eug_html_chunked");
         break;
     case(ONLINEPAGE_FAQ):
         browser_open_url ("http://www.ethereal.com/faq.html");
         break;
     case(ONLINEPAGE_SAMPLE_FILES):
-        browser_open_url ("http://www.ethereal.com/sample");
+        browser_open_url ("http://wiki.ethereal.com/SampleCaptures");
         break;
 
     /* local manual pages */
@@ -295,6 +366,9 @@ url_page_action(url_page_action_e action)
     case(LOCALPAGE_MAN_TETHEREAL):
         browser_open_data_file("tethereal.html");
         break;
+    case(LOCALPAGE_MAN_DUMPCAP):
+        browser_open_data_file("dumpcap.html");
+        break;
     case(LOCALPAGE_MAN_MERGECAP):
         browser_open_data_file("mergecap.html");
         break;
@@ -308,16 +382,84 @@ url_page_action(url_page_action_e action)
 #ifdef ETHEREAL_EUG_DIR
     /* local help pages (User's Guide) */
     case(HELP_CONTENT):
-        browser_open_data_file("eug_html_chunked/index.html");
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "index.html");
+        break;
+    case(HELP_CAPTURE_OPTIONS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChCapCaptureOptions.html");
+        break;
+    case(HELP_CAPTURE_FILTERS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChWorkDefineFilterSection.html");
+        break;
+    case(HELP_DISPLAY_FILTERS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX "ChWorkDefineFilterSection.html");
+        break;
+    case(HELP_COLORING_RULES_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChCustColorizationSection.html");
+        break;
+    case(HELP_PRINT_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChIOPrintSection.html");
+        break;
+    case(HELP_FIND_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChWorkFindPacketSection.html");
+        break;
+    case(HELP_GOTO_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChWorkGoToPacketSection.html");
+        break;
+    case(HELP_CAPTURE_INTERFACES_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChCapInterfaceSection.html");
+        break;
+    case(HELP_ENABLED_PROTOCOLS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChCustProtocolDissectionSection.html");
+        break;
+    case(HELP_DECODE_AS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChCustProtocolDissectionSection.html");
+        break;
+    case(HELP_DECODE_AS_SHOW_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChCustProtocolDissectionSection.html");
+        break;
+    case(HELP_FOLLOW_TCP_STREAM_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChAdvFollowTCPSection.html");
+        break;
+    case(HELP_STATS_SUMMARY_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChStatSummary.html");
+        break;
+    case(HELP_STATS_PROTO_HIERARCHY_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChStatHierarchy.html");
+        break;
+    case(HELP_STATS_ENDPOINTS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChStatEndpoints.html");
+        break;
+    case(HELP_STATS_CONVERSATIONS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChStatConversations.html");
+        break;
+    case(HELP_STATS_IO_GRAPH_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChStatIOGraphs.html");
+        break;
+    case(HELP_FILESET_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChIOFileSetSection.html");
+        break;
+    case(HELP_CAPTURE_INTERFACES_DETAILS_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChCapInterfaceDetailsSection.html");
+        break;
+    case(HELP_PREFERENCES_DIALOG):
+        ONLINE_HELP_CALL(ONLINE_HELP_PREFIX  "ChCustPreferencesSection.html");
+        break;
+#else
+    /* only some help pages are available for offline reading */
+    case(HELP_CONTENT):
+        help_topic("Overview");
+        break;
+    case(HELP_GETTING_STARTED):
+        help_topic("Getting Started");
         break;
     case(HELP_CAPTURE_OPTIONS_DIALOG):
-        browser_open_data_file("eug_html_chunked/ChCapCaptureOptions.html");
+        help_topic("Capturing");
         break;
     case(HELP_CAPTURE_FILTERS_DIALOG):
-        browser_open_data_file("eug_html_chunked/ChWorkDefineFilterSection.html");
+        help_topic("Capture Filters");
         break;
     case(HELP_DISPLAY_FILTERS_DIALOG):
-        browser_open_data_file("eug_html_chunked/ChWorkDefineFilterSection.html");
+        help_topic("Display Filters");
         break;
 #endif
 
@@ -327,16 +469,14 @@ url_page_action(url_page_action_e action)
 }
 
 
-void
-url_page_cb(GtkWidget *w _U_, url_page_action_e action)
+void 
+topic_cb(GtkWidget *w _U_, topic_action_e action)
 {
-    url_page_action(action);
+    topic_action(action);
 }
 
-
-void
-url_page_menu_cb( GtkWidget *w _U_, gpointer data _U_, url_page_action_e action)
-{
-    url_page_action(action);
+void 
+topic_menu_cb(GtkWidget *w _U_, gpointer data _U_, topic_action_e action) {
+    topic_action(action);
 }