1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* GimpConfig object property dumper.
5
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30
#include <glib-object.h>
32
#include "libgimpbase/gimpbase.h"
33
#include "libgimpcolor/gimpcolor.h"
36
#include "libgimpbase/gimpwin32-io.h"
39
#include "config-types.h"
41
#include "gimpconfig.h"
42
#include "gimpconfig-dump.h"
43
#include "gimpconfig-params.h"
44
#include "gimpconfig-serialize.h"
45
#include "gimpconfig-types.h"
46
#include "gimpconfigwriter.h"
51
static void dump_gimprc_system (GimpConfig *rc,
52
GimpConfigWriter *writer,
54
static void dump_gimprc_manpage (GimpConfig *rc,
55
GimpConfigWriter *writer,
57
static gchar * dump_describe_param (GParamSpec *param_spec);
58
static void dump_with_linebreaks (gint fd,
63
gimp_config_dump (GimpConfigDumpFormat format)
65
GimpConfigWriter *writer;
68
rc = g_object_new (GIMP_TYPE_RC, NULL);
69
writer = gimp_config_writer_new_fd (1);
73
case GIMP_CONFIG_DUMP_NONE:
76
case GIMP_CONFIG_DUMP_GIMPRC:
77
gimp_config_writer_comment (writer,
78
"Dump of the GIMP default configuration");
79
gimp_config_writer_linefeed (writer);
80
gimp_config_serialize_properties (rc, writer);
81
gimp_config_writer_linefeed (writer);
84
case GIMP_CONFIG_DUMP_GIMPRC_SYSTEM:
85
dump_gimprc_system (rc, writer, 1);
88
case GIMP_CONFIG_DUMP_GIMPRC_MANPAGE:
89
dump_gimprc_manpage (rc, writer, 1);
93
gimp_config_writer_finish (writer, NULL, NULL);
100
static const gchar *system_gimprc_header =
101
"This is the system-wide gimprc file. Any change made in this file "
102
"will affect all users of this system, provided that they are not "
103
"overriding the default values in their personal gimprc file.\n"
105
"Lines that start with a '#' are comments. Blank lines are ignored.\n"
107
"By default everything in this file is commented out. The file then "
108
"documents the default values and shows what changes are possible.\n"
110
"The variable ${gimp_dir} is set to the value of the environment "
111
"variable GIMP2_DIRECTORY or, if that is not set, the compiled-in "
112
"default value is used. If GIMP2_DIRECTORY is not an absolute path, "
113
"it is interpreted relative to your home directory.";
116
dump_gimprc_system (GimpConfig *rc,
117
GimpConfigWriter *writer,
121
GParamSpec **property_specs;
122
guint n_property_specs;
125
gimp_config_writer_comment (writer, system_gimprc_header);
126
gimp_config_writer_linefeed (writer);
128
klass = G_OBJECT_GET_CLASS (rc);
129
property_specs = g_object_class_list_properties (klass, &n_property_specs);
131
for (i = 0; i < n_property_specs; i++)
133
GParamSpec *prop_spec = property_specs[i];
136
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
139
if (prop_spec->flags & GIMP_PARAM_IGNORE)
142
comment = dump_describe_param (prop_spec);
145
gimp_config_writer_comment (writer, comment);
149
gimp_config_writer_comment_mode (writer, TRUE);
150
gimp_config_writer_linefeed (writer);
152
gimp_config_serialize_property (rc, prop_spec, writer);
154
gimp_config_writer_comment_mode (writer, FALSE);
155
gimp_config_writer_linefeed (writer);
158
g_free (property_specs);
162
static const gchar *man_page_header =
163
".\\\" This man-page is auto-generated by gimp --dump-gimprc-manpage.\n"
165
".TH GIMPRC 5 \"Version @GIMP_VERSION@\" \"GIMP Manual Pages\"\n"
167
"gimprc \\- gimp configuration file\n"
171
"file is a configuation file read by the GIMP when it starts up. There\n"
172
"are two of these: one system-wide one stored in\n"
173
"@gimpsysconfdir@/gimprc and a per-user \\fB$HOME\\fP/@gimpdir@/gimprc\n"
174
"which may override system settings.\n"
176
"Comments are introduced by a hash sign (#), and continue until the end\n"
177
"of the line. Blank lines are ignored.\n"
181
"file associates values with properties. These properties may be set\n"
182
"by lisp-like assignments of the form:\n"
184
"\\f3(\\f2property\\-name\\ value\\f3)\\f1\n"
188
".I property\\-name\n"
189
"is one of the property names described below.\n"
192
"is the value the property is to be set to.\n"
195
"Either spaces or tabs may be used to separate the name from the value.\n"
198
"Valid properties and their default values are:\n"
201
static const gchar *man_page_path =
203
".SH PATH EXPANSION\n"
204
"Strings of type PATH are expanded in a manner similar to\n"
206
"Specifically: tilde (~) is expanded to the user's home directory. Note that\n"
207
"the bash feature of being able to refer to other user's home directories\n"
208
"by writing ~userid/ is not valid in this file.\n"
210
"${variable} is expanded to the current value of an environment variable.\n"
211
"There are a few variables that are pre-defined:\n"
214
"The personal gimp directory which is set to the value of the environment\n"
215
"variable GIMP2_DIRECTORY or to ~/@gimpdir@.\n"
218
"Nase for paths to shareable data, which is set to the value of the\n"
219
"environment variable GIMP2_DATADIR or to the compiled-in default value\n"
222
".I gimp_plug_in_dir\n"
223
"Base to paths for architecture-specific plugins and modules, which is set\n"
224
"to the value of the environment variable GIMP2_PLUGINDIR or to the\n"
225
"compiled-in default value @gimpplugindir@.\n"
227
".I gimp_sysconf_dir\n"
228
"Path to configuration files, which is set to the value of the environment\n"
229
"variable GIMP2_SYSCONFDIR or to the compiled-in default value \n"
230
"@gimpsysconfdir@.\n"
233
static const gchar *man_page_footer =
236
".I @gimpsysconfdir@/gimprc\n"
237
"System-wide configuration file\n"
239
".I \\fB$HOME\\fP/@gimpdir@/gimprc\n"
240
"Per-user configuration file\n"
244
".BR gimptool (1),\n"
245
".BR gimp\\-remote (1)\n";
249
dump_gimprc_manpage (GimpConfig *rc,
250
GimpConfigWriter *writer,
254
GParamSpec **property_specs;
255
guint n_property_specs;
258
write (fd, man_page_header, strlen (man_page_header));
260
klass = G_OBJECT_GET_CLASS (rc);
261
property_specs = g_object_class_list_properties (klass, &n_property_specs);
263
for (i = 0; i < n_property_specs; i++)
265
GParamSpec *prop_spec = property_specs[i];
268
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
271
if (prop_spec->flags & GIMP_PARAM_IGNORE)
274
write (fd, ".TP\n", strlen (".TP\n"));
276
if (gimp_config_serialize_property (rc, prop_spec, writer))
280
desc = dump_describe_param (prop_spec);
282
dump_with_linebreaks (fd, desc);
289
g_free (property_specs);
291
write (fd, man_page_path, strlen (man_page_path));
292
write (fd, man_page_footer, strlen (man_page_footer));
296
static const gchar * display_format_description =
297
"This is a format string; certain % character sequences are recognised and "
298
"expanded as follows:\n"
300
"%% literal percent sign\n"
301
"%f bare filename, or \"Untitled\"\n"
302
"%F full path to file, or \"Untitled\"\n"
304
"%i view instance number\n"
305
"%t image type (RGB, grayscale, indexed)\n"
306
"%z zoom factor as a percentage\n"
307
"%s source scale factor\n"
308
"%d destination scale factor\n"
309
"%Dx expands to x if the image is dirty, the empty string otherwise\n"
310
"%Cx expands to x if the image is clean, the empty string otherwise\n"
311
"%B expands to (modified) if the image is dirty, the empty string otherwise\n"
312
"%A expands to (clean) if the image is clean, the empty string otherwise\n"
313
"%l the number of layers\n"
314
"%L the number of layers (long form)\n"
315
"%m memory used by the image\n"
316
"%n the name of the active layer/channel\n"
317
"%P the PDB id of the active layer/channel\n"
318
"%w image width in pixels\n"
319
"%W image width in real-world units\n"
320
"%h image height in pixels\n"
321
"%H image height in real-world units\n"
323
"%U unit abbreviation\n\n";
327
dump_describe_param (GParamSpec *param_spec)
331
const gchar *values = NULL;
333
blurb = g_param_spec_get_blurb (param_spec);
337
g_warning ("FIXME: Property '%s' has no blurb.", param_spec->name);
339
blurb = g_strdup_printf ("The %s property has no description.",
343
type = param_spec->value_type;
345
if (g_type_is_a (type, GIMP_TYPE_RGB))
348
"The color is specified in the form (color-rgba red green blue alpha) "
349
"with channel values as floats between 0.0 and 1.0.";
351
else if (g_type_is_a (type, GIMP_TYPE_MEMSIZE))
354
"The integer size can contain a suffix of 'B', 'K', 'M' or 'G' which "
355
"makes GIMP interpret the size as being specified in bytes, kilobytes, "
356
"megabytes or gigabytes. If no suffix is specified the size defaults "
357
"to being specified in kilobytes.";
359
else if (g_type_is_a (type, GIMP_TYPE_PATH))
361
switch (gimp_param_spec_path_type (param_spec))
363
case GIMP_PARAM_PATH_FILE:
364
values = "This is a single filename.";
367
case GIMP_PARAM_PATH_FILE_LIST:
368
switch (G_SEARCHPATH_SEPARATOR)
371
values = "This is a colon-separated list of files.";
374
values = "This is a semicolon-separated list of files.";
377
g_warning ("unhandled G_SEARCHPATH_SEPARATOR value");
382
case GIMP_PARAM_PATH_DIR:
383
values = "This is a single folder.";
386
case GIMP_PARAM_PATH_DIR_LIST:
387
switch (G_SEARCHPATH_SEPARATOR)
390
values = "This is a colon-separated list of folders to search.";
393
values = "This is a semicolon-separated list of folders to search.";
396
g_warning ("unhandled G_SEARCHPATH_SEPARATOR value");
402
else if (g_type_is_a (type, GIMP_TYPE_UNIT))
405
"The unit can be one inches, millimeters, points or picas plus "
406
"those in your user units database.";
408
else if (g_type_is_a (type, GIMP_TYPE_CONFIG))
410
values = "This is a parameter list.";
414
switch (G_TYPE_FUNDAMENTAL (type))
417
values = "Possible values are yes and no.";
423
values = "This is an integer value.";
427
values = "This is a float value.";
431
if (strcmp (g_param_spec_get_name (param_spec), "image-title-format")
433
strcmp (g_param_spec_get_name (param_spec), "image-status-format"))
435
values = "This is a string value.";
439
values = display_format_description;
444
GEnumClass *enum_class;
445
GEnumValue *enum_value;
449
enum_class = g_type_class_peek (type);
451
str = g_string_new (blurb);
453
g_string_append (str, " Possible values are ");
455
for (i = 0, enum_value = enum_class->values;
456
i < enum_class->n_values;
459
g_string_append (str, enum_value->value_nick);
461
switch (enum_class->n_values - i)
464
g_string_append_c (str, '.');
467
g_string_append (str, " and ");
470
g_string_append (str, ", ");
475
return g_string_free (str, FALSE);
484
g_warning ("FIXME: Can't tell anything about a %s.", g_type_name (type));
486
return g_strdup_printf ("%s %s", blurb, values);
490
#define LINE_LENGTH 78
493
dump_with_linebreaks (gint fd,
496
gint len = strlen (text);
503
/* groff doesn't like lines to start with a single quote */
505
write (fd, "\\&", 2); /* this represents a zero width space */
507
for (t = text, i = 0, space = 0;
508
*t != '\n' && (i <= LINE_LENGTH || space == 0) && i < len;
511
if (g_ascii_isspace (*t))
515
if (i > LINE_LENGTH && space && *t != '\n')
522
write (fd, ".br\n", 4);