Have a "toc" file in the help directory, which gives a list of help
topic titles and help file names. svn path=/trunk/; revision=9416
This commit is contained in:
parent
f86e376f5b
commit
9c89878b2e
215
gtk/help_dlg.c
215
gtk/help_dlg.c
|
@ -1,6 +1,6 @@
|
|||
/* help_dlg.c
|
||||
*
|
||||
* $Id: help_dlg.c,v 1.39 2003/12/22 08:01:01 ulfl Exp $
|
||||
* $Id: help_dlg.c,v 1.40 2003/12/22 21:52:41 guy Exp $
|
||||
*
|
||||
* Laurent Deniel <laurent.deniel@free.fr>
|
||||
*
|
||||
|
@ -30,6 +30,7 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "epan/filesystem.h"
|
||||
#include "help_dlg.h"
|
||||
|
@ -40,29 +41,12 @@
|
|||
#include "dlg_utils.h"
|
||||
#include "simple_dialog.h"
|
||||
|
||||
typedef enum {
|
||||
OVERVIEW_HELP,
|
||||
CFILTER_HELP,
|
||||
DFILTER_HELP,
|
||||
WELL_KNOWN_HELP,
|
||||
FAQ_HELP,
|
||||
NUM_HELP_TYPES
|
||||
} help_type_t;
|
||||
|
||||
#define HELP_DIR "help"
|
||||
|
||||
static const char *helpfile_names[NUM_HELP_TYPES] = {
|
||||
HELP_DIR G_DIR_SEPARATOR_S "overview.txt",
|
||||
HELP_DIR G_DIR_SEPARATOR_S "capture_filters.txt",
|
||||
HELP_DIR G_DIR_SEPARATOR_S "display_filters.txt",
|
||||
HELP_DIR G_DIR_SEPARATOR_S "well_known.txt",
|
||||
HELP_DIR G_DIR_SEPARATOR_S "faq.txt"
|
||||
};
|
||||
|
||||
static void help_close_cb(GtkWidget *w, gpointer data);
|
||||
static void help_destroy_cb(GtkWidget *w, gpointer data);
|
||||
static void insert_text(GtkWidget *w, const char *buffer, int nchars);
|
||||
static void set_help_text(GtkWidget *w, help_type_t type);
|
||||
static void set_help_text(GtkWidget *w, const char *help_file_path);
|
||||
|
||||
/*
|
||||
* Keep a static pointer to the current "Help" window, if any, so that
|
||||
|
@ -73,18 +57,24 @@ static void set_help_text(GtkWidget *w, help_type_t type);
|
|||
static GtkWidget *help_w = NULL;
|
||||
|
||||
/*
|
||||
* Keep static pointers to the text widgets as well (for text format changes).
|
||||
* Keep a list of text widgets and corresponding file names as well
|
||||
* (for text format changes).
|
||||
*/
|
||||
static GtkWidget *overview_text, *cfilter_text, *dfilter_text;
|
||||
static GtkWidget *well_known_text, *faq_text;
|
||||
typedef struct {
|
||||
char *pathname;
|
||||
GtkWidget *txt;
|
||||
} help_page_t;
|
||||
|
||||
static GSList *help_text_pages = NULL;
|
||||
|
||||
/*
|
||||
* Helper function to show a simple help text page.
|
||||
*/
|
||||
static GtkWidget * help_page(help_type_t page_type, GtkWidget **page_text)
|
||||
static GtkWidget * help_page(const char *filename)
|
||||
{
|
||||
GtkWidget *page_vb, *txt_scrollw;
|
||||
GtkWidget *page_vb, *txt_scrollw, *txt;
|
||||
char *relative_path, *absolute_path;
|
||||
help_page_t *page;
|
||||
|
||||
page_vb = gtk_vbox_new(FALSE, 0);
|
||||
gtk_container_border_width(GTK_CONTAINER(page_vb), 1);
|
||||
|
@ -93,23 +83,32 @@ static GtkWidget * help_page(help_type_t page_type, GtkWidget **page_text)
|
|||
#if GTK_MAJOR_VERSION < 2
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
|
||||
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
||||
*page_text = gtk_text_new(NULL, NULL );
|
||||
gtk_text_set_editable(GTK_TEXT(*page_text), FALSE);
|
||||
gtk_text_set_word_wrap(GTK_TEXT(*page_text), TRUE);
|
||||
gtk_text_set_line_wrap(GTK_TEXT(*page_text), TRUE);
|
||||
txt = gtk_text_new(NULL, NULL);
|
||||
gtk_text_set_editable(GTK_TEXT(txt), FALSE);
|
||||
gtk_text_set_word_wrap(GTK_TEXT(txt), TRUE);
|
||||
gtk_text_set_line_wrap(GTK_TEXT(txt), TRUE);
|
||||
#else
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
|
||||
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||
*page_text = gtk_text_view_new();
|
||||
gtk_text_view_set_editable(GTK_TEXT_VIEW(*page_text), FALSE);
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(*page_text), GTK_WRAP_WORD);
|
||||
txt = gtk_text_view_new();
|
||||
gtk_text_view_set_editable(GTK_TEXT_VIEW(txt), FALSE);
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt), GTK_WRAP_WORD);
|
||||
#endif
|
||||
set_help_text(*page_text, page_type);
|
||||
gtk_container_add(GTK_CONTAINER(txt_scrollw), *page_text);
|
||||
|
||||
relative_path = g_strconcat(HELP_DIR, G_DIR_SEPARATOR_S, filename, NULL);
|
||||
absolute_path = get_datafile_path(relative_path);
|
||||
g_free(relative_path);
|
||||
set_help_text(txt, absolute_path);
|
||||
gtk_container_add(GTK_CONTAINER(txt_scrollw), txt);
|
||||
gtk_widget_show(txt_scrollw);
|
||||
gtk_widget_show(*page_text);
|
||||
gtk_widget_show(txt);
|
||||
gtk_widget_show(page_vb);
|
||||
|
||||
page = g_malloc(sizeof (help_page_t));
|
||||
page->pathname = absolute_path;
|
||||
page->txt = txt;
|
||||
help_text_pages = g_slist_prepend(help_text_pages, page);
|
||||
|
||||
return page_vb;
|
||||
}
|
||||
|
||||
|
@ -119,13 +118,12 @@ static GtkWidget * help_page(help_type_t page_type, GtkWidget **page_text)
|
|||
*/
|
||||
void help_cb(GtkWidget *w _U_, gpointer data _U_)
|
||||
{
|
||||
|
||||
GtkWidget *main_vb, *bbox, *help_nb, *close_bt, *label,
|
||||
*overview_vb,
|
||||
*cfilter_vb,
|
||||
*dfilter_vb,
|
||||
*well_known_vb,
|
||||
*faq_vb;
|
||||
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;
|
||||
|
||||
if (help_w != NULL) {
|
||||
/* There's already a "Help" dialog box; reactivate it. */
|
||||
|
@ -133,6 +131,15 @@ void help_cb(GtkWidget *w _U_, gpointer data _U_)
|
|||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
simple_dialog(ESD_TYPE_CRIT, ESD_BTN_OK, "Could not open file \"%s\": %s",
|
||||
help_toc_file_path, strerror(errno));
|
||||
g_free(help_toc_file_path);
|
||||
return;
|
||||
}
|
||||
|
||||
help_w = dlg_window_new("Ethereal: Help");
|
||||
SIGNAL_CONNECT(help_w, "destroy", help_destroy_cb, NULL);
|
||||
/* XXX: improve this, e.g. remember the last window size in a file */
|
||||
|
@ -149,33 +156,33 @@ void help_cb(GtkWidget *w _U_, gpointer data _U_)
|
|||
help_nb = gtk_notebook_new();
|
||||
gtk_container_add(GTK_CONTAINER(main_vb), 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;
|
||||
|
||||
/* Overview panel */
|
||||
overview_vb = help_page(OVERVIEW_HELP, &overview_text);
|
||||
label = gtk_label_new("Overview");
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), overview_vb, label);
|
||||
|
||||
/* capture filter help (this one has no horizontal scrollbar) */
|
||||
cfilter_vb = help_page(CFILTER_HELP, &cfilter_text);
|
||||
label = gtk_label_new("Capture Filters");
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), cfilter_vb, label);
|
||||
|
||||
/* display filter help (this one has no horizontal scrollbar) */
|
||||
dfilter_vb = help_page(DFILTER_HELP, &dfilter_text);
|
||||
label = gtk_label_new("Display Filters");
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), dfilter_vb, label);
|
||||
|
||||
/* well known things help (this one has no horizontal scrollbar) */
|
||||
well_known_vb = help_page(WELL_KNOWN_HELP, &well_known_text);
|
||||
label = gtk_label_new("Well Known");
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), well_known_vb, label);
|
||||
|
||||
/* FAQ help (this one has no horizontal scrollbar) */
|
||||
faq_vb = help_page(FAQ_HELP, &faq_text);
|
||||
label = gtk_label_new("FAQ");
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(help_nb), faq_vb, label);
|
||||
|
||||
/* XXX add other help panels here ... */
|
||||
/*
|
||||
* "line" refers to the topic now, and "filename" refers to the
|
||||
* file name.
|
||||
*/
|
||||
topic_vb = help_page(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_WARN, ESD_BTN_OK, "Error reading file \"%s\": %s",
|
||||
help_toc_file_path, strerror(errno));
|
||||
}
|
||||
fclose(help_toc_file);
|
||||
|
||||
gtk_widget_show(help_nb);
|
||||
|
||||
|
@ -221,6 +228,19 @@ static void help_close_cb(GtkWidget *w _U_, gpointer data)
|
|||
*/
|
||||
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->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;
|
||||
}
|
||||
|
@ -249,42 +269,28 @@ static void insert_text(GtkWidget *w, const char *buffer, int nchars)
|
|||
/*
|
||||
* Put the complete help text into a help page.
|
||||
*/
|
||||
static void set_help_text(GtkWidget *w, help_type_t type)
|
||||
static void set_help_text(GtkWidget *w, const char *help_file_path)
|
||||
{
|
||||
#ifndef HAVE_LIBPCAP
|
||||
char *tmp;
|
||||
#endif
|
||||
char *help_file_path;
|
||||
FILE *help_file;
|
||||
char line[4096+1]; /* XXX - size? */
|
||||
|
||||
g_assert(type < NUM_HELP_TYPES);
|
||||
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
gtk_text_freeze(GTK_TEXT(w));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LIBPCAP
|
||||
if (type == CFILTER_HELP) {
|
||||
tmp = "NOTE: packet capturing is not enabled in this version!\n \n";
|
||||
insert_text(w, tmp, strlen(tmp));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
help_file_path = get_datafile_path(helpfile_names[type]);
|
||||
help_file = fopen(help_file_path, "r");
|
||||
if (help_file != NULL) {
|
||||
while (fgets(line, sizeof line, help_file) != NULL) {
|
||||
insert_text(w, line, strlen(line));
|
||||
}
|
||||
if(ferror(help_file)) {
|
||||
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not read file: \"%s\"", help_file_path);
|
||||
}
|
||||
fclose(help_file);
|
||||
} else {
|
||||
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open file: \"%s\"", help_file_path);
|
||||
help_file = fopen(help_file_path, "r");
|
||||
if (help_file != NULL) {
|
||||
while (fgets(line, sizeof line, help_file) != NULL) {
|
||||
insert_text(w, line, strlen(line));
|
||||
}
|
||||
g_free(help_file_path);
|
||||
if(ferror(help_file)) {
|
||||
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Error reading file \"%s\": %s",
|
||||
help_file_path, strerror(errno));
|
||||
}
|
||||
fclose(help_file);
|
||||
} else {
|
||||
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open file \"%s\": %s",
|
||||
help_file_path, strerror(errno));
|
||||
}
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
gtk_text_thaw(GTK_TEXT(w));
|
||||
|
@ -318,29 +324,28 @@ static void clear_help_text(GtkWidget *w)
|
|||
/*
|
||||
* Redraw a single help page.
|
||||
*/
|
||||
void help_redraw_page(GtkWidget *page, help_type_t page_type)
|
||||
void help_redraw_page(const help_page_t *page)
|
||||
{
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
gtk_text_freeze(GTK_TEXT(page));
|
||||
gtk_text_freeze(GTK_TEXT(page->txt));
|
||||
#endif
|
||||
clear_help_text(page);
|
||||
set_help_text(page, page_type);
|
||||
clear_help_text(page->txt);
|
||||
set_help_text(page->txt, page->pathname);
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
gtk_text_thaw(GTK_TEXT(page));
|
||||
gtk_text_thaw(GTK_TEXT(page->txt));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Redraw all help pages, to use a new font.
|
||||
*/
|
||||
void help_redraw(void)
|
||||
{
|
||||
GSList *help_page_ent;
|
||||
|
||||
if (help_w != NULL) {
|
||||
help_redraw_page(overview_text, OVERVIEW_HELP);
|
||||
help_redraw_page(cfilter_text, CFILTER_HELP);
|
||||
help_redraw_page(dfilter_text, DFILTER_HELP);
|
||||
help_redraw_page(well_known_text, WELL_KNOWN_HELP);
|
||||
help_redraw_page(faq_text, FAQ_HELP);
|
||||
for (help_page_ent = help_text_pages; help_page_ent != NULL;
|
||||
help_page_ent = g_slist_next(help_page_ent))
|
||||
help_redraw_page((help_page_t *)help_page_ent->data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue