libgimpbase: moving GIMP_TYPE_PARAM_CHOICE and GIMP_TYPE_PARAM_EXPORT_OPTIONS…

… in gimpchoice.[ch] and gimpexportoptions.[ch] respectively.

The overlong gimpparamspecs.[ch] makes it harder to read IMO.
This commit is contained in:
Jehan
2024-10-17 19:41:39 +02:00
parent 47470880b2
commit 732adc1f23
6 changed files with 303 additions and 301 deletions

View File

@ -394,3 +394,169 @@ gimp_choice_desc_free (GimpChoiceDesc *desc)
g_free (desc->help);
g_free (desc);
}
/*
* GIMP_TYPE_PARAM_CHOICE
*/
static void gimp_param_choice_class_init (GParamSpecClass *klass);
static void gimp_param_choice_init (GParamSpec *pspec);
static void gimp_param_choice_value_set_default (GParamSpec *pspec,
GValue *value);
static void gimp_param_choice_finalize (GParamSpec *pspec);
static gboolean gimp_param_choice_validate (GParamSpec *pspec,
GValue *value);
static gint gimp_param_choice_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
GType
gimp_param_choice_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_choice_class_init,
NULL, NULL,
sizeof (GimpParamSpecChoice),
0,
(GInstanceInitFunc) gimp_param_choice_init
};
type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamChoice", &info, 0);
}
return type;
}
static void
gimp_param_choice_class_init (GParamSpecClass *klass)
{
klass->value_type = G_TYPE_STRING;
klass->value_set_default = gimp_param_choice_value_set_default;
klass->finalize = gimp_param_choice_finalize;
klass->value_validate = gimp_param_choice_validate;
klass->values_cmp = gimp_param_choice_values_cmp;
}
static void
gimp_param_choice_init (GParamSpec *pspec)
{
GimpParamSpecChoice *choice = GIMP_PARAM_SPEC_CHOICE (pspec);
choice->choice = NULL;
choice->default_value = NULL;
}
static void
gimp_param_choice_value_set_default (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecChoice *cspec = GIMP_PARAM_SPEC_CHOICE (pspec);
g_value_set_string (value, cspec->default_value);
}
static void
gimp_param_choice_finalize (GParamSpec *pspec)
{
GimpParamSpecChoice *spec_choice = GIMP_PARAM_SPEC_CHOICE (pspec);
GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_CHOICE));
g_free (spec_choice->default_value);
g_object_unref (spec_choice->choice);
parent_class->finalize (pspec);
}
static gboolean
gimp_param_choice_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecChoice *spec_choice = GIMP_PARAM_SPEC_CHOICE (pspec);
GimpChoice *choice = spec_choice->choice;
const gchar *strval = g_value_get_string (value);
if (! gimp_choice_is_valid (choice, strval))
{
if (gimp_choice_is_valid (choice, spec_choice->default_value))
{
g_value_set_string (value, spec_choice->default_value);
}
else
{
/* This might happen if the default value is set insensitive. Then we
* should just set any valid random nick.
*/
GList *nicks;
nicks = gimp_choice_list_nicks (choice);
for (GList *iter = nicks; iter; iter = iter->next)
if (gimp_choice_is_valid (choice, (gchar *) iter->data))
{
g_value_set_string (value, (gchar *) iter->data);
break;
}
}
return TRUE;
}
return FALSE;
}
static gint
gimp_param_choice_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
const gchar *choice1 = g_value_get_string (value1);
const gchar *choice2 = g_value_get_string (value2);
return g_strcmp0 (choice1, choice2);
}
/**
* gimp_param_spec_choice:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @choice: (transfer full): the %GimpChoice describing allowed choices.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecChoice specifying a
* #G_TYPE_STRING property.
* This %GimpParamSpecChoice takes ownership of the reference on @choice.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer floating): The newly created #GimpParamSpecChoice.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags)
{
GimpParamSpecChoice *choice_spec;
choice_spec = g_param_spec_internal (GIMP_TYPE_PARAM_CHOICE,
name, nick, blurb, flags);
g_return_val_if_fail (choice_spec, NULL);
choice_spec->choice = choice;
choice_spec->default_value = g_strdup (default_value);
return G_PARAM_SPEC (choice_spec);
}

View File

@ -68,6 +68,34 @@ void gimp_choice_set_sensitive (GimpChoice *choice,
gboolean sensitive);
/*
* GIMP_TYPE_PARAM_CHOICE
*/
#define GIMP_TYPE_PARAM_CHOICE (gimp_param_choice_get_type ())
#define GIMP_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_CHOICE, GimpParamSpecChoice))
#define GIMP_IS_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_CHOICE))
typedef struct _GimpParamSpecChoice GimpParamSpecChoice;
struct _GimpParamSpecChoice
{
GParamSpecBoxed parent_instance;
gchar *default_value;
GimpChoice *choice;
};
GType gimp_param_choice_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags);
G_END_DECLS
#endif /* __GIMP_CHOICE_H__ */

