~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/plug-in/gimppluginmanager.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
 
3
 *
 
4
 * gimppluginmanager.c
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <string.h>
 
24
 
 
25
#include <glib-object.h>
 
26
 
 
27
#include "libgimpbase/gimpbase.h"
 
28
#include "libgimpconfig/gimpconfig.h"
 
29
 
 
30
#include "plug-in-types.h"
 
31
 
 
32
#include "config/gimpcoreconfig.h"
 
33
 
 
34
#include "core/gimp.h"
 
35
#include "core/gimp-utils.h"
 
36
#include "core/gimpmarshal.h"
 
37
 
 
38
#include "pdb/gimppdb.h"
 
39
 
 
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"
 
53
 
 
54
#include "gimp-intl.h"
 
55
 
 
56
 
 
57
enum
 
58
{
 
59
  PLUG_IN_OPENED,
 
60
  PLUG_IN_CLOSED,
 
61
  MENU_BRANCH_ADDED,
 
62
  HISTORY_CHANGED,
 
63
  LAST_SIGNAL
 
64
};
 
65
 
 
66
 
 
67
static void     gimp_plug_in_manager_dispose     (GObject    *object);
 
68
static void     gimp_plug_in_manager_finalize    (GObject    *object);
 
69
 
 
70
static gint64   gimp_plug_in_manager_get_memsize (GimpObject *object,
 
71
                                                  gint64     *gui_size);
 
72
 
 
73
 
 
74
G_DEFINE_TYPE (GimpPlugInManager, gimp_plug_in_manager, GIMP_TYPE_OBJECT)
 
75
 
 
76
#define parent_class gimp_plug_in_manager_parent_class
 
77
 
 
78
static guint manager_signals[LAST_SIGNAL] = { 0, };
 
79
 
 
80
 
 
81
static void
 
82
gimp_plug_in_manager_class_init (GimpPlugInManagerClass *klass)
 
83
{
 
84
  GObjectClass    *object_class      = G_OBJECT_CLASS (klass);
 
85
  GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
 
86
 
 
87
  manager_signals[PLUG_IN_OPENED] =
 
88
    g_signal_new ("plug-in-opened",
 
89
                  G_TYPE_FROM_CLASS (klass),
 
90
                  G_SIGNAL_RUN_LAST,
 
91
                  G_STRUCT_OFFSET (GimpPlugInManagerClass,
 
92
                                   plug_in_opened),
 
93
                  NULL, NULL,
 
94
                  gimp_marshal_VOID__OBJECT,
 
95
                  G_TYPE_NONE, 1,
 
96
                  GIMP_TYPE_PLUG_IN);
 
97
 
 
98
  manager_signals[PLUG_IN_CLOSED] =
 
99
    g_signal_new ("plug-in-closed",
 
100
                  G_TYPE_FROM_CLASS (klass),
 
101
                  G_SIGNAL_RUN_LAST,
 
102
                  G_STRUCT_OFFSET (GimpPlugInManagerClass,
 
103
                                   plug_in_closed),
 
104
                  NULL, NULL,
 
105
                  gimp_marshal_VOID__OBJECT,
 
106
                  G_TYPE_NONE, 1,
 
107
                  GIMP_TYPE_PLUG_IN);
 
108
 
 
109
  manager_signals[MENU_BRANCH_ADDED] =
 
110
    g_signal_new ("menu-branch-added",
 
111
                  G_TYPE_FROM_CLASS (klass),
 
112
                  G_SIGNAL_RUN_LAST,
 
113
                  G_STRUCT_OFFSET (GimpPlugInManagerClass,
 
114
                                   menu_branch_added),
 
115
                  NULL, NULL,
 
116
                  gimp_marshal_VOID__STRING_STRING_STRING,
 
117
                  G_TYPE_NONE, 1,
 
118
                  G_TYPE_STRING,
 
119
                  G_TYPE_STRING,
 
120
                  G_TYPE_STRING);
 
121
 
 
122
  manager_signals[HISTORY_CHANGED] =
 
123
    g_signal_new ("history-changed",
 
124
                  G_TYPE_FROM_CLASS (klass),
 
125
                  G_SIGNAL_RUN_LAST,
 
126
                  G_STRUCT_OFFSET (GimpPlugInManagerClass,
 
127
                                   history_changed),
 
128
                  NULL, NULL,
 
129
                  gimp_marshal_VOID__VOID,
 
130
                  G_TYPE_NONE, 0);
 
131
 
 
132
  object_class->dispose          = gimp_plug_in_manager_dispose;
 
133
  object_class->finalize         = gimp_plug_in_manager_finalize;
 
134
 
 
135
  gimp_object_class->get_memsize = gimp_plug_in_manager_get_memsize;
 
136
}
 
