update expert info LED also while doing live capturing
[obnox/wireshark/wip.git] / gtk / help_dlg.c
index eb53b0e5ce11626c7a386dfeadc1abb19aa5080e..8a7a302af59c7a08613ae1a85fc77100f817d97c 100644 (file)
@@ -1,11 +1,11 @@
 /* help_dlg.c
  *
- * $Id: help_dlg.c,v 1.29 2002/12/01 19:11:53 gerald Exp $
+ * $Id$
  *
- * Laurent Deniel <deniel@worldnet.fr>
+ * 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 <gtk/gtk.h>
 #include <string.h>
+#include <stdio.h>
+#include <errno.h>
 
-#ifdef NEED_SNPRINTF_H
-# include "snprintf.h"
-#endif
-
+#include "epan/filesystem.h"
 #include "help_dlg.h"
-#include "prefs.h"
-#include "globals.h"
+#include "text_page.h"
+#include <epan/prefs.h>
 #include "gtkglobals.h"
-#include "main.h"
-#include "ui_util.h"
-#include <epan/proto.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/unicode-utils.h"
+#endif
+
+
+#define HELP_DIR       "help"
 
-typedef enum {
-  OVERVIEW_HELP,
-  PROTOCOL_HELP,
-  DFILTER_HELP,
-  CFILTER_HELP
-} help_type_t;
 
-static void help_close_cb(GtkWidget *w, gpointer data);
-static void help_destroy_cb(GtkWidget *w, gpointer data);
-static void insert_text(GtkWidget *w, char *buffer, int nchars);
-static void set_help_text(GtkWidget *w, help_type_t type);
+#define NOTEBOOK_KEY    "notebook_key"
 
 /*
  * Keep a static pointer to the current "Help" window, if any, so that
  * if somebody tries to do "Help->Help" while there's already a
  * "Help" window up, we just pop up the existing one, rather than
  * creating a new one.
- */
+*/
 static GtkWidget *help_w = NULL;
 
 /*
- * Keep static pointers to the text widgets as well.
+ * Keep a list of text widgets and corresponding file names as well
+ * (for text format changes).
  */
-GtkWidget *overview_text, *proto_text, *dfilter_text, *cfilter_text;
+typedef struct {
+  char *topic;
+  char *pathname;
+  GtkWidget *page;
+} help_page_t;
 