View File

@ -151,3 +151,86 @@ gimp_export_options_get_property (GObject *object,
break;
}
}
/*
* GIMP_TYPE_PARAM_EXPORT_OPTIONS
*/
static void gimp_param_export_options_class_init (GParamSpecClass *klass);
static void gimp_param_export_options_init (GParamSpec *pspec);
GType
gimp_param_export_options_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_export_options_class_init,
NULL, NULL,
sizeof (GimpParamSpecExportOptions),
0,
(GInstanceInitFunc) gimp_param_export_options_init
};
type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamExportOptions", &info, 0);
}
return type;
}
static void
gimp_param_export_options_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_EXPORT_OPTIONS;
}
static void
gimp_param_export_options_init (GParamSpec *pspec)
{
GimpParamSpecExportOptions *options = GIMP_PARAM_SPEC_EXPORT_OPTIONS (pspec);
options->capabilities = 0;
}
/**
* gimp_param_spec_export_options:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @capabilities: Int representing the image export capabilities
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecExportOptions specifying a
* #G_TYPE_INT property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer floating): The newly created #GimpParamSpecExportOptions.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_export_options (const gchar *name,
const gchar *nick,
const gchar *blurb,
gint capabilities,
GParamFlags flags)
{
GimpParamSpecExportOptions *options_spec;
options_spec = g_param_spec_internal (GIMP_TYPE_PARAM_EXPORT_OPTIONS,
name, nick, blurb, flags);
g_return_val_if_fail (options_spec, NULL);
options_spec->capabilities = capabilities;
return G_PARAM_SPEC (options_spec);
}

View File

@ -69,6 +69,32 @@ typedef enum
} GimpExportCapabilities;
/*
* GIMP_TYPE_PARAM_EXPORT_OPTIONS
*/
#define GIMP_TYPE_PARAM_EXPORT_OPTIONS (gimp_param_export_options_get_type ())
#define GIMP_PARAM_SPEC_EXPORT_OPTIONS(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_EXPORT_OPTIONS, GimpParamSpecExportOptions))
#define GIMP_IS_PARAM_SPEC_EXPORT_OPTIONS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_EXPORT_OPTIONS))
typedef struct _GimpParamSpecExportOptions GimpParamSpecExportOptions;
struct _GimpParamSpecExportOptions
{
GParamSpecBoxed parent_instance;
gint capabilities;
};
GType gimp_param_export_options_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_export_options (const gchar *name,
const gchar *nick,
const gchar *blurb,
gint capabilities,
GParamFlags flags);
G_END_DECLS
#endif /* __GIMP_EXPORT_OPTIONS_H__ */

View File

