small cleanup.

2002-12-01  Sven Neumann  <sven@gimp.org>

	* app/config/gimpconfig-blurbs.h: small cleanup.

	* app/config/gimpconfig-serialize.[ch]: export more functionality.

	* app/config/gimpconfig-dump.c: added some code to dump a
	commented version of the system-wide gimprc with default values.

2002-12-01  Sven Neumann  <neo@wintermute>

	* libgimp/Makefile.am (IGNORE_HFILES): ignore gimpmiscui.h.
This commit is contained in:
Sven Neumann 2002-12-01 22:31:36 +00:00 committed by Sven Neumann
parent acb7bac011
commit 62be2fff30
7 changed files with 401 additions and 204 deletions

View File

@ -1,3 +1,12 @@
2002-12-01 Sven Neumann <sven@gimp.org>
* app/config/gimpconfig-blurbs.h: small cleanup.
* app/config/gimpconfig-serialize.[ch]: export more functionality.
* app/config/gimpconfig-dump.c: added some code to dump a
commented version of the system-wide gimprc with default values.
2002-12-01 Sven Neumann <sven@gimp.org>
* app/core/core-types.h: prefix PIXELS and POINTS with GIMP

View File

@ -171,9 +171,7 @@
#define DEFAULT_UNIT_BLURB \
"Set the default unit for new images and for the File/New dialog. " \
"This units will be used for coordinate display when not in dot-for-dot " \
"mode. The default unit can be one of inches , millimeters, points or " \
"picas or the identifier of one of the units defined in your user units " \
"database."
"mode."
#define DEFAULT_XRESOLUTION_BLURB \
"Set the default horizontal resolution for new images and for the " \
@ -185,9 +183,7 @@
#define DEFAULT_RESOLUTION_UNIT_BLURB \
"Set the units for the display of the default resolution in the " \
"File/New dialog. The default resolution units can be one of inches, " \
"millimeters, points or picas or the identifier of one of the units " \
"defined in your user unit database. The default is inches."
"File/New dialog."
#define MONITOR_XRESOLUTION_BLURB \
"Set the monitor's horizontal resolution, in dots per inch. If set to " \
@ -226,7 +222,8 @@
"%h image height in pixels\n" \
"%H image height in real-world units\n" \
"%u unit symbol\n" \
"%U unit abbreviation\n"
"%U unit abbreviation\n\n"
#define IMAGE_STATUS_FORMAT_BLURB \
"Set the text to appear in image window status bars. See image-title-format " \

View File

