Add "gtk/webbrowser.h" to declare functions from "gtk/webbrowser.c".

Rename "browser_open_program_file()" to "browser_open_data_file()", and
make it open files relative to the application's data directory, as
that's where data files such as HTMLized man pages would be put.  (That
happens to be the program directory on Windows, but it's a different
directory on UN*X - and you aren't guaranteed to be able to find the
program directory on UN*X by looking at argv[0] in any case.)  Move it
to "gtk/webbrowser.c".

Fix "filename2url()" to put "file://", not just "file:", in front of
pathnames on UN*X.

svn path=/trunk/; revision=11216
This commit is contained in:
Guy Harris 2004-06-23 01:38:39 +00:00
parent fe40fa191e
commit aacb8bc9b6
5 changed files with 73 additions and 47 deletions

View File

@ -1,7 +1,7 @@
# Makefile.am
# Automake file for the GTK interface routines for Ethereal
#
# $Id: Makefile.am,v 1.103 2004/06/17 16:35:25 ulfl Exp $
# $Id: Makefile.am,v 1.104 2004/06/23 01:38:39 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@ethereal.com>
@ -87,7 +87,8 @@ noinst_HEADERS = \
tap_menu.h \
text_page.h \
toolbar.h \
ui_util.h
ui_util.h \
webbrowser.h
if USE_GTK2
libui_a_SOURCES = \

View File

@ -1,6 +1,6 @@
/* about_dlg.c
*
* $Id: about_dlg.c,v 1.16 2004/06/22 21:51:55 guy Exp $
* $Id: about_dlg.c,v 1.17 2004/06/23 01:38:39 guy Exp $
*
* Ulf Lamping <ulf.lamping@web.de>
*
@ -39,7 +39,7 @@
#if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
#include "text_page.h"
#endif
#include "main.h"
#include "webbrowser.h"
#include "cvsversion.h"
@ -311,57 +311,27 @@ url_onlinepage_cb( GtkWidget *widget _U_, gpointer data _U_, onlinepage_action_e
}
}
extern gchar *
filename2uri(gchar *filename);
/* browse a file relative to the program dir */
void
browser_open_program_file(gchar *filename)
{
gchar *uri;
gchar *prog_path;
gchar *file_path;
/* get ethereal program base dir */
prog_path = g_strdup(ethereal_path);
prog_path = get_dirname((char *) prog_path);
/* build filename */
file_path = g_strdup_printf("%s/%s", prog_path, filename);
/* convert filename to uri */
uri = filename2uri(file_path);
/* show the uri */
browser_open_url (uri);
g_free(prog_path);
g_free(file_path);
g_free(uri);
}
void
url_localpage_cb( GtkWidget *w _U_, gpointer data _U_, localpage_action_e action)
{
switch(action) {
case(LOCALPAGE_MAN_ETHEREAL):
browser_open_program_file("ethereal.html");
browser_open_data_file("ethereal.html");
break;
case(LOCALPAGE_MAN_ETHEREAL_FILTER):
browser_open_program_file("ethereal-filter.html");
browser_open_data_file("ethereal-filter.html");
break;
case(LOCALPAGE_MAN_TETHEREAL):
browser_open_program_file("tethereal.html");
browser_open_data_file("tethereal.html");
break;
case(LOCALPAGE_MAN_MERGECAP):
browser_open_program_file("mergecap.html");
browser_open_data_file("mergecap.html");
break;
case(LOCALPAGE_MAN_EDITCAP):
browser_open_program_file("editcap.html");
browser_open_data_file("editcap.html");
break;
case(LOCALPAGE_MAN_TEXT2PCAP):
browser_open_program_file("text2pcap.html");
browser_open_data_file("text2pcap.html");
break;
default:
g_assert_not_reached();

View File

@ -1,7 +1,7 @@
/* main.h
* Global defines, etc.
*
* $Id: main.h,v 1.55 2004/06/21 20:12:45 tuexen Exp $
* $Id: main.h,v 1.56 2004/06/23 01:38:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -250,6 +250,4 @@ extern void packets_bar_update(void);
extern void create_console(void);
#endif
extern gboolean browser_open_url (const gchar *url);
#endif /* __MAIN_H__ */

View File

@ -32,6 +32,10 @@
#include <glib.h>
#include <epan/filesystem.h>
#include "webbrowser.h"
#if defined(G_OS_WIN32)
/* Win32 - use Windows shell services to start a browser */
#include <windows.h>
@ -77,7 +81,7 @@ browser_open_url (const gchar *url)
* XXX - this is a Launch Services result code, and we should probably
* display a dialog box if it's not 0, describing what the error was.
* Then again, we should probably do the same for the ShellExecute call,
* unless that call itself happens to pop up a dialog box.
* unless that call itself happens to pop up a dialog box for all errors.
*/
status = LSOpenCFURLRef(url_CFURL, NULL);
CFRelease(url_CFURL);
@ -175,7 +179,7 @@ strreplace (const gchar *string,
* @param filename to (absolute pathed) filename to convert
* @return a newly allocated uri, you must g_free it later
*/
gchar *
static gchar *
filename2uri(gchar *filename)
{
int i = 0;
@ -209,7 +213,7 @@ filename2uri(gchar *filename)
/* XXX - how do we handle UNC names (e.g. //servername/sharename/dir1/dir2/capture-file.cap) */
g_string_prepend(filestr, "file:///");
#else
g_string_prepend(filestr, "file:");
g_string_prepend(filestr, "file://");
#endif
file_tmp = filestr->str;
@ -217,4 +221,24 @@ filename2uri(gchar *filename)
g_string_free(filestr, FALSE /* don't free segment data */);
return file_tmp;
}
}
/* browse a file relative to the data dir */
void
browser_open_data_file(const gchar *filename)
{
gchar *file_path;
gchar *uri;
/* build filename */
file_path = g_strdup_printf("%s/%s", get_datafile_dir(), filename);
/* convert filename to uri */
uri = filename2uri(file_path);
/* show the uri */
browser_open_url (uri);
g_free(file_path);
g_free(uri);
}

33
gtk/webbrowser.h Normal file
View File

@ -0,0 +1,33 @@
/* webbrowser.h
* Web browser activation functions
*
* $Id: webbrowser.h,v 1.1 2004/06/23 01:38:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 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.
*
* 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.
*
* 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.
*/
#ifndef __WEBBROWSER_H__
#define __WEBBROWSER_H__
extern gboolean browser_open_url (const gchar *url);
/* browse a file relative to the data dir */
extern void browser_open_data_file (const gchar *filename);
#endif /* __WEBBROWSER_H__ */