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

« back to all changes in this revision

Viewing changes to app/config/gimprc.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
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * GimpRc, the object for GIMPs user configuration file gimprc.
26
26
#include <glib-object.h>
27
27
 
28
28
#include "libgimpbase/gimpbase.h"
 
29
#include "libgimpconfig/gimpconfig.h"
29
30
 
30
31
#include "config-types.h"
31
32
 
32
 
#include "gimpconfig.h"
33
 
#include "gimpconfig-deserialize.h"
34
 
#include "gimpconfig-error.h"
35
 
#include "gimpconfig-params.h"
36
 
#include "gimpconfig-path.h"
37
 
#include "gimpconfig-serialize.h"
38
 
#include "gimpconfig-utils.h"
 
33
#include "gimpconfig-file.h"
39
34
#include "gimprc.h"
 
35
#include "gimprc-deserialize.h"
 
36
#include "gimprc-serialize.h"
 
37
#include "gimprc-unknown.h"
40
38
 
41
39
#include "gimp-intl.h"
42
40
 
50
48
};
51
49
 
52
50
 
53
 
static void         gimp_rc_class_init        (GimpRcClass      *klass);
54
 
static void         gimp_rc_config_iface_init (gpointer          iface,
55
 
                                               gpointer          iface_data);
56
 
static void         gimp_rc_init              (GimpRc           *rc);
57
 
static void         gimp_rc_dispose           (GObject          *object);
58
 
static void         gimp_rc_finalize          (GObject          *object);
59
 
static void         gimp_rc_set_property      (GObject          *object,
60
 
                                               guint             property_id,
61
 
                                               const GValue     *value,
62
 
                                               GParamSpec       *pspec);
63
 
static void         gimp_rc_get_property      (GObject          *object,
64
 
                                               guint             property_id,
65
 
                                               GValue           *value,
66
 
                                               GParamSpec       *pspec);
67
 
static gboolean     gimp_rc_serialize         (GimpConfig       *object,
68
 
                                               GimpConfigWriter *writer,
69
 
                                               gpointer          data);
70
 
static gboolean     gimp_rc_deserialize       (GimpConfig       *object,
71
 
                                               GScanner         *scanner,
72
 
                                               gint              nest_level,
73
 
                                               gpointer          data);
74
 
static GimpConfig * gimp_rc_duplicate         (GimpConfig       *object);
75
 
static void         gimp_rc_load              (GimpRc           *rc);
76
 
static gboolean     gimp_rc_idle_save         (GimpRc           *rc);
77
 
static void         gimp_rc_notify            (GimpRc           *rc,
78
 
                                               GParamSpec       *param,
79
 
                                               gpointer          data);
80
 
 
81
 
 
82
 
static GObjectClass *parent_class = NULL;
83
 
 
84
 
 
85
 
GType
86
 
gimp_rc_get_type (void)
87
 
{
88
 
  static GType rc_type = 0;
89
 
 
90
 
  if (! rc_type)
91
 
    {
92
 
      static const GTypeInfo rc_info =
93
 
      {
94
 
        sizeof (GimpRcClass),
95
 
        NULL,           /* base_init      */
96
 
        NULL,           /* base_finalize  */
97
 
        (GClassInitFunc) gimp_rc_class_init,
98
 
        NULL,           /* class_finalize */
99
 
        NULL,           /* class_data     */
100
 
        sizeof (GimpRc),
101
 
        0,              /* n_preallocs    */
102
 
        (GInstanceInitFunc) gimp_rc_init
103
 
      };
104
 
      static const GInterfaceInfo rc_iface_info =
105
 
      {
106
 
        gimp_rc_config_iface_init,
107
 
        NULL,           /* iface_finalize */
108
 
        NULL            /* iface_data     */
109
 
      };
110
 
 
111
 
      rc_type = g_type_register_static (GIMP_TYPE_PLUGIN_CONFIG,
112
 
                                        "GimpRc", &rc_info, 0);
113
 
 
114
 
      g_type_add_interface_static (rc_type, GIMP_TYPE_CONFIG, &rc_iface_info);
115
 
    }
116
 
 
117
 
  return rc_type;
118
 
}
 
