2003-11-23 23:35:27 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2001-10-19 01:27:36 +08:00
|
|
|
*
|
2002-10-21 22:15:02 +08:00
|
|
|
* gimpmodule.c
|
2001-10-19 01:27:36 +08:00
|
|
|
* (C) 1999 Austin Donnelly <austin@gimp.org>
|
|
|
|
*
|
2003-11-23 23:35:27 +08:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
2001-10-19 01:27:36 +08:00
|
|
|
*
|
2003-11-23 23:35:27 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2001-10-19 01:27:36 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-11-23 23:35:27 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-10-19 01:27:36 +08:00
|
|
|
*
|
2003-11-23 23:35:27 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2001-10-19 01:27:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2004-01-24 01:24:44 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
#include "gimpmodule.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-29 20:09:46 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MODIFIED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
static void gimp_module_class_init (GimpModuleClass *klass);
|
|
|
|
static void gimp_module_init (GimpModule *module);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
static void gimp_module_finalize (GObject *object);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
static gboolean gimp_module_load (GTypeModule *module);
|
|
|
|
static void gimp_module_unload (GTypeModule *module);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static gboolean gimp_module_open (GimpModule *module);
|
|
|
|
static gboolean gimp_module_close (GimpModule *module);
|
2002-10-21 22:15:02 +08:00
|
|
|
static void gimp_module_set_last_error (GimpModule *module,
|
|
|
|
const gchar *error_str);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
static guint module_signals[LAST_SIGNAL];
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static GTypeModuleClass *parent_class = NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_get_type (void)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
static GType module_type = 0;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
if (! module_type)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
static const GTypeInfo module_info =
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
sizeof (GimpModuleClass),
|
2001-10-19 01:27:36 +08:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2002-10-21 22:15:02 +08:00
|
|
|
(GClassInitFunc) gimp_module_class_init,
|
2001-10-19 01:27:36 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2002-10-21 22:15:02 +08:00
|
|
|
sizeof (GimpModule),
|
2001-10-19 01:27:36 +08:00
|
|
|
0, /* n_preallocs */
|
2002-10-21 22:15:02 +08:00
|
|
|
(GInstanceInitFunc) gimp_module_init,
|
2001-10-19 01:27:36 +08:00
|
|
|
};
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
module_type = g_type_register_static (G_TYPE_TYPE_MODULE,
|
|
|
|
"GimpModule",
|
|
|
|
&module_info, 0);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
return module_type;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_class_init (GimpModuleClass *klass)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GTypeModuleClass *module_class;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
module_class = G_TYPE_MODULE_CLASS (klass);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
module_signals[MODIFIED] =
|
2001-10-19 01:27:36 +08:00
|
|
|
g_signal_new ("modified",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2002-10-21 22:15:02 +08:00
|
|
|
G_STRUCT_OFFSET (GimpModuleClass, modified),
|
2001-10-19 01:27:36 +08:00
|
|
|
NULL, NULL,
|
2002-10-21 22:15:02 +08:00
|
|
|
g_cclosure_marshal_VOID__VOID,
|
2001-10-19 01:27:36 +08:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
object_class->finalize = gimp_module_finalize;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
module_class->load = gimp_module_load;
|
|
|
|
module_class->unload = gimp_module_unload;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
klass->modified = NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_init (GimpModule *module)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
module->filename = NULL;
|
|
|
|
module->verbose = FALSE;
|
|
|
|
module->state = GIMP_MODULE_STATE_ERROR;
|
|
|
|
module->on_disk = FALSE;
|
|
|
|
module->load_inhibit = FALSE;
|
|
|
|
|
|
|
|
module->module = NULL;
|
|
|
|
module->info = NULL;
|
|
|
|
module->last_module_error = NULL;
|
|
|
|
|
|
|
|
module->query_module = NULL;
|
|
|
|
module->register_module = NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_finalize (GObject *object)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
GimpModule *module;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
module = GIMP_MODULE (object);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
if (module->info)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_info_free (module->info);
|
|
|
|
module->info = NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
if (module->last_module_error)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
g_free (module->last_module_error);
|
|
|
|
module->last_module_error = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (module->filename)
|
|
|
|
{
|
|
|
|
g_free (module->filename);
|
|
|
|
module->filename = NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static gboolean
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_load (GTypeModule *module)
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
2004-07-07 00:05:32 +08:00
|
|
|
GimpModule *gimp_module;
|
|
|
|
gpointer func;
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_MODULE (module), FALSE);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module = GIMP_MODULE (module);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
g_return_val_if_fail (gimp_module->filename != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (gimp_module->module == NULL, FALSE);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
if (gimp_module->verbose)
|
2005-02-21 05:49:53 +08:00
|
|
|
{
|
|
|
|
gchar *name = g_filename_display_name (gimp_module->filename);
|
|
|
|
|
|
|
|
g_print (_("Loading module: '%s'\n"), name);
|
|
|
|
g_free (name);
|
|
|
|
}
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (! gimp_module_open (gimp_module))
|
2004-01-24 01:24:44 +08:00
|
|
|
return FALSE;
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (! gimp_module_query_module (gimp_module))
|
2004-01-24 01:24:44 +08:00
|
|
|
return FALSE;
|
2002-10-20 20:40:30 +08:00
|
|
|
|
|
|
|
/* find the gimp_module_register symbol */
|
2004-07-07 00:05:32 +08:00
|
|
|
if (! g_module_symbol (gimp_module->module, "gimp_module_register", &func))
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_set_last_error (gimp_module,
|
2002-10-21 23:16:47 +08:00
|
|
|
"Missing gimp_module_register() symbol");
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
if (gimp_module->verbose)
|
2003-11-15 20:36:09 +08:00
|
|
|
g_message (_("Module '%s' load error: %s"),
|
2004-01-24 01:24:44 +08:00
|
|
|
gimp_filename_to_utf8 (gimp_module->filename),
|
|
|
|
gimp_module->last_module_error);
|
2002-11-05 07:09:34 +08:00
|
|
|
|
|
|
|
gimp_module_close (gimp_module);
|
|
|
|
|
|
|
|
gimp_module->state = GIMP_MODULE_STATE_ERROR;
|
2004-01-14 10:03:37 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-07-03 02:01:19 +08:00
|
|
|
gimp_module->register_module = func;
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-11-05 07:09:34 +08:00
|
|
|
if (! gimp_module->register_module (module))
|
|
|
|
{
|
|
|
|
gimp_module_set_last_error (gimp_module,
|
|
|
|
"gimp_module_register() returned FALSE");
|
|
|
|
|
|
|
|
if (gimp_module->verbose)
|
2003-11-15 20:36:09 +08:00
|
|
|
g_message (_("Module '%s' load error: %s"),
|
2004-01-24 01:24:44 +08:00
|
|
|
gimp_filename_to_utf8 (gimp_module->filename),
|
|
|
|
gimp_module->last_module_error);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-11-05 07:09:34 +08:00
|
|
|
gimp_module_close (gimp_module);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-11-05 07:09:34 +08:00
|
|
|
gimp_module->state = GIMP_MODULE_STATE_LOAD_FAILED;
|
2004-01-14 10:03:37 +08:00
|
|
|
|
2002-11-05 07:09:34 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-11-06 21:56:37 +08:00
|
|
|
gimp_module->state = GIMP_MODULE_STATE_LOADED;
|
2004-01-14 10:03:37 +08:00
|
|
|
|
2002-11-05 07:09:34 +08:00
|
|
|
return TRUE;
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_unload (GTypeModule *module)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
GimpModule *gimp_module;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
g_return_if_fail (GIMP_IS_MODULE (module));
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module = GIMP_MODULE (module);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
g_return_if_fail (gimp_module->module != NULL);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
gimp_module_close (gimp_module);
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_new:
|
|
|
|
* @filename: The filename of a loadable module.
|
2003-02-07 05:17:12 +08:00
|
|
|
* @load_inhibit: Pass %TRUE to exclude this module from auto-loading.
|
|
|
|
* @verbose: Pass %TRUE to enable debugging output.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Creates a new #GimpModule instance.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Return value: The new #GimpModule object.
|
|
|
|
**/
|
2002-10-21 22:15:02 +08:00
|
|
|
GimpModule *
|
|
|
|
gimp_module_new (const gchar *filename,
|
2002-10-23 22:55:07 +08:00
|
|
|
gboolean load_inhibit,
|
2002-10-21 22:15:02 +08:00
|
|
|
gboolean verbose)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
GimpModule *module;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
module = g_object_new (GIMP_TYPE_MODULE, NULL);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
module->filename = g_strdup (filename);
|
|
|
|
module->load_inhibit = load_inhibit ? TRUE : FALSE;
|
|
|
|
module->verbose = verbose ? TRUE : FALSE;
|
|
|
|
module->on_disk = TRUE;
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
if (! module->load_inhibit)
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
if (gimp_module_load (G_TYPE_MODULE (module)))
|
|
|
|
gimp_module_unload (G_TYPE_MODULE (module));
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (verbose)
|
2004-01-14 10:03:37 +08:00
|
|
|
{
|
2005-02-21 05:49:53 +08:00
|
|
|
gchar *name = g_filename_display_name (filename);
|
|
|
|
|
|
|
|
g_print (_("Skipping module: '%s'\n"), name);
|
|
|
|
g_free (name);
|
2004-01-14 10:03:37 +08:00
|
|
|
}
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2002-11-06 21:56:37 +08:00
|
|
|
module->state = GIMP_MODULE_STATE_NOT_LOADED;
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
return module;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_query_module:
|
|
|
|
* @module: A #GimpModule.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Queries the module without actually registering any of the types it
|
|
|
|
* may implement. After successful query, the @info field of the
|
|
|
|
* #GimpModule struct will be available for further inspection.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-02-07 05:17:12 +08:00
|
|
|
* Return value: %TRUE on success.
|
2003-01-03 05:34:35 +08:00
|
|
|
**/
|
2002-10-23 22:55:07 +08:00
|
|
|
gboolean
|
|
|
|
gimp_module_query_module (GimpModule *module)
|
|
|
|
{
|
|
|
|
const GimpModuleInfo *info;
|
|
|
|
gboolean close_module = FALSE;
|
2004-07-07 00:05:32 +08:00
|
|
|
gpointer func;
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_MODULE (module), FALSE);
|
|
|
|
|
|
|
|
if (! module->module)
|
|
|
|
{
|
|
|
|
if (! gimp_module_open (module))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
close_module = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the gimp_module_query symbol */
|
2004-07-07 00:05:32 +08:00
|
|
|
if (! g_module_symbol (module->module, "gimp_module_query", &func))
|
2002-10-23 22:55:07 +08:00
|
|
|
{
|
2002-11-06 21:56:37 +08:00
|
|
|
gimp_module_set_last_error (module,
|
|
|
|
"Missing gimp_module_query() symbol");
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
if (module->verbose)
|
2004-01-24 01:24:44 +08:00
|
|
|
g_message (_("Module '%s' load error: %s"),
|
|
|
|
gimp_filename_to_utf8 (module->filename),
|
|
|
|
module->last_module_error);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
gimp_module_close (module);
|
2002-11-05 07:09:34 +08:00
|
|
|
|
|
|
|
module->state = GIMP_MODULE_STATE_ERROR;
|
2002-10-23 22:55:07 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-07-03 02:01:19 +08:00
|
|
|
module->query_module = func;
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
if (module->info)
|
|
|
|
{
|
|
|
|
gimp_module_info_free (module->info);
|
|
|
|
module->info = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = module->query_module (G_TYPE_MODULE (module));
|
|
|
|
|
2003-01-03 01:44:28 +08:00
|
|
|
if (! info || info->abi_version != GIMP_MODULE_ABI_VERSION)
|
2002-10-23 22:55:07 +08:00
|
|
|
{
|
2003-01-03 01:44:28 +08:00
|
|
|
gimp_module_set_last_error (module,
|
|
|
|
info ?
|
|
|
|
"module ABI version does not match" :
|
|
|
|
"gimp_module_query() returned NULL");
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
if (module->verbose)
|
2004-01-24 01:24:44 +08:00
|
|
|
g_message (_("Module '%s' load error: %s"),
|
|
|
|
gimp_filename_to_utf8 (module->filename),
|
|
|
|
module->last_module_error);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
gimp_module_close (module);
|
2002-11-05 07:09:34 +08:00
|
|
|
|
|
|
|
module->state = GIMP_MODULE_STATE_ERROR;
|
2002-10-23 22:55:07 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
module->info = gimp_module_info_copy (info);
|
|
|
|
|
|
|
|
if (close_module)
|
|
|
|
return gimp_module_close (module);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_modified:
|
|
|
|
* @module: A #GimpModule.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Emits the "modified" signal. Call it whenever you have modified the module
|
|
|
|
* manually (which you shouldn't do).
|
|
|
|
**/
|
2001-10-19 01:27:36 +08:00
|
|
|
void
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_modified (GimpModule *module)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
g_return_if_fail (GIMP_IS_MODULE (module));
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (module, module_signals[MODIFIED], 0);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_set_load_inhibit:
|
|
|
|
* @module: A #GimpModule.
|
2003-02-07 05:17:12 +08:00
|
|
|
* @load_inhibit: Pass %TRUE to exclude this module from auto-loading.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Sets the @load_inhibit property if the module. Emits "modified".
|
|
|
|
**/
|
2001-10-19 01:27:36 +08:00
|
|
|
void
|
2002-10-23 22:55:07 +08:00
|
|
|
gimp_module_set_load_inhibit (GimpModule *module,
|
|
|
|
gboolean load_inhibit)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
g_return_if_fail (GIMP_IS_MODULE (module));
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (load_inhibit != module->load_inhibit)
|
|
|
|
{
|
|
|
|
module->load_inhibit = load_inhibit ? TRUE : FALSE;
|
|
|
|
|
|
|
|
gimp_module_modified (module);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_state_name:
|
|
|
|
* @state: A #GimpModuleState.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Returns the translated textual representation of a #GimpModuleState.
|
|
|
|
* The returned string must not be freed.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Return value: The @state's name.
|
|
|
|
**/
|
2002-10-23 22:55:07 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_module_state_name (GimpModuleState state)
|
|
|
|
{
|
|
|
|
static const gchar * const statenames[] =
|
|
|
|
{
|
|
|
|
N_("Module error"),
|
2002-11-06 21:56:37 +08:00
|
|
|
N_("Loaded"),
|
2002-10-23 22:55:07 +08:00
|
|
|
N_("Load failed"),
|
2002-11-06 21:56:37 +08:00
|
|
|
N_("Not loaded")
|
2002-10-23 22:55:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
g_return_val_if_fail (state >= GIMP_MODULE_STATE_ERROR &&
|
2002-11-06 21:56:37 +08:00
|
|
|
state <= GIMP_MODULE_STATE_NOT_LOADED, NULL);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
return gettext (statenames[state]);
|
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2004-07-05 00:29:28 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_register_enum:
|
|
|
|
* @module:
|
|
|
|
* @name:
|
|
|
|
* @const_static_values:
|
|
|
|
*
|
2005-06-15 17:26:01 +08:00
|
|
|
* This function is deprecated! Use g_type_module_register_enum() instead.
|
2004-07-05 00:29:28 +08:00
|
|
|
*
|
|
|
|
* Return value: a new enum #GType
|
|
|
|
**/
|
|
|
|
GType
|
|
|
|
gimp_module_register_enum (GTypeModule *module,
|
|
|
|
const gchar *name,
|
|
|
|
const GEnumValue *const_static_values)
|
|
|
|
{
|
2005-06-15 17:26:01 +08:00
|
|
|
return g_type_module_register_enum (module, name, const_static_values);
|
2004-07-05 00:29:28 +08:00
|
|
|
}
|
|
|
|
|
2003-02-01 17:56:31 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_module_open (GimpModule *module)
|
|
|
|
{
|
2003-11-19 07:44:35 +08:00
|
|
|
module->module = g_module_open (module->filename, 0);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (! module->module)
|
|
|
|
{
|
|
|
|
module->state = GIMP_MODULE_STATE_ERROR;
|
|
|
|
gimp_module_set_last_error (module, g_module_error ());
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (module->verbose)
|
2004-01-24 01:24:44 +08:00
|
|
|
g_message (_("Module '%s' load error: %s"),
|
|
|
|
gimp_filename_to_utf8 (module->filename),
|
|
|
|
module->last_module_error);
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_module_close (GimpModule *module)
|
|
|
|
{
|
|
|
|
g_module_close (module->module); /* FIXME: error handling */
|
|
|
|
module->module = NULL;
|
|
|
|
module->query_module = NULL;
|
|
|
|
module->register_module = NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-11-06 21:56:37 +08:00
|
|
|
module->state = GIMP_MODULE_STATE_NOT_LOADED;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
return TRUE;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-21 22:15:02 +08:00
|
|
|
gimp_module_set_last_error (GimpModule *module,
|
|
|
|
const gchar *error_str)
|
|
|
|
{
|
|
|
|
if (module->last_module_error)
|
|
|
|
g_free (module->last_module_error);
|
|
|
|
|
|
|
|
module->last_module_error = g_strdup (error_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* GimpModuleInfo functions */
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_info_new:
|
|
|
|
* @abi_version: The #GIMP_MODULE_ABI_VERSION the module was compiled against.
|
|
|
|
* @purpose: The module's general purpose.
|
|
|
|
* @author: The module's author.
|
|
|
|
* @version: The module's version.
|
|
|
|
* @copyright: The module's copyright.
|
|
|
|
* @date: The module's release date.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Creates a newly allocated #GimpModuleInfo struct.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Return value: The new #GimpModuleInfo struct.
|
|
|
|
**/
|
2002-10-21 22:15:02 +08:00
|
|
|
GimpModuleInfo *
|
2003-01-03 01:44:28 +08:00
|
|
|
gimp_module_info_new (guint32 abi_version,
|
|
|
|
const gchar *purpose,
|
|
|
|
const gchar *author,
|
|
|
|
const gchar *version,
|
|
|
|
const gchar *copyright,
|
|
|
|
const gchar *date)
|
2002-10-21 22:15:02 +08:00
|
|
|
{
|
|
|
|
GimpModuleInfo *info;
|
|
|
|
|
|
|
|
info = g_new0 (GimpModuleInfo, 1);
|
|
|
|
|
2003-01-03 01:44:28 +08:00
|
|
|
info->abi_version = abi_version;
|
|
|
|
info->purpose = g_strdup (purpose);
|
|
|
|
info->author = g_strdup (author);
|
|
|
|
info->version = g_strdup (version);
|
|
|
|
info->copyright = g_strdup (copyright);
|
|
|
|
info->date = g_strdup (date);
|
2002-10-21 22:15:02 +08:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_info_copy:
|
|
|
|
* @info: The #GimpModuleInfo struct to copy.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Copies a #GimpModuleInfo struct.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Return value: The new copy.
|
|
|
|
**/
|
2002-10-21 22:15:02 +08:00
|
|
|
GimpModuleInfo *
|
|
|
|
gimp_module_info_copy (const GimpModuleInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
2003-01-03 01:44:28 +08:00
|
|
|
return gimp_module_info_new (info->abi_version,
|
|
|
|
info->purpose,
|
2002-10-21 22:15:02 +08:00
|
|
|
info->author,
|
|
|
|
info->version,
|
|
|
|
info->copyright,
|
|
|
|
info->date);
|
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_info_free:
|
|
|
|
* @info: The #GimpModuleInfo struct to free
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Frees the passed #GimpModuleInfo.
|
|
|
|
**/
|
2002-10-21 22:15:02 +08:00
|
|
|
void
|
|
|
|
gimp_module_info_free (GimpModuleInfo *info)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
|
|
|
g_free (info->purpose);
|
|
|
|
g_free (info->author);
|
|
|
|
g_free (info->version);
|
|
|
|
g_free (info->copyright);
|
|
|
|
g_free (info->date);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
g_free (info);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|