changeset 4540:6e4576191cff

Use GIO in preference to Gnome-VFS to open URLs in java.awt.Desktop when available
author andrew
date Wed, 31 Aug 2011 04:28:42 +0100
parents a66317d3a7fe
children 95946d35b704
files make/sun/xawt/FILES_c_unix.gmk make/sun/xawt/Makefile src/solaris/native/common/deps/glib2/gio/gio.h src/solaris/native/common/deps/glib2/gio_fp.c src/solaris/native/common/deps/glib2/gio_fp.h src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c src/solaris/native/sun/xawt/awt_Desktop.c
diffstat 7 files changed, 97 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/make/sun/xawt/FILES_c_unix.gmk	Wed Aug 24 18:04:16 2011 +0100
+++ b/make/sun/xawt/FILES_c_unix.gmk	Wed Aug 31 04:28:42 2011 +0100
@@ -98,3 +98,8 @@
 FILES_c += \
 	fontconfig_fp.c
 endif
+
+ifndef USE_SYSTEM_GIO
+FILES_c += \
+	gio_fp.c
+endif
--- a/make/sun/xawt/Makefile	Wed Aug 24 18:04:16 2011 +0100
+++ b/make/sun/xawt/Makefile	Wed Aug 31 04:28:42 2011 +0100
@@ -92,6 +92,10 @@
 vpath %.c   $(PLATFORM_SRC)/native/sun/java2d/opengl
 vpath %.c   $(PLATFORM_SRC)/native/sun/java2d/x11
 
+ifndef USE_SYSTEM_GIO
+vpath %.c   $(PLATFORM_SRC)/native/common/deps/glib2
+endif
+
 ifndef USE_SYSTEM_GTK
 vpath %.c   $(PLATFORM_SRC)/native/common/deps/gtk2
 endif
@@ -119,6 +123,10 @@
   OTHER_LDLIBS += $(FONTCONFIG_LIBS)
 endif
 
+ifdef USE_SYSTEM_GIO
+  OTHER_LDLIBS += $(GIO_LIBS)
+endif
+
 ifeq  ($(PLATFORM), solaris)
 CPPFLAGS += -DFUNCPROTO=15
 dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
@@ -174,6 +182,12 @@
   CPPFLAGS += -I$(PLATFORM_SRC)/native/common/deps/fontconfig2
 endif
 
+ifdef USE_SYSTEM_GIO
+  CPPFLAGS += $(GIO_CFLAGS) -DUSE_SYSTEM_GIO
+else
+  CPPFLAGS += -I$(PLATFORM_SRC)/native/common/deps/glib2
+endif
+
 ifeq ($(PLATFORM), linux)
   ifndef CROSS_COMPILE_ARCH
     # Allows for builds on Debian GNU Linux, X11 is in a different place 
--- a/src/solaris/native/common/deps/glib2/gio/gio.h	Wed Aug 24 18:04:16 2011 +0100
+++ b/src/solaris/native/common/deps/glib2/gio/gio.h	Wed Aug 31 04:28:42 2011 +0100
@@ -31,10 +31,13 @@
 #define G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "standard::content-type"
 
 typedef void* gpointer;
+typedef int    gint;
+typedef gint   gboolean;
 typedef struct _GFile GFile;
 typedef struct _GFileInfo GFileInfo;
 typedef struct _GCancellable GCancellable;
 typedef struct _GError GError;
+typedef struct _GAppLaunchContext GAppLaunchContext;
 
 typedef enum {
   G_FILE_QUERY_INFO_NONE = 0
@@ -47,5 +50,8 @@
     const char *attributes, GFileQueryInfoFlags flags,
     GCancellable *cancellable, GError **error);
 typedef char* (*file_info_get_content_type_func)(GFileInfo *info);
+typedef gboolean  (*app_info_launch_default_for_uri_func)(const char              *uri,
+							  GAppLaunchContext       *launch_context,
+							  GError                 **error);
 
 #endif
--- a/src/solaris/native/common/deps/glib2/gio_fp.c	Wed Aug 24 18:04:16 2011 +0100
+++ b/src/solaris/native/common/deps/glib2/gio_fp.c	Wed Aug 31 04:28:42 2011 +0100
@@ -33,8 +33,9 @@
 file_new_for_path_func file_new_for_path;
 file_query_info_func file_query_info;
 file_info_get_content_type_func file_info_get_content_type;
+app_info_launch_default_for_uri_func app_info_launch_default_for_uri;
 