-void help_cb(GtkWidget *w _U_, gpointer data _U_)
-{
+static GSList *help_text_pages = NULL;
 
-  GtkWidget *main_vb, *bbox, *help_nb, *close_bt, *label, *txt_scrollw,
-    *overview_vb,
-    *proto_vb,
-#if GTK_MAJOR_VERSION < 2
-    *dfilter_tb, *dfilter_vsb,
-#else
-    *dfilter_vb,
-#endif
-    *cfilter_vb;
 
-  if (help_w != NULL) {
-    /* There's already a "Help" dialog box; reactivate it. */
-    reactivate_window(help_w);
-    return;
-  }
 
-#if GTK_MAJOR_VERSION < 2
-  help_w = gtk_window_new(GTK_WINDOW_DIALOG);
+gboolean topic_available(topic_action_e action) {
+
+#if (GLIB_MAJOR_VERSION >= 2)
+    if(action == HELP_CAPTURE_INTERFACES_DETAILS_DIALOG) {
+        /* XXX - add the page HELP_CAPTURE_INTERFACES_DETAILS_DIALOG and remove this if */
+        /* page currently not existing in user's guide */
+        return FALSE;
+    }
+    /* online: we have almost all possible pages available */
+    return TRUE;
 #else
-  help_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    /* 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
-  gtk_widget_set_name(help_w, "Ethereal Help window" );
-  gtk_window_set_title(GTK_WINDOW(help_w), "Ethereal: Help");
-  SIGNAL_CONNECT(help_w, "destroy", help_destroy_cb, NULL);
-  SIGNAL_CONNECT(help_w, "realize", window_icon_realize_cb, NULL);
-  WIDGET_SET_SIZE(help_w, DEF_WIDTH * 2/3, DEF_HEIGHT * 2/3);
-  gtk_container_border_width(GTK_CONTAINER(help_w), 2);
+}
 
-  /* Container for each row of widgets */
 
-  main_vb = gtk_vbox_new(FALSE, 1);
-  gtk_container_border_width(GTK_CONTAINER(main_vb), 1);
-  gtk_container_add(GTK_CONTAINER(help_w), main_vb);
-  gtk_widget_show(main_vb);
+#if (GLIB_MAJOR_VERSION >= 2)
+/*
+ * Open the help dialog and show a specific HTML help page.
+ */
+void help_topic_html(const gchar *topic) {
+    GString *url;
 
-  /* help topics container */
 
-  help_nb = gtk_notebook_new();
-  gtk_container_add(GTK_CONTAINER(main_vb), help_nb);
+    /* try to open local .chm file */
+#ifdef HHC_DIR
+    HWND hw;
 
-  /* Overview panel */
-
-  overview_vb = gtk_vbox_new(FALSE, 0);
-  gtk_container_border_width(GTK_CONTAINER(overview_vb), 1);
-  txt_scrollw = scrolled_window_new(NULL, NULL);
-  gtk_box_pack_start(GTK_BOX(overview_vb), txt_scrollw, TRUE, TRUE, 0);
-#if GTK_MAJOR_VERSION < 2
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_NEVER,
-                                GTK_POLICY_ALWAYS);
-  overview_text = gtk_text_new(NULL, NULL );
-  gtk_text_set_editable(GTK_TEXT(overview_text), FALSE);
-  gtk_text_set_word_wrap(GTK_TEXT(overview_text), TRUE);
-  gtk_text_set_line_wrap(GTK_TEXT(overview_text), TRUE);
-#else
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_AUTOMATIC,
-                                GTK_POLICY_AUTOMATIC);
-  overview_text = gtk_text_view_new();
-  gtk_text_view_set_editable(GTK_TEXT_VIEW(overview_text), FALSE);
-  gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(overview_text), GTK_WRAP_WORD);
-#endif
-  set_help_text(overview_text, OVERVIEW_HELP);
-  gtk_container_add(GTK_CONTAINER(txt_scrollw), overview_text);
-  gtk_widget_show(txt_scrollw);
-  gtk_widget_show(overview_text);
-  gtk_widget_show(overview_vb);
-  label = gtk_label_new("Overview");
-  gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), overview_vb, label);
-
-  /* humm, gtk 1.2 does not support horizontal scrollbar for text widgets */
-
-  /* protocol list */
-
-  proto_vb = gtk_vbox_new(FALSE, 0);
-  gtk_container_border_width(GTK_CONTAINER(proto_vb), 1);
-
-  txt_scrollw = scrolled_window_new(NULL, NULL);
-  gtk_box_pack_start(GTK_BOX(proto_vb), txt_scrollw, TRUE, TRUE, 0);
-#if GTK_MAJOR_VERSION < 2
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_ALWAYS,
-                                GTK_POLICY_ALWAYS);
-  proto_text = gtk_text_new(NULL, NULL);
-  gtk_text_set_editable(GTK_TEXT(proto_text), FALSE);
-  gtk_text_set_line_wrap(GTK_TEXT(proto_text), FALSE);
-  set_help_text(proto_text, PROTOCOL_HELP);
-  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                       proto_text);
-#else
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_AUTOMATIC,
-                                GTK_POLICY_AUTOMATIC);
-  proto_text = gtk_text_view_new();
-  gtk_text_view_set_editable(GTK_TEXT_VIEW(proto_text), FALSE);
-  set_help_text(proto_text, PROTOCOL_HELP);
-  gtk_container_add(GTK_CONTAINER(txt_scrollw), proto_text);
-#endif
-  gtk_widget_show(txt_scrollw);
-  gtk_widget_show(proto_text);
-  gtk_widget_show(proto_vb);
-  label = gtk_label_new("Protocols");
-  gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), proto_vb, label);
-
-  /* display filter help */
-#if GTK_MAJOR_VERSION < 2
-  /* X windows have a maximum size of 32767.  Since the height can easily
-     exceed this, we have to jump through some hoops to have a functional
-     vertical scroll bar. */
-
-  dfilter_tb = gtk_table_new(2, 2, FALSE);
-  gtk_table_set_col_spacing (GTK_TABLE (dfilter_tb), 0, 3);
-  gtk_table_set_row_spacing (GTK_TABLE (dfilter_tb), 0, 3);
-  gtk_container_border_width(GTK_CONTAINER(dfilter_tb), 1);
-
-  txt_scrollw = scrolled_window_new(NULL, NULL);
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_ALWAYS,
-                                GTK_POLICY_NEVER);
-  dfilter_text = gtk_text_new(NULL, NULL);
-  dfilter_vsb = gtk_vscrollbar_new(GTK_TEXT(dfilter_text)->vadj);
-  if (prefs.gui_scrollbar_on_right) {
-    gtk_table_attach (GTK_TABLE (dfilter_tb), txt_scrollw, 0, 1, 0, 1,
-                            GTK_EXPAND | GTK_SHRINK | GTK_FILL,
-                            GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
-    gtk_table_attach (GTK_TABLE (dfilter_tb), dfilter_vsb, 1, 2, 0, 1,
-                            GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
-  } else {
-    gtk_table_attach (GTK_TABLE (dfilter_tb), txt_scrollw, 1, 2, 0, 1,
-                            GTK_EXPAND | GTK_SHRINK | GTK_FILL,
-                            GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
-    gtk_table_attach (GTK_TABLE (dfilter_tb), dfilter_vsb, 0, 1, 0, 1,
-                            GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
-  }
-  gtk_text_set_editable(GTK_TEXT(dfilter_text), FALSE);
-  gtk_text_set_line_wrap(GTK_TEXT(dfilter_text), FALSE);
-  set_help_text(dfilter_text, DFILTER_HELP);
-  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                       dfilter_text);
-#else
-  dfilter_vb = gtk_vbox_new(FALSE, 0);
-  gtk_container_border_width(GTK_CONTAINER(dfilter_vb), 1);
-
-  txt_scrollw = scrolled_window_new(NULL, NULL);
-  gtk_box_pack_start(GTK_BOX(dfilter_vb), txt_scrollw, TRUE, TRUE, 0);
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_AUTOMATIC,
-                                GTK_POLICY_AUTOMATIC);
-  dfilter_text = gtk_text_view_new();
-  if (prefs.gui_scrollbar_on_right) {
-    gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                      GTK_CORNER_TOP_LEFT);
-  }
-  else {
-    gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                      GTK_CORNER_TOP_RIGHT);
-  }
-  gtk_text_view_set_editable(GTK_TEXT_VIEW(dfilter_text), FALSE);
-  set_help_text(dfilter_text, DFILTER_HELP);
-  gtk_container_add(GTK_CONTAINER(txt_scrollw), dfilter_text);
-#endif
-  gtk_widget_show(txt_scrollw);
-  gtk_widget_show(dfilter_text);
-#if GTK_MAJOR_VERSION < 2
-  gtk_widget_show(dfilter_tb);
-  gtk_widget_show(dfilter_vsb);
-#else
-  gtk_widget_show(dfilter_vb);
-#endif
-  label = gtk_label_new("Display Filters");
-#if GTK_MAJOR_VERSION < 2
-  gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), dfilter_tb, label);
-#else
-  gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), dfilter_vb, label);
-#endif
+    url = g_string_new("");
 