51
static void         gimp_rc_config_iface_init (GimpConfigInterface *iface);
 
52
 
 
53
static void         gimp_rc_dispose           (GObject      *object);
 
54
static void         gimp_rc_finalize          (GObject      *object);
 
55
static void         gimp_rc_set_property      (GObject      *object,
 
56
                                               guint         property_id,
 
57
                                               const GValue *value,
 
58
                                               GParamSpec   *pspec);
 
59
static void         gimp_rc_get_property      (GObject      *object,
 
60
                                               guint         property_id,
 
61
                                               GValue       *value,
 
62
                                               GParamSpec   *pspec);
 
63
 
 
64
static GimpConfig * gimp_rc_duplicate         (GimpConfig   *object);
 
65
static void         gimp_rc_load              (GimpRc       *rc);
 
66
static gboolean     gimp_rc_idle_save         (GimpRc       *rc);
 
67
static void         gimp_rc_notify            (GimpRc       *rc,
 
68
                                               GParamSpec   *param,
 
69
                                               gpointer      data);
 
70
 
 
71
 
 
72
G_DEFINE_TYPE_WITH_CODE (GimpRc, gimp_rc, GIMP_TYPE_PLUGIN_CONFIG,
 
73
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
 
74
                                                gimp_rc_config_iface_init))
 
75
 
 
76
#define parent_class gimp_rc_parent_class
 
77
 
119
78
 
120
79
static void
121
80
gimp_rc_class_init (GimpRcClass *klass)
122
81
{
123
 
  GObjectClass *object_class;
124
 
 
125
 
  parent_class = g_type_class_peek_parent (klass);
126
 
 
127
 
  object_class = G_OBJECT_CLASS (klass);
 
82
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
128
83
 
129
84
  object_class->dispose      = gimp_rc_dispose;
130
85
  object_class->finalize     = gimp_rc_finalize;
132
87
  object_class->get_property = gimp_rc_get_property;
133
88
 
134
89
  g_object_class_install_property (object_class, PROP_VERBOSE,
135
 
                                   g_param_spec_boolean ("verbose",
136
 
                                                         NULL, NULL,
137
 
                                                         FALSE,
138
 
                                                         G_PARAM_READWRITE |
139
 
                                                         G_PARAM_CONSTRUCT));
 
90
                                   g_param_spec_boolean ("verbose",
 
91
                                                         NULL, NULL,
 
92
                                                         FALSE,
 
93
                                                         G_PARAM_READWRITE |
 
94
                                                         G_PARAM_CONSTRUCT));
 
95
 
140
96
  g_object_class_install_property (object_class, PROP_SYSTEM_GIMPRC,
141
 
                                   g_param_spec_string ("system-gimprc",
 
97
                                   g_param_spec_string ("system-gimprc",
142
98
                                                        NULL, NULL,
143
 
                                                        NULL,
 
99
                                                        NULL,
144
100
                                                        G_PARAM_READWRITE |
145
101
                                                        G_PARAM_CONSTRUCT));
 
102
 
146
103
  g_object_class_install_property (object_class, PROP_USER_GIMPRC,
147
 
                                   g_param_spec_string ("user-gimprc",
 
104
                                   g_param_spec_string ("user-gimprc",
148
105
                                                        NULL, NULL,
149
 
                                                        NULL,
 
106
                                                        NULL,
150
107
                                                        G_PARAM_READWRITE |
151
108
                                                        G_PARAM_CONSTRUCT));
152
109
}
263
220
}
264
221
 
265
222
static void
266
 
gimp_rc_config_iface_init (gpointer  iface,
267
 
                           gpointer  iface_data)
268
 
{
269
 
  GimpConfigInterface *config_iface = (GimpConfigInterface *) iface;
270
 
 
271
 
  config_iface->serialize   = gimp_rc_serialize;
272
 
  config_iface->deserialize = gimp_rc_deserialize;
273
 
  config_iface->duplicate   = gimp_rc_duplicate;
274
 
}
275
 
 
276
 
static gboolean
277
 
