1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gnome-open-url.c,v $
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 ************************************************************************/
39 typedef struct _GError GError
;
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 */
65 gchar
* (* g_strdup
)(const gchar
*) = (gchar
* (*)(const gchar
*)) dlsym(handle
, "g_strdup");
68 return g_strdup("/apps/gnome-settings/gnome-open-url");
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
);
83 (void)error
; /* avoid warning due to unused parameter */
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");
96 ret
= (GNOME_VFS_OK
== func(url
));
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
;
118 fprintf( stderr
, "Usage: gnome-open-url <uri>\n" );
122 if( gnome_url_show(argv
[1], &error
) )
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");
138 strncpy(index
, "open-url", 9);
142 return execv(fallback
, args
);