-  /* capture filter help (this one has no horizontal scrollbar) */
-
-  cfilter_vb = gtk_vbox_new(FALSE, 0);
-  gtk_container_border_width(GTK_CONTAINER(cfilter_vb), 1);
-  txt_scrollw = scrolled_window_new(NULL, NULL);
-  gtk_box_pack_start(GTK_BOX(cfilter_vb), txt_scrollw, TRUE, TRUE, 0);
-#if GTK_MAJOR_VERSION < 2
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_NEVER,
-                                GTK_POLICY_ALWAYS);
-  cfilter_text = gtk_text_new(NULL, NULL );
-  gtk_text_set_editable(GTK_TEXT(cfilter_text), FALSE);
-  gtk_text_set_word_wrap(GTK_TEXT(cfilter_text), TRUE);
-  gtk_text_set_line_wrap(GTK_TEXT(cfilter_text), TRUE);
-#else
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
-                                GTK_POLICY_NEVER,
-                                GTK_POLICY_AUTOMATIC);
-  cfilter_text = gtk_text_view_new();
-  gtk_text_view_set_editable(GTK_TEXT_VIEW(cfilter_text), FALSE);
-  gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(cfilter_text), GTK_WRAP_WORD);
-#endif
-  set_help_text(cfilter_text, CFILTER_HELP);
-  gtk_container_add(GTK_CONTAINER(txt_scrollw), cfilter_text);
-  gtk_widget_show(txt_scrollw);
-  gtk_widget_show(cfilter_text);
-  gtk_widget_show(cfilter_vb);
-  label = gtk_label_new("Capture Filters");
-  gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), cfilter_vb, label);
+    g_string_append_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help",
+        get_datafile_dir(), topic);
 
-  /* XXX add other help panels here ... */
+    hw = HtmlHelpW(NULL,
+        utf_8to16(url->str),
+        HH_DISPLAY_TOPIC, 0);
 
-  gtk_widget_show(help_nb);
+    g_string_free(url, TRUE /* free_segment */);
 
-  /* Buttons (only one for now) */
+    /* if the .chm file could be opened, stop here */
+    if(hw != NULL) {
+        return;
+    }
+#endif /* HHC_DIR */
 
-  bbox = gtk_hbox_new(FALSE, 1);
-  gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
-  gtk_widget_show(bbox);
-#if GTK_MAJOR_VERSION < 2
-  close_bt = gtk_button_new_with_label("Close");
-#else
-  close_bt = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
-#endif
-  SIGNAL_CONNECT(close_bt, "clicked", help_close_cb, help_w);
-  GTK_WIDGET_SET_FLAGS(close_bt, GTK_CAN_DEFAULT);
-  gtk_container_add(GTK_CONTAINER(bbox), close_bt);
-  gtk_widget_grab_default(close_bt);
-  gtk_widget_show(close_bt);
+    url = g_string_new("");
 
-  gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(help_w));
-  gtk_widget_show(help_w);
+    /* try to open the HTML page from wireshark.org instead */
+    g_string_append_printf(url, "http://www.wireshark.org/docs/wsug_html_chunked/%s", topic);
 