@ -25,172 +25,6 @@
#include "gimpbase.h"
/*
* GIMP_TYPE_PARAM_CHOICE
*/
static void gimp_param_choice_class_init (GParamSpecClass *klass);
static void gimp_param_choice_init (GParamSpec *pspec);
static void gimp_param_choice_value_set_default (GParamSpec *pspec,
GValue *value);
static void gimp_param_choice_finalize (GParamSpec *pspec);
static gboolean gimp_param_choice_validate (GParamSpec *pspec,
GValue *value);
static gint gimp_param_choice_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2);
GType
gimp_param_choice_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_choice_class_init,
NULL, NULL,
sizeof (GimpParamSpecChoice),
0,
(GInstanceInitFunc) gimp_param_choice_init
};
type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamChoice", &info, 0);
}
return type;
}
static void
gimp_param_choice_class_init (GParamSpecClass *klass)
{
klass->value_type = G_TYPE_STRING;
klass->value_set_default = gimp_param_choice_value_set_default;
klass->finalize = gimp_param_choice_finalize;
klass->value_validate = gimp_param_choice_validate;
klass->values_cmp = gimp_param_choice_values_cmp;
}
static void
gimp_param_choice_init (GParamSpec *pspec)
{
GimpParamSpecChoice *choice = GIMP_PARAM_SPEC_CHOICE (pspec);
choice->choice = NULL;
choice->default_value = NULL;
}
static void
gimp_param_choice_value_set_default (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecChoice *cspec = GIMP_PARAM_SPEC_CHOICE (pspec);
g_value_set_string (value, cspec->default_value);
}
static void
gimp_param_choice_finalize (GParamSpec *pspec)
{
GimpParamSpecChoice *spec_choice = GIMP_PARAM_SPEC_CHOICE (pspec);
GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_CHOICE));
g_free (spec_choice->default_value);
g_object_unref (spec_choice->choice);
parent_class->finalize (pspec);
}
static gboolean
gimp_param_choice_validate (GParamSpec *pspec,
GValue *value)
{
GimpParamSpecChoice *spec_choice = GIMP_PARAM_SPEC_CHOICE (pspec);
GimpChoice *choice = spec_choice->choice;
const gchar *strval = g_value_get_string (value);
if (! gimp_choice_is_valid (choice, strval))
{
if (gimp_choice_is_valid (choice, spec_choice->default_value))
{
g_value_set_string (value, spec_choice->default_value);
}
else
{
/* This might happen if the default value is set insensitive. Then we
* should just set any valid random nick.
*/
GList *nicks;
nicks = gimp_choice_list_nicks (choice);
for (GList *iter = nicks; iter; iter = iter->next)
if (gimp_choice_is_valid (choice, (gchar *) iter->data))
{
g_value_set_string (value, (gchar *) iter->data);
break;
}
}
return TRUE;
}
return FALSE;
}
static gint
gimp_param_choice_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
const gchar *choice1 = g_value_get_string (value1);
const gchar *choice2 = g_value_get_string (value2);
return g_strcmp0 (choice1, choice2);
}
/**
* gimp_param_spec_choice:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @choice: (transfer full): the %GimpChoice describing allowed choices.
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecChoice specifying a
* #G_TYPE_STRING property.
* This %GimpParamSpecChoice takes ownership of the reference on @choice.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer floating): The newly created #GimpParamSpecChoice.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags)
{
GimpParamSpecChoice *choice_spec;
choice_spec = g_param_spec_internal (GIMP_TYPE_PARAM_CHOICE,
name, nick, blurb, flags);
g_return_val_if_fail (choice_spec, NULL);
choice_spec->choice = choice;
choice_spec->default_value = g_strdup (default_value);
return G_PARAM_SPEC (choice_spec);
}
/*
* GIMP_TYPE_PARAM_OBJECT
*/
@ -1404,85 +1238,3 @@ gimp_value_take_object_array (GValue *value,
g_value_take_boxed (value, array);
}
/*
* GIMP_TYPE_PARAM_EXPORT_OPTIONS
*/
static void gimp_param_export_options_class_init (GParamSpecClass *klass);
static void gimp_param_export_options_init (GParamSpec *pspec);
GType
gimp_param_export_options_get_type (void)
{
static GType type = 0;
if (! type)
{
const GTypeInfo info =
{
sizeof (GParamSpecClass),
NULL, NULL,
(GClassInitFunc) gimp_param_export_options_class_init,
NULL, NULL,
sizeof (GimpParamSpecExportOptions),
0,
(GInstanceInitFunc) gimp_param_export_options_init
};
type = g_type_register_static (G_TYPE_PARAM_BOXED,
"GimpParamExportOptions", &info, 0);
}
return type;
}
static void
gimp_param_export_options_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_EXPORT_OPTIONS;
}
static void
gimp_param_export_options_init (GParamSpec *pspec)
{
GimpParamSpecExportOptions *options = GIMP_PARAM_SPEC_EXPORT_OPTIONS (pspec);
options->capabilities = 0;
}
/**
* gimp_param_spec_export_options:
* @name: Canonical name of the property specified.
* @nick: Nick name of the property specified.
* @blurb: Description of the property specified.
* @capabilities: Int representing the image export capabilities
* @flags: Flags for the property specified.
*
* Creates a new #GimpParamSpecExportOptions specifying a
* #G_TYPE_INT property.
*
* See g_param_spec_internal() for details on property names.
*
* Returns: (transfer floating): The newly created #GimpParamSpecExportOptions.
*
* Since: 3.0
**/
GParamSpec *
gimp_param_spec_export_options (const gchar *name,
const gchar *nick,
const gchar *blurb,
gint capabilities,
GParamFlags flags)
{
GimpParamSpecExportOptions *options_spec;
options_spec = g_param_spec_internal (GIMP_TYPE_PARAM_EXPORT_OPTIONS,
name, nick, blurb, flags);
g_return_val_if_fail (options_spec, NULL);
options_spec->capabilities = capabilities;
return G_PARAM_SPEC (options_spec);
}