gimp_rc_serialize (GimpConfig       *config,
278
 
                   GimpConfigWriter *writer,
279
 
                   gpointer          data)
280
 
{
281
 
  if (data && GIMP_IS_RC (data))
282
 
    {
283
 
      if (! gimp_config_serialize_properties_diff (config, GIMP_CONFIG (data),
284
 
                                                   writer))
285
 
        return FALSE;
286
 
    }
287
 
  else
288
 
    {
289
 
      if (! gimp_config_serialize_properties (config, writer))
290
 
        return FALSE;
291
 
    }
292
 
 
293
 
  return gimp_config_serialize_unknown_tokens (config, writer);
294
 
}
295
 
 
296
 
static gboolean
297
 
gimp_rc_deserialize (GimpConfig *config,
298
 
                     GScanner   *scanner,
299
 
                     gint        nest_level,
300
 
                     gpointer    data)
301
 
{
302
 
  return gimp_config_deserialize_properties (config,
303
 
                                             scanner, nest_level, TRUE);
 
223
gimp_rc_config_iface_init (GimpConfigInterface *iface)
 
224
{
 
225
  iface->serialize   = gimp_rc_serialize;
 
226
  iface->deserialize = gimp_rc_deserialize;
 
227
  iface->duplicate   = gimp_rc_duplicate;
304
228
}
305
229
 
306
230
static void
308
232
                                 const gchar *value,
309
233
                                 gpointer     user_data)
310
234
{
311
 
  gimp_config_add_unknown_token (GIMP_CONFIG (user_data), key, value);
 
235
  gimp_rc_add_unknown_token (GIMP_CONFIG (user_data), key, value);
312
236
}
313
237
 
314
238
static GimpConfig *
316
240
{
317
241
  GimpConfig *dup = g_object_new (GIMP_TYPE_RC, NULL);
318
242
 
319
 
  gimp_config_sync (config, dup, 0);
 
243
  gimp_config_sync (G_OBJECT (config), G_OBJECT (dup), 0);
320
244
 
321
 
  gimp_config_foreach_unknown_token (config,
322
 
                                     gimp_rc_duplicate_unknown_token, dup);
 
245
  gimp_rc_foreach_unknown_token (config,
 
246
                                 gimp_rc_duplicate_unknown_token, dup);
323
247
 
324
248
  return dup;
325
249
}
332
256
  g_return_if_fail (GIMP_IS_RC (rc));
333
257
 
334
258
  if (rc->verbose)
335
 
    g_print (_("Parsing '%s'\n"),
336
 
             gimp_filename_to_utf8 (rc->system_gimprc));
 
259
    g_print ("Parsing '%s'\n",
 
260
             gimp_filename_to_utf8 (rc->system_gimprc));
337
261
 
338
262
  if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
339
 
                                      rc->system_gimprc, NULL, &error))
 
263
                                      rc->system_gimprc, NULL, &error))
340
264
    {
341
265
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
342
 
        g_message (error->message);
 
266
        g_message (error->message);
343
267
 
344
268
      g_clear_error (&error);
345
269
    }
346
270
 
347
271
  if (rc->verbose)
348
 
    g_print (_("Parsing '%s'\n"),
349
 
             gimp_filename_to_utf8 (rc->user_gimprc));
 
272
    g_print ("Parsing '%s'\n",
 
273
             gimp_filename_to_utf8 (rc->user_gimprc));
350
274
 
351
275
  if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
352
 
                                      rc->user_gimprc, NULL, &error))
 
276
                                      rc->user_gimprc, NULL, &error))
