awt_Desktop.c 3.4 KB
Newer Older
D
duke 已提交
1
/*
O
ohair 已提交
2
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Oracle designates this
D
duke 已提交
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Oracle in the LICENSE file that accompanied this code.
D
duke 已提交
10 11 12 13 14 15 16 17 18 19 20
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
21 22 23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
24 25 26 27 28 29 30
 */

#include <jni.h>
#include <dlfcn.h>

typedef int gboolean;

A
art 已提交
31 32 33 34 35
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;
D
duke 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49

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");
#endif
        return 0;
    }
    dlerror(); /* Clear errors */
A
art 已提交
50
    gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init");
D
duke 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    if ((errmsg = dlerror()) != NULL) {
#ifdef INTERNAL_BUILD
        fprintf(stderr, "can not find symble gnome_vfs_init\n");
#endif
        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 load libgnome-2.so\n");
#endif
        return 0;
    }
    dlerror(); /* Clear errors */
A
art 已提交
68
    gnome_url_show = (GNOME_URL_SHOW_TYPE*)dlsym(gnome_handle, "gnome_url_show");
D
duke 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    if ((errmsg = dlerror()) != NULL) {
#ifdef INTERNAL_BUILD
        fprintf(stderr, "can not find symble gnome_url_show\n");
#endif
        return 0;
    }

    return 1;
}

/*
 * Class:     sun_awt_X11_XDesktopPeer
 * Method:    init
 * Signature: ()Z
 */
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init
  (JNIEnv *env, jclass cls)
{
    int init_ok = init();
    return init_ok ? JNI_TRUE : JNI_FALSE;
}

/*
 * Class:     sun_awt_X11_XDesktopPeer
 * Method:    gnome_url_show
 * Signature: (Ljava/lang/[B;)Z
 */
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show
  (JNIEnv *env, jobject obj, jbyteArray url_j)
{
    gboolean success;
A
art 已提交
100
    const char* url_c;
D
duke 已提交
101

A
art 已提交
102 103 104
    if (gnome_url_show == NULL) {
        return JNI_FALSE;
    }
D
duke 已提交
105

A
art 已提交
106
    url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
D
duke 已提交
107 108 109 110 111 112
    // 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;
}