View File

@ -90,34 +90,6 @@ G_BEGIN_DECLS
GIMP_PARAM_STATIC_STRINGS)
/*
* GIMP_TYPE_PARAM_CHOICE
*/
#define GIMP_TYPE_PARAM_CHOICE (gimp_param_choice_get_type ())
#define GIMP_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_CHOICE, GimpParamSpecChoice))
#define GIMP_IS_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_CHOICE))
typedef struct _GimpParamSpecChoice GimpParamSpecChoice;
struct _GimpParamSpecChoice
{
GParamSpecBoxed parent_instance;
gchar *default_value;
GimpChoice *choice;
};
GType gimp_param_choice_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_choice (const gchar *name,
const gchar *nick,
const gchar *blurb,
GimpChoice *choice,
const gchar *default_value,
GParamFlags flags);
/*
* GIMP_TYPE_PARAM_OBJECT
*/
@ -448,31 +420,6 @@ void gimp_value_take_object_array (GValue *value,
gsize length);
/*
* GIMP_TYPE_PARAM_EXPORT_OPTIONS
*/
#define GIMP_TYPE_PARAM_EXPORT_OPTIONS (gimp_param_export_options_get_type ())
#define GIMP_PARAM_SPEC_EXPORT_OPTIONS(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_EXPORT_OPTIONS, GimpParamSpecExportOptions))
#define GIMP_IS_PARAM_SPEC_EXPORT_OPTIONS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_EXPORT_OPTIONS))
typedef struct _GimpParamSpecExportOptions GimpParamSpecExportOptions;
struct _GimpParamSpecExportOptions
{
GParamSpecBoxed parent_instance;
gint capabilities;
};
GType gimp_param_export_options_get_type (void) G_GNUC_CONST;
GParamSpec * gimp_param_spec_export_options (const gchar *name,
const gchar *nick,
const gchar *blurb,
gint capabilities,
GParamFlags flags);
G_END_DECLS
#endif /* __GIMP_PARAM_SPECS_H__ */