-jboolean init()
+jboolean gio_init()
 {
     void* gio_handle;
 
@@ -60,12 +61,15 @@
     file_info_get_content_type = (file_info_get_content_type_func)
         dlsym(gio_handle, "g_file_info_get_content_type");
 
+    app_info_launch_default_for_uri = (app_info_launch_default_for_uri_func)
+	dlsym (gio_handle, "g_app_info_launch_default_for_uri");
 
-    if (g_type_init == NULL ||
-        g_object_unref == NULL ||
-        g_file_new_for_path == NULL ||
-        g_file_query_info == NULL ||
-        g_file_info_get_content_type == NULL)
+    if (type_init == NULL ||
+        object_unref == NULL ||
+        file_new_for_path == NULL ||
+        file_query_info == NULL ||
+        file_info_get_content_type == NULL ||
+	app_info_launch_default_for_uri == NULL)
     {
         dlclose(gio_handle);
         return JNI_FALSE;
--- a/src/solaris/native/common/deps/glib2/gio_fp.h	Wed Aug 24 18:04:16 2011 +0100
+++ b/src/solaris/native/common/deps/glib2/gio_fp.h	Wed Aug 31 04:28:42 2011 +0100
@@ -33,13 +33,15 @@
 extern file_new_for_path_func file_new_for_path;
 extern file_query_info_func file_query_info;
 extern file_info_get_content_type_func file_info_get_content_type;
+extern app_info_launch_default_for_uri_func app_info_launch_default_for_uri;
 
 #define g_type_init (*type_init)
 #define g_object_unref (*object_unref)
 #define g_file_new_for_path (*file_new_for_path)
 #define g_file_query_info (*file_query_info)
 #define g_file_info_get_content_type (*file_info_get_content_type)
+#define g_app_info_launch_default_for_uri (*app_info_launch_default_for_uri)
 
-jboolean init();
+jboolean gio_init();
 
 #endif
--- a/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c	Wed Aug 24 18:04:16 2011 +0100
+++ b/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c	Wed Aug 31 04:28:42 2011 +0100
@@ -67,7 +67,7 @@
 #ifdef USE_SYSTEM_GIO
     ret = JNI_TRUE;
 #else
-    ret = init();
+    ret = gio_init();
 #endif
 
     g_type_init ();
--- a/src/solaris/native/sun/xawt/awt_Desktop.c	Wed Aug 24 18:04:16 2011 +0100
+++ b/src/solaris/native/sun/xawt/awt_Desktop.c	Wed Aug 31 04:28:42 2011 +0100
@@ -26,57 +26,75 @@
 #include <jni.h>
 #include <dlfcn.h>
 
+#include <gio/gio.h>
+
+#ifndef USE_SYSTEM_GIO
+#include <gio_fp.h>
+#endif
+
 typedef int gboolean;
 
 typedef gboolean (GNOME_URL_SHOW_TYPE)(const char *, void **);
 typedef gboolean (GNOME_VFS_INIT_TYPE)(void);
-
+				      
 GNOME_URL_SHOW_TYPE *gnome_url_show;
 GNOME_VFS_INIT_TYPE *gnome_vfs_init;
 
+jboolean use_gio;
+
 int init(){
     void *vfs_handle;
     void *gnome_handle;
     const char *errmsg;
 
-    vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
-    if (vfs_handle == NULL) {
-#ifdef INTERNAL_BUILD
-        fprintf(stderr, "can not load libgnomevfs-2.so\n");
+#ifdef USE_SYSTEM_GIO
+    use_gio = JNI_TRUE;
+#else
+    use_gio = gio_init();
 #endif
-        return 0;
-    }
-    dlerror(); /* Clear errors */
-    gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init");
-    if (gnome_vfs_init == NULL){
+
+    if (use_gio == JNI_TRUE) {
+        g_type_init();
+    } else {
+	vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
+	if (vfs_handle == NULL) {
 #ifdef INTERNAL_BUILD
-        fprintf(stderr, "dlsym( gnome_vfs_init) returned NULL\n");
+	    fprintf(stderr, "can not load libgnomevfs-2.so\n");
 #endif
-        return 0;
-    }
-    if ((errmsg = dlerror()) != NULL) {
+	    return 0;
+	}
+	dlerror(); /* Clear errors */
+	gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init");
+	if (gnome_vfs_init == NULL){
 #ifdef INTERNAL_BUILD
-        fprintf(stderr, "can not find symbol gnome_vfs_init %s \n", errmsg);
+	    fprintf(stderr, "dlsym( gnome_vfs_init) returned NULL\n");
 #endif
-        return 0;
-    }
-    // call gonme_vfs_init()
-    (*gnome_vfs_init)();
-
-    gnome_handle = dlopen("libgnome-2.so.0", RTLD_LAZY);
-    if (gnome_handle == NULL) {
+	    return 0;
+	}
+	if ((errmsg = dlerror()) != NULL) {
 #ifdef INTERNAL_BUILD
-        fprintf(stderr, "can not load libgnome-2.so\n");
+	    fprintf(stderr, "can not find symbol gnome_vfs_init %s \n", errmsg);
 #endif
-        return 0;
-    }
-    dlerror(); /* Clear errors */
-    gnome_url_show = (GNOME_URL_SHOW_TYPE*)dlsym(gnome_handle, "gnome_url_show");
-    if ((errmsg = dlerror()) != NULL) {
+	    return 0;
+	}
+	// call gonme_vfs_init()
+	(*gnome_vfs_init)();
+	
+	gnome_handle = dlopen("libgnome-2.so.0", RTLD_LAZY);
+	if (gnome_handle == NULL) {
 #ifdef INTERNAL_BUILD
-        fprintf(stderr, "can not find symble gnome_url_show\n");
+	    fprintf(stderr, "can not load libgnome-2.so\n");
 #endif
-        return 0;
+	    return 0;
+	}
+	dlerror(); /* Clear errors */
+	gnome_url_show = (GNOME_URL_SHOW_TYPE*)dlsym(gnome_handle, "gnome_url_show");
+	if ((errmsg = dlerror()) != NULL) {
+#ifdef INTERNAL_BUILD
+	    fprintf(stderr, "can not find symbol gnome_url_show\n");
+#endif
+	    return 0;
+	}
     }
 
     return 1;
@@ -105,14 +123,17 @@
     gboolean success;
     const char* url_c;
 
-    if (gnome_url_show == NULL) {
-        return JNI_FALSE;
-    }
+    url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
+    if (use_gio) {
+	success = g_app_info_launch_default_for_uri (url_c, NULL, NULL);
+    } else {
+	if (gnome_url_show == NULL) {
+	    return JNI_FALSE;
+	}
 
-    url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
-    // call gnome_url_show(const char* , GError**)
-    success = (*gnome_url_show)(url_c, NULL);
+	// call gnome_url_show(const char* , GError**)
+	success = (*gnome_url_show)(url_c, NULL);
+    }
     (*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0);
-
     return success ? JNI_TRUE : JNI_FALSE;
 }