Re: How is Help browser started?

Hubert Figuière <[email protected]> Sat, 24 Mar 2012 22:33:24 -0700
Newsgroups gmane.editors.abiword.devel,gmane.editors.abiword.user
Message-ID <[email protected]>
> Well, and just in case gnomevfs of gvfs isn't present on a Gtk 2 build (guess
> on whose build it is missing ;-)) we should consider the attached patch which
> fixes the issue on both Larry Short's and my system. Any objections?

I have that patch. That's the best we can do and IMHO it is already too
much given the state of brokenness of some distro that can't get a
working gtk_show_uri().

And compared to the previous fallback I added xdg-open.
  http://portland.freedesktop.org/wiki/

Hub
open_uri_fallback.diff (text/x-patch, 3.5 KB)
diff --git a/src/af/util/xp/ut_go_file.cpp b/src/af/util/xp/ut_go_file.cpp
index 0fcd0c2..ff556cf 100644
--- a/src/af/util/xp/ut_go_file.cpp
+++ b/src/af/util/xp/ut_go_file.cpp
@@ -1663,8 +1663,11 @@ UT_go_file_get_date_changed (char const *uri)
 }
 
 /* ------------------------------------------------------------------------- */
-
-#if !defined(TOOLKIT_GTK_ALL) && !defined(TOOLKIT_COCOA)
+#ifdef TOOLKIT_GTK_ALL
+// we need this for systems where gtk_show_uri() is broken
+// don't get me started.
+// Note that is gtk_show_uri() fails but return true, then
+// there is nothing that can be done.
 static char *
 check_program (char const *prog)
 {
@@ -1677,39 +1680,10 @@ check_program (char const *prog)
 		return NULL;
 	return g_strdup (prog);
 }
-#endif
 
-#ifdef G_OS_WIN32
-#include "ut_Win32LocaleString.h"
-#endif
-
-GError *
-UT_go_url_show (gchar const *url)
+static void 
+fallback_open_uri(const gchar* url, GError** err)
 {
-#ifdef G_OS_WIN32
-	UT_Win32LocaleString str;
-	str.fromUTF8 (url);
-	ShellExecuteW (NULL, L"open", str.c_str(), NULL, NULL, SW_SHOWNORMAL);
-	return NULL;
-#elif TOOLKIT_COCOA
-	CFStringRef urlStr = CFStringCreateWithCString(kCFAllocatorDefault, url, kCFStringEncodingUTF8);
-	CFURLRef cfUrl = CFURLCreateWithString(kCFAllocatorDefault, urlStr, NULL);
-	OSStatus err = LSOpenCFURLRef(cfUrl, NULL);
-	CFRelease(cfUrl);
-	CFRelease(urlStr);
-	if (err != noErr) {
-		;
-	}
-	return NULL;
-#else
-	GError *err = NULL;
-#if GTK_CHECK_VERSION(2,14,0)
-	gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &err);
-	return err;
-#elif defined(WITH_GNOMEVFS)
-	gnome_vfs_url_show (url);
-	return err;
-#else
 	gchar *browser = NULL;
 	gchar *clean_url = NULL;
 
@@ -1718,6 +1692,7 @@ UT_go_url_show (gchar const *url)
 
 	if (browser == NULL) {
 		static char const * const browsers[] = {
+			"xdg-open",             /* XDG. you shouldn't need anything else */
 			"sensible-browser",	/* debian */
 			"epiphany",		/* primary gnome */
 			"galeon",		/* secondary gnome */
@@ -1742,7 +1717,7 @@ UT_go_url_show (gchar const *url)
 		gchar **argv = NULL;
 		char   *cmd_line = g_strconcat (browser, " %1", NULL);
 
-		if (g_shell_parse_argv (cmd_line, &argc, &argv, &err)) {
+		if (g_shell_parse_argv (cmd_line, &argc, &argv, err)) {
 			/* check for '%1' in an argument and substitute the url
 			 * otherwise append it */
 			gint i;
@@ -1765,13 +1740,50 @@ UT_go_url_show (gchar const *url)
 				argv[argc-1] = NULL;
 			}
 			g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
-				NULL, NULL, NULL, &err);
+				NULL, NULL, NULL, err);
 			g_strfreev (argv);
 		}
 		g_free (cmd_line);
 	}
 	g_free (browser);
 	g_free (clean_url);
+}
+#endif
+
+#ifdef G_OS_WIN32
+#include "ut_Win32LocaleString.h"
+#endif
+
+GError *
+UT_go_url_show (gchar const *url)
+{
+#ifdef G_OS_WIN32
+	UT_Win32LocaleString str;
+	str.fromUTF8 (url);
+	ShellExecuteW (NULL, L"open", str.c_str(), NULL, NULL, SW_SHOWNORMAL);
+	return NULL;
+#elif TOOLKIT_COCOA
+	CFStringRef urlStr = CFStringCreateWithCString(kCFAllocatorDefault, url, kCFStringEncodingUTF8);
+	CFURLRef cfUrl = CFURLCreateWithString(kCFAllocatorDefault, urlStr, NULL);
+	OSStatus err = LSOpenCFURLRef(cfUrl, NULL);
+	CFRelease(cfUrl);
+	CFRelease(urlStr);
+	if (err != noErr) {
+		;
+	}
+	return NULL;
+#else
+	GError *err = NULL;
+#if GTK_CHECK_VERSION(2,14,0)
+	if(!gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &err)) {
+		fallback_open_uri(url, &err);
+	}
+	return err;
+#elif defined(WITH_GNOMEVFS)
+	gnome_vfs_url_show (url);
+	return err;
+#else
+	fallback_open_uri(url, &err);
 	return err;
 #endif
 #endif