J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | #include <jni.h> |
| 27 | #include <dlfcn.h> |
| 28 | |
| 29 | typedef int gboolean; |
| 30 | |
| 31 | gboolean (*gnome_url_show) (const char *url, void **error); |
| 32 | |
| 33 | int init(){ |
| 34 | void *vfs_handle; |
| 35 | void *gnome_handle; |
| 36 | gboolean (*gnome_vfs_init) (void); |
| 37 | const char *errmsg; |
| 38 | |
| 39 | vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY); |
| 40 | if (vfs_handle == NULL) { |
| 41 | #ifdef INTERNAL_BUILD |
| 42 | fprintf(stderr, "can not load libgnomevfs-2.so\n"); |
| 43 | #endif |
| 44 | return 0; |
| 45 | } |
| 46 | dlerror(); /* Clear errors */ |
| 47 | gnome_vfs_init = dlsym(vfs_handle, "gnome_vfs_init"); |
| 48 | if ((errmsg = dlerror()) != NULL) { |
| 49 | #ifdef INTERNAL_BUILD |
| 50 | fprintf(stderr, "can not find symble gnome_vfs_init\n"); |
| 51 | #endif |
| 52 | return 0; |
| 53 | } |
| 54 | // call gonme_vfs_init() |
| 55 | (*gnome_vfs_init)(); |
| 56 | |
| 57 | gnome_handle = dlopen("libgnome-2.so.0", RTLD_LAZY); |
| 58 | if (gnome_handle == NULL) { |
| 59 | #ifdef INTERNAL_BUILD |
| 60 | fprintf(stderr, "can not load libgnome-2.so\n"); |
| 61 | #endif |
| 62 | return 0; |
| 63 | } |
| 64 | dlerror(); /* Clear errors */ |
| 65 | gnome_url_show = dlsym(gnome_handle, "gnome_url_show"); |
| 66 | if ((errmsg = dlerror()) != NULL) { |
| 67 | #ifdef INTERNAL_BUILD |
| 68 | fprintf(stderr, "can not find symble gnome_url_show\n"); |
| 69 | #endif |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Class: sun_awt_X11_XDesktopPeer |
| 78 | * Method: init |
| 79 | * Signature: ()Z |
| 80 | */ |
| 81 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init |
| 82 | (JNIEnv *env, jclass cls) |
| 83 | { |
| 84 | int init_ok = init(); |
| 85 | return init_ok ? JNI_TRUE : JNI_FALSE; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Class: sun_awt_X11_XDesktopPeer |
| 90 | * Method: gnome_url_show |
| 91 | * Signature: (Ljava/lang/[B;)Z |
| 92 | */ |
| 93 | JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show |
| 94 | (JNIEnv *env, jobject obj, jbyteArray url_j) |
| 95 | { |
| 96 | gboolean success; |
| 97 | |
| 98 | const char* url_c = (*env)->GetByteArrayElements(env, url_j, NULL); |
| 99 | |
| 100 | if (gnome_url_show == NULL) return JNI_FALSE; |
| 101 | |
| 102 | // call gnome_url_show(const char* , GError**) |
| 103 | success = (*gnome_url_show)(url_c, NULL); |
| 104 | |
| 105 | (*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0); |
| 106 | |
| 107 | return success ? JNI_TRUE : JNI_FALSE; |
| 108 | } |