3 * This file is part of Evince
5 * Copyright (C) 2005 - Paolo Maggi
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* This is a modified version of ephy-module.c from Epiphany source code.
24 * Here the original copyright assignment:
26 * Copyright (C) 2003 Marco Pesenti Gritti
27 * Copyright (C) 2003, 2004 Christian Persch
32 * Modified by the gedit Team, 2005. See the AUTHORS file for a
33 * list of people on the gedit Team.
34 * See the ChangeLog files for a list of changes.
36 * $Id: gedit-module.c 5367 2006-12-17 14:29:49Z pborelli $
39 /* Modified by evince team */
43 #include "ev-module.h"
47 typedef struct _EvModuleClass EvModuleClass;
49 struct _EvModuleClass {
50 GTypeModuleClass parent_class;
54 GTypeModule parent_instance;
62 typedef GType (*EvModuleRegisterFunc) (GTypeModule *);
64 static void ev_module_init (EvModule *action);
65 static void ev_module_class_init (EvModuleClass *class);
67 G_DEFINE_TYPE (EvModule, ev_module, G_TYPE_TYPE_MODULE)
70 ev_module_load (GTypeModule *gmodule)
72 EvModule *module = EV_MODULE (gmodule);
73 EvModuleRegisterFunc register_func;
75 module->library = g_module_open (module->path, 0);
77 if (!module->library) {
78 g_warning (g_module_error ());
83 /* extract symbols from the lib */
84 if (!g_module_symbol (module->library, "register_evince_backend",
85 (void *) ®ister_func)) {
86 g_warning (g_module_error ());
87 g_module_close (module->library);
92 /* symbol can still be NULL even though g_module_symbol
95 g_warning ("Symbol 'register_evince_backend' should not be NULL");
96 g_module_close (module->library);
101 module->type = register_func (gmodule);
103 if (module->type == 0) {
104 g_warning ("Invalid evince backend contained by module %s", module->path);
113 ev_module_unload (GTypeModule *gmodule)
115 EvModule *module = EV_MODULE (gmodule);
117 g_module_close (module->library);
119 module->library = NULL;
124 ev_module_get_path (EvModule *module)
126 g_return_val_if_fail (EV_IS_MODULE (module), NULL);
132 ev_module_new_object (EvModule *module)
134 g_return_val_if_fail (EV_IS_MODULE (module), NULL);
136 if (module->type == 0)
139 return g_object_new (module->type, NULL);
143 ev_module_get_object_type (EvModule *module)
145 g_return_val_if_fail (EV_IS_MODULE (module), 0);
151 ev_module_init (EvModule *module)
156 ev_module_finalize (GObject *object)
158 EvModule *module = EV_MODULE (object);
160 g_free (module->path);
162 G_OBJECT_CLASS (ev_module_parent_class)->finalize (object);
166 ev_module_class_init (EvModuleClass *class)
168 GObjectClass *object_class = G_OBJECT_CLASS (class);
169 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
171 object_class->finalize = ev_module_finalize;
173 module_class->load = ev_module_load;
174 module_class->unload = ev_module_unload;
178 ev_module_new (const gchar *path)
182 g_return_val_if_fail (path != NULL && path[0] != '\0', NULL);
184 result = g_object_new (EV_TYPE_MODULE, NULL);
186 g_type_module_set_name (G_TYPE_MODULE (result), path);
187 result->path = g_strdup (path);