2000-08-08 12:28:50 +00:00
|
|
|
/* help_dlg.c
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-08-08 12:28:50 +00:00
|
|
|
*
|
2003-01-26 19:35:31 +00:00
|
|
|
* Laurent Deniel <laurent.deniel@free.fr>
|
2000-08-08 12:28:50 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
2000-08-08 12:28:50 +00:00
|
|
|
* Copyright 2000 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-08-08 12:28:50 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-08-08 12:28:50 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2002-09-06 21:27:57 +00:00
|
|
|
#include <string.h>
|
2003-11-27 00:22:12 +00:00
|
|
|
#include <stdio.h>
|
2003-12-22 21:52:41 +00:00
|
|
|
#include <errno.h>
|
2000-08-08 12:28:50 +00:00
|
|
|
|
2003-12-22 08:01:01 +00:00
|
|
|
#include "epan/filesystem.h"
|
2000-08-08 12:28:50 +00:00
|
|
|
#include "help_dlg.h"
|
2004-05-22 04:25:57 +00:00
|
|
|
#include "text_page.h"
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2000-08-08 12:28:50 +00:00
|
|
|
#include "gtkglobals.h"
|
|
|
|
#include "ui_util.h"
|
2002-11-11 15:39:06 +00:00
|
|
|
#include "compat_macros.h"
|
2003-11-27 23:25:55 +00:00
|
|
|
#include "dlg_utils.h"
|
2003-12-22 08:01:01 +00:00
|
|
|
#include "simple_dialog.h"
|
2004-09-16 22:07:03 +00:00
|
|
|
#include "webbrowser.h"
|
2003-11-27 00:22:12 +00:00
|
|
|
|
2003-12-22 08:01:01 +00:00
|
|
|
#define HELP_DIR "help"
|
|
|
|
|
2004-01-25 21:27:16 +00:00
|
|
|
|
|
|
|
#define NOTEBOOK_KEY "notebook_key"
|
|
|
|
|
2000-08-17 08:17:38 +00:00
|
|
|
static void help_destroy_cb(GtkWidget *w, gpointer data);
|
2000-08-08 12:28:50 +00:00
|
|
|
|
2000-08-17 08:17:38 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
2003-01-29 12:58:48 +00:00
|
|
|
*/
|
2000-08-08 12:28:50 +00:00
|
|
|
static GtkWidget *help_w = NULL;
|
|
|
|
|
2000-09-08 10:59:21 +00:00
|
|
|
/*
|
2003-12-22 21:52:41 +00:00
|
|
|
* Keep a list of text widgets and corresponding file names as well
|
|
|
|
* (for text format changes).
|
2000-09-08 10:59:21 +00:00
|
|
|
*/
|
2003-12-22 21:52:41 +00:00
|
|
|
typedef struct {
|
2004-01-25 21:27:16 +00:00
|
|
|
char *topic;
|
2003-12-22 21:52:41 +00:00
|
|
|
char *pathname;
|
2004-06-05 09:57:11 +00:00
|
|
|
GtkWidget *page;
|
2003-12-22 21:52:41 +00:00
|
|
|
} help_page_t;
|
2000-09-08 10:59:21 +00:00
|
|
|
|
2003-12-22 21:52:41 +00:00
|
|
|
static GSList *help_text_pages = NULL;
|
2003-11-27 00:22:12 +00:00
|
|
|
|
2004-05-21 00:27:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function to show a simple help text page.
|
|
|
|
*/
|
|
|
|
static GtkWidget * help_page(const char *topic, const char *filename)
|
|
|
|
{
|
2004-06-05 09:57:11 +00:00
|
|
|
GtkWidget *text_page;
|
2004-05-21 00:27:56 +00:00
|
|
|
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);
|
2004-06-05 09:57:11 +00:00
|
|
|
text_page = text_page_new(absolute_path);
|
2004-05-21 00:27:56 +00:00
|
|
|
g_free(relative_path);
|
2004-06-05 09:57:11 +00:00
|
|
|
gtk_widget_show(text_page);
|
2003-11-27 00:22:12 +00:00
|
|
|
|
2003-12-22 21:52:41 +00:00
|
|
|
page = g_malloc(sizeof (help_page_t));
|
2004-01-25 21:27:16 +00:00
|
|
|
page->topic = g_strdup(topic);
|
2003-12-22 21:52:41 +00:00
|
|
|
page->pathname = absolute_path;
|
2004-06-05 09:57:11 +00:00
|
|
|
page->page = text_page;
|
2004-01-25 21:27:16 +00:00
|
|
|
help_text_pages = g_slist_append(help_text_pages, page);
|
2003-12-22 21:52:41 +00:00
|
|
|
|
2004-06-05 09:57:11 +00:00
|
|
|
return text_page;
|
2003-11-27 00:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 08:01:01 +00:00
|
|
|
/*
|
|
|
|
* Create and show help dialog.
|
|
|
|
*/
|
2003-11-27 00:22:12 +00:00
|
|
|
void help_cb(GtkWidget *w _U_, gpointer data _U_)
|
|
|
|
{
|
2003-12-22 21:52:41 +00:00
|
|
|
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;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-08-08 12:28:50 +00:00
|
|
|
if (help_w != NULL) {
|
2000-08-17 08:17:38 +00:00
|
|
|
/* There's already a "Help" dialog box; reactivate it. */
|
2000-08-08 12:28:50 +00:00
|
|
|
reactivate_window(help_w);
|
|
|
|
return;
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2003-12-22 21:52:41 +00:00
|
|
|
help_toc_file_path = get_datafile_path(HELP_DIR G_DIR_SEPARATOR_S "toc");
|
|
|
|
help_toc_file = fopen(help_toc_file_path, "r");
|
|
|
|
if (help_toc_file == NULL) {
|
2004-01-31 02:25:46 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open file \"%s\": %s",
|
2003-12-22 21:52:41 +00:00
|
|
|
help_toc_file_path, strerror(errno));
|
|
|
|
g_free(help_toc_file_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-30 11:54:37 +00:00
|
|
|
help_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, "Ethereal: Help", "help");
|
2004-05-23 17:37:36 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(help_w), DEF_WIDTH, DEF_HEIGHT);
|
2000-08-08 12:28:50 +00:00
|
|
|
gtk_container_border_width(GTK_CONTAINER(help_w), 2);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-08-08 12:28:50 +00:00
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* help topics container */
|
|
|
|
help_nb = gtk_notebook_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), help_nb);
|
2004-01-25 21:27:16 +00:00
|
|
|
OBJECT_SET_DATA(help_w, NOTEBOOK_KEY, help_nb);
|
2000-08-08 12:28:50 +00:00
|
|
|
|
2003-12-22 21:52:41 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
2004-01-25 21:27:16 +00:00
|
|
|
topic_vb = help_page(line, filename);
|
2003-12-22 21:52:41 +00:00
|
|
|
label = gtk_label_new(line);
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), topic_vb, label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ferror(help_toc_file)) {
|
2004-01-31 03:22:42 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Error reading file \"%s\": %s",
|
2003-12-22 21:52:41 +00:00
|
|
|
help_toc_file_path, strerror(errno));
|
|
|
|
}
|
|
|
|
fclose(help_toc_file);
|
2000-08-08 12:28:50 +00:00
|
|
|
|
|
|
|
|
2004-05-23 17:37:36 +00:00
|
|
|
/* Button row */
|
2004-01-21 21:19:34 +00:00
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
|
|
|
|
gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
|
|
|
|
|
|
|
|
close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
|
2004-05-23 17:37:36 +00:00
|
|
|
window_set_cancel_button(help_w, close_bt, window_cancel_button_cb);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2004-05-23 17:37:36 +00:00
|
|
|
SIGNAL_CONNECT(help_w, "delete_event", window_delete_event_cb, NULL);
|
|
|
|
SIGNAL_CONNECT(help_w, "destroy", help_destroy_cb, NULL);
|
2003-11-27 23:25:55 +00:00
|
|
|
|
2004-05-23 17:37:36 +00:00
|
|
|
gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(help_w));
|
2003-11-27 23:25:55 +00:00
|
|
|
|
2004-05-22 19:56:19 +00:00
|
|
|
gtk_widget_show_all(help_w);
|
2004-05-23 17:37:36 +00:00
|
|
|
window_present(help_w);
|
2000-08-08 12:28:50 +00:00
|
|
|
} /* help_cb */
|
|
|
|
|
2003-12-22 08:01:01 +00:00
|
|
|
|
2004-01-25 21:27:16 +00:00
|
|
|
/*
|
|
|
|
* Open the help dialog and show a specific help page.
|
|
|
|
*/
|
|
|
|
|
2004-06-01 17:33:37 +00:00
|
|
|
void help_topic_cb(GtkWidget *w _U_, gpointer data) {
|
2004-01-25 21:27:16 +00:00
|
|
|
gchar *topic = data;
|
|
|
|
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_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++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* topic page not found, default (first page) will be shown */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 08:01:01 +00:00
|
|
|
/*
|
|
|
|
* Help dialog is closed now.
|
|
|
|
*/
|
2002-03-05 11:56:00 +00:00
|
|
|
static void help_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
|
2000-08-17 08:17:38 +00:00
|
|
|
{
|
2003-12-22 21:52:41 +00:00
|
|
|
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;
|
2004-01-25 21:27:16 +00:00
|
|
|
g_free(page->topic);
|
2003-12-22 21:52:41 +00:00
|
|
|
g_free(page->pathname);
|
|
|
|
g_free(page);
|
|
|
|
}
|
|
|
|
g_slist_free(help_text_pages);
|
|
|
|
help_text_pages = NULL;
|
|
|
|
|
2000-08-17 08:17:38 +00:00
|
|
|
/* Note that we no longer have a Help window. */
|
|
|
|
help_w = NULL;
|
|
|
|
}
|
2000-08-08 12:28:50 +00:00
|
|
|
|
2003-12-22 08:01:01 +00:00
|
|
|
|
2004-06-05 09:57:11 +00:00
|
|
|
/**
|
2003-12-22 08:01:01 +00:00
|
|
|
* Redraw all help pages, to use a new font.
|
|
|
|
*/
|
|
|
|
void help_redraw(void)
|
|
|
|
{
|
2003-12-22 21:52:41 +00:00
|
|
|
GSList *help_page_ent;
|
2004-06-05 09:57:11 +00:00
|
|
|
help_page_t *help_page;
|
2003-12-22 21:52:41 +00:00
|
|
|
|
2003-12-22 08:01:01 +00:00
|
|
|
if (help_w != NULL) {
|
2003-12-22 21:52:41 +00:00
|
|
|
for (help_page_ent = help_text_pages; help_page_ent != NULL;
|
2004-06-05 09:57:11 +00:00
|
|
|
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);
|
|
|
|
}
|
2000-09-08 10:59:21 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-16 22:07:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
url_page_action(url_page_action_e action)
|
|
|
|
{
|
|
|
|
/* pages online at www.ethereal.com */
|
|
|
|
switch(action) {
|
|
|
|
case(ONLINEPAGE_HOME):
|
|
|
|
browser_open_url ("http://www.ethereal.com");
|
|
|
|
break;
|
2004-09-24 15:41:46 +00:00
|
|
|
case(ONLINEPAGE_WIKI):
|
|
|
|
browser_open_url ("http://wiki.ethereal.com");
|
|
|
|
break;
|
2004-09-16 22:07:03 +00:00
|
|
|
case(ONLINEPAGE_DOWNLOAD):
|
|
|
|
browser_open_url ("http://www.ethereal.com/download.html");
|
|
|
|
break;
|
|
|
|
case(ONLINEPAGE_USERGUIDE):
|
|
|
|
browser_open_url ("http://www.ethereal.com/docs/user-guide");
|
|
|
|
break;
|
|
|
|
case(ONLINEPAGE_FAQ):
|
|
|
|
browser_open_url ("http://www.ethereal.com/faq.html");
|
|
|
|
break;
|
|
|
|
case(ONLINEPAGE_SAMPLE_FILES):
|
2004-10-07 20:30:35 +00:00
|
|
|
browser_open_url ("http://wiki.ethereal.com/SampleCaptures");
|
2004-09-16 22:07:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* local manual pages */
|
|
|
|
case(LOCALPAGE_MAN_ETHEREAL):
|
|
|
|
browser_open_data_file("ethereal.html");
|
|
|
|
break;
|
|
|
|
case(LOCALPAGE_MAN_ETHEREAL_FILTER):
|
|
|
|
browser_open_data_file("ethereal-filter.html");
|
|
|
|
break;
|
|
|
|
case(LOCALPAGE_MAN_TETHEREAL):
|
|
|
|
browser_open_data_file("tethereal.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;
|
|
|
|
|
|
|
|
#ifdef ETHEREAL_EUG_DIR
|
|
|
|
/* local help pages (User's Guide) */
|
|
|
|
case(HELP_CONTENT):
|
|
|
|
browser_open_data_file("eug_html_chunked/index.html");
|
|
|
|
break;
|
|
|
|
case(HELP_CAPTURE_OPTIONS_DIALOG):
|
|
|
|
browser_open_data_file("eug_html_chunked/ChCapCaptureOptions.html");
|
|
|
|
break;
|
|
|
|
case(HELP_CAPTURE_FILTERS_DIALOG):
|
|
|
|
browser_open_data_file("eug_html_chunked/ChWorkDefineFilterSection.html");
|
|
|
|
break;
|
|
|
|
case(HELP_DISPLAY_FILTERS_DIALOG):
|
|
|
|
browser_open_data_file("eug_html_chunked/ChWorkDefineFilterSection.html");
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
url_page_cb(GtkWidget *w _U_, url_page_action_e action)
|
|
|
|
{
|
|
|
|
url_page_action(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
url_page_menu_cb( GtkWidget *w _U_, gpointer data _U_, url_page_action_e action)
|
|
|
|
{
|
|
|
|
url_page_action(action);
|
|
|
|
}
|
|
|
|
|