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
This commit is contained in:
Colomban Wendling 2011-09-15 02:01:38 +00:00
parent 9d365be4cd
commit 4151a973dd
2 changed files with 25 additions and 26 deletions

View File

@ -1,3 +1,10 @@
2011-09-15 Colomban Wendling <colomban(at)geany(dot)org>
* 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 <nick(dot)treleaven(at)btinternet(dot)com>
* src/win32.c:

View File

@ -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
}