-} /* help_cb */
+    browser_open_url(url->str);
 
-static void help_close_cb(GtkWidget *w _U_, gpointer data)
+    g_string_free(url, TRUE /* free_segment */);
+}
+#endif
+
+
+#if (GLIB_MAJOR_VERSION < 2)
+/*
+ * Helper function to show a simple help text page.
+ */
+static GtkWidget * help_page(const char *topic, const char *filename)
 {
-  gtk_widget_destroy(GTK_WIDGET(data));
+  GtkWidget *text_page;
+  char *relative_path, *absolute_path;
+  help_page_t *page;
+
+  relative_path = g_strconcat(HELP_DIR, G_DIR_SEPARATOR_S, filename, NULL);
+  absolute_path = get_datafile_path(relative_path);
+  text_page = text_page_new(absolute_path);
+  g_free(relative_path);
+  gtk_widget_show(text_page);
+
+  page = g_malloc(sizeof (help_page_t));
+  page->topic = g_strdup(topic);
+  page->pathname = absolute_path;
+  page->page = text_page;
+  help_text_pages = g_slist_append(help_text_pages, page);
+
+  return text_page;
 }
 
+
+/*
+ * Help dialog is closed now.
+ */
 static void help_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
 {
+  GSList *help_page_ent;
+  help_page_t *page;
+
+  /* Free up the list of help pages. */
+  for (help_page_ent = help_text_pages; help_page_ent != NULL;
+       help_page_ent = g_slist_next(help_page_ent)) {
+    page = (help_page_t *)help_page_ent->data;
+    g_free(page->topic);
+    g_free(page->pathname);
+    g_free(page);
+  }
+  g_slist_free(help_text_pages);
+  help_text_pages = NULL;
+
   /* Note that we no longer have a Help window. */
   help_w = NULL;
 }
 
-static void insert_text(GtkWidget *w, char *buffer, int nchars)
-{
-#if GTK_MAJOR_VERSION < 2
-    gtk_text_insert(GTK_TEXT(w), m_r_font, NULL, NULL, buffer, nchars);
-#else
-    GtkTextBuffer *buf= gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
-    GtkTextIter    iter;
-
-    gtk_text_buffer_get_end_iter(buf, &iter);
-    gtk_widget_modify_font(w, m_r_font);
-    if (!g_utf8_validate(buffer, -1, NULL))
-        printf(buffer);
-    gtk_text_buffer_insert(buf, &iter, buffer, nchars);
-#endif
-}
 
-static char *proto_help =
-"The following protocols (and packet types) are currently\n"
-"supported by Ethereal:\n\n";
+/*
+ * Create and show help dialog.
+ */
+static
+void help_dialog(void)
+{
+  GtkWidget *main_vb, *bbox, *help_nb, *close_bt, *label, *topic_vb;
+  char line[4096+1];   /* XXX - size? */
+  char *p;
+  char *filename;
+  char *help_toc_file_path;
+  FILE *help_toc_file;
 
-static char *dfilter_help =
-"The following per-protocol fields can be used in display\n"
-"filters:\n";
+  if (help_w != NULL) {
+    /* There's already a "Help" dialog box; reactivate it. */
+    reactivate_window(help_w);
+    return;
+  }
 
-static char *cfilter_help =
-"Packet capturing is performed with the pcap library. The capture filter "
-"syntax follows the rules of this library.\nSo this syntax is different "
-"from the display filter syntax: see manual page of tcpdump.\n"
-#ifndef HAVE_LIBPCAP
-"\nNote: packet capturing is not enabled in this version.\n";
-#else
-;
-#endif
+  help_toc_file_path = get_datafile_path(HELP_DIR G_DIR_SEPARATOR_S "toc");
+  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));
+    g_free(help_toc_file_path);
+    return;
+  }
 
-static char *overview_help =
-"Ethereal is a GUI network protocol analyzer. It lets you interactively "
-"browse packet data from a live network or from a previously saved capture "
-"file.\n\nEthereal knows how to read libpcap capture files, including those "
-"of tcpdump. In addition, Ethereal can read capture files from snoop "
-"(including Shomiti) and atmsnoop, LanAlyzer, Sniffer (compressed or "
-"uncompressed), Microsoft Network Monitor, AIX's iptrace, NetXray, "
-"Sniffer Pro, RADCOM's WAN/LAN analyzer, Lucent/Ascend router debug output, "
-"HP-UX's nettl, the dump output from Toshiba's ISDN routers, the output from "
-"i4btrace from the ISDN4BSD project, and output in IPLog format from the "
-"Cisco Secure Intrusion Detection System.\n\n"
-"There is no need to tell Ethereal what type of file you are reading; it will "
-"determine the file type by itself. Ethereal is also capable of reading any "
-"of these file formats if they are compressed using gzip. Ethereal recognizes "
-"this directly from the file; the '.gz' extension is not required for this "
-"purpose.";
-
-static void set_help_text(GtkWidget *w, help_type_t type)
-{
+  help_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, "Wireshark: Help", "help");
+  gtk_window_set_default_size(GTK_WINDOW(help_w), DEF_WIDTH, DEF_HEIGHT);
+  gtk_container_border_width(GTK_CONTAINER(help_w), 2);
 