353
277
    {
354
278
      if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
355
279
        {
474
398
    {
475
399
      prop_spec = property_specs[i];
476
400
 
477
 
      if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE) ||
 
401
      if (! (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE) ||
478
402
          strcmp (prop_spec->name, key))
479
403
        {
480
404
          prop_spec = NULL;
498
422
    }
499
423
  else
500
424
    {
501
 
      retval = g_strdup (gimp_config_lookup_unknown_token (GIMP_CONFIG (rc),
502
 
                                                           key));
 
425
      retval = g_strdup (gimp_rc_lookup_unknown_token (GIMP_CONFIG (rc), key));
503
426
    }
504
427
 
505
428
  g_free (property_specs);
506
429
 
507
430
  if (!retval)
508
431
    {
509
 
      const gchar *path_tokens[] =
 
432
      const gchar * const path_tokens[] =
510
433
      {
511
434
        "gimp_dir",
512
435
        "gimp_data_dir",
540
463
 * @token:
541
464
 * @value:
542
465
 *
543
 
 * Calls gimp_config_add_unknown_token() and triggers an idle-save if
 
466
 * Calls gimp_rc_add_unknown_token() and triggers an idle-save if
544
467
 * autosave is enabled on @gimprc.
545
468
 **/
546
469
void
550
473
{
551
474
  g_return_if_fail (GIMP_IS_RC (rc));
552
475
 
553
 
  gimp_config_add_unknown_token (GIMP_CONFIG (rc), token, value);
 
476
  gimp_rc_add_unknown_token (GIMP_CONFIG (rc), token, value);
554
477
 
555
478
  if (rc->autosave)
556
479
    gimp_rc_notify (rc, NULL, NULL);
577
500
    "takes precedence over the value defined in the system-wide gimprc: ";
578
501
  const gchar *bottom =
579
502
    "\n"
580
 
    "Most values can be set within The GIMP by changing some options in "
 
503
    "Most values can be set within GIMP by changing some options in "
581
504
    "the Preferences dialog.";
582
505
  const gchar *footer =
583
506
    "end of gimprc";
587
510
  global = g_object_new (GIMP_TYPE_RC, NULL);
588
511
 
589
512
  gimp_config_deserialize_file (GIMP_CONFIG (global),
590
 
                                rc->system_gimprc, NULL, NULL);
 
513
                                rc->system_gimprc, NULL, NULL);
591
514
 
592
515
  header = g_strconcat (top, rc->system_gimprc, bottom, NULL);
593
516
 
594
517
  if (rc->verbose)
595
 
    g_print (_("Saving '%s'\n"),
596
 
             gimp_filename_to_utf8 (rc->user_gimprc));
 
518
    g_print ("Writing '%s'\n",
 
519
             gimp_filename_to_utf8 (rc->user_gimprc));
597
520
 
598
521
  if (! gimp_config_serialize_to_file (GIMP_CONFIG (rc),
599
 
                                       rc->user_gimprc,
600
 
                                       header, footer, global,
601
 
                                       &error))
 
522
                                       rc->user_gimprc,
 
523
                                       header, footer, global,
 
524
                                       &error))
602
525
    {
603
526
      g_message (error->message);
604
527
      g_error_free (error);
607
530
  g_free (header);
608
531
  g_object_unref (global);
609
532
}
 
533
 
 
534
/**
 
535
 * gimp_rc_migrate:
 
536
 * @rc: a #GimpRc object.
 
537
 *
 
538
 * Resets all GimpParamConfigPath properties of the passed rc object
 
539
 * to their default values, in order to prevent paths in a migrated
 
540
 * gimprc to refer to folders in the old GIMP's user directory.
 
541
 **/
 
542
void
 
543
gimp_rc_migrate (GimpRc *rc)
 
544
{
 
545
  GParamSpec **pspecs;
 
546
  guint        n_pspecs;
 
547
  gint         i;
 
548
 
 
549
  g_return_if_fail (GIMP_IS_RC (rc));
 
550
 
 
551
  pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (rc), &n_pspecs);
 
552
 
 
553
  for (i = 0; i < n_pspecs; i++)
 
554
    {
 
555
      GParamSpec *pspec = pspecs[i];
 
556
 
 
557
      if (GIMP_IS_PARAM_SPEC_CONFIG_PATH (pspec))
 
558
        {
 
559
          GValue value = { 0, };
 
560
 
 
561
          g_value_init (&value, pspec->value_type);
 
562
 
 
563
          g_param_value_set_default (pspec, &value);
 
564
          g_object_set_property (G_OBJECT (rc), pspec->name, &value);
 
565
 
 
566
          g_value_unset (&value);
 
567
        }
 
568
    }
 
569
 
 
570
  g_free (pspecs);
 
571
}