Updated with upstream update
This commit is contained in:
@ -51,6 +51,7 @@ stamp_compat_enums = custom_target('stamp-pikacompatenums.h',
|
||||
libpikabase_sources_introspectable = files(
|
||||
'pikabasetypes.c',
|
||||
'pikachecks.c',
|
||||
'pikachoice.c',
|
||||
'pikacpuaccel.c',
|
||||
'pikaenv.c',
|
||||
'pikamemsize.c',
|
||||
|
@ -31,6 +31,17 @@ EXPORTS
|
||||
pika_check_size_get_type
|
||||
pika_check_type_get_type
|
||||
pika_checks_get_colors
|
||||
pika_choice_add
|
||||
pika_choice_get_documentation
|
||||
pika_choice_get_help
|
||||
pika_choice_get_id
|
||||
pika_choice_get_label
|
||||
pika_choice_get_type
|
||||
pika_choice_is_valid
|
||||
pika_choice_list_nicks
|
||||
pika_choice_new
|
||||
pika_choice_new_with_values
|
||||
pika_choice_set_sensitive
|
||||
pika_clone_type_get_type
|
||||
pika_color_tag_get_type
|
||||
pika_component_type_get_type
|
||||
@ -121,6 +132,7 @@ EXPORTS
|
||||
pika_orientation_type_get_type
|
||||
pika_paint_application_mode_get_type
|
||||
pika_param_array_get_type
|
||||
pika_param_choice_get_type
|
||||
pika_param_float_array_get_type
|
||||
pika_param_int32_array_get_type
|
||||
pika_param_memsize_get_type
|
||||
@ -128,6 +140,7 @@ EXPORTS
|
||||
pika_param_parasite_get_type
|
||||
pika_param_rgb_array_get_type
|
||||
pika_param_spec_array
|
||||
pika_param_spec_choice
|
||||
pika_param_spec_float_array
|
||||
pika_param_spec_int32_array
|
||||
pika_param_spec_memsize
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <libpikabase/pikabasetypes.h>
|
||||
|
||||
#include <libpikabase/pikachecks.h>
|
||||
#include <libpikabase/pikachoice.h>
|
||||
#include <libpikabase/pikacpuaccel.h>
|
||||
#include <libpikabase/pikaenv.h>
|
||||
#include <libpikabase/pikalimits.h>
|
||||
|
@ -44,6 +44,7 @@ G_BEGIN_DECLS
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct _PikaChoice PikaChoice;
|
||||
typedef struct _PikaParasite PikaParasite;
|
||||
typedef struct _PikaEnumDesc PikaEnumDesc;
|
||||
typedef struct _PikaFlagsDesc PikaFlagsDesc;
|
||||
|
@ -34,6 +34,7 @@ G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* PikaMetadataLoadFlags:
|
||||
* @PIKA_METADATA_LOAD_NONE: Do not load the metadata
|
||||
* @PIKA_METADATA_LOAD_COMMENT: Load the comment
|
||||
* @PIKA_METADATA_LOAD_RESOLUTION: Load the resolution
|
||||
* @PIKA_METADATA_LOAD_ORIENTATION: Load the orientation (rotation)
|
||||
@ -44,6 +45,7 @@ G_BEGIN_DECLS
|
||||
**/
|
||||
typedef enum
|
||||
{
|
||||
PIKA_METADATA_LOAD_NONE = 0,
|
||||
PIKA_METADATA_LOAD_COMMENT = 1 << 0,
|
||||
PIKA_METADATA_LOAD_RESOLUTION = 1 << 1,
|
||||
PIKA_METADATA_LOAD_ORIENTATION = 1 << 2,
|
||||
|
@ -25,6 +25,169 @@
|
||||
#include "pikabase.h"
|
||||
|
||||
|
||||
/*
|
||||
* PIKA_TYPE_PARAM_CHOICE
|
||||
*/
|
||||
|
||||
static void pika_param_choice_class_init (GParamSpecClass *klass);
|
||||
static void pika_param_choice_init (GParamSpec *pspec);
|
||||
static void pika_param_choice_value_set_default (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static void pika_param_choice_finalize (GParamSpec *pspec);
|
||||
static gboolean pika_param_choice_validate (GParamSpec *pspec,
|
||||
GValue *value);
|
||||
static gint pika_param_choice_values_cmp (GParamSpec *pspec,
|
||||
const GValue *value1,
|
||||
const GValue *value2);
|
||||
|
||||
GType
|
||||
pika_param_choice_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (! type)
|
||||
{
|
||||
const GTypeInfo info =
|
||||
{
|
||||
sizeof (GParamSpecClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) pika_param_choice_class_init,
|
||||
NULL, NULL,
|
||||
sizeof (PikaParamSpecChoice),
|
||||
0,
|
||||
(GInstanceInitFunc) pika_param_choice_init
|
||||
};
|
||||
|
||||
type = g_type_register_static (G_TYPE_PARAM_BOXED,
|
||||
"PikaParamChoice", &info, 0);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
pika_param_choice_class_init (GParamSpecClass *klass)
|
||||
{
|
||||
klass->value_type = G_TYPE_STRING;
|
||||
klass->value_set_default = pika_param_choice_value_set_default;
|
||||
klass->finalize = pika_param_choice_finalize;
|
||||
klass->value_validate = pika_param_choice_validate;
|
||||
klass->values_cmp = pika_param_choice_values_cmp;
|
||||
}
|
||||
|
||||
static void
|
||||
pika_param_choice_init (GParamSpec *pspec)
|
||||
{
|
||||
PikaParamSpecChoice *choice = PIKA_PARAM_SPEC_CHOICE (pspec);
|
||||
|
||||
choice->choice = NULL;
|
||||
choice->default_value = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
pika_param_choice_value_set_default (GParamSpec *pspec,
|
||||
GValue *value)
|
||||
{
|
||||
PikaParamSpecChoice *cspec = PIKA_PARAM_SPEC_CHOICE (pspec);
|
||||
|
||||
g_value_set_string (value, cspec->default_value);
|
||||
}
|
||||
|
||||
static void
|
||||
pika_param_choice_finalize (GParamSpec *pspec)
|
||||
{
|
||||
PikaParamSpecChoice *spec_choice = PIKA_PARAM_SPEC_CHOICE (pspec);
|
||||
|
||||
g_free (spec_choice->default_value);
|
||||
g_object_unref (spec_choice->choice);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pika_param_choice_validate (GParamSpec *pspec,
|
||||
GValue *value)
|
||||
{
|
||||
PikaParamSpecChoice *spec_choice = PIKA_PARAM_SPEC_CHOICE (pspec);
|
||||
PikaChoice *choice = spec_choice->choice;
|
||||
const gchar *strval = g_value_get_string (value);
|
||||
|
||||
if (! pika_choice_is_valid (choice, strval))
|
||||
{
|
||||
if (pika_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 = pika_choice_list_nicks (choice);
|
||||
for (GList *iter = nicks; iter; iter = iter->next)
|
||||
if (pika_choice_is_valid (choice, (gchar *) iter->data))
|
||||
{
|
||||
g_value_set_string (value, (gchar *) iter->data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
pika_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);
|
||||
}
|
||||
|
||||
/**
|
||||
* pika_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 %PikaChoice describing allowed choices.
|
||||
* @flags: Flags for the property specified.
|
||||
*
|
||||
* Creates a new #PikaParamSpecChoice specifying a
|
||||
* #G_TYPE_STRING property.
|
||||
* This %PikaParamSpecChoice takes ownership of the reference on @choice.
|
||||
*
|
||||
* See g_param_spec_internal() for details on property names.
|
||||
*
|
||||
* Returns: (transfer full): The newly created #PikaParamSpecChoice.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GParamSpec *
|
||||
pika_param_spec_choice (const gchar *name,
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
PikaChoice *choice,
|
||||
const gchar *default_value,
|
||||
GParamFlags flags)
|
||||
{
|
||||
PikaParamSpecChoice *choice_spec;
|
||||
|
||||
choice_spec = g_param_spec_internal (PIKA_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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* PIKA_TYPE_ARRAY
|
||||
*/
|
||||
|
@ -74,6 +74,34 @@ G_BEGIN_DECLS
|
||||
PIKA_PARAM_STATIC_STRINGS)
|
||||
|
||||
|
||||
/*
|
||||
* PIKA_TYPE_PARAM_CHOICE
|
||||
*/
|
||||
|
||||
#define PIKA_TYPE_PARAM_CHOICE (pika_param_choice_get_type ())
|
||||
#define PIKA_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), PIKA_TYPE_PARAM_CHOICE, PikaParamSpecChoice))
|
||||
#define PIKA_IS_PARAM_SPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), PIKA_TYPE_PARAM_CHOICE))
|
||||
|
||||
typedef struct _PikaParamSpecChoice PikaParamSpecChoice;
|
||||
|
||||
struct _PikaParamSpecChoice
|
||||
{
|
||||
GParamSpecBoxed parent_instance;
|
||||
|
||||
gchar *default_value;
|
||||
PikaChoice *choice;
|
||||
};
|
||||
|
||||
GType pika_param_choice_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GParamSpec * pika_param_spec_choice (const gchar *name,
|
||||
const gchar *nick,
|
||||
const gchar *blurb,
|
||||
PikaChoice *choice,
|
||||
const gchar *default_value,
|
||||
GParamFlags flags);
|
||||
|
||||
|
||||
/*
|
||||
* PIKA_TYPE_ARRAY
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "pikabasetypes.h"
|
||||
|
||||
#include "pikachoice.h"
|
||||
#include "pikaparamspecs.h"
|
||||
#include "pikaparasite.h"
|
||||
#include "pikaprotocol.h"
|
||||
@ -1100,6 +1101,47 @@ _gp_param_def_read (GIOChannel *channel,
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_CHOICE:
|
||||
{
|
||||
PikaChoice *choice;
|
||||
guint32 size;
|
||||
gchar *nick;
|
||||
|
||||
if (! _pika_wire_read_string (channel, &nick, (int) 1, user_data))
|
||||
return FALSE;
|
||||
|
||||
param_def->meta.m_choice.default_val = g_strdup (nick);
|
||||
|
||||
if (! _pika_wire_read_int32 (channel, &size, 1, user_data))
|
||||
return FALSE;
|
||||
|
||||
choice = pika_choice_new ();
|
||||
|
||||
for (gint i = 0; i < size; i++)
|
||||
{
|
||||
gchar *label;
|
||||
gchar *help;
|
||||
gint id;
|
||||
|
||||
if (! _pika_wire_read_string (channel, &nick,
|
||||
(int) 1, user_data) ||
|
||||
! _pika_wire_read_int32 (channel, (guint32 *) &id,
|
||||
1, user_data) ||
|
||||
! _pika_wire_read_string (channel, &label,
|
||||
(int) 1, user_data) ||
|
||||
! _pika_wire_read_string (channel, &help,
|
||||
(int) 1, user_data))
|
||||
{
|
||||
g_object_unref (choice);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pika_choice_add (choice, nick, id, label, help);
|
||||
}
|
||||
param_def->meta.m_choice.choice = choice;
|
||||
}
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_UNIT:
|
||||
if (! _pika_wire_read_int32 (channel,
|
||||
(guint32 *) ¶m_def->meta.m_unit.allow_pixels, 1,
|
||||
@ -1196,6 +1238,11 @@ _gp_param_def_destroy (GPParamDef *param_def)
|
||||
case GP_PARAM_DEF_TYPE_FLOAT:
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_CHOICE:
|
||||
g_free (param_def->meta.m_choice.default_val);
|
||||
g_object_unref (param_def->meta.m_choice.choice);
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_STRING:
|
||||
g_free (param_def->meta.m_string.default_val);
|
||||
break;
|
||||
@ -1342,6 +1389,51 @@ _gp_param_def_write (GIOChannel *channel,
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_CHOICE:
|
||||
{
|
||||
GList *values;
|
||||
gint size;
|
||||
|
||||
if (! _pika_wire_write_string (channel,
|
||||
¶m_def->meta.m_choice.default_val,
|
||||
1, user_data))
|
||||
return FALSE;
|
||||
|
||||
values = pika_choice_list_nicks (param_def->meta.m_choice.choice);
|
||||
size = g_list_length (values);
|
||||
|
||||
if (! _pika_wire_write_int32 (channel,
|
||||
(guint32 *) &size, 1,
|
||||
user_data))
|
||||
return FALSE;
|
||||
|
||||
for (GList *iter = values; iter; iter = iter->next)
|
||||
{
|
||||
const gchar *label;
|
||||
const gchar *help;
|
||||
gint id;
|
||||
|
||||
pika_choice_get_documentation (param_def->meta.m_choice.choice,
|
||||
iter->data, &label, &help);
|
||||
id = pika_choice_get_id (param_def->meta.m_choice.choice,
|
||||
iter->data);
|
||||
if (! _pika_wire_write_string (channel,
|
||||
(gchar **) &iter->data,
|
||||
1, user_data) ||
|
||||
! _pika_wire_write_int32 (channel,
|
||||
(guint32 *) &id, 1,
|
||||
user_data) ||
|
||||
! _pika_wire_write_string (channel,
|
||||
(gchar **) &label,
|
||||
1, user_data) ||
|
||||
! _pika_wire_write_string (channel,
|
||||
(gchar **) &help,
|
||||
1, user_data))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GP_PARAM_DEF_TYPE_UNIT:
|
||||
if (! _pika_wire_write_int32 (channel,
|
||||
(guint32 *) ¶m_def->meta.m_unit.allow_pixels, 1,
|
||||
|
@ -26,7 +26,7 @@ G_BEGIN_DECLS
|
||||
|
||||
/* Increment every time the protocol changes
|
||||
*/
|
||||
#define PIKA_PROTOCOL_VERSION 0x010F
|
||||
#define PIKA_PROTOCOL_VERSION 0x0110
|
||||
|
||||
|
||||
enum
|
||||
@ -52,6 +52,7 @@ typedef enum
|
||||
GP_PARAM_DEF_TYPE_INT,
|
||||
GP_PARAM_DEF_TYPE_UNIT,
|
||||
GP_PARAM_DEF_TYPE_ENUM,
|
||||
GP_PARAM_DEF_TYPE_CHOICE,
|
||||
GP_PARAM_DEF_TYPE_BOOLEAN,
|
||||
GP_PARAM_DEF_TYPE_FLOAT,
|
||||
GP_PARAM_DEF_TYPE_STRING,
|
||||
@ -87,6 +88,7 @@ typedef struct _GPParamDefEnum GPParamDefEnum;
|
||||
typedef struct _GPParamDefBoolean GPParamDefBoolean;
|
||||
typedef struct _GPParamDefFloat GPParamDefFloat;
|
||||
typedef struct _GPParamDefString GPParamDefString;
|
||||
typedef struct _GPParamDefChoice GPParamDefChoice;
|
||||
typedef struct _GPParamStrv GPParamStrv;
|
||||
typedef struct _GPParamDefColor GPParamDefColor;
|
||||
typedef struct _GPParamDefID GPParamDefID;
|
||||
@ -203,6 +205,12 @@ struct _GPParamDefIDArray
|
||||
gchar *type_name;
|
||||
};
|
||||
|
||||
struct _GPParamDefChoice
|
||||
{
|
||||
PikaChoice *choice;
|
||||
gchar *default_val;
|
||||
};
|
||||
|
||||
struct _GPParamDef
|
||||
{
|
||||
GPParamDefType param_def_type;
|
||||
@ -224,6 +232,7 @@ struct _GPParamDef
|
||||
GPParamDefColor m_color;
|
||||
GPParamDefID m_id;
|
||||
GPParamDefIDArray m_id_array;
|
||||
GPParamDefChoice m_choice;
|
||||
} meta;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user