merge the formfield patch from ooo-build
[ooovba.git] / shell / source / unix / misc / gnome-open-url.c
blob891edc630b94c39994f7b68e812e65af2fc0b9a0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gnome-open-url.c,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <dlfcn.h>
34 #include <string.h>
35 #include <unistd.h>
37 typedef int gboolean;
38 typedef char gchar;
39 typedef struct _GError GError;
41 struct _GError
43 int domain;
44 int code;
45 char *message;
48 typedef enum {
49 GNOME_VFS_OK
50 } GnomeVFSResult;
54 * HACK: avoid error messages caused by not setting a GNOME program name
57 gchar* gnome_gconf_get_gnome_libs_settings_relative (const gchar *subkey)
59 void* handle = dlopen("libglib-2.0.so.0", RTLD_LAZY);
61 (void)subkey; /* avoid warning due to unused parameter */
63 if( NULL != handle )
65 gchar* (* g_strdup)(const gchar*) = (gchar* (*)(const gchar*)) dlsym(handle, "g_strdup");
67 if( NULL != g_strdup)
68 return g_strdup("/apps/gnome-settings/gnome-open-url");
71 return NULL;
75 * Wrapper function which extracs gnome_url_show from libgnome
78 gboolean gnome_url_show (const char *url, GError **error)
80 void* handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
81 gboolean ret = 0;
83 (void)error; /* avoid warning due to unused parameter */
85 if( NULL != handle )
87 gboolean (* init) (void) =
88 (gboolean (*) (void)) dlsym(handle, "gnome_vfs_init");
90 if( NULL != init && init() )
92 GnomeVFSResult (* func) (const char *url) =
93 (GnomeVFSResult (*) (const char *)) dlsym(handle, "gnome_vfs_url_show");
95 if( NULL != func )
96 ret = (GNOME_VFS_OK == func(url));
99 dlclose(handle);
102 return ret;
106 * The intended use of this tool is to pass the argument to
107 * the gnome_show_url function of libgnome2.
110 int main(int argc, char *argv[] )
112 GError *error = NULL;
113 char *fallback;
114 char *index;
116 if( argc != 2 )
118 fprintf( stderr, "Usage: gnome-open-url <uri>\n" );
119 return -1;
122 if( gnome_url_show(argv[1], &error) )
124 return 0;
128 * launch open-url command by replacing gnome-open-url from
129 * the command line. This is the fallback when running on
130 * remote machines with no GNOME installed.
133 fallback = strdup(argv[0]);
134 index = strstr(fallback, "gnome-open-url");
135 if ( NULL != index )
137 char *args[3];
138 strncpy(index, "open-url", 9);
139 args[0] = fallback;
140 args[1] = argv[1];
141 args[2] = NULL;
142 return execv(fallback, args);
145 return -1;