[beast/win32] Move browser start function to Birnet::OS. Provide win32 version.
- From: Stefan Westerfeld <stw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [beast/win32] Move browser start function to Birnet::OS. Provide win32 version.
- Date: Thu, 19 Nov 2009 09:04:07 +0000 (UTC)
commit c95a47b87dd5412827b96cb1fadfd10cebb1ff9a
Author: Stefan Westerfeld <stefan space twc de>
Date: Thu Nov 19 10:03:03 2009 +0100
Move browser start function to Birnet::OS. Provide win32 version.
* birnet/birnet*[hc]: Make browser start working on windows by moving the
browser start code from birnetutils.cc to birnetosunix.cc, and by adding
a new browser start function based on the win32 API to birnetoswin32.cc.
* sfi/sfiwrapper.cc: Use Birnet::OS::url_test_show function which works
on win32 and unix.
birnet/birnetos.hh | 1 +
birnet/birnetosunix.cc | 87 ++++++++++++++++++++++++++++++++++++++++++++
birnet/birnetoswin32.cc | 9 +++++
birnet/birnetutils.cc | 92 ++---------------------------------------------
birnet/birnetutils.hh | 1 -
sfi/sfiwrapper.cc | 2 +-
6 files changed, 101 insertions(+), 91 deletions(-)
---
diff --git a/birnet/birnetos.hh b/birnet/birnetos.hh
index 5bf6947..a4b58bd 100644
--- a/birnet/birnetos.hh
+++ b/birnet/birnetos.hh
@@ -71,6 +71,7 @@ int getpid();
void memset4 (uint32 *mem, uint32 filler, uint count);
void memcpy4 (uint32 *dest, const uint32 *src, size_t count);
int mkdir (const char *path, mode_t mode);
+bool url_test_show (const char *url);
// stat
int lstat (const char *path, struct stat *buf);
diff --git a/birnet/birnetosunix.cc b/birnet/birnetosunix.cc
index a7124c9..f0dde9b 100644
--- a/birnet/birnetosunix.cc
+++ b/birnet/birnetosunix.cc
@@ -184,6 +184,93 @@ mkdir (const char *path,
return ::mkdir (path, mode);
}
+bool
+url_test_show (const char *url)
+{
+ static struct {
+ const char *prg, *arg1, *prefix, *postfix;
+ bool asyncronous; /* start asyncronously and check exit code to catch launch errors */
+ volatile bool disabled;
+ } www_browsers[] = {
+ /* program */ /* arg1 */ /* prefix+URL+postfix */
+ /* configurable, working browser launchers */
+ { "gnome-open", NULL, "", "", 0 }, /* opens in background, correct exit_code */
+ { "exo-open", NULL, "", "", 0 }, /* opens in background, correct exit_code */
+ /* non-configurable working browser launchers */
+ { "kfmclient", "openURL", "", "", 0 }, /* opens in background, correct exit_code */
+ { "gnome-moz-remote", "--newwin", "", "", 0 }, /* opens in background, correct exit_code */
+#if 0
+ /* broken/unpredictable browser launchers */
+ { "browser-config", NULL, "", "", 0 }, /* opens in background (+ sleep 5), broken exit_code (always 0) */
+ { "xdg-open", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
+ { "sensible-browser", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
+ { "htmlview", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
+#endif
+ /* direct browser invocation */
+ { "x-www-browser", NULL, "", "", 1 }, /* opens in foreground, browser alias */
+ { "firefox", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "mozilla-firefox", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "mozilla", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "konqueror", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "opera", "-newwindow", "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "galeon", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "epiphany", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "amaya", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ { "dillo", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
+ };
+ uint i;
+ for (i = 0; i < G_N_ELEMENTS (www_browsers); i++)
+ if (!www_browsers[i].disabled)
+ {
+ char *args[128] = { 0, };
+ uint n = 0;
+ args[n++] = (char*) www_browsers[i].prg;
+ if (www_browsers[i].arg1)
+ args[n++] = (char*) www_browsers[i].arg1;
+ char *string = g_strconcat (www_browsers[i].prefix, url, www_browsers[i].postfix, NULL);
+ args[n] = string;
+ GError *error = NULL;
+ char fallback_error[64] = "Ok";
+ bool success;
+ if (!www_browsers[i].asyncronous) /* start syncronously and check exit code */
+ {
+ int exit_status = -1;
+ success = g_spawn_sync (NULL, /* cwd */
+ args,
+ NULL, /* envp */
+ G_SPAWN_SEARCH_PATH,
+ NULL, /* child_setup() */
+ NULL, /* user_data */
+ NULL, /* standard_output */
+ NULL, /* standard_error */
+ &exit_status,
+ &error);
+ success = success && !exit_status;
+ if (exit_status)
+ g_snprintf (fallback_error, sizeof (fallback_error), "exitcode: %u", exit_status);
+ }
+ else
+ success = g_spawn_async (NULL, /* cwd */
+ args,
+ NULL, /* envp */
+ G_SPAWN_SEARCH_PATH,
+ NULL, /* child_setup() */
+ NULL, /* user_data */
+ NULL, /* child_pid */
+ &error);
+ g_free (string);
+ Msg::display (debug_browser, "show \"%s\": %s: %s", url, args[0], error ? error->message : fallback_error);
+ g_clear_error (&error);
+ if (success)
+ return true;
+ www_browsers[i].disabled = true;
+ }
+ /* reset all disabled states if no browser could be found */
+ for (i = 0; i < G_N_ELEMENTS (www_browsers); i++)
+ www_browsers[i].disabled = false;
+ return false;
+}
+
} // OS
// permissions
diff --git a/birnet/birnetoswin32.cc b/birnet/birnetoswin32.cc
index d3abb15..7edd060 100644
--- a/birnet/birnetoswin32.cc
+++ b/birnet/birnetoswin32.cc
@@ -18,6 +18,7 @@
#include <glib.h>
#include <glib/gprintf.h>
#include <process.h>
+#include <windows.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
@@ -153,6 +154,14 @@ mkdir (const char *path,
return ::mkdir (path);
}
+bool
+url_test_show (const char *url)
+{
+ int r = (int) ShellExecute (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
+ // ShellExecute returns a value greater that 32 on success
+ return (r > 32);
+}
+
} // OS
/* fake permissions */
diff --git a/birnet/birnetutils.cc b/birnet/birnetutils.cc
index d44bcd1..ea7aa70 100644
--- a/birnet/birnetutils.cc
+++ b/birnet/birnetutils.cc
@@ -1097,92 +1097,6 @@ DataList::~DataList()
}
/* --- url handling --- */
-bool
-url_test_show (const char *url)
-{
- static struct {
- const char *prg, *arg1, *prefix, *postfix;
- bool asyncronous; /* start asyncronously and check exit code to catch launch errors */
- volatile bool disabled;
- } www_browsers[] = {
- /* program */ /* arg1 */ /* prefix+URL+postfix */
- /* configurable, working browser launchers */
- { "gnome-open", NULL, "", "", 0 }, /* opens in background, correct exit_code */
- { "exo-open", NULL, "", "", 0 }, /* opens in background, correct exit_code */
- /* non-configurable working browser launchers */
- { "kfmclient", "openURL", "", "", 0 }, /* opens in background, correct exit_code */
- { "gnome-moz-remote", "--newwin", "", "", 0 }, /* opens in background, correct exit_code */
-#if 0
- /* broken/unpredictable browser launchers */
- { "browser-config", NULL, "", "", 0 }, /* opens in background (+ sleep 5), broken exit_code (always 0) */
- { "xdg-open", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
- { "sensible-browser", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
- { "htmlview", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */
-#endif
- /* direct browser invocation */
- { "x-www-browser", NULL, "", "", 1 }, /* opens in foreground, browser alias */
- { "firefox", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- { "mozilla-firefox", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- { "mozilla", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- { "konqueror", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- { "opera", "-newwindow", "", "", 1 }, /* opens in foreground, correct exit_code */
- { "galeon", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- { "epiphany", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- { "amaya", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- { "dillo", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */
- };
- uint i;
- for (i = 0; i < G_N_ELEMENTS (www_browsers); i++)
- if (!www_browsers[i].disabled)
- {
- char *args[128] = { 0, };
- uint n = 0;
- args[n++] = (char*) www_browsers[i].prg;
- if (www_browsers[i].arg1)
- args[n++] = (char*) www_browsers[i].arg1;
- char *string = g_strconcat (www_browsers[i].prefix, url, www_browsers[i].postfix, NULL);
- args[n] = string;
- GError *error = NULL;
- char fallback_error[64] = "Ok";
- bool success;
- if (!www_browsers[i].asyncronous) /* start syncronously and check exit code */
- {
- int exit_status = -1;
- success = g_spawn_sync (NULL, /* cwd */
- args,
- NULL, /* envp */
- G_SPAWN_SEARCH_PATH,
- NULL, /* child_setup() */
- NULL, /* user_data */
- NULL, /* standard_output */
- NULL, /* standard_error */
- &exit_status,
- &error);
- success = success && !exit_status;
- if (exit_status)
- g_snprintf (fallback_error, sizeof (fallback_error), "exitcode: %u", exit_status);
- }
- else
- success = g_spawn_async (NULL, /* cwd */
- args,
- NULL, /* envp */
- G_SPAWN_SEARCH_PATH,
- NULL, /* child_setup() */
- NULL, /* user_data */
- NULL, /* child_pid */
- &error);
- g_free (string);
- Msg::display (debug_browser, "show \"%s\": %s: %s", url, args[0], error ? error->message : fallback_error);
- g_clear_error (&error);
- if (success)
- return true;
- www_browsers[i].disabled = true;
- }
- /* reset all disabled states if no browser could be found */
- for (i = 0; i < G_N_ELEMENTS (www_browsers); i++)
- www_browsers[i].disabled = false;
- return false;
-}
static void
browser_launch_warning (const char *url)
@@ -1197,7 +1111,7 @@ browser_launch_warning (const char *url)
void
url_show (const char *url)
{
- bool success = url_test_show (url);
+ bool success = OS::url_test_show (url);
if (!success)
browser_launch_warning (url);
}
@@ -1270,9 +1184,9 @@ url_test_show_with_cookie (const char *url,
{
const char *redirect = url_create_redirect (url, url_title, cookie);
if (redirect)
- return url_test_show (redirect);
+ return OS::url_test_show (redirect);
else
- return url_test_show (url);
+ return OS::url_test_show (url);
}
void
diff --git a/birnet/birnetutils.hh b/birnet/birnetutils.hh
index 3b13549..a8f6fe4 100644
--- a/birnet/birnetutils.hh
+++ b/birnet/birnetutils.hh
@@ -185,7 +185,6 @@ void url_show (const char *url);
void url_show_with_cookie (const char *url,
const char *url_title,
const char *cookie);
-bool url_test_show (const char *url);
bool url_test_show_with_cookie (const char *url,
const char *url_title,
const char *cookie);
diff --git a/sfi/sfiwrapper.cc b/sfi/sfiwrapper.cc
index 3f7965f..dd029a7 100644
--- a/sfi/sfiwrapper.cc
+++ b/sfi/sfiwrapper.cc
@@ -273,7 +273,7 @@ sfi_url_show_with_cookie (const char *url,
bool
sfi_url_test_show (const char *url)
{
- return Birnet::url_test_show (url);
+ return Birnet::OS::url_test_show (url);
}
bool
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]