Added the OS dependent function subsurface_launch_for_uri()

Opening URI addresses from Subsurface does not work on Windows using
the latest GTK bundle from the Gnome website. The reason lies in GIO
and GLib and how it obtains assigned applications for protocols and MIME
types.

While gtk_show_uri() should be viable for both linux.c and macos.c,
in windows.c ShellExecute() is used, which provides proper support
for the URI calls.

subsurface_launch_for_uri() returns TRUE on success.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2013-01-15 01:20:29 +02:00 committed by Dirk Hohndel
parent 2330f9b379
commit 678fffdcf4
4 changed files with 33 additions and 0 deletions

1
dive.h
View file

@ -583,6 +583,7 @@ typedef enum {
extern const char *existing_filename;
extern const char *subsurface_gettext_domainpath(char *);
extern gboolean subsurface_os_feature_available(os_feature_t);
extern gboolean subsurface_launch_for_uri(const char *);
extern void subsurface_command_line_init(gint *, gchar ***);
extern void subsurface_command_line_exit(gint *, gchar ***);

12
linux.c
View file

@ -176,3 +176,15 @@ gboolean subsurface_os_feature_available(os_feature_t f)
{
return TRUE;
}
gboolean subsurface_launch_for_uri(const char* uri)
{
GError *err = NULL;
gtk_show_uri(NULL, uri, gtk_get_current_event_time(), &err);
if (err) {
g_message("%s: %s", err->message, uri);
g_error_free(err);
return FALSE;
}
return TRUE;
}

12
macos.c
View file

@ -220,3 +220,15 @@ gboolean subsurface_os_feature_available(os_feature_t f)
{
return TRUE;
}
gboolean subsurface_launch_for_uri(const char* uri)
{
GError *err = NULL;
gtk_show_uri(NULL, uri, gtk_get_current_event_time(), &err);
if (err) {
g_message("%s: %s", err->message, uri);
g_error_free(err);
return FALSE;
}
return TRUE;
}

View file

@ -298,6 +298,14 @@ void subsurface_command_line_exit(gint *argc, gchar ***argv)
g_free(*argv);
}
gboolean subsurface_launch_for_uri(const char* uri)
{
if ((INT_PTR)ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNORMAL) > 32)
return TRUE;
g_message("ShellExecute failed for: %s", uri);
return FALSE;
}
/* check if we are running a newer OS version */
gboolean subsurface_os_feature_available(os_feature_t f)
{