@ -23,6 +23,9 @@
#include "stdlib.h"
#include "string.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <glib-object.h>
@ -32,24 +35,44 @@
#include "config-types.h"
#include "gimpconfig.h"
#include "gimpconfig-params.h"
#include "gimpconfig-serialize.h"
#include "gimpconfig-types.h"
#include "gimprc.h"
static gint dump_system_gimprc (void);
static gchar * dump_get_comment (GParamSpec *param_spec);
int
main (int argc,
char *argv[])
{
GObject *rc;
g_type_init ();
if (argc > 1)
{
if (strcmp (argv[1], "--system-gimprc") == 0)
{
return dump_system_gimprc ();
}
else
{
g_printerr ("%s -- GimpConfig dump utility\n\n", argv[0]);
g_printerr ("Options:\n"
" --system-gimprc create a commented system gimprc\n");
return EXIT_FAILURE;
}
}
rc = g_object_new (GIMP_TYPE_RC, NULL);
g_print ("# Dump of the GIMP default configuration\n\n");
gimp_config_serialize_properties (rc, 1, 0);
g_print ("\n");
g_object_unref (rc);
@ -58,6 +81,192 @@ main (int argc,
}
static gint
dump_system_gimprc (void)
{
GObjectClass *klass;
GParamSpec **property_specs;
GObject *rc;
GString *str;
guint n_property_specs;
guint i;
str = g_string_new
("# This is the system-wide gimprc file. Any change made in this file\n"
"# will affect all users of this system, provided that they are not\n"
"# overriding the default values in their personal gimprc file.\n"
"#\n"
"# Lines that start with a '#' are comments.\n"
"# Blank lines are ignored.\n"
"\n"
"# The variable gimp_dir is set to either the interned value\n"
"# @gimpdir@ or the environment variable GIMP_DIRECTORY. If\n"
"# the path in GIMP_DIRECTORY is relative, it is considered\n"
"# relative to your home directory.\n"
"\n"
"(prefix \"@prefix@\"\n"
"(exec_prefix \"@exec_prefix@\")\n"
"(gimp_data_dir \"@gimpdatadir@\")\n"
"(gimp_plugin_dir \"@gimpplugindir@\")\n"
"\n");
write (1, str->str, str->len);
rc = g_object_new (GIMP_TYPE_RC, NULL);
klass = G_OBJECT_GET_CLASS (rc);
property_specs = g_object_class_list_properties (klass, &n_property_specs);
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec = property_specs[i];
gchar *comment;
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
g_string_assign (str, "");
comment = dump_get_comment (prop_spec);
if (comment)
{
gimp_config_serialize_comment (str, comment);
g_free (comment);
g_string_append (str, "#\n");
}
g_string_append (str, "# ");
if (gimp_config_serialize_property (rc, prop_spec, str, TRUE))
{
g_string_append (str, "\n");
write (1, str->str, str->len);
}
else if (prop_spec->value_type != G_TYPE_STRING)
{
g_warning ("couldn't serialize property %s::%s of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (rc)),
prop_spec->name,
g_type_name (prop_spec->value_type));
}
}
g_free (property_specs);
g_object_unref (rc);
g_string_free (str, TRUE);
return EXIT_SUCCESS;
}
static gchar *
dump_get_comment (GParamSpec *param_spec)
{
GType type;
const gchar *blurb;
const gchar *values = NULL;
blurb = g_param_spec_get_blurb (param_spec);
if (!blurb)
{
g_warning ("FIXME: Property '%s' has no blurb.", param_spec->name);
blurb = param_spec->name;
}
type = param_spec->value_type;
if (g_type_is_a (type, GIMP_TYPE_COLOR))
{
values = "The color is specified as a list of doubles (r g b a).";
}
else if (g_type_is_a (type, GIMP_TYPE_MEMSIZE))
{
values =
"The integer size can contain a suffix of 'B', 'K', 'M' or 'G' which "
"makes GIMP interpret the size as being specified in bytes, kilobytes, "
"megabytes or gigabytes. If no suffix is specified the size defaults "
"to being specified in kilobytes.";
}
else if (g_type_is_a (type, GIMP_TYPE_PATH))
{
values = "This is a colon-separated list of directories to search.";
}
else if (g_type_is_a (type, GIMP_TYPE_UNIT))
{
values =
"The unit can be one inches, millimeters, points or picas plus "
"those in your user units database.";
}
else
{
switch (G_TYPE_FUNDAMENTAL (type))
{
case G_TYPE_BOOLEAN:
values = "Possible values are yes and no.";
break;
case G_TYPE_INT:
case G_TYPE_UINT:
case G_TYPE_LONG:
case G_TYPE_ULONG:
values = "This is an integer value.";
break;
case G_TYPE_FLOAT:
case G_TYPE_DOUBLE:
values = "This is a float value.";
break;
case G_TYPE_STRING:
values = "This is a string value.";
break;
case G_TYPE_ENUM:
{
GEnumClass *enum_class;
GEnumValue *enum_value;
GString *str;
gint i;
enum_class = g_type_class_peek (type);
str = g_string_new (blurb);
g_string_append (str, " Possible values are ");
for (i = 0, enum_value = enum_class->values;
i < enum_class->n_values;
i++, enum_value++)
{
g_string_append (str, enum_value->value_nick);
switch (enum_class->n_values - i)
{
case 1:
g_string_append_c (str, '.');
break;
case 2:
g_string_append (str, " and ");
break;
default:
g_string_append (str, ", ");
break;
}
}
return g_string_free (str, FALSE);
}
break;
default:
break;
}
}
if (!values)
g_warning ("FIXME: Can't tell anything about a %s.", g_type_name (type));
return g_strdup_printf ("%s %s", blurb, values);
}
/* some dummy funcs so we can properly link this beast */
const gchar *

View File

