From 2a6da1361c62b7f2834a8399a7af4c018a31ba64 Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Mon, 21 Jun 2004 17:27:35 +0000 Subject: Add experimental feature of opening a webbrowser, to show some of the webpages from http://www.ethereal.com. This functionality is copied from the Gimp. Win32 will use ShellExecute to use the system registered webbrowser. On unix builds, currently the mozilla browser is hardcoded, we still need a preference setting for this (I will add this later). svn path=/trunk/; revision=11206 --- gtk/Makefile.common | 5 +- gtk/about_dlg.c | 28 ++++++++++- gtk/about_dlg.h | 32 +++++++++++- gtk/main.h | 4 +- gtk/menu.c | 7 ++- gtk/webbrowser.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 208 insertions(+), 7 deletions(-) create mode 100644 gtk/webbrowser.c (limited to 'gtk') diff --git a/gtk/Makefile.common b/gtk/Makefile.common index 2ec414bc38..73fa38630d 100644 --- a/gtk/Makefile.common +++ b/gtk/Makefile.common @@ -3,7 +3,7 @@ # a) common to both files and # b) portable between both files # -# $Id: Makefile.common,v 1.15 2004/06/17 16:35:25 ulfl Exp $ +# $Id: Makefile.common,v 1.16 2004/06/21 17:25:19 ulfl Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs @@ -79,7 +79,8 @@ ETHEREAL_GTK_SRC = \ tap_dfilter_dlg.c \ text_page.c \ toolbar.c \ - ui_util.c + ui_util.c \ + webbrowser.c ETHEREAL_TAP_SRC = \ diff --git a/gtk/about_dlg.c b/gtk/about_dlg.c index 52f51bbf2c..ce00784336 100644 --- a/gtk/about_dlg.c +++ b/gtk/about_dlg.c @@ -1,6 +1,6 @@ /* about_dlg.c * - * $Id: about_dlg.c,v 1.13 2004/06/01 17:33:35 ulfl Exp $ + * $Id: about_dlg.c,v 1.14 2004/06/21 17:25:19 ulfl Exp $ * * Ulf Lamping * @@ -39,6 +39,7 @@ #if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3 #include "text_page.h" #endif +#include "main.h" #include "cvsversion.h" @@ -285,3 +286,28 @@ about_ethereal_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_) about_ethereal_w = NULL; } + +void +url_ethereal_cb( GtkWidget *w _U_, gpointer data _U_) +{ + browser_open_url ("http://www.ethereal.com"); +} + +void +url_downloads_cb( GtkWidget *w _U_, gpointer data _U_) +{ + browser_open_url ("http://www.ethereal.com/download.html"); +} + +void +url_user_guide_cb( GtkWidget *w _U_, gpointer data _U_) +{ + browser_open_url ("http://www.ethereal.com/docs/user-guide"); +} + +void +url_faqs_cb( GtkWidget *w _U_, gpointer data _U_) +{ + browser_open_url ("http://www.ethereal.com/faq.html"); +} + diff --git a/gtk/about_dlg.h b/gtk/about_dlg.h index 2b93669156..fd31e73fc4 100644 --- a/gtk/about_dlg.h +++ b/gtk/about_dlg.h @@ -1,7 +1,7 @@ /* about_dlg.h * Declarations of routines for the "About" dialog * - * $Id: about_dlg.h,v 1.3 2004/06/04 20:05:30 ulfl Exp $ + * $Id: about_dlg.h,v 1.4 2004/06/21 17:25:19 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -35,6 +35,34 @@ * @param widget parent widget (unused) * @param data unused */ -void about_ethereal_cb( GtkWidget *widget, gpointer data); +extern void about_ethereal_cb( GtkWidget *widget, gpointer data); + +/** User requested the "Homepage" by menu. + * + * @param widget parent widget (unused) + * @param data unused + */ +extern void url_ethereal_cb( GtkWidget *widget, gpointer data); + +/** User requested the "Downloads" page by menu. + * + * @param widget parent widget (unused) + * @param data unused + */ +extern void url_downloads_cb( GtkWidget *widget, gpointer data); + +/** User requested the "User's Guide" page by menu. + * + * @param widget parent widget (unused) + * @param data unused + */ +extern void url_user_guide_cb( GtkWidget *widget, gpointer data); + +/** User requested the "FAQ's" page by menu. + * + * @param widget parent widget (unused) + * @param data unused + */ +extern void url_faqs_cb( GtkWidget *widget, gpointer data); #endif /* __ABOUT_DLG_H__ */ diff --git a/gtk/main.h b/gtk/main.h index 6e0cffca2d..901a84c002 100644 --- a/gtk/main.h +++ b/gtk/main.h @@ -1,7 +1,7 @@ /* main.h * Global defines, etc. * - * $Id: main.h,v 1.53 2004/06/21 10:53:35 jmayer Exp $ + * $Id: main.h,v 1.54 2004/06/21 17:25:19 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -250,4 +250,6 @@ extern void packets_bar_update(void); extern void create_console(void); #endif +extern gboolean browser_open_url (const gchar *url); + #endif /* __MAIN_H__ */ diff --git a/gtk/menu.c b/gtk/menu.c index 689dde0735..91f4a3b6ea 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -1,7 +1,7 @@ /* menu.c * Menu routines * - * $Id: menu.c,v 1.203 2004/06/20 15:57:11 ulfl Exp $ + * $Id: menu.c,v 1.204 2004/06/21 17:25:19 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -322,6 +322,11 @@ static GtkItemFactoryEntry menu_items[] = ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "", NULL), ITEM_FACTORY_STOCK_ENTRY("/Help/_Contents", "F1", help_cb, 0, GTK_STOCK_HELP), ITEM_FACTORY_ENTRY("/Help/_Supported Protocols", NULL, supported_cb, 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/Help/Ethereal Online", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_STOCK_ENTRY("/Help/Ethereal Online/Homepage", NULL, url_ethereal_cb, 0, GTK_STOCK_HOME), + ITEM_FACTORY_ENTRY("/Help/Ethereal Online/User's Guide", NULL, url_user_guide_cb, 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/Help/Ethereal Online/FAQ's", NULL, url_faqs_cb, 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/Help/Ethereal Online/Downloads", NULL, url_downloads_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/Help/", NULL, NULL, 0, "", NULL), ITEM_FACTORY_ENTRY("/Help/_About Ethereal", NULL, about_ethereal_cb, 0, NULL, NULL) diff --git a/gtk/webbrowser.c b/gtk/webbrowser.c new file mode 100644 index 0000000000..e882514a6c --- /dev/null +++ b/gtk/webbrowser.c @@ -0,0 +1,139 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * Web Browser Plug-in + * Copyright (C) 2003 Henrik Brix Andersen + * + * 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. + */ + +/* Ethereal - this file is copied from "The GIMP" V2.0.2 + * You will find the original file in the gimp distribution zip under: + * \plug-ins\common\webbrowser.c + * + * It was modified to suit the Ethereal environment (#if 0)! + */ + +#include "config.h" + +#include /* strlen, strstr */ + +#include + +#ifdef G_OS_WIN32 +#include +#endif + + + +#ifndef G_OS_WIN32 +static gchar* strreplace (const gchar *string, + const gchar *delimiter, + const gchar *replacement); +#endif + + +gboolean +browser_open_url (const gchar *url) +{ +#ifdef G_OS_WIN32 + + return ((gint) ShellExecute (HWND_DESKTOP, "open", url, NULL, NULL, SW_SHOWNORMAL) > 32); + +#else + + GError *error = NULL; + gchar *browser; + gchar *argument; + gchar *cmd; + gchar **argv; + gboolean retval; + + g_return_val_if_fail (url != NULL, FALSE); + +/* browser = gimp_gimprc_query ("web-browser");*/ + browser = g_strdup("mozilla %s"); + + if (browser == NULL || ! strlen (browser)) + { + g_message (("Web browser not specified.\n" + "Please specify a web browser using the Preferences Dialog.")); + g_free (browser); + return FALSE; + } + + /* quote the url since it might contains special chars */ + argument = g_shell_quote (url); + + /* replace %s with URL */ + if (strstr (browser, "%s")) + cmd = strreplace (browser, "%s", argument); + else + cmd = g_strconcat (browser, " ", argument, NULL); + + g_free (argument); + + /* parse the cmd line */ + if (! g_shell_parse_argv (cmd, NULL, &argv, &error)) + { + g_message (("Could not parse specified web browser command:\n%s"), + error->message); + g_error_free (error); + return FALSE; + } + + retval = g_spawn_async (NULL, argv, NULL, + G_SPAWN_SEARCH_PATH, + NULL, NULL, + NULL, &error); + + if (! retval) + { + g_message (("Could not execute specified web browser:\n%s"), + error->message); + g_error_free (error); + } + + g_free (browser); + g_free (cmd); + g_strfreev (argv); + + return retval; + +#endif +} + +#ifndef G_OS_WIN32 + +static gchar* +strreplace (const gchar *string, + const gchar *delimiter, + const gchar *replacement) +{ + gchar *ret; + gchar **tmp; + + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (delimiter != NULL, NULL); + g_return_val_if_fail (replacement != NULL, NULL); + + tmp = g_strsplit (string, delimiter, 0); + ret = g_strjoinv (replacement, tmp); + g_strfreev (tmp); + + return ret; +} + +#endif /* !G_OS_WIN32 */ -- cgit v1.2.3