137
 
 
138
static void
 
139
gimp_plug_in_manager_init (GimpPlugInManager *manager)
 
140
{
 
141
  manager->gimp               = NULL;
 
142
 
 
143
  manager->plug_in_defs       = NULL;
 
144
  manager->write_pluginrc     = FALSE;
 
145
 
 
146
  manager->plug_in_procedures = NULL;
 
147
  manager->load_procs         = NULL;
 
148
  manager->save_procs         = NULL;
 
149
 
 
150
  manager->current_plug_in    = NULL;
 
151
  manager->open_plug_ins      = NULL;
 
152
  manager->plug_in_stack      = NULL;
 
153
  manager->history            = NULL;
 
154
 
 
155
  manager->shm                = 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;
 
160
}
 
161
 
 
162
static void
 
163
gimp_plug_in_manager_dispose (GObject *object)
 
164
{
 
165
  GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
 
166
 
 
167
  gimp_plug_in_manager_history_clear (manager);
 
168
 
 
169
  G_OBJECT_CLASS (parent_class)->dispose (object);
 
170
}
 
171
 
 
172
static void
 
173
gimp_plug_in_manager_finalize (GObject *object)
 
174
{
 
175
  GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
 
176
 
 
177
  if (manager->load_procs)
 
178
    {
 
179
      g_slist_free (manager->load_procs);
 
180
      manager->load_procs = NULL;
 
181
    }
 
182
 
 
183
  if (manager->save_procs)
 
184
    {
 
185
      g_slist_free (manager->save_procs);
 
186
      manager->save_procs = NULL;
 
187
    }
 
188
 
 
189
  if (manager->plug_in_procedures)
 
190
    {
 
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;
 
195
    }
 
196
 
 
197
  if (manager->plug_in_defs)
 
198
    {
 
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;
 
202
    }
 
203
 
 
204
  if (manager->shm)
 
205
    {
 
206
      gimp_plug_in_shm_free (manager->shm);
 
207
      manager->shm = NULL;
 
208
    }
 
209
 
 
210
  if (manager->environ_table)
 
211
    {
 
212
      g_object_unref (manager->environ_table);
 
213
      manager->environ_table = NULL;
 
214
    }
 
215
 
 
216
  if (manager->interpreter_db)
 
217
    {
 
218
      g_object_unref (manager->interpreter_db);
 
219
      manager->interpreter_db = NULL;
 
220
    }
 
221
 
 
222
  if (manager->debug)
 
223
    {
 
224
      gimp_plug_in_debug_free (manager->debug);
 
225
      manager->debug = NULL;
 
226
    }
 
227
 
 
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);
 
232
 
 
233
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
234
}
 
235
 
 
236
static gint64
 
237
gimp_plug_in_manager_get_memsize (GimpObject *object,
 
238
                                  gint64     *gui_size)
 
239
{
 
240
  GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
 
241
  gint64             memsize = 0;
 
242
 
 
243
  memsize += gimp_g_slist_get_memsize_foreach (manager->plug_in_defs,
 
244
                                               (GimpMemsizeFunc)
 
245
                                               gimp_object_get_memsize,
 
246
                                               gui_size);
 
247
 
 
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);
 
251
 
 
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 */);
 
255
 
 
256
  memsize += gimp_g_slist_get_memsize_foreach (manager->open_plug_ins,
 
257
                                               (GimpMemsizeFunc)
 
258
                                               gimp_object_get_memsize,
 
259
                                               gui_size);
 