@ -43,15 +43,9 @@
#include "gimpconfig-utils.h"
static gboolean gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped);
static void gimp_config_serialize_comment (GString *str,
const gchar *comment);
static void serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data);
static void serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data);
/**
@ -71,7 +65,6 @@ gimp_config_serialize_properties (GObject *object,
guint n_property_specs;
guint i;
GString *str;
gboolean property_written = FALSE;
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
@ -86,33 +79,19 @@ gimp_config_serialize_properties (GObject *object,
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec;
const gchar *blurb;
prop_spec = property_specs[i];
GParamSpec *prop_spec = property_specs[i];
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
if (property_written)
g_string_assign (str, "\n");
else
g_string_assign (str, "");
if ((blurb = g_param_spec_get_blurb (prop_spec)) != NULL)
gimp_config_serialize_comment (str, blurb);
gimp_config_string_indent (str, indent_level);
g_string_append_printf (str, "(%s ", prop_spec->name);
if (gimp_config_serialize_property (object, prop_spec, str, TRUE))
{
g_string_append (str, ")\n");
property_written = TRUE;
{
if (write (fd, str->str, str->len) == -1)
return FALSE;
g_string_assign (str, "\n");
}
else if (prop_spec->value_type != G_TYPE_STRING)
{
@ -120,6 +99,8 @@ gimp_config_serialize_properties (GObject *object,
g_type_name (G_TYPE_FROM_INSTANCE (object)),
prop_spec->name,
g_type_name (prop_spec->value_type));
g_string_assign (str, "");
}
}
@ -168,7 +149,6 @@ gimp_config_serialize_changed_properties (GObject *new,
for (list = diff; list; list = g_list_next (list))
{
GParamSpec *prop_spec;
const gchar *blurb;
GValue new_value = { 0, };
prop_spec = (GParamSpec *) list->data;
@ -182,9 +162,6 @@ gimp_config_serialize_changed_properties (GObject *new,
else
g_string_assign (str, "");
if ((blurb = g_param_spec_get_blurb (prop_spec)) != NULL)
gimp_config_serialize_comment (str, blurb);
gimp_config_string_indent (str, indent_level);
g_string_append_printf (str, "(%s ", prop_spec->name);
@ -214,6 +191,75 @@ gimp_config_serialize_changed_properties (GObject *new,
return TRUE;
}
gboolean
gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped)
{
GTypeClass *owner_class;
GimpConfigInterface *config_iface;
GimpConfigInterface *parent_iface;
GValue value = { 0, };
if (! (param_spec->flags & GIMP_PARAM_SERIALIZE))
return FALSE;
g_string_append_printf (str, "(%s ", param_spec->name);
g_value_init (&value, param_spec->value_type);
g_object_get_property (object, param_spec->name, &value);
owner_class = g_type_class_peek (param_spec->owner_type);
config_iface = g_type_interface_peek (owner_class,
GIMP_TYPE_CONFIG_INTERFACE);
/* We must call deserialize_property() *only* if the *exact* class
* which implements it is param_spec->owner_type's class.
*
* Therefore, we ask param_spec->owner_type's immediate parent class
* for it's GimpConfigInterface and check if we get a different pointer.
*
* (if the pointers are the same, param_spec->owner_type's
* GimpConfigInterface is inherited from one of it's parent classes
* and thus not able to handle param_spec->owner_type's properties).
*/
if (config_iface)
{
GTypeClass *owner_parent_class;
owner_parent_class = g_type_class_peek_parent (owner_class),
parent_iface = g_type_interface_peek (owner_parent_class,
GIMP_TYPE_CONFIG_INTERFACE);
}
if (config_iface &&
config_iface != parent_iface && /* see comment above */
config_iface->serialize_property)
{
if (! config_iface->serialize_property (object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
return FALSE;
}
else
{
if (! gimp_config_serialize_value (&value, str, escaped))
return FALSE;
}
g_value_unset (&value);
g_string_append (str, ")\n");
return TRUE;
}
/**
* gimp_config_serialize_value:
* @value: a #GValue.
@ -329,7 +375,8 @@ gimp_config_serialize_value (const GValue *value,
{
g_string_append (str, " ");
if (! gimp_config_serialize_value (g_value_array_get_nth (array, i),
if (! gimp_config_serialize_value (g_value_array_get_nth (array,
i),
str, escaped))
return FALSE;
}
@ -382,68 +429,7 @@ gimp_config_serialize_unknown_tokens (GObject *object,
return (write (fd, str->str, str->len) != -1);
}
static gboolean
gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped)
{
GTypeClass *owner_class;
GimpConfigInterface *gimp_config_iface;
GimpConfigInterface *parent_iface;
GValue value = { 0, };
gboolean retval;
g_value_init (&value, param_spec->value_type);
g_object_get_property (object, param_spec->name, &value);
owner_class = g_type_class_peek (param_spec->owner_type);
gimp_config_iface = g_type_interface_peek (owner_class,
GIMP_TYPE_CONFIG_INTERFACE);
/* We must call deserialize_property() *only* if the *exact* class
* which implements it is param_spec->owner_type's class.
*
* Therefore, we ask param_spec->owner_type's immediate parent class
* for it's GimpConfigInterface and check if we get a different pointer.
*
* (if the pointers are the same, param_spec->owner_type's
* GimpConfigInterface is inherited from one of it's parent classes
* and thus not able to handle param_spec->owner_type's properties).
*/
if (gimp_config_iface)
{
GTypeClass *owner_parent_class;
owner_parent_class = g_type_class_peek_parent (owner_class),
parent_iface = g_type_interface_peek (owner_parent_class,
GIMP_TYPE_CONFIG_INTERFACE);
}
if (gimp_config_iface &&
gimp_config_iface != parent_iface && /* see comment above */
gimp_config_iface->serialize_property &&
gimp_config_iface->serialize_property (object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
{
retval = TRUE;
}
else
{
retval = gimp_config_serialize_value (&value, str, escaped);
}
g_value_unset (&value);
return retval;
}
static void
void
gimp_config_serialize_comment (GString *str,
const gchar *comment)
{
@ -474,8 +460,6 @@ gimp_config_serialize_comment (GString *str,
comment += i;
len -= i;
}
g_string_append_printf (str, "#\n");
}
static void

View File

@ -33,8 +33,15 @@ gboolean gimp_config_serialize_changed_properties (GObject *new,
gboolean gimp_config_serialize_unknown_tokens (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped);
gboolean gimp_config_serialize_value (const GValue *value,
GString *str,
gboolean escaped);
void gimp_config_serialize_comment (GString *str,
const gchar *comment);
#endif /* __GIMP_CONFIG_SERIALIZE_H__ */

View File

@ -43,15 +43,9 @@
#include "gimpconfig-utils.h"
static gboolean gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped);
static void gimp_config_serialize_comment (GString *str,
const gchar *comment);
static void serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data);
static void serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data);
/**
@ -71,7 +65,6 @@ gimp_config_serialize_properties (GObject *object,
guint n_property_specs;
guint i;
GString *str;
gboolean property_written = FALSE;
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
@ -86,33 +79,19 @@ gimp_config_serialize_properties (GObject *object,
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec;
const gchar *blurb;
prop_spec = property_specs[i];
GParamSpec *prop_spec = property_specs[i];
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
if (property_written)
g_string_assign (str, "\n");
else
g_string_assign (str, "");
if ((blurb = g_param_spec_get_blurb (prop_spec)) != NULL)
gimp_config_serialize_comment (str, blurb);
gimp_config_string_indent (str, indent_level);
g_string_append_printf (str, "(%s ", prop_spec->name);
if (gimp_config_serialize_property (object, prop_spec, str, TRUE))
{
g_string_append (str, ")\n");
property_written = TRUE;
{
if (write (fd, str->str, str->len) == -1)
return FALSE;
g_string_assign (str, "\n");
}
else if (prop_spec->value_type != G_TYPE_STRING)
{
@ -120,6 +99,8 @@ gimp_config_serialize_properties (GObject *object,
g_type_name (G_TYPE_FROM_INSTANCE (object)),
prop_spec->name,
g_type_name (prop_spec->value_type));
g_string_assign (str, "");
}
}
@ -168,7 +149,6 @@ gimp_config_serialize_changed_properties (GObject *new,
for (list = diff; list; list = g_list_next (list))
{
GParamSpec *prop_spec;
const gchar *blurb;
GValue new_value = { 0, };
prop_spec = (GParamSpec *) list->data;
@ -182,9 +162,6 @@ gimp_config_serialize_changed_properties (GObject *new,
else
g_string_assign (str, "");
if ((blurb = g_param_spec_get_blurb (prop_spec)) != NULL)
gimp_config_serialize_comment (str, blurb);
gimp_config_string_indent (str, indent_level);
g_string_append_printf (str, "(%s ", prop_spec->name);
@ -214,6 +191,75 @@ gimp_config_serialize_changed_properties (GObject *new,
return TRUE;
}
gboolean
gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped)
{
GTypeClass *owner_class;
GimpConfigInterface *config_iface;
GimpConfigInterface *parent_iface;
GValue value = { 0, };
if (! (param_spec->flags & GIMP_PARAM_SERIALIZE))
return FALSE;
g_string_append_printf (str, "(%s ", param_spec->name);
g_value_init (&value, param_spec->value_type);
g_object_get_property (object, param_spec->name, &value);
owner_class = g_type_class_peek (param_spec->owner_type);
config_iface = g_type_interface_peek (owner_class,
GIMP_TYPE_CONFIG_INTERFACE);
/* We must call deserialize_property() *only* if the *exact* class
* which implements it is param_spec->owner_type's class.
*
* Therefore, we ask param_spec->owner_type's immediate parent class
* for it's GimpConfigInterface and check if we get a different pointer.
*
* (if the pointers are the same, param_spec->owner_type's
* GimpConfigInterface is inherited from one of it's parent classes
* and thus not able to handle param_spec->owner_type's properties).
*/
if (config_iface)
{
GTypeClass *owner_parent_class;
owner_parent_class = g_type_class_peek_parent (owner_class),
parent_iface = g_type_interface_peek (owner_parent_class,
GIMP_TYPE_CONFIG_INTERFACE);
}
if (config_iface &&
config_iface != parent_iface && /* see comment above */
config_iface->serialize_property)
{
if (! config_iface->serialize_property (object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
return FALSE;
}
else
{
if (! gimp_config_serialize_value (&value, str, escaped))
return FALSE;
}
g_value_unset (&value);
g_string_append (str, ")\n");
return TRUE;
}
/**
* gimp_config_serialize_value:
* @value: a #GValue.
@ -329,7 +375,8 @@ gimp_config_serialize_value (const GValue *value,
{
g_string_append (str, " ");
if (! gimp_config_serialize_value (g_value_array_get_nth (array, i),
if (! gimp_config_serialize_value (g_value_array_get_nth (array,
i),
str, escaped))
return FALSE;
}
@ -382,68 +429,7 @@ gimp_config_serialize_unknown_tokens (GObject *object,
return (write (fd, str->str, str->len) != -1);
}
static gboolean
gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped)
{
GTypeClass *owner_class;
GimpConfigInterface *gimp_config_iface;
GimpConfigInterface *parent_iface;
GValue value = { 0, };
gboolean retval;
g_value_init (&value, param_spec->value_type);
g_object_get_property (object, param_spec->name, &value);
owner_class = g_type_class_peek (param_spec->owner_type);
gimp_config_iface = g_type_interface_peek (owner_class,
GIMP_TYPE_CONFIG_INTERFACE);
/* We must call deserialize_property() *only* if the *exact* class
* which implements it is param_spec->owner_type's class.
*
* Therefore, we ask param_spec->owner_type's immediate parent class
* for it's GimpConfigInterface and check if we get a different pointer.
*
* (if the pointers are the same, param_spec->owner_type's
* GimpConfigInterface is inherited from one of it's parent classes
* and thus not able to handle param_spec->owner_type's properties).
*/
if (gimp_config_iface)
{
GTypeClass *owner_parent_class;
owner_parent_class = g_type_class_peek_parent (owner_class),
parent_iface = g_type_interface_peek (owner_parent_class,
GIMP_TYPE_CONFIG_INTERFACE);
}
if (gimp_config_iface &&
gimp_config_iface != parent_iface && /* see comment above */
gimp_config_iface->serialize_property &&
gimp_config_iface->serialize_property (object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
{
retval = TRUE;
}
else
{
retval = gimp_config_serialize_value (&value, str, escaped);
}
g_value_unset (&value);
return retval;
}
static void
void
gimp_config_serialize_comment (GString *str,
const gchar *comment)
{
@ -474,8 +460,6 @@ gimp_config_serialize_comment (GString *str,
comment += i;
len -= i;
}
g_string_append_printf (str, "#\n");
}
static void

View File

@ -33,8 +33,15 @@ gboolean gimp_config_serialize_changed_properties (GObject *new,
gboolean gimp_config_serialize_unknown_tokens (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped);
gboolean gimp_config_serialize_value (const GValue *value,
GString *str,
gboolean escaped);
void gimp_config_serialize_comment (GString *str,
const gchar *comment);
#endif /* __GIMP_CONFIG_SERIALIZE_H__ */