app, libgimp, libgimpbase: forgot to support GIMP_TYPE_UNIT on the wire

This commit can serve as an example how to add new types to
GimpProtocol, note that zero public API changes.
This commit is contained in:
Michael Natterer 2019-07-30 15:04:06 +02:00
parent 65a8ae2c91
commit e36028d2ac
4 changed files with 62 additions and 3 deletions

View file

@ -104,6 +104,15 @@ _gimp_gp_param_def_to_param_spec (Gimp *gimp,
flags);
break;
case GP_PARAM_DEF_TYPE_UNIT:
if (! strcmp (param_def->type_name, "GimpParamUnit"))
return gimp_param_spec_unit (name, nick, blurb,
param_def->meta.m_unit.allow_pixels,
param_def->meta.m_unit.allow_percent,
param_def->meta.m_unit.default_val,
flags);
break;
case GP_PARAM_DEF_TYPE_ENUM:
if (! strcmp (param_def->type_name, "GParamEnum"))
return g_param_spec_enum (name, nick, blurb,

View file

@ -59,6 +59,17 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
param_def->meta.m_int.max_val = uspec->maximum;
param_def->meta.m_int.default_val = uspec->default_value;
}
else if (pspec_type == GIMP_TYPE_PARAM_UNIT)
{
GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
param_def->param_def_type = GP_PARAM_DEF_TYPE_UNIT;
param_def->meta.m_unit.allow_pixels = (ispec->minimum < GIMP_UNIT_INCH);
param_def->meta.m_unit.allow_percent = uspec->allow_percent;
param_def->meta.m_unit.default_val = ispec->default_value;
}
else if (pspec_type == G_TYPE_PARAM_ENUM)
{
GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
@ -211,7 +222,8 @@ _gimp_gp_params_to_value_array (GParamSpec **pspecs,
if (type == G_TYPE_INT ||
type == GIMP_TYPE_INT32 ||
type == GIMP_TYPE_INT16)
type == GIMP_TYPE_INT16 ||
type == GIMP_TYPE_UNIT)
{
g_value_set_int (&value, params[i].data.d_int);
}
@ -379,7 +391,8 @@ _gimp_value_array_to_gp_params (GimpValueArray *args,
if (type == G_TYPE_INT ||
type == GIMP_TYPE_INT32 ||
type == GIMP_TYPE_INT16)
type == GIMP_TYPE_INT16 ||
type == GIMP_TYPE_UNIT)
{
params[i].param_type = GP_PARAM_TYPE_INT;

View file

@ -1076,6 +1076,19 @@ _gp_param_def_read (GIOChannel *channel,
return FALSE;
break;
case GP_PARAM_DEF_TYPE_UNIT:
if (! _gimp_wire_read_int32 (channel,
(guint32 *) &param_def->meta.m_unit.allow_pixels, 1,
user_data) ||
! _gimp_wire_read_int32 (channel,
(guint32 *) &param_def->meta.m_unit.allow_percent, 1,
user_data) ||
! _gimp_wire_read_int32 (channel,
(guint32 *) &param_def->meta.m_unit.default_val, 1,
user_data))
return FALSE;
break;
case GP_PARAM_DEF_TYPE_ENUM:
if (! _gimp_wire_read_string (channel,
&param_def->meta.m_enum.type_name, 1,
@ -1155,6 +1168,7 @@ _gp_param_def_destroy (GPParamDef *param_def)
{
case GP_PARAM_DEF_TYPE_DEFAULT:
case GP_PARAM_DEF_TYPE_INT:
case GP_PARAM_DEF_TYPE_UNIT:
break;
case GP_PARAM_DEF_TYPE_ENUM:
@ -1329,6 +1343,19 @@ _gp_param_def_write (GIOChannel *channel,
return FALSE;
break;
case GP_PARAM_DEF_TYPE_UNIT:
if (! _gimp_wire_write_int32 (channel,
(guint32 *) &param_def->meta.m_unit.allow_pixels, 1,
user_data) ||
! _gimp_wire_write_int32 (channel,
(guint32 *) &param_def->meta.m_unit.allow_percent, 1,
user_data) ||
! _gimp_wire_write_int32 (channel,
(guint32 *) &param_def->meta.m_unit.default_val, 1,
user_data))
return FALSE;
break;
case GP_PARAM_DEF_TYPE_ENUM:
if (! _gimp_wire_write_string (channel,
&param_def->meta.m_enum.type_name, 1,

View file

@ -26,7 +26,7 @@ G_BEGIN_DECLS
/* Increment every time the protocol changes
*/
#define GIMP_PROTOCOL_VERSION 0x0105
#define GIMP_PROTOCOL_VERSION 0x0106
enum
@ -61,6 +61,7 @@ typedef enum
{
GP_PARAM_DEF_TYPE_DEFAULT,
GP_PARAM_DEF_TYPE_INT,
GP_PARAM_DEF_TYPE_UNIT,
GP_PARAM_DEF_TYPE_ENUM,
GP_PARAM_DEF_TYPE_BOOLEAN,
GP_PARAM_DEF_TYPE_FLOAT,
@ -79,6 +80,7 @@ typedef struct _GPParamArray GPParamArray;
typedef struct _GPParamStringArray GPParamStringArray;
typedef struct _GPParamDef GPParamDef;
typedef struct _GPParamDefInt GPParamDefInt;
typedef struct _GPParamDefUnit GPParamDefUnit;
typedef struct _GPParamDefEnum GPParamDefEnum;
typedef struct _GPParamDefBoolean GPParamDefBoolean;
typedef struct _GPParamDefFloat GPParamDefFloat;
@ -172,6 +174,13 @@ struct _GPParamDefInt
gint32 default_val;
};
struct _GPParamDefUnit
{
gint32 allow_pixels;
gint32 allow_percent;
gint32 default_val;
};
struct _GPParamDefEnum
{
gchar *type_name;
@ -220,6 +229,7 @@ struct _GPParamDef
union
{
GPParamDefInt m_int;
GPParamDefUnit m_unit;
GPParamDefEnum m_enum;
GPParamDefBoolean m_boolean;
GPParamDefFloat m_float;