260
  memsize += gimp_g_slist_get_memsize (manager->plug_in_stack, 0 /* FIXME */);
 
261
  memsize += gimp_g_slist_get_memsize (manager->history,       0);
 
262
 
 
263
  memsize += 0; /* FIXME manager->shm */
 
264
  memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->interpreter_db),
 
265
                                      gui_size);
 
266
  memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->environ_table),
 
267
                                      gui_size);
 
268
  memsize += 0; /* FIXME manager->plug_in_debug */
 
269
  memsize += gimp_g_list_get_memsize (manager->data_list, 0 /* FIXME */);
 
270
 
 
271
  return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
 
272
                                                                  gui_size);
 
273
}
 
274
 
 
275
GimpPlugInManager *
 
276
gimp_plug_in_manager_new (Gimp *gimp)
 
277
{
 
278
  GimpPlugInManager *manager;
 
279
 
 
280
  manager = g_object_new (GIMP_TYPE_PLUG_IN_MANAGER, NULL);
 
281
 
 
282
  manager->gimp = gimp;
 
283
 
 
284
  return manager;
 
285
}
 
286
 
 
287
void
 
288
gimp_plug_in_manager_initialize (GimpPlugInManager  *manager,
 
289
                                 GimpInitStatusFunc  status_callback)
 
290
{
 
291
  gchar *path;
 
292
 
 
293
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
294
  g_return_if_fail (status_callback != NULL);
 
295
 
 
296
  status_callback (NULL, _("Plug-In Interpreters"), 0.8);
 
297
 
 
298
  path = gimp_config_path_expand (manager->gimp->config->interpreter_path,
 
299
                                  TRUE, NULL);
 
300
  gimp_interpreter_db_load (manager->interpreter_db, path);
 
301
  g_free (path);
 
302
 
 
303
  status_callback (NULL, _("Plug-In Environment"), 0.9);
 
304
 
 
305
  path = gimp_config_path_expand (manager->gimp->config->environ_path,
 
306
                                  TRUE, NULL);
 
307
  gimp_environ_table_load (manager->environ_table, path);
 
308
  g_free (path);
 
309
 
 
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.
 
313
   */
 
314
  if (manager->gimp->use_shm)
 
315
    manager->shm = gimp_plug_in_shm_new ();
 
316
 
 
317
  manager->debug = gimp_plug_in_debug_new ();
 
318
}
 
319
 
 
320
void
 
321
gimp_plug_in_manager_exit (GimpPlugInManager *manager)
 
322
{
 
323
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
324
 
 
325
  while (manager->open_plug_ins)
 
326
    gimp_plug_in_close (manager->open_plug_ins->data, TRUE);
 
327
}
 
328
 
 
329
void
 
330
gimp_plug_in_manager_add_procedure (GimpPlugInManager   *manager,
 
331
                                    GimpPlugInProcedure *procedure)
 
332
{
 
333
  GSList *list;
 
334
 
 
335
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
336
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (procedure));
 
337
 
 
338
  for (list = manager->plug_in_procedures; list; list = list->next)
 
339
    {
 
340
      GimpPlugInProcedure *tmp_proc = list->data;
 
341
 
 
342
      if (strcmp (GIMP_OBJECT (procedure)->name,
 
343
                  GIMP_OBJECT (tmp_proc)->name) == 0)
 
344
        {
 
345
          GSList *list2;
 
346
 
 
347
          list->data = g_object_ref (procedure);
 
348
 
 
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));
 
353
 
 
354
          /* search the plugin list to see if any plugins had references to
 
355
           * the tmp_proc.
 
356
           */
 
357
          for (list2 = manager->plug_in_defs; list2; list2 = list2->next)
 
358
            {
 
359
              GimpPlugInDef *plug_in_def = list2->data;
 
360
 
 
361
              if (g_slist_find (plug_in_def->procedures, tmp_proc))
 
362
                gimp_plug_in_def_remove_procedure (plug_in_def, tmp_proc);
 
363
            }
 
364
 
 
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);
 
368
 
 
369
          /* and from the history */
 
370
          gimp_plug_in_manager_history_remove (manager, tmp_proc);
 
