1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include <glib-object.h>
27
#include "libgimpbase/gimpbase.h"
28
#include "libgimpconfig/gimpconfig.h"
30
#include "plug-in-types.h"
32
#include "config/gimpcoreconfig.h"
34
#include "core/gimp.h"
35
#include "core/gimp-utils.h"
36
#include "core/gimpmarshal.h"
38
#include "pdb/gimppdb.h"
40
#include "gimpenvirontable.h"
41
#include "gimpinterpreterdb.h"
42
#include "gimpplugin.h"
43
#include "gimpplugindebug.h"
44
#include "gimpplugindef.h"
45
#include "gimppluginmanager.h"
46
#include "gimppluginmanager-data.h"
47
#include "gimppluginmanager-help-domain.h"
48
#include "gimppluginmanager-history.h"
49
#include "gimppluginmanager-locale-domain.h"
50
#include "gimppluginmanager-menu-branch.h"
51
#include "gimppluginshm.h"
52
#include "gimptemporaryprocedure.h"
54
#include "gimp-intl.h"
67
static void gimp_plug_in_manager_dispose (GObject *object);
68
static void gimp_plug_in_manager_finalize (GObject *object);
70
static gint64 gimp_plug_in_manager_get_memsize (GimpObject *object,
74
G_DEFINE_TYPE (GimpPlugInManager, gimp_plug_in_manager, GIMP_TYPE_OBJECT)
76
#define parent_class gimp_plug_in_manager_parent_class
78
static guint manager_signals[LAST_SIGNAL] = { 0, };
82
gimp_plug_in_manager_class_init (GimpPlugInManagerClass *klass)
84
GObjectClass *object_class = G_OBJECT_CLASS (klass);
85
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
87
manager_signals[PLUG_IN_OPENED] =
88
g_signal_new ("plug-in-opened",
89
G_TYPE_FROM_CLASS (klass),
91
G_STRUCT_OFFSET (GimpPlugInManagerClass,
94
gimp_marshal_VOID__OBJECT,
98
manager_signals[PLUG_IN_CLOSED] =
99
g_signal_new ("plug-in-closed",
100
G_TYPE_FROM_CLASS (klass),
102
G_STRUCT_OFFSET (GimpPlugInManagerClass,
105
gimp_marshal_VOID__OBJECT,
109
manager_signals[MENU_BRANCH_ADDED] =
110
g_signal_new ("menu-branch-added",
111
G_TYPE_FROM_CLASS (klass),
113
G_STRUCT_OFFSET (GimpPlugInManagerClass,
116
gimp_marshal_VOID__STRING_STRING_STRING,
122
manager_signals[HISTORY_CHANGED] =
123
g_signal_new ("history-changed",
124
G_TYPE_FROM_CLASS (klass),
126
G_STRUCT_OFFSET (GimpPlugInManagerClass,
129
gimp_marshal_VOID__VOID,
132
object_class->dispose = gimp_plug_in_manager_dispose;
133
object_class->finalize = gimp_plug_in_manager_finalize;
135
gimp_object_class->get_memsize = gimp_plug_in_manager_get_memsize;
139
gimp_plug_in_manager_init (GimpPlugInManager *manager)
141
manager->gimp = NULL;
143
manager->plug_in_defs = NULL;
144
manager->write_pluginrc = FALSE;
146
manager->plug_in_procedures = NULL;
147
manager->load_procs = NULL;
148
manager->save_procs = NULL;
150
manager->current_plug_in = NULL;
151
manager->open_plug_ins = NULL;
152
manager->plug_in_stack = NULL;
153
manager->history = NULL;
156
manager->interpreter_db = gimp_interpreter_db_new ();
157
manager->environ_table = gimp_environ_table_new ();
158
manager->debug = NULL;
159
manager->data_list = NULL;
163
gimp_plug_in_manager_dispose (GObject *object)
165
GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
167
gimp_plug_in_manager_history_clear (manager);
169
G_OBJECT_CLASS (parent_class)->dispose (object);
173
gimp_plug_in_manager_finalize (GObject *object)
175
GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
177
if (manager->load_procs)
179
g_slist_free (manager->load_procs);
180
manager->load_procs = NULL;
183
if (manager->save_procs)
185
g_slist_free (manager->save_procs);
186
manager->save_procs = NULL;
189
if (manager->plug_in_procedures)
191
g_slist_foreach (manager->plug_in_procedures,
192
(GFunc) g_object_unref, NULL);
193
g_slist_free (manager->plug_in_procedures);
194
manager->plug_in_procedures = NULL;
197
if (manager->plug_in_defs)
199
g_slist_foreach (manager->plug_in_defs, (GFunc) g_object_unref, NULL);
200
g_slist_free (manager->plug_in_defs);
201
manager->plug_in_defs = NULL;
206
gimp_plug_in_shm_free (manager->shm);
210
if (manager->environ_table)
212
g_object_unref (manager->environ_table);
213
manager->environ_table = NULL;
216
if (manager->interpreter_db)
218
g_object_unref (manager->interpreter_db);
219
manager->interpreter_db = NULL;
224
gimp_plug_in_debug_free (manager->debug);
225
manager->debug = NULL;
228
gimp_plug_in_manager_menu_branch_exit (manager);
229
gimp_plug_in_manager_locale_domain_exit (manager);
230
gimp_plug_in_manager_help_domain_exit (manager);
231
gimp_plug_in_manager_data_free (manager);
233
G_OBJECT_CLASS (parent_class)->finalize (object);
237
gimp_plug_in_manager_get_memsize (GimpObject *object,
240
GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
243
memsize += gimp_g_slist_get_memsize_foreach (manager->plug_in_defs,
245
gimp_object_get_memsize,
248
memsize += gimp_g_slist_get_memsize (manager->plug_in_procedures, 0);
249
memsize += gimp_g_slist_get_memsize (manager->load_procs, 0);
250
memsize += gimp_g_slist_get_memsize (manager->save_procs, 0);
252
memsize += gimp_g_slist_get_memsize (manager->menu_branches, 0 /* FIXME */);
253
memsize += gimp_g_slist_get_memsize (manager->locale_domains, 0 /* FIXME */);
254
memsize += gimp_g_slist_get_memsize (manager->help_domains, 0 /* FIXME */);
256
memsize += gimp_g_slist_get_memsize_foreach (manager->open_plug_ins,
258
gimp_object_get_memsize,
260
memsize += gimp_g_slist_get_memsize (manager->plug_in_stack, 0 /* FIXME */);
261
memsize += gimp_g_slist_get_memsize (manager->history, 0);
263
memsize += 0; /* FIXME manager->shm */
264
memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->interpreter_db),
266
memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->environ_table),
268
memsize += 0; /* FIXME manager->plug_in_debug */
269
memsize += gimp_g_list_get_memsize (manager->data_list, 0 /* FIXME */);
271
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
276
gimp_plug_in_manager_new (Gimp *gimp)
278
GimpPlugInManager *manager;
280
manager = g_object_new (GIMP_TYPE_PLUG_IN_MANAGER, NULL);
282
manager->gimp = gimp;
288
gimp_plug_in_manager_initialize (GimpPlugInManager *manager,
289
GimpInitStatusFunc status_callback)
293
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
294
g_return_if_fail (status_callback != NULL);
296
status_callback (NULL, _("Plug-In Interpreters"), 0.8);
298
path = gimp_config_path_expand (manager->gimp->config->interpreter_path,
300
gimp_interpreter_db_load (manager->interpreter_db, path);
303
status_callback (NULL, _("Plug-In Environment"), 0.9);
305
path = gimp_config_path_expand (manager->gimp->config->environ_path,
307
gimp_environ_table_load (manager->environ_table, path);
310
/* allocate a piece of shared memory for use in transporting tiles
311
* to plug-ins. if we can't allocate a piece of shared memory then
312
* we'll fall back on sending the data over the pipe.
314
if (manager->gimp->use_shm)
315
manager->shm = gimp_plug_in_shm_new ();
317
manager->debug = gimp_plug_in_debug_new ();
321
gimp_plug_in_manager_exit (GimpPlugInManager *manager)
323
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
325
while (manager->open_plug_ins)
326
gimp_plug_in_close (manager->open_plug_ins->data, TRUE);
330
gimp_plug_in_manager_add_procedure (GimpPlugInManager *manager,
331
GimpPlugInProcedure *procedure)
335
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
336
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (procedure));
338
for (list = manager->plug_in_procedures; list; list = list->next)
340
GimpPlugInProcedure *tmp_proc = list->data;
342
if (strcmp (GIMP_OBJECT (procedure)->name,
343
GIMP_OBJECT (tmp_proc)->name) == 0)
347
list->data = g_object_ref (procedure);
349
g_printerr ("Removing duplicate PDB procedure '%s' "
350
"registered by '%s'\n",
351
GIMP_OBJECT (tmp_proc)->name,
352
gimp_filename_to_utf8 (tmp_proc->prog));
354
/* search the plugin list to see if any plugins had references to
357
for (list2 = manager->plug_in_defs; list2; list2 = list2->next)
359
GimpPlugInDef *plug_in_def = list2->data;
361
if (g_slist_find (plug_in_def->procedures, tmp_proc))
362
gimp_plug_in_def_remove_procedure (plug_in_def, tmp_proc);
365
/* also remove it from the lists of load and save procs */
366
manager->load_procs = g_slist_remove (manager->load_procs, tmp_proc);
367
manager->save_procs = g_slist_remove (manager->save_procs, tmp_proc);
369
/* and from the history */
370
gimp_plug_in_manager_history_remove (manager, tmp_proc);
372
g_object_unref (tmp_proc);
378
manager->plug_in_procedures = g_slist_prepend (manager->plug_in_procedures,
379
g_object_ref (procedure));
383
gimp_plug_in_manager_add_temp_proc (GimpPlugInManager *manager,
384
GimpTemporaryProcedure *procedure)
386
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
387
g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (procedure));
389
gimp_pdb_register_procedure (manager->gimp->pdb, GIMP_PROCEDURE (procedure));
391
manager->plug_in_procedures = g_slist_prepend (manager->plug_in_procedures,
392
g_object_ref (procedure));
396
gimp_plug_in_manager_remove_temp_proc (GimpPlugInManager *manager,
397
GimpTemporaryProcedure *procedure)
399
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
400
g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (procedure));
402
manager->plug_in_procedures = g_slist_remove (manager->plug_in_procedures,
405
gimp_plug_in_manager_history_remove (manager,
406
GIMP_PLUG_IN_PROCEDURE (procedure));
408
gimp_pdb_unregister_procedure (manager->gimp->pdb,
409
GIMP_PROCEDURE (procedure));
411
g_object_unref (procedure);
415
gimp_plug_in_manager_add_open_plug_in (GimpPlugInManager *manager,
418
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
419
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
421
manager->open_plug_ins = g_slist_prepend (manager->open_plug_ins,
422
g_object_ref (plug_in));
424
g_signal_emit (manager, manager_signals[PLUG_IN_OPENED], 0,
429
gimp_plug_in_manager_remove_open_plug_in (GimpPlugInManager *manager,
432
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
433
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
435
manager->open_plug_ins = g_slist_remove (manager->open_plug_ins, plug_in);
437
g_signal_emit (manager, manager_signals[PLUG_IN_CLOSED], 0,
440
g_object_unref (plug_in);
444
gimp_plug_in_manager_plug_in_push (GimpPlugInManager *manager,
447
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
448
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
450
manager->current_plug_in = plug_in;
452
manager->plug_in_stack = g_slist_prepend (manager->plug_in_stack,
453
manager->current_plug_in);
457
gimp_plug_in_manager_plug_in_pop (GimpPlugInManager *manager)
459
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
461
if (manager->current_plug_in)
462
manager->plug_in_stack = g_slist_remove (manager->plug_in_stack,
463
manager->plug_in_stack->data);
465
if (manager->plug_in_stack)
466
manager->current_plug_in = manager->plug_in_stack->data;
468
manager->current_plug_in = NULL;
472
gimp_plug_in_manager_history_changed (GimpPlugInManager *manager)
474
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
476
g_signal_emit (manager, manager_signals[HISTORY_CHANGED], 0);