-#define BUFF_LEN 4096
-#define B_LEN    256
-  char buffer[BUFF_LEN];
-  header_field_info *hfinfo;
-  int i, len, maxlen = 0, maxlen2 = 0;
-#if GTK_MAJOR_VERSION < 2
-  int maxlen3 = 0, nb_lines = 0;
-  int width, height;
-#endif
-  const char *type_name;
-  char blanks[B_LEN];
-  int blks;
-  void *cookie;
-
-  /*
-   * XXX quick hack:
-   * the width and height computations are performed to make the
-   * horizontal scrollbar work in gtk1.2. This is only necessary for the
-   * PROTOCOL_HELP and DFILTER_HELP windows since all others should
-   * not have any horizontal scrollbar (line wrapping enabled).
-   */
-
-  memset(blanks, ' ', B_LEN - 1);
-  blanks[B_LEN-1] = '\0';
-
-#if GTK_MAJOR_VERSION < 2
-  gtk_text_freeze(GTK_TEXT(w));
-#endif
+  /* Container for each row of widgets */
+  main_vb = gtk_vbox_new(FALSE, 1);
+  gtk_container_border_width(GTK_CONTAINER(main_vb), 1);
+  gtk_container_add(GTK_CONTAINER(help_w), main_vb);
 
-  switch(type) {
+  /* help topics container */
+  help_nb = gtk_notebook_new();
+  gtk_container_add(GTK_CONTAINER(main_vb), help_nb);
+  OBJECT_SET_DATA(help_w, NOTEBOOK_KEY, help_nb);
+
+  /* help topics */
+  while (fgets(line, sizeof line, help_toc_file) != NULL) {
+    /* Strip off line ending. */
+    p = strpbrk(line, "\r\n");
+    if (p == NULL)
+      break;           /* last line has no line ending */
+    *p = '\0';
+    /* {Topic title}:{filename of help file} */
+    p = strchr(line, ':');
+    if (p != NULL) {
+      *p++ = '\0';
+      filename = p;
+
+      /*
+       * "line" refers to the topic now, and "filename" refers to the
+       * file name.
+       */
+      topic_vb = help_page(line, filename);
+      label = gtk_label_new(line);
+      gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), topic_vb, label);
+    }
+  }
+  if(ferror(help_toc_file)) {
+    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Error reading file \"%s\": %s",
+                  help_toc_file_path, strerror(errno));
+  }
+  fclose(help_toc_file);
 
-  case OVERVIEW_HELP :
-    insert_text(w, overview_help, -1);
-    break;
 
-  case PROTOCOL_HELP :
-    /* first pass to know the maximum length of first field */
-    for (i = proto_get_first_protocol(&cookie); i != -1;
-         i = proto_get_next_protocol(&cookie)) {
-      hfinfo = proto_registrar_get_nth(i);
-      if ((len = strlen(hfinfo->abbrev)) > maxlen)
-       maxlen = len;
-    }
-    maxlen++;
+  /* Button row */
+  bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
+  gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
 
-#if GTK_MAJOR_VERSION < 2
-    maxlen2 = strlen(proto_help);
-    width = gdk_string_width(m_r_font, proto_help);
-    insert_text(w, proto_help, maxlen2);
-#else
-    insert_text(w, proto_help, strlen(proto_help));
-#endif
+  close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
+  window_set_cancel_button(help_w, close_bt, window_cancel_button_cb);
 
-    /* ok, display the correctly aligned strings */
-    for (i = proto_get_first_protocol(&cookie); i != -1;
-         i = proto_get_next_protocol(&cookie)) {
-      hfinfo = proto_registrar_get_nth(i);
-      blks = maxlen - strlen(hfinfo->abbrev);
-      snprintf(buffer, BUFF_LEN, "%s%s%s\n",
-              hfinfo->abbrev,
-              &blanks[B_LEN - blks - 2],
-              hfinfo->name);
-#if GTK_MAJOR_VERSION < 2
-      if ((len = strlen(buffer)) > maxlen2) {
-       maxlen2 = len;
-       if ((len = gdk_string_width(m_r_font, buffer)) > width)
-         width = len;
-      }
-      insert_text(w, buffer, strlen(buffer));
-      nb_lines++;
-#else
-      insert_text(w, buffer, strlen(buffer));
-#endif
-    }
+  SIGNAL_CONNECT(help_w, "delete_event", window_delete_event_cb, NULL);
+  SIGNAL_CONNECT(help_w, "destroy", help_destroy_cb, NULL);
 
