1
/* -*- Mode: C; c-basic-offset: 4 -*-
2
* libglade - a library for building interfaces from XML files at runtime
3
* Copyright (C) 1998-2002 James Henstridge <james@daa.com.au>
5
* glade-init.c: initialisation functions for libglade
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
30
#include <pango/pango-utils.h>
32
#include "glade-init.h"
33
#include "glade-build.h"
34
#include "glade-private.h"
37
guint _glade_debug_flags = 0;
38
static const GDebugKey libglade_debug_keys[] = {
39
{ "parser", GLADE_DEBUG_PARSER },
40
{ "build", GLADE_DEBUG_BUILD },
42
static const guint libglade_ndebug_keys = G_N_ELEMENTS(libglade_debug_keys);
46
void _glade_init_gtk_widgets (void);
51
* It used to be necessary to call glade_init() before creating
52
* GladeXML objects. This is now no longer the case, as libglade will
53
* be initialised on demand now. Calling glade_init() manually will
54
* not cause any problems though.
59
static gboolean initialised = FALSE;
61
const gchar *env_string;
64
if (initialised) return;
66
_glade_init_gtk_widgets();
69
env_string = g_getenv("LIBGLADE_DEBUG");
70
if (env_string != NULL) {
71
_glade_debug_flags = g_parse_debug_string (env_string,
73
libglade_ndebug_keys);
81
glade_module_check_version(gint version)
83
if (version != GLADE_MODULE_API_VERSION)
84
return "Wrong plugin API version";
89
static GPtrArray *loaded_packages = NULL;
92
get_module_path (void)
94
const gchar *module_path_env = g_getenv ("LIBGLADE_MODULE_PATH");
95
const gchar *exe_prefix = g_getenv("LIBGLADE_EXE_PREFIX");
101
default_dir = g_build_filename (exe_prefix, "lib", NULL);
103
default_dir = g_strdup (GLADE_LIBDIR);
105
module_path = g_strconcat (module_path_env ? module_path_env : "",
106
module_path_env ? G_SEARCHPATH_SEPARATOR_S : "",
109
result = pango_split_file_list (module_path);
111
g_free (default_dir);
112
g_free (module_path);
118
find_module (gchar **module_path,
126
if (g_path_is_absolute (name))
127
return g_module_open (name, G_MODULE_BIND_LAZY);
129
for (i = 0; module_path[i]; i++) {
130
gchar *version_directory;
132
#ifndef G_OS_WIN32 /* ignoring GTK_BINARY_VERSION elsewhere too */
133
version_directory = g_build_filename (module_path[i], subdir, NULL);
134
module_name = g_module_build_path (version_directory, name);
135
g_free (version_directory);
137
/*g_print ("trying: %s\n", module_name);*/
139
if (g_file_test (module_name, G_FILE_TEST_EXISTS)) {
140
module = g_module_open (module_name, G_MODULE_BIND_LAZY);
141
g_free (module_name);
145
g_free (module_name);
148
module_name = g_module_build_path (module_path[i], name);
150
if (g_file_test (module_name, G_FILE_TEST_EXISTS)) {
151
module = g_module_open (module_name, G_MODULE_BIND_LAZY);
152
g_free (module_name);
156
g_free (module_name);
159
/* As last resort, try loading without an absolute path (using system
162
module_name = g_module_build_path (NULL, name);
163
module = g_module_open (module_name, G_MODULE_BIND_LAZY);
171
* @library: the required library
173
* Ensure that a required library is available. If it is not already
174
* available, libglade will attempt to dynamically load a module that
175
* contains the handlers for that library.
179
glade_require(const gchar *library)
181
gboolean already_loaded = FALSE;
183
void (* init_func)(void);
184
static char **module_path = NULL;
186
/* a call to glade_init here to make sure libglade is initialised */
189
if (loaded_packages) {
192
for (i = 0; i < loaded_packages->len; i++)
193
if (!strcmp(library, g_ptr_array_index(loaded_packages, i))) {
194
already_loaded = TRUE;
203
module_path = get_module_path ();
205
module = find_module (module_path, "libglade/2.0", library);
208
g_warning("Could not load support for `%s': %s", library,
213
if (!g_module_symbol(module, "glade_module_register_widgets",
214
(gpointer)&init_func)) {
215
g_warning("could not find `%s' init function: %s", library,
217
g_module_close(module);
222
g_module_make_resident(module);
227
* @library: the provided library
229
* This function should be called by a module to assert that it
230
* provides wrappers for a particular library. This should be called
231
* by the register_widgets() function of a libglade module so that it
232
* isn't loaded twice, for instance.
236
glade_provide(const gchar *library)
238
gboolean already_loaded = FALSE;
241
if (!loaded_packages)
242
loaded_packages = g_ptr_array_new();
244
for (i = 0; i < loaded_packages->len; i++)
245
if (!strcmp(library, g_ptr_array_index(loaded_packages, i))) {
246
already_loaded = TRUE;
251
g_ptr_array_add(loaded_packages, g_strdup(library));
255
* GLADE_MODULE_CHECK_INIT:
257
* This macro will insert a suitable version check function into a
258
* libglade loadable module.