371
 
 
372
          g_object_unref (tmp_proc);
 
373
 
 
374
          return;
 
375
        }
 
376
    }
 
377
 
 
378
  manager->plug_in_procedures = g_slist_prepend (manager->plug_in_procedures,
 
379
                                                 g_object_ref (procedure));
 
380
}
 
381
 
 
382
void
 
383
gimp_plug_in_manager_add_temp_proc (GimpPlugInManager      *manager,
 
384
                                    GimpTemporaryProcedure *procedure)
 
385
{
 
386
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
387
  g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (procedure));
 
388
 
 
389
  gimp_pdb_register_procedure (manager->gimp->pdb, GIMP_PROCEDURE (procedure));
 
390
 
 
391
  manager->plug_in_procedures = g_slist_prepend (manager->plug_in_procedures,
 
392
                                                 g_object_ref (procedure));
 
393
}
 
394
 
 
395
void
 
396
gimp_plug_in_manager_remove_temp_proc (GimpPlugInManager      *manager,
 
397
                                       GimpTemporaryProcedure *procedure)
 
398
{
 
399
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
400
  g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (procedure));
 
401
 
 
402
  manager->plug_in_procedures = g_slist_remove (manager->plug_in_procedures,
 
403
                                                procedure);
 
404
 
 
405
  gimp_plug_in_manager_history_remove (manager,
 
406
                                       GIMP_PLUG_IN_PROCEDURE (procedure));
 
407
 
 
408
  gimp_pdb_unregister_procedure (manager->gimp->pdb,
 
409
                                 GIMP_PROCEDURE (procedure));
 
410
 
 
411
  g_object_unref (procedure);
 
412
}
 
413
 
 
414
void
 
415
gimp_plug_in_manager_add_open_plug_in (GimpPlugInManager *manager,
 
416
                                       GimpPlugIn        *plug_in)
 
417
{
 
418
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
419
  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
420
 
 
421
  manager->open_plug_ins = g_slist_prepend (manager->open_plug_ins,
 
422
                                            g_object_ref (plug_in));
 
423
 
 
424
  g_signal_emit (manager, manager_signals[PLUG_IN_OPENED], 0,
 
425
                 plug_in);
 
426
}
 
427
 
 
428
void
 
429
gimp_plug_in_manager_remove_open_plug_in (GimpPlugInManager *manager,
 
430
                                          GimpPlugIn        *plug_in)
 
431
{
 
432
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
433
  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
434
 
 
435
  manager->open_plug_ins = g_slist_remove (manager->open_plug_ins, plug_in);
 
436
 
 
437
  g_signal_emit (manager, manager_signals[PLUG_IN_CLOSED], 0,
 
438
                 plug_in);
 
439
 
 
440
  g_object_unref (plug_in);
 
441
}
 
442
 
 
443
void
 
444
gimp_plug_in_manager_plug_in_push (GimpPlugInManager *manager,
 
445
                                   GimpPlugIn        *plug_in)
 
446
{
 
447
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
448
  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
449
 
 
450
  manager->current_plug_in = plug_in;
 
451
 
 
452
  manager->plug_in_stack = g_slist_prepend (manager->plug_in_stack,
 
453
                                            manager->current_plug_in);
 
454
}
 
455
 
 
456
void
 
457
gimp_plug_in_manager_plug_in_pop (GimpPlugInManager *manager)
 
458
{
 
459
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
460
 
 
461
  if (manager->current_plug_in)
 
462
    manager->plug_in_stack = g_slist_remove (manager->plug_in_stack,
 
463
                                             manager->plug_in_stack->data);
 
464
 
 
465
  if (manager->plug_in_stack)
 
466
    manager->current_plug_in = manager->plug_in_stack->data;
 
467
  else
 
468
    manager->current_plug_in = NULL;
 
469
}
 
470
 
 
471
void
 
472
gimp_plug_in_manager_history_changed (GimpPlugInManager *manager)
 
473
{
 
474
  g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
 
475
 
 
476
  g_signal_emit (manager, manager_signals[HISTORY_CHANGED], 0);
 
477
}