From 4e688c2660236b6d8674882655fa494946f41a8e Mon Sep 17 00:00:00 2001 From: dooglus Date: Sun, 17 Feb 2008 11:46:10 +0000 Subject: [PATCH] Basic support for opening URLs. Not tested on Windows yet. Uses glib's g_spawn_async() rather than glibmm's spawn_async() because it allows us to pass NULL for the environmrnt and inherit the parent's environment. git-svn-id: http://svn.voria.com/code@1726 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-studio/trunk/src/gtkmm/app.cpp | 37 +++++++++++++++++++++++++++++++---- synfig-studio/trunk/src/gtkmm/app.h | 2 ++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/synfig-studio/trunk/src/gtkmm/app.cpp b/synfig-studio/trunk/src/gtkmm/app.cpp index f02e1db..d9ff579 100644 --- a/synfig-studio/trunk/src/gtkmm/app.cpp +++ b/synfig-studio/trunk/src/gtkmm/app.cpp @@ -1884,10 +1884,39 @@ App::dialog_not_implemented() void App::dialog_help() { - Gtk::MessageDialog dialog(_("Documentation"), false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_CLOSE, true); - dialog.set_secondary_text(_("Documentation for Synfig Studio is available on the website:\n\nhttp://www.synfig.org/Documentation")); - dialog.set_title(_("Help")); - dialog.run(); + if (!open_url("http://www.synfig.org/Documentation")) + { + Gtk::MessageDialog dialog(_("Documentation"), false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_CLOSE, true); + dialog.set_secondary_text(_("Documentation for Synfig Studio is available on the website:\n\nhttp://www.synfig.org/Documentation")); + dialog.set_title(_("Help")); + dialog.run(); + } +} + +bool +App::open_url(const std::string &url) +{ +#ifdef WIN32 + return ShellExecute(GetDesktopWindow(), "open", url.c_str(), NULL, NULL, SW_SHOW); +#else // WIN32 + String browser_program("firefox"); + gchar* argv[3] = {strdup(browser_program.c_str()), strdup(url.c_str()), NULL}; + + GError* gerror = NULL; + gboolean retval; + retval = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &gerror); + free(argv[0]); + free(argv[1]); + + if (!retval) + { + error(_("Could not execute specified web browser: %s"), gerror->message); + g_error_free(gerror); + return false; + } + + return true; +#endif // WIN32 } bool diff --git a/synfig-studio/trunk/src/gtkmm/app.h b/synfig-studio/trunk/src/gtkmm/app.h index ac5cb54..65a737e 100644 --- a/synfig-studio/trunk/src/gtkmm/app.h +++ b/synfig-studio/trunk/src/gtkmm/app.h @@ -334,6 +334,8 @@ public: static void dialog_help(); + static bool open_url(const std::string &url); + static synfig::String get_user_app_directory(); static synfig::String get_config_file(const synfig::String& file); }; // END of class App -- 2.7.4