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
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2003-11-23 23:35:27 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 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
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2001-10-19 01:27:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2002-02-18 22:34:50 +08:00
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gio/gio.h>
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2014-08-04 00:30:02 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
#include "gimpmoduletypes.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
#include "gimpmodule.h"
|
|
|
|
#include "gimpmoduledb.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2010-06-30 04:35:34 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpmoduledb
|
|
|
|
* @title: GimpModuleDB
|
|
|
|
* @short_description: Keeps a list of #GimpModule's found in a given
|
|
|
|
* searchpath.
|
|
|
|
*
|
|
|
|
* Keeps a list of #GimpModule's found in a given searchpath.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ADD,
|
|
|
|
REMOVE,
|
|
|
|
MODULE_MODIFIED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2018-05-06 02:41:02 +08:00
|
|
|
struct _GimpModuleDBPrivate
|
|
|
|
{
|
|
|
|
GList *modules;
|
|
|
|
|
|
|
|
gchar *load_inhibit;
|
|
|
|
gboolean verbose;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static void gimp_module_db_finalize (GObject *object);
|
|
|
|
|
2014-08-04 00:30:02 +08:00
|
|
|
static void gimp_module_db_load_directory (GimpModuleDB *db,
|
|
|
|
GFile *directory);
|
|
|
|
static void gimp_module_db_load_module (GimpModuleDB *db,
|
|
|
|
GFile *file);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
static GimpModule * gimp_module_db_module_find_by_file (GimpModuleDB *db,
|
|
|
|
GFile *file);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2014-08-03 05:47:10 +08:00
|
|
|
static void gimp_module_db_module_dump_func (gpointer data,
|
2002-10-23 22:55:07 +08:00
|
|
|
gpointer user_data);
|
2014-08-03 05:47:10 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static void gimp_module_db_module_modified (GimpModule *module,
|
|
|
|
GimpModuleDB *db);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpModuleDB, gimp_module_db, G_TYPE_OBJECT)
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_module_db_parent_class
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static guint db_signals[LAST_SIGNAL] = { 0 };
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static void
|
|
|
|
gimp_module_db_class_init (GimpModuleDBClass *klass)
|
|
|
|
{
|
2004-01-24 01:24:44 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
db_signals[ADD] =
|
|
|
|
g_signal_new ("add",
|
2004-07-30 03:22:32 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpModuleDBClass, add),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2004-07-30 03:22:32 +08:00
|
|
|
G_TYPE_NONE, 1,
|
2002-10-23 22:55:07 +08:00
|
|
|
GIMP_TYPE_MODULE);
|
|
|
|
|
|
|
|
db_signals[REMOVE] =
|
|
|
|
g_signal_new ("remove",
|
2004-07-30 03:22:32 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpModuleDBClass, remove),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2004-07-30 03:22:32 +08:00
|
|
|
G_TYPE_NONE, 1,
|
2002-10-23 22:55:07 +08:00
|
|
|
GIMP_TYPE_MODULE);
|
|
|
|
|
|
|
|
db_signals[MODULE_MODIFIED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("module-modified",
|
2004-07-30 03:22:32 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpModuleDBClass, module_modified),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2004-07-30 03:22:32 +08:00
|
|
|
G_TYPE_NONE, 1,
|
2002-10-23 22:55:07 +08:00
|
|
|
GIMP_TYPE_MODULE);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_module_db_finalize;
|
|
|
|
|
|
|
|
klass->add = NULL;
|
|
|
|
klass->remove = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_module_db_init (GimpModuleDB *db)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
db->priv = gimp_module_db_get_instance_private (db);
|
2018-05-06 02:41:02 +08:00
|
|
|
|
|
|
|
db->priv->modules = NULL;
|
|
|
|
db->priv->load_inhibit = NULL;
|
|
|
|
db->priv->verbose = FALSE;
|
2002-10-23 22:55:07 +08:00
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static void
|
|
|
|
gimp_module_db_finalize (GObject *object)
|
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
GimpModuleDB *db = GIMP_MODULE_DB (object);
|
|
|
|
GList *list;
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
for (list = db->priv->modules; list; list = g_list_next (list))
|
2002-10-23 22:55:07 +08:00
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (list->data,
|
|
|
|
gimp_module_db_module_modified,
|
|
|
|
object);
|
2002-10-23 22:55:07 +08:00
|
|
|
}
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
g_clear_pointer (&db->priv->modules, g_list_free);
|
|
|
|
g_clear_pointer (&db->priv->load_inhibit, g_free);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_db_new:
|
2003-02-07 05:17:12 +08:00
|
|
|
* @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 #GimpModuleDB instance. The @verbose parameter will be
|
|
|
|
* passed to the created #GimpModule instances using gimp_module_new().
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: The new #GimpModuleDB instance.
|
2003-01-03 05:34:35 +08:00
|
|
|
**/
|
2002-10-23 22:55:07 +08:00
|
|
|
GimpModuleDB *
|
|
|
|
gimp_module_db_new (gboolean verbose)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-23 22:55:07 +08:00
|
|
|
GimpModuleDB *db;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
db = g_object_new (GIMP_TYPE_MODULE_DB, NULL);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2018-05-06 02:41:02 +08:00
|
|
|
db->priv->verbose = verbose ? TRUE : FALSE;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
return db;
|
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2018-05-06 02:41:02 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_db_get_modules:
|
|
|
|
* @db: A #GimpModuleDB.
|
|
|
|
*
|
|
|
|
* Returns a #GList of the modules kept by @db. The list must not be
|
|
|
|
* modified or freed.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (element-type GimpModule) (transfer none): a #GList
|
2019-08-01 16:21:47 +08:00
|
|
|
* of #GimpModule instances.
|
2018-05-06 02:41:02 +08:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
GList *
|
|
|
|
gimp_module_db_get_modules (GimpModuleDB *db)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_MODULE_DB (db), NULL);
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
return db->priv->modules;
|
2018-05-06 02:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_module_db_set_verbose:
|
|
|
|
* @db: A #GimpModuleDB.
|
|
|
|
* @verbose: the new 'verbose' setting
|
|
|
|
*
|
|
|
|
* Sets the 'verbose' setting of @db.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_module_db_set_verbose (GimpModuleDB *db,
|
|
|
|
gboolean verbose)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_MODULE_DB (db));
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
db->priv->verbose = verbose ? TRUE : FALSE;
|
2018-05-06 02:41:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_module_db_get_verbose:
|
|
|
|
* @db: A #GimpModuleDB.
|
|
|
|
*
|
|
|
|
* Returns the 'verbose' setting of @db.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the 'verbose' setting.
|
2018-05-06 02:41:02 +08:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_module_db_get_verbose (GimpModuleDB *db)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_MODULE_DB (db), FALSE);
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
return db->priv->verbose;
|
2018-05-06 02:41:02 +08:00
|
|
|
}
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static gboolean
|
2019-09-13 19:11:23 +08:00
|
|
|
is_in_inhibit_list (GFile *file,
|
2002-10-23 22:55:07 +08:00
|
|
|
const gchar *inhibit_list)
|
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
gchar *filename;
|
2002-10-23 22:55:07 +08:00
|
|
|
gchar *p;
|
|
|
|
gint pathlen;
|
|
|
|
const gchar *start;
|
|
|
|
const gchar *end;
|
|
|
|
|
|
|
|
if (! inhibit_list || ! strlen (inhibit_list))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
filename = g_file_get_path (file);
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
p = strstr (inhibit_list, filename);
|
2019-09-13 19:11:23 +08:00
|
|
|
if (! p)
|
|
|
|
{
|
|
|
|
g_free (filename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
/* we have a substring, but check for colons either side */
|
|
|
|
start = p;
|
|
|
|
while (start != inhibit_list && *start != G_SEARCHPATH_SEPARATOR)
|
|
|
|
start--;
|
|
|
|
|
|
|
|
if (*start == G_SEARCHPATH_SEPARATOR)
|
|
|
|
start++;
|
|
|
|
|
|
|
|
end = strchr (p, G_SEARCHPATH_SEPARATOR);
|
|
|
|
if (! end)
|
|
|
|
end = inhibit_list + strlen (inhibit_list);
|
|
|
|
|
|
|
|
pathlen = strlen (filename);
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
g_free (filename);
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if ((end - start) == pathlen)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_db_set_load_inhibit:
|
|
|
|
* @db: A #GimpModuleDB.
|
|
|
|
* @load_inhibit: A #G_SEARCHPATH_SEPARATOR delimited list of module
|
|
|
|
* filenames to exclude from auto-loading.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Sets the @load_inhibit flag for all #GimpModule's which are kept
|
|
|
|
* by @db (using gimp_module_set_load_inhibit()).
|
|
|
|
**/
|
2001-10-19 01:27:36 +08:00
|
|
|
void
|
2002-10-23 22:55:07 +08:00
|
|
|
gimp_module_db_set_load_inhibit (GimpModuleDB *db,
|
|
|
|
const gchar *load_inhibit)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
GList *list;
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_MODULE_DB (db));
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
if (db->priv->load_inhibit)
|
|
|
|
g_free (db->priv->load_inhibit);
|
2018-05-06 02:41:02 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
db->priv->load_inhibit = g_strdup (load_inhibit);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
for (list = db->priv->modules; list; list = g_list_next (list))
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2004-01-24 01:24:44 +08:00
|
|
|
GimpModule *module = list->data;
|
2019-09-13 19:11:23 +08:00
|
|
|
gboolean inhibit;
|
|
|
|
|
|
|
|
inhibit =is_in_inhibit_list (gimp_module_get_file (module),
|
|
|
|
load_inhibit);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
gimp_module_set_auto_load (module, ! inhibit);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_db_get_load_inhibit:
|
|
|
|
* @db: A #GimpModuleDB.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2012-09-13 15:14:17 +08:00
|
|
|
* Return the #G_SEARCHPATH_SEPARATOR delimited list of module filenames
|
2003-01-03 05:34:35 +08:00
|
|
|
* which are excluded from auto-loading.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the @db's @load_inhibit string.
|
2003-01-03 05:34:35 +08:00
|
|
|
**/
|
2002-10-23 22:55:07 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_module_db_get_load_inhibit (GimpModuleDB *db)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_MODULE_DB (db), NULL);
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
return db->priv->load_inhibit;
|
2002-10-23 22:55:07 +08:00
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_db_load:
|
|
|
|
* @db: A #GimpModuleDB.
|
|
|
|
* @module_path: A #G_SEARCHPATH_SEPARATOR delimited list of directories
|
|
|
|
* to load modules from.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2014-08-04 05:09:30 +08:00
|
|
|
* Scans the directories contained in @module_path and creates a
|
|
|
|
* #GimpModule instance for every loadable module contained in the
|
|
|
|
* directories.
|
2003-01-03 05:34:35 +08:00
|
|
|
**/
|
2002-10-23 22:55:07 +08:00
|
|
|
void
|
|
|
|
gimp_module_db_load (GimpModuleDB *db,
|
|
|
|
const gchar *module_path)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_MODULE_DB (db));
|
|
|
|
g_return_if_fail (module_path != NULL);
|
|
|
|
|
|
|
|
if (g_module_supported ())
|
2014-08-04 00:30:02 +08:00
|
|
|
{
|
|
|
|
GList *path;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
path = gimp_config_path_expand_to_files (module_path, NULL);
|
|
|
|
|
|
|
|
for (list = path; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gimp_module_db_load_directory (db, list->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free_full (path, (GDestroyNotify) g_object_unref);
|
|
|
|
}
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
if (FALSE)
|
|
|
|
g_list_foreach (db->priv->modules, gimp_module_db_module_dump_func, NULL);
|
2002-10-23 22:55:07 +08:00
|
|
|
}
|
|
|
|
|
2003-01-03 05:34:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_module_db_refresh:
|
|
|
|
* @db: A #GimpModuleDB.
|
|
|
|
* @module_path: A #G_SEARCHPATH_SEPARATOR delimited list of directories
|
|
|
|
* to load modules from.
|
2003-11-15 20:36:09 +08:00
|
|
|
*
|
2003-01-03 05:34:35 +08:00
|
|
|
* Does the same as gimp_module_db_load(), plus removes all #GimpModule
|
|
|
|
* instances whose modules have been deleted from disk.
|
|
|
|
*
|
|
|
|
* Note that the #GimpModule's will just be removed from the internal
|
|
|
|
* list and not freed as this is not possible with #GTypeModule
|
|
|
|
* instances which actually implement types.
|
|
|
|
**/
|
2001-10-19 01:27:36 +08:00
|
|
|
void
|
2002-10-23 22:55:07 +08:00
|
|
|
gimp_module_db_refresh (GimpModuleDB *db,
|
|
|
|
const gchar *module_path)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
GList *list;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_MODULE_DB (db));
|
|
|
|
g_return_if_fail (module_path != NULL);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
list = db->priv->modules;
|
|
|
|
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
GimpModule *module = list->data;
|
2018-05-06 02:41:02 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
list = g_list_next (list);
|
|
|
|
|
|
|
|
if (! gimp_module_is_on_disk (module) &&
|
|
|
|
! gimp_module_is_loaded (module))
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (module,
|
|
|
|
gimp_module_db_module_modified,
|
|
|
|
db);
|
|
|
|
|
|
|
|
db->priv->modules = g_list_remove (db->priv->modules, module);
|
|
|
|
|
|
|
|
g_signal_emit (db, db_signals[REMOVE], 0, module);
|
|
|
|
}
|
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
/* walk filesystem and add new things we find */
|
2014-08-04 00:30:02 +08:00
|
|
|
gimp_module_db_load (db, module_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_module_db_load_directory (GimpModuleDB *db,
|
|
|
|
GFile *directory)
|
|
|
|
{
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
|
|
|
|
enumerator = g_file_enumerate_children (directory,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_NAME ","
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (enumerator)
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)))
|
|
|
|
{
|
|
|
|
GFileType file_type = g_file_info_get_file_type (info);
|
|
|
|
|
|
|
|
if (file_type == G_FILE_TYPE_REGULAR &&
|
|
|
|
! g_file_info_get_is_hidden (info))
|
|
|
|
{
|
|
|
|
GFile *child = g_file_enumerator_get_child (enumerator, info);
|
|
|
|
|
|
|
|
gimp_module_db_load_module (db, child);
|
|
|
|
|
|
|
|
g_object_unref (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (enumerator);
|
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-04 00:30:02 +08:00
|
|
|
gimp_module_db_load_module (GimpModuleDB *db,
|
|
|
|
GFile *file)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
GimpModule *module;
|
|
|
|
gboolean load_inhibit;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2014-08-04 02:46:28 +08:00
|
|
|
if (! gimp_file_has_extension (file, "." G_MODULE_SUFFIX))
|
|
|
|
return;
|
2014-08-04 00:30:02 +08:00
|
|
|
|
2001-10-19 01:27:36 +08:00
|
|
|
/* don't load if we already know about it */
|
2019-09-13 19:11:23 +08:00
|
|
|
if (gimp_module_db_module_find_by_file (db, file))
|
|
|
|
return;
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
load_inhibit = is_in_inhibit_list (file, db->priv->load_inhibit);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
module = gimp_module_new (file,
|
|
|
|
! load_inhibit,
|
|
|
|
db->priv->verbose);
|
2014-08-04 00:30:02 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (module, "modified",
|
2002-10-23 22:55:07 +08:00
|
|
|
G_CALLBACK (gimp_module_db_module_modified),
|
|
|
|
db);
|
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
db->priv->modules = g_list_append (db->priv->modules, module);
|
2014-08-04 00:30:02 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (db, db_signals[ADD], 0, module);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
static GimpModule *
|
2019-09-13 19:11:23 +08:00
|
|
|
gimp_module_db_module_find_by_file (GimpModuleDB *db,
|
|
|
|
GFile *file)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
GList *list;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
for (list = db->priv->modules; list; list = g_list_next (list))
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
2004-01-24 01:24:44 +08:00
|
|
|
GimpModule *module = list->data;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
if (g_file_equal (file, gimp_module_get_file (module)))
|
2002-10-21 22:15:02 +08:00
|
|
|
return module;
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
return NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-03 05:47:10 +08:00
|
|
|
gimp_module_db_module_dump_func (gpointer data,
|
|
|
|
gpointer user_data)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2019-09-13 19:11:23 +08:00
|
|
|
static const gchar * const statenames[] =
|
|
|
|
{
|
|
|
|
N_("Module error"),
|
|
|
|
N_("Loaded"),
|
|
|
|
N_("Load failed"),
|
|
|
|
N_("Not loaded")
|
|
|
|
};
|
|
|
|
|
|
|
|
GimpModule *module = data;
|
|
|
|
const GimpModuleInfo *info = gimp_module_get_info (module);
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
g_print ("\n%s: %s\n",
|
2019-09-13 19:11:23 +08:00
|
|
|
gimp_file_get_utf8_name (gimp_module_get_file (module)),
|
|
|
|
gettext (statenames[gimp_module_get_state (module)]));
|
2002-10-20 20:40:30 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
#if 0
|
2004-01-24 01:24:44 +08:00
|
|
|
g_print (" module: %p lasterr: %s query: %p register: %p\n",
|
2004-07-30 03:22:32 +08:00
|
|
|
module->module,
|
2004-01-24 01:24:44 +08:00
|
|
|
module->last_module_error ? module->last_module_error : "NONE",
|
2004-07-30 03:22:32 +08:00
|
|
|
module->query_module,
|
|
|
|
module->register_module);
|
2019-09-13 19:11:23 +08:00
|
|
|
#endif
|
2002-10-20 20:40:30 +08:00
|
|
|
|
2019-09-13 19:11:23 +08:00
|
|
|
if (info)
|
2002-10-21 22:15:02 +08:00
|
|
|
{
|
|
|
|
g_print (" purpose: %s\n"
|
|
|
|
" author: %s\n"
|
|
|
|
" version: %s\n"
|
|
|
|
" copyright: %s\n"
|
|
|
|
" date: %s\n",
|
2019-09-13 19:11:23 +08:00
|
|
|
info->purpose ? info->purpose : "NONE",
|
|
|
|
info->author ? info->author : "NONE",
|
|
|
|
info->version ? info->version : "NONE",
|
|
|
|
info->copyright ? info->copyright : "NONE",
|
|
|
|
info->date ? info->date : "NONE");
|
2002-10-21 22:15:02 +08:00
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static void
|
|
|
|
gimp_module_db_module_modified (GimpModule *module,
|
|
|
|
GimpModuleDB *db)
|
|
|
|
{
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (db, db_signals[MODULE_MODIFIED], 0, module);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|