From 4151a973dde2d95b87c7c551bfe0776e11f9625f Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Thu, 15 Sep 2011 02:01:38 +0000 Subject: [PATCH] Ask the user if spawn fails in utils_open_browser() Ask the user to configure a valid browser command if spawning it fails rather than falling back to some arbitrary hardcoded defaults. This avoid spawning an unexpected browser when the configured one is wrong, and gives the user a chance to correctly fix the preference. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5918 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 7 +++++++ src/utils.c | 44 ++++++++++++++++++-------------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4453667..4ec0ec12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-09-15 Colomban Wendling + + * src/utils.c: + Ask the user to configure a valid browser command if spawning it + fails rather than falling back to some arbitrary hardcoded defaults. + + 2011-09-14 Nick Treleaven * src/win32.c: diff --git a/src/utils.c b/src/utils.c index 416cf504..02d25487 100644 --- a/src/utils.c +++ b/src/utils.c @@ -53,6 +53,7 @@ #include "dialogs.h" #include "win32.h" #include "project.h" +#include "ui_utils.h" #include "utils.h" @@ -61,8 +62,7 @@ * Tries to open the given URI in a browser. * On Windows, the system's default browser is opened. * On non-Windows systems, the browser command set in the preferences dialog is used. In case - * that fails or it is unset, @c xdg-open is used as fallback as well as some other known - * browsers. + * that fails or it is unset, the user is asked to correct or fill it. * * @param uri The URI to open in the web browser. * @@ -74,38 +74,30 @@ void utils_open_browser(const gchar *uri) g_return_if_fail(uri != NULL); win32_open_browser(uri); #else - gchar *cmdline; + gboolean again = TRUE; g_return_if_fail(uri != NULL); - cmdline = g_strconcat(tool_prefs.browser_cmd, " \"", uri, "\"", NULL); - if (! g_spawn_command_line_async(cmdline, NULL)) + while (again) { - static const gchar *browsers[] = - { - "xdg-open", - "firefox", - "mozilla", - "opera", - "konqueror", - "netscape" - }; - const gchar *argv[3]; - guint i; + gchar *cmdline = g_strconcat(tool_prefs.browser_cmd, " \"", uri, "\"", NULL); - argv[0] = NULL; - argv[1] = uri; - argv[2] = NULL; - - for (i = 0; i < G_N_ELEMENTS (browsers); i++) + if (g_spawn_command_line_async(cmdline, NULL)) + again = FALSE; + else { - argv[0] = browsers[i]; - if (g_spawn_async(NULL, (gchar**)argv, NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, NULL)) - break; + gchar *new_cmd = dialogs_show_input(_("Select Browser"), GTK_WINDOW(main_widgets.window), + _("Failed to spawn the configured browser command. " + "Please correct it or select another one."), + tool_prefs.browser_cmd); + + if (new_cmd == NULL) /* user canceled */ + again = FALSE; + else + setptr(tool_prefs.browser_cmd, new_cmd); } + g_free(cmdline); } - g_free(cmdline); #endif }