-#if GTK_MAJOR_VERSION < 2
-    height = (2 + nb_lines) * m_font_height;
-    WIDGET_SET_SIZE(w, 20 + width, 20 + height);
-#endif
-    break;
+  gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(help_w));
 
-  case DFILTER_HELP  :
+  gtk_widget_show_all(help_w);
+  window_present(help_w);
+} /* help_dialog */
 
-    /* XXX we should display hinfo->blurb instead of name (if not empty) */
 
-    /* first pass to know the maximum length of first and second fields */
-    for (i = 0; i < proto_registrar_n() ; i++) {
-      if (!proto_registrar_is_protocol(i)) {
-       hfinfo = proto_registrar_get_nth(i);
-       if ((len = strlen(hfinfo->abbrev)) > maxlen)
-         maxlen = len;
-       if ((len = strlen(hfinfo->name)) > maxlen2)
-         maxlen2 = len;
-      }
+/*
+ * Open the help dialog and show a specific GTK help page.
+ */
+static void help_topic_gtk(const gchar *topic) {
+    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_dialog();
+
+    help_nb = OBJECT_GET_DATA(help_w, NOTEBOOK_KEY);
+
+    /* find page to display */
+    for (help_page_ent = help_text_pages; help_page_ent != NULL;
+         help_page_ent = g_slist_next(help_page_ent))
+    {
+        page = (help_page_t *)help_page_ent->data;
+        page_topic = page->topic;
+        if (strcmp (page_topic, topic) == 0) {
+            /* topic page found, switch to notebook page */
+            gtk_notebook_set_page(GTK_NOTEBOOK(help_nb), page_num);
+            return;
+        }
+        page_num++;
     }
-    maxlen++;
-    maxlen2++;
 
-#if GTK_MAJOR_VERSION < 2
-    maxlen3 = strlen(dfilter_help);
-    width = gdk_string_width(m_r_font, dfilter_help);
-    insert_text(w, dfilter_help, maxlen3);
-#else
-    insert_text(w, dfilter_help, strlen(dfilter_help));
-#endif
+    /* topic page not found, default (first page) will be shown */
+}
+#endif /* GLIB_MAJOR_VERSION < 2 */
 
-    for (i = 0; i < proto_registrar_n() ; i++) {
-      hfinfo = proto_registrar_get_nth(i);
-      if (proto_registrar_is_protocol(i)) {
-       snprintf(buffer, BUFF_LEN, "\n%s:\n", hfinfo->name);
-       insert_text(w, buffer, strlen(buffer));
-#if GTK_MAJOR_VERSION < 2
-       nb_lines += 2;
-#endif
-      } else {
-
-       type_name = ftype_pretty_name(hfinfo->type);
-       snprintf(buffer, BUFF_LEN, "%s%s%s%s(%s)\n",
-                hfinfo->abbrev,
-                &blanks[B_LEN - (maxlen - strlen(hfinfo->abbrev)) - 2],
-                hfinfo->name,
-                &blanks[B_LEN - (maxlen2 - strlen(hfinfo->name)) - 2],
-                type_name);
-#if GTK_MAJOR_VERSION < 2
-       if ((len = strlen(buffer)) > maxlen3) {
-         maxlen3 = len;
-         if ((len = gdk_string_width(m_r_font, buffer)) > width)
-           width = len;
-       }
-       insert_text(w, buffer, strlen(buffer));
-       nb_lines ++;
-#else
-        insert_text(w, buffer, strlen(buffer));
-#endif
-      }
-    }
-#if GTK_MAJOR_VERSION < 2
-    height = (1 + nb_lines) * m_font_height;
-    WIDGET_SET_SIZE(w, 20 + width, 20 + height);
-#endif
-    break;
-  case CFILTER_HELP :
-    insert_text(w, cfilter_help, -1);
-    break;
-  default :
-    g_assert_not_reached();
-    break;
-  } /* switch(type) */
-#if GTK_MAJOR_VERSION < 2
-  gtk_text_thaw(GTK_TEXT(w));
-#endif
-} /* set_help_text */
 
-static void clear_help_text(GtkWidget *w)
+/**
+ * Redraw all help pages, to use a new font.
+ */
+void help_redraw(void)
 {
-#if GTK_MAJOR_VERSION < 2
-  GtkText *txt = GTK_TEXT(w);
-
-  gtk_text_set_point(txt, 0);
-  /* Keep GTK+ 1.2.3 through 1.2.6 from dumping core - see
-     http://www.ethereal.com/lists/ethereal-dev/199912/msg00312.html and
-     http://www.gnome.org/mailing-lists/archives/gtk-devel-list/1999-October/0051.shtml
-     for more information */
-  gtk_adjustment_set_value(txt->vadj, 0.0);
-  gtk_text_forward_delete(txt, gtk_text_get_length(txt));
-#else
-  GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w));
+  GSList *help_page_ent;
+  help_page_t *help_page;
 
