26
26
#include <glib-object.h>
28
28
#include "libgimpbase/gimpbase.h"
29
#include "libgimpconfig/gimpconfig.h"
30
31
#include "config-types.h"
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"
41
39
#include "gimp-intl.h"
53
static void gimp_rc_class_init (GimpRcClass *klass);
54
static void gimp_rc_config_iface_init (gpointer iface,
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,
63
static void gimp_rc_get_property (GObject *object,
67
static gboolean gimp_rc_serialize (GimpConfig *object,
68
GimpConfigWriter *writer,
70
static gboolean gimp_rc_deserialize (GimpConfig *object,
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,
82
static GObjectClass *parent_class = NULL;
86
gimp_rc_get_type (void)
88
static GType rc_type = 0;
92
static const GTypeInfo rc_info =
96
NULL, /* base_finalize */
97
(GClassInitFunc) gimp_rc_class_init,
98
NULL, /* class_finalize */
99
NULL, /* class_data */
102
(GInstanceInitFunc) gimp_rc_init
104
static const GInterfaceInfo rc_iface_info =
106
gimp_rc_config_iface_init,
107
NULL, /* iface_finalize */
108
NULL /* iface_data */
111
rc_type = g_type_register_static (GIMP_TYPE_PLUGIN_CONFIG,
112
"GimpRc", &rc_info, 0);
114
g_type_add_interface_static (rc_type, GIMP_TYPE_CONFIG, &rc_iface_info);
51
static void gimp_rc_config_iface_init (GimpConfigInterface *iface);
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,
59
static void gimp_rc_get_property (GObject *object,
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,
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))
76
#define parent_class gimp_rc_parent_class
121
80
gimp_rc_class_init (GimpRcClass *klass)
123
GObjectClass *object_class;
125
parent_class = g_type_class_peek_parent (klass);
127
object_class = G_OBJECT_CLASS (klass);
82
GObjectClass *object_class = G_OBJECT_CLASS (klass);
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;
134
89
g_object_class_install_property (object_class, PROP_VERBOSE,
135
g_param_spec_boolean ("verbose",
90
g_param_spec_boolean ("verbose",
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",
144
100
G_PARAM_READWRITE |
145
101
G_PARAM_CONSTRUCT));
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",
150
107
G_PARAM_READWRITE |
151
108
G_PARAM_CONSTRUCT));
266
gimp_rc_config_iface_init (gpointer iface,
269
GimpConfigInterface *config_iface = (GimpConfigInterface *) iface;
271
config_iface->serialize = gimp_rc_serialize;
272
config_iface->deserialize = gimp_rc_deserialize;
273
config_iface->duplicate = gimp_rc_duplicate;
277
gimp_rc_serialize (GimpConfig *config,
278
GimpConfigWriter *writer,
281
if (data && GIMP_IS_RC (data))
283
if (! gimp_config_serialize_properties_diff (config, GIMP_CONFIG (data),
289
if (! gimp_config_serialize_properties (config, writer))
293
return gimp_config_serialize_unknown_tokens (config, writer);
297
gimp_rc_deserialize (GimpConfig *config,
302
return gimp_config_deserialize_properties (config,
303
scanner, nest_level, TRUE);
223
gimp_rc_config_iface_init (GimpConfigInterface *iface)
225
iface->serialize = gimp_rc_serialize;
226
iface->deserialize = gimp_rc_deserialize;
227
iface->duplicate = gimp_rc_duplicate;
317
241
GimpConfig *dup = g_object_new (GIMP_TYPE_RC, NULL);
319
gimp_config_sync (config, dup, 0);
243
gimp_config_sync (G_OBJECT (config), G_OBJECT (dup), 0);
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);
332
256
g_return_if_fail (GIMP_IS_RC (rc));
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));
338
262
if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
339
rc->system_gimprc, NULL, &error))
263
rc->system_gimprc, NULL, &error))
341
265
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
342
g_message (error->message);
266
g_message (error->message);
344
268
g_clear_error (&error);
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));
351
275
if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
352
rc->user_gimprc, NULL, &error))
276
rc->user_gimprc, NULL, &error))
354
278
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
587
510
global = g_object_new (GIMP_TYPE_RC, NULL);
589
512
gimp_config_deserialize_file (GIMP_CONFIG (global),
590
rc->system_gimprc, NULL, NULL);
513
rc->system_gimprc, NULL, NULL);
592
515
header = g_strconcat (top, rc->system_gimprc, bottom, NULL);
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));
598
521
if (! gimp_config_serialize_to_file (GIMP_CONFIG (rc),
600
header, footer, global,
523
header, footer, global,
603
526
g_message (error->message);
604
527
g_error_free (error);
608
531
g_object_unref (global);
536
* @rc: a #GimpRc object.
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.
543
gimp_rc_migrate (GimpRc *rc)
549
g_return_if_fail (GIMP_IS_RC (rc));
551
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (rc), &n_pspecs);
553
for (i = 0; i < n_pspecs; i++)
555
GParamSpec *pspec = pspecs[i];
557
if (GIMP_IS_PARAM_SPEC_CONFIG_PATH (pspec))
559
GValue value = { 0, };
561
g_value_init (&value, pspec->value_type);
563
g_param_value_set_default (pspec, &value);
564
g_object_set_property (G_OBJECT (rc), pspec->name, &value);
566
g_value_unset (&value);