-  gtk_text_buffer_set_text(buf, "", 0);
-#endif
+  if (help_w != NULL) {
+    for (help_page_ent = help_text_pages; help_page_ent != NULL;
+        help_page_ent = g_slist_next(help_page_ent))
+    {
+      help_page = (help_page_t *)help_page_ent->data;
+      text_page_redraw(help_page->page, help_page->pathname);
+    }
+  }
 }
 
-/* Redraw all the text widgets, to use a new font. */
-void help_redraw(void)
+
+static void
+topic_action(topic_action_e action)
 {
-  if (help_w != NULL) {
-#if GTK_MAJOR_VERSION < 2
-    gtk_text_freeze(GTK_TEXT(overview_text));
-#endif
-    clear_help_text(overview_text);
-    set_help_text(overview_text, OVERVIEW_HELP);
-#if GTK_MAJOR_VERSION < 2
-    gtk_text_thaw(GTK_TEXT(overview_text));
+    /* pages online at www.wireshark.org */
+    switch(action) {
+    case(ONLINEPAGE_HOME):
+        browser_open_url ("http://www.wireshark.org");
+        break;
+    case(ONLINEPAGE_WIKI):
+        browser_open_url ("http://wiki.wireshark.org");
+        break;
+    case(ONLINEPAGE_DOWNLOAD):
+        browser_open_url ("http://www.wireshark.org/download/");
+        break;
+    case(ONLINEPAGE_USERGUIDE):
+        browser_open_url ("http://www.wireshark.org/docs/wsug_html_chunked/");
+        break;
+    case(ONLINEPAGE_FAQ):
+        browser_open_url ("http://www.wireshark.org/faq.html");
+        break;
+    case(ONLINEPAGE_SAMPLE_FILES):
+        browser_open_url ("http://wiki.wireshark.org/SampleCaptures");
+        break;
+
+    /* local manual pages */
+    case(LOCALPAGE_MAN_WIRESHARK):
+        browser_open_data_file("wireshark.html");
+        break;
+    case(LOCALPAGE_MAN_WIRESHARK_FILTER):
+        browser_open_data_file("wireshark-filter.html");
+        break;
+    case(LOCALPAGE_MAN_TSHARK):
+        browser_open_data_file("tshark.html");
+        break;
+    case(LOCALPAGE_MAN_RAWSHARK):
+        browser_open_data_file("rawshark.html");
+        break;
+    case(LOCALPAGE_MAN_DUMPCAP):
+        browser_open_data_file("dumpcap.html");
+        break;
+    case(LOCALPAGE_MAN_MERGECAP):
+        browser_open_data_file("mergecap.html");
+        break;
+    case(LOCALPAGE_MAN_EDITCAP):
+        browser_open_data_file("editcap.html");
+        break;
+    case(LOCALPAGE_MAN_TEXT2PCAP):
+        browser_open_data_file("text2pcap.html");
+        break;
+
+#if (GLIB_MAJOR_VERSION >= 2)
+    /* local help pages (User's Guide) */
+    case(HELP_CONTENT):
+        help_topic_html( "index.html");
+        break;
+    case(HELP_CAPTURE_OPTIONS_DIALOG):
+        help_topic_html("ChCapCaptureOptions.html");
+        break;
+    case(HELP_CAPTURE_FILTERS_DIALOG):
+        help_topic_html("ChWorkDefineFilterSection.html");
+        break;
+    case(HELP_DISPLAY_FILTERS_DIALOG):
+        help_topic_html("ChWorkDefineFilterSection.html");
+        break;
+    case(HELP_COLORING_RULES_DIALOG):
+        help_topic_html("ChCustColorizationSection.html");
+        break;
+    case(HELP_CONFIG_PROFILES_DIALOG):
+        help_topic_html("ChCustConfigProfilesSection.html");
+        break;
+    case(HELP_PRINT_DIALOG):
+        help_topic_html("ChIOPrintSection.html");
+        break;
+    case(HELP_FIND_DIALOG):
+        help_topic_html("ChWorkFindPacketSection.html");
+        break;
+    case(HELP_GOTO_DIALOG):
+        help_topic_html("ChWorkGoToPacketSection.html");
+        break;
+    case(HELP_CAPTURE_INTERFACES_DIALOG):
+        help_topic_html("ChCapInterfaceSection.html");
+        break;
+    case(HELP_CAPTURE_INFO_DIALOG):
+        help_topic_html("ChCapRunningSection.html");
+        break;
+    case(HELP_ENABLED_PROTOCOLS_DIALOG):
+        help_topic_html("ChCustProtocolDissectionSection.html");
+        break;
+    case(HELP_DECODE_AS_DIALOG):
+        help_topic_html("ChCustProtocolDissectionSection.html");
+        break;
+    case(HELP_DECODE_AS_SHOW_DIALOG):
+        help_topic_html("ChCustProtocolDissectionSection.html");
+        break;
+    case(HELP_FOLLOW_TCP_STREAM_DIALOG):
+        help_topic_html("ChAdvFollowTCPSection.html");
+        break;
+    case(HELP_EXPERT_INFO_DIALOG):
+        help_topic_html("ChAdvExpert.html");
+        break;
+    case(HELP_STATS_SUMMARY_DIALOG):
+        help_topic_html("ChStatSummary.html");
+        break;
+    case(HELP_STATS_PROTO_HIERARCHY_DIALOG):
+        help_topic_html("ChStatHierarchy.html");
+        break;
+    case(HELP_STATS_ENDPOINTS_DIALOG):
+        help_topic_html("ChStatEndpoints.html");
+        break;
+    case(HELP_STATS_CONVERSATIONS_DIALOG):
+        help_topic_html("ChStatConversations.html");
+        break;
+    case(HELP_STATS_IO_GRAPH_DIALOG):
+        help_topic_html("ChStatIOGraphs.html");
+        break;
+    case(HELP_STATS_WLAN_TRAFFIC_DIALOG):
+        help_topic_html("ChStatWLANTraffic.html");
+        break;
+    case(HELP_FILESET_DIALOG):
+        help_topic_html("ChIOFileSetSection.html");
+        break;
+    case(HELP_CAPTURE_INTERFACES_DETAILS_DIALOG):
+        help_topic_html("ChCapInterfaceDetailsSection.html");
+        break;
+    case(HELP_PREFERENCES_DIALOG):
+        help_topic_html("ChCustPreferencesSection.html");
+        break;
+    case(HELP_EXPORT_FILE_DIALOG):
+    case(HELP_EXPORT_FILE_WIN32_DIALOG):
+        help_topic_html("ChIOExportSection.html");
+        break;
+    case(HELP_EXPORT_BYTES_DIALOG):
+    case(HELP_EXPORT_BYTES_WIN32_DIALOG):
+        help_topic_html("ChIOExportSection.html#ChIOExportSelectedDialog");
+        break;
+    case(HELP_EXPORT_OBJECT_LIST):
+       help_topic_html("ChIOExportSection.html#ChIOExportObjectsDialog");
+       break;
+    case(HELP_OPEN_DIALOG):
+    case(HELP_OPEN_WIN32_DIALOG):
+        help_topic_html("ChIOOpenSection.html");
+        break;
+    case(HELP_MERGE_DIALOG):
+    case(HELP_MERGE_WIN32_DIALOG):
+        help_topic_html("ChIOMergeSection.html");
+        break;
+    case(HELP_SAVE_DIALOG):
+    case(HELP_SAVE_WIN32_DIALOG):
+        help_topic_html("ChIOSaveSection.html");
+        break;
+#else
+    /* only some help pages are available for offline reading */
+    case(HELP_CONTENT):
+        help_topic_gtk("Overview");
+        break;
+    case(HELP_GETTING_STARTED):
+        help_topic_gtk("Getting Started");
+        break;
+    case(HELP_CAPTURE_OPTIONS_DIALOG):
+        help_topic_gtk("Capturing");
+        break;
+    case(HELP_CAPTURE_FILTERS_DIALOG):
+        help_topic_gtk("Capture Filters");
+        break;
+    case(HELP_DISPLAY_FILTERS_DIALOG):
+        help_topic_gtk("Display Filters");
+        break;
+#endif /* GLIB_MAJOR_VERSION */
+
+    default:
+        g_assert_not_reached();
+    }
+}
 
-    gtk_text_freeze(GTK_TEXT(proto_text));
-#endif
-    clear_help_text(proto_text);
-    set_help_text(proto_text, PROTOCOL_HELP);
-#if GTK_MAJOR_VERSION < 2
-    gtk_text_thaw(GTK_TEXT(proto_text));
 
-    gtk_text_freeze(GTK_TEXT(dfilter_text));
-#endif
-    clear_help_text(dfilter_text);
-    set_help_text(dfilter_text, DFILTER_HELP);
-#if GTK_MAJOR_VERSION < 2
-    gtk_text_thaw(GTK_TEXT(dfilter_text));
+void
+topic_cb(GtkWidget *w _U_, topic_action_e action)
+{
+    topic_action(action);
+}
 
-    gtk_text_freeze(GTK_TEXT(cfilter_text));
-#endif
-    clear_help_text(cfilter_text);
-    set_help_text(cfilter_text, CFILTER_HELP);
-#if GTK_MAJOR_VERSION < 2
-    gtk_text_thaw(GTK_TEXT(cfilter_text));
-#endif
-  }
+void
+topic_menu_cb(GtkWidget *w _U_, gpointer data _U_, topic_action_e action) {
+    topic_action(action);
 }
+