diff --git a/app/core/gimpparamspecs.c b/app/core/gimpparamspecs.c index 3c9bcbf41b..5235c2067a 100644 --- a/app/core/gimpparamspecs.c +++ b/app/core/gimpparamspecs.c @@ -34,6 +34,174 @@ #include "vectors/gimpvectors.h" +/* + * GIMP_TYPE_PARAM_STRING + */ + +static void gimp_param_string_class_init (GParamSpecClass *klass); +static void gimp_param_string_init (GParamSpec *pspec); +static gboolean gimp_param_string_validate (GParamSpec *pspec, + GValue *value); + +static GParamSpecClass * gimp_param_string_parent_class = NULL; + +GType +gimp_param_string_get_type (void) +{ + static GType type = 0; + + if (! type) + { + const GTypeInfo info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_string_class_init, + NULL, NULL, + sizeof (GimpParamSpecString), + 0, + (GInstanceInitFunc) gimp_param_string_init + }; + + type = g_type_register_static (G_TYPE_PARAM_STRING, + "GimpParamString", &info, 0); + } + + return type; +} + +static void +gimp_param_string_class_init (GParamSpecClass *klass) +{ + gimp_param_string_parent_class = g_type_class_peek_parent (klass); + + klass->value_type = G_TYPE_STRING; + klass->value_validate = gimp_param_string_validate; +} + +static void +gimp_param_string_init (GParamSpec *pspec) +{ + GimpParamSpecString *sspec = GIMP_PARAM_SPEC_STRING (pspec); + + G_PARAM_SPEC_STRING (pspec)->ensure_non_null = TRUE; + + sspec->allow_non_utf8 = FALSE; + sspec->non_empty = FALSE; +} + +static gboolean +gimp_param_string_validate (GParamSpec *pspec, + GValue *value) +{ + GimpParamSpecString *sspec = GIMP_PARAM_SPEC_STRING (pspec); + gchar *string = value->data[0].v_pointer; + + if (gimp_param_string_parent_class->value_validate (pspec, value)) + return TRUE; + + if (string) + { + gchar *s; + + if (sspec->non_empty && ! string[0]) + { + if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) + g_free (string); + else + value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; + + value->data[0].v_pointer = g_strdup ("none"); + return TRUE; + } + + if (! sspec->allow_non_utf8 && + ! g_utf8_validate (string, -1, (const gchar **) &s)) + { + if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) + { + value->data[0].v_pointer = g_strdup (string); + value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; + string = value->data[0].v_pointer; + } + + for (s = string; *s; s++) + if (*s < ' ') + *s = '?'; + + return TRUE; + } + } + else if (sspec->non_empty) + { + value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; + value->data[0].v_pointer = g_strdup ("none"); + return TRUE; + } + + return FALSE; +} + +/** + * gimp_param_spec_string: + * @name: Canonical name of the property specified. + * @nick: Nick name of the property specified. + * @blurb: Description of the property specified. + * @allow_non_utf8: Whether non-UTF-8 strings are allowed. + * @null_ok: Whether %NULL is allowed. + * @non_empty: Whether a non-½NULL value must be set. + * @default_value: The default value. + * @flags: Flags for the property specified. + * + * Creates a new #GimpParamSpecString specifying a + * #G_TYPE_STRING property. + * + * If @allow_non_utf8 is %FALSE, non-valid UTF-8 strings will be + * replaced by question marks. + * + * If @null_ok is %FALSE, %NULL strings will be replaced by an empty + * string. + * + * If @non_empty is %TRUE, empty strings will be replaced by `"none"`. + * + * See g_param_spec_internal() for details on property names. + * + * Returns: (transfer full): The newly created #GimpParamSpecString. + * + * Since: 3.0 + **/ +GParamSpec * +gimp_param_spec_string (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_non_utf8, + gboolean null_ok, + gboolean non_empty, + const gchar *default_value, + GParamFlags flags) +{ + GimpParamSpecString *sspec; + + g_return_val_if_fail (! (null_ok && non_empty), NULL); + + sspec = g_param_spec_internal (GIMP_TYPE_PARAM_STRING, + name, nick, blurb, flags); + + if (sspec) + { + g_free (G_PARAM_SPEC_STRING (sspec)->default_value); + G_PARAM_SPEC_STRING (sspec)->default_value = g_strdup (default_value); + + G_PARAM_SPEC_STRING (sspec)->ensure_non_null = null_ok ? FALSE : TRUE; + + sspec->allow_non_utf8 = allow_non_utf8 ? TRUE : FALSE; + sspec->non_empty = non_empty ? TRUE : FALSE; + } + + return G_PARAM_SPEC (sspec); +} + + /* * GIMP_TYPE_PARAM_ENUM */ diff --git a/app/core/gimpparamspecs.h b/app/core/gimpparamspecs.h index 2bd10b7706..ef6ab5e913 100644 --- a/app/core/gimpparamspecs.h +++ b/app/core/gimpparamspecs.h @@ -19,6 +19,36 @@ #define __APP_GIMP_PARAM_SPECS_H__ +/* + * GIMP_TYPE_PARAM_STRING + */ + +#define GIMP_TYPE_PARAM_STRING (gimp_param_string_get_type ()) +#define GIMP_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_STRING, GimpParamSpecString)) +#define GIMP_IS_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_STRING)) + +typedef struct _GimpParamSpecString GimpParamSpecString; + +struct _GimpParamSpecString +{ + GParamSpecString parent_instance; + + guint allow_non_utf8 : 1; + guint non_empty : 1; +}; + +GType gimp_param_string_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_string (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean allow_non_utf8, + gboolean null_ok, + gboolean non_empty, + const gchar *default_value, + GParamFlags flags); + + /* * GIMP_TYPE_PARAM_ENUM */ diff --git a/app/plug-in/gimpgpparams.c b/app/plug-in/gimpgpparams.c index 5a8c738b38..59460bf6ef 100644 --- a/app/plug-in/gimpgpparams.c +++ b/app/plug-in/gimpgpparams.c @@ -55,7 +55,9 @@ _gimp_gp_param_def_to_param_spec (gpointer gimp, const gchar *name = param_def->name; const gchar *nick = param_def->nick; const gchar *blurb = param_def->blurb; - GParamFlags flags = G_PARAM_READWRITE; + GParamFlags flags = param_def->flags; + + flags &= ~G_PARAM_STATIC_STRINGS; switch (param_def->param_def_type) { @@ -145,14 +147,10 @@ _gimp_gp_param_def_to_param_spec (gpointer gimp, break; case GP_PARAM_DEF_TYPE_STRING: - if (! strcmp (param_def->type_name, "GimpParamString") || - ! strcmp (param_def->type_name, "GParamString")) - return gimp_param_spec_string (name, nick, blurb, - param_def->meta.m_string.allow_non_utf8, - param_def->meta.m_string.null_ok, - param_def->meta.m_string.non_empty, - param_def->meta.m_string.default_val, - flags); + if (! strcmp (param_def->type_name, "GParamString")) + return g_param_spec_string (name, nick, blurb, + param_def->meta.m_string.default_val, + flags); break; case GP_PARAM_DEF_TYPE_COLOR: diff --git a/app/plug-in/plug-in-rc.c b/app/plug-in/plug-in-rc.c index 2ceca10e51..1dcd53619f 100644 --- a/app/plug-in/plug-in-rc.c +++ b/app/plug-in/plug-in-rc.c @@ -40,7 +40,7 @@ #include "gimp-intl.h" -#define PLUG_IN_RC_FILE_VERSION 10 +#define PLUG_IN_RC_FILE_VERSION 11 /* @@ -764,7 +764,8 @@ plug_in_proc_arg_deserialize (GScanner *scanner, if (! gimp_scanner_parse_string (scanner, ¶m_def.type_name) || ! gimp_scanner_parse_string (scanner, ¶m_def.name) || ! gimp_scanner_parse_string (scanner, ¶m_def.nick) || - ! gimp_scanner_parse_string (scanner, ¶m_def.blurb)) + ! gimp_scanner_parse_string (scanner, ¶m_def.blurb) || + ! gimp_scanner_parse_int (scanner, (gint *) ¶m_def.flags)) { token = G_TOKEN_STRING; goto error; @@ -839,16 +840,6 @@ plug_in_proc_arg_deserialize (GScanner *scanner, break; case GP_PARAM_DEF_TYPE_STRING: - if (! gimp_scanner_parse_int (scanner, - ¶m_def.meta.m_string.allow_non_utf8) || - ! gimp_scanner_parse_int (scanner, - ¶m_def.meta.m_string.null_ok) || - ! gimp_scanner_parse_int (scanner, - ¶m_def.meta.m_string.non_empty)) - { - token = G_TOKEN_INT; - goto error; - } if (! gimp_scanner_parse_string (scanner, ¶m_def.meta.m_string.default_val)) { @@ -1017,6 +1008,7 @@ plug_in_rc_write_proc_arg (GimpConfigWriter *writer, gimp_config_writer_string (writer, g_param_spec_get_name (pspec)); gimp_config_writer_string (writer, g_param_spec_get_nick (pspec)); gimp_config_writer_string (writer, g_param_spec_get_blurb (pspec)); + gimp_config_writer_printf (writer, "%d", pspec->flags); switch (param_def.param_def_type) { @@ -1066,10 +1058,6 @@ plug_in_rc_write_proc_arg (GimpConfigWriter *writer, break; case GP_PARAM_DEF_TYPE_STRING: - gimp_config_writer_printf (writer, "%d %d %d", - param_def.meta.m_string.allow_non_utf8, - param_def.meta.m_string.null_ok, - param_def.meta.m_string.non_empty); gimp_config_writer_string (writer, param_def.meta.m_string.default_val); break; diff --git a/devel-docs/libgimpbase/libgimpbase3-sections.txt b/devel-docs/libgimpbase/libgimpbase3-sections.txt index cb365f86e0..24bd5653de 100644 --- a/devel-docs/libgimpbase/libgimpbase3-sections.txt +++ b/devel-docs/libgimpbase/libgimpbase3-sections.txt @@ -296,7 +296,6 @@ GIMP_PARAM_STATIC_STRINGS GIMP_PARAM_READABLE GIMP_PARAM_WRITABLE GIMP_PARAM_READWRITE -gimp_param_spec_string gimp_array_new gimp_array_copy gimp_array_free @@ -387,7 +386,6 @@ GimpParamSpecInt16Array GimpParamSpecInt32Array GimpParamSpecUInt8Array GimpParamSpecRGBArray -GimpParamSpecString GimpParamSpecStringArray gimp_array_get_type gimp_float_array_get_type diff --git a/devel-docs/libgimpbase/libgimpbase3.types b/devel-docs/libgimpbase/libgimpbase3.types index e09ebcaf06..d72b812345 100644 --- a/devel-docs/libgimpbase/libgimpbase3.types +++ b/devel-docs/libgimpbase/libgimpbase3.types @@ -12,7 +12,6 @@ gimp_param_int32_array_get_type gimp_param_uint8_array_get_type gimp_param_rgb_array_get_type gimp_param_string_array_get_type -gimp_param_string_get_type gimp_parasite_get_type gimp_rgb_array_get_type gimp_string_array_get_type diff --git a/libgimp/gimp.c b/libgimp/gimp.c index 7a7c67e58e..600542bef9 100644 --- a/libgimp/gimp.c +++ b/libgimp/gimp.c @@ -449,7 +449,7 @@ _gimp_main_internal (GType plug_in_type, G_TYPE_INT, G_TYPE_PARAM_INT, G_TYPE_UCHAR, G_TYPE_PARAM_UCHAR, - G_TYPE_STRING, GIMP_TYPE_PARAM_STRING, + G_TYPE_STRING, G_TYPE_PARAM_STRING, GIMP_TYPE_ARRAY, GIMP_TYPE_PARAM_ARRAY, GIMP_TYPE_UINT8_ARRAY, GIMP_TYPE_PARAM_UINT8_ARRAY, diff --git a/libgimp/gimpgpcompat.c b/libgimp/gimpgpcompat.c index 5a842a1cd9..294bc40e9f 100644 --- a/libgimp/gimpgpcompat.c +++ b/libgimp/gimpgpcompat.c @@ -70,10 +70,9 @@ _gimp_gp_compat_param_spec (GimpPDBArgType arg_type, break; case GIMP_PDB_STRING: - pspec = gimp_param_spec_string (name, nick, blurb, - TRUE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string (name, nick, blurb, + NULL, + G_PARAM_READWRITE); break; case GIMP_PDB_INT32ARRAY: diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c index 9edbdac9e2..80f67933ab 100644 --- a/libgimp/gimpgpparams-body.c +++ b/libgimp/gimpgpparams-body.c @@ -36,6 +36,7 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec, param_def->name = (gchar *) g_param_spec_get_name (pspec); param_def->nick = (gchar *) g_param_spec_get_nick (pspec); param_def->blurb = (gchar *) g_param_spec_get_blurb (pspec); + param_def->flags = pspec->flags; pspec_type = G_PARAM_SPEC_TYPE (pspec); @@ -108,28 +109,17 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec, param_def->meta.m_float.max_val = dspec->maximum; param_def->meta.m_float.default_val = dspec->default_value; } - else if (pspec_type == GIMP_TYPE_PARAM_STRING || - pspec_type == G_TYPE_PARAM_STRING) + else if (G_IS_PARAM_SPEC_STRING (pspec)) { GParamSpecString *gsspec = G_PARAM_SPEC_STRING (pspec); + if (! strcmp (param_def->type_name, "GimpParamSpecString")) + param_def->type_name = "GParamSpecString"; + param_def->param_def_type = GP_PARAM_DEF_TYPE_STRING; - param_def->meta.m_string.null_ok = ! gsspec->ensure_non_null; - param_def->meta.m_string.default_val = gsspec->default_value; + param_def->meta.m_string.default_val = gsspec->default_value; - if (pspec_type == GIMP_TYPE_PARAM_STRING) - { - GimpParamSpecString *sspec = GIMP_PARAM_SPEC_STRING (pspec); - - param_def->meta.m_string.allow_non_utf8 = sspec->allow_non_utf8; - param_def->meta.m_string.non_empty = sspec->non_empty; - } - else - { - param_def->meta.m_string.allow_non_utf8 = FALSE; - param_def->meta.m_string.non_empty = FALSE; - } } else if (pspec_type == GIMP_TYPE_PARAM_RGB) { diff --git a/libgimp/gimpgpparams.c b/libgimp/gimpgpparams.c index e740fce7fc..a7bfd1daaf 100644 --- a/libgimp/gimpgpparams.c +++ b/libgimp/gimpgpparams.c @@ -46,7 +46,9 @@ _gimp_gp_param_def_to_param_spec (gpointer gimp, const gchar *name = param_def->name; const gchar *nick = param_def->nick; const gchar *blurb = param_def->blurb; - GParamFlags flags = G_PARAM_READWRITE; + GParamFlags flags = param_def->flags; + + flags &= ~G_PARAM_STATIC_STRINGS; switch (param_def->param_def_type) { @@ -137,14 +139,10 @@ _gimp_gp_param_def_to_param_spec (gpointer gimp, break; case GP_PARAM_DEF_TYPE_STRING: - if (! strcmp (param_def->type_name, "GimpParamString") || - ! strcmp (param_def->type_name, "GParamString")) - return gimp_param_spec_string (name, nick, blurb, - param_def->meta.m_string.allow_non_utf8, - param_def->meta.m_string.null_ok, - param_def->meta.m_string.non_empty, - param_def->meta.m_string.default_val, - flags); + if (! strcmp (param_def->type_name, "GParamString")) + return g_param_spec_string (name, nick, blurb, + param_def->meta.m_string.default_val, + flags); break; case GP_PARAM_DEF_TYPE_COLOR: diff --git a/libgimp/gimploadprocedure.c b/libgimp/gimploadprocedure.c index 0492a949e4..1139170029 100644 --- a/libgimp/gimploadprocedure.c +++ b/libgimp/gimploadprocedure.c @@ -79,22 +79,17 @@ gimp_load_procedure_constructed (GObject *object) G_OBJECT_CLASS (parent_class)->constructed (object); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("uri", - "URI", - "The URI of the file " - "to load", - FALSE, FALSE, TRUE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("raw-uri", - "Raw URI", - "The URI of the file " - "to load", - FALSE, FALSE, TRUE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "The URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); + + GIMP_PROC_ARG_STRING (procedure, "raw-uri", + "Raw URI", + "The URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); GIMP_PROC_VAL_IMAGE (procedure, "image", "Image", diff --git a/libgimp/gimpsaveprocedure.c b/libgimp/gimpsaveprocedure.c index f907424a90..21367a00ed 100644 --- a/libgimp/gimpsaveprocedure.c +++ b/libgimp/gimpsaveprocedure.c @@ -84,27 +84,21 @@ gimp_save_procedure_constructed (GObject *object) GIMP_PROC_ARG_DRAWABLE (procedure, "drawable", "Drawable", - "The drawable " - "to save", + "The drawable to save", FALSE, G_PARAM_READWRITE); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("uri", - "URI", - "The URI of the file " - "to save to", - FALSE, FALSE, TRUE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("raw-uri", - "Raw URI", - "The URI of the file " - "to save to", - FALSE, FALSE, TRUE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "The URI of the file to save to", + NULL, + GIMP_PARAM_READWRITE); + + GIMP_PROC_ARG_STRING (procedure, "raw-uri", + "Raw URI", + "The URI of the file to save to", + NULL, + GIMP_PARAM_READWRITE); } static void diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def index 83a6e19eee..9f3ef2a3ea 100644 --- a/libgimpbase/gimpbase.def +++ b/libgimpbase/gimpbase.def @@ -118,13 +118,11 @@ EXPORTS gimp_param_spec_memsize gimp_param_spec_parasite gimp_param_spec_rgb_array - gimp_param_spec_string gimp_param_spec_string_array gimp_param_spec_uint8_array gimp_param_spec_unit gimp_param_spec_value_array gimp_param_string_array_get_type - gimp_param_string_get_type gimp_param_uint8_array_get_type gimp_param_unit_get_type gimp_param_value_array_get_type diff --git a/libgimpbase/gimpparamspecs.c b/libgimpbase/gimpparamspecs.c index 93f92c5dd5..64d7241447 100644 --- a/libgimpbase/gimpparamspecs.c +++ b/libgimpbase/gimpparamspecs.c @@ -25,174 +25,6 @@ #include "gimpbase.h" -/* - * GIMP_TYPE_PARAM_STRING - */ - -static void gimp_param_string_class_init (GParamSpecClass *klass); -static void gimp_param_string_init (GParamSpec *pspec); -static gboolean gimp_param_string_validate (GParamSpec *pspec, - GValue *value); - -static GParamSpecClass * gimp_param_string_parent_class = NULL; - -GType -gimp_param_string_get_type (void) -{ - static GType type = 0; - - if (! type) - { - const GTypeInfo info = - { - sizeof (GParamSpecClass), - NULL, NULL, - (GClassInitFunc) gimp_param_string_class_init, - NULL, NULL, - sizeof (GimpParamSpecString), - 0, - (GInstanceInitFunc) gimp_param_string_init - }; - - type = g_type_register_static (G_TYPE_PARAM_STRING, - "GimpParamString", &info, 0); - } - - return type; -} - -static void -gimp_param_string_class_init (GParamSpecClass *klass) -{ - gimp_param_string_parent_class = g_type_class_peek_parent (klass); - - klass->value_type = G_TYPE_STRING; - klass->value_validate = gimp_param_string_validate; -} - -static void -gimp_param_string_init (GParamSpec *pspec) -{ - GimpParamSpecString *sspec = GIMP_PARAM_SPEC_STRING (pspec); - - G_PARAM_SPEC_STRING (pspec)->ensure_non_null = TRUE; - - sspec->allow_non_utf8 = FALSE; - sspec->non_empty = FALSE; -} - -static gboolean -gimp_param_string_validate (GParamSpec *pspec, - GValue *value) -{ - GimpParamSpecString *sspec = GIMP_PARAM_SPEC_STRING (pspec); - gchar *string = value->data[0].v_pointer; - - if (gimp_param_string_parent_class->value_validate (pspec, value)) - return TRUE; - - if (string) - { - gchar *s; - - if (sspec->non_empty && ! string[0]) - { - if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) - g_free (string); - else - value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; - - value->data[0].v_pointer = g_strdup ("none"); - return TRUE; - } - - if (! sspec->allow_non_utf8 && - ! g_utf8_validate (string, -1, (const gchar **) &s)) - { - if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) - { - value->data[0].v_pointer = g_strdup (string); - value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; - string = value->data[0].v_pointer; - } - - for (s = string; *s; s++) - if (*s < ' ') - *s = '?'; - - return TRUE; - } - } - else if (sspec->non_empty) - { - value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; - value->data[0].v_pointer = g_strdup ("none"); - return TRUE; - } - - return FALSE; -} - -/** - * gimp_param_spec_string: - * @name: Canonical name of the property specified. - * @nick: Nick name of the property specified. - * @blurb: Description of the property specified. - * @allow_non_utf8: Whether non-UTF-8 strings are allowed. - * @null_ok: Whether %NULL is allowed. - * @non_empty: Whether a non-½NULL value must be set. - * @default_value: The default value. - * @flags: Flags for the property specified. - * - * Creates a new #GimpParamSpecString specifying a - * #G_TYPE_STRING property. - * - * If @allow_non_utf8 is %FALSE, non-valid UTF-8 strings will be - * replaced by question marks. - * - * If @null_ok is %FALSE, %NULL strings will be replaced by an empty - * string. - * - * If @non_empty is %TRUE, empty strings will be replaced by `"none"`. - * - * See g_param_spec_internal() for details on property names. - * - * Returns: (transfer full): The newly created #GimpParamSpecString. - * - * Since: 3.0 - **/ -GParamSpec * -gimp_param_spec_string (const gchar *name, - const gchar *nick, - const gchar *blurb, - gboolean allow_non_utf8, - gboolean null_ok, - gboolean non_empty, - const gchar *default_value, - GParamFlags flags) -{ - GimpParamSpecString *sspec; - - g_return_val_if_fail (! (null_ok && non_empty), NULL); - - sspec = g_param_spec_internal (GIMP_TYPE_PARAM_STRING, - name, nick, blurb, flags); - - if (sspec) - { - g_free (G_PARAM_SPEC_STRING (sspec)->default_value); - G_PARAM_SPEC_STRING (sspec)->default_value = g_strdup (default_value); - - G_PARAM_SPEC_STRING (sspec)->ensure_non_null = null_ok ? FALSE : TRUE; - - sspec->allow_non_utf8 = allow_non_utf8 ? TRUE : FALSE; - sspec->non_empty = non_empty ? TRUE : FALSE; - } - - return G_PARAM_SPEC (sspec); -} - - /* * GIMP_TYPE_ARRAY */ diff --git a/libgimpbase/gimpparamspecs.h b/libgimpbase/gimpparamspecs.h index 689b1cf72e..20985cdaf7 100644 --- a/libgimpbase/gimpparamspecs.h +++ b/libgimpbase/gimpparamspecs.h @@ -74,36 +74,6 @@ G_BEGIN_DECLS GIMP_PARAM_STATIC_STRINGS) -/* - * GIMP_TYPE_PARAM_STRING - */ - -#define GIMP_TYPE_PARAM_STRING (gimp_param_string_get_type ()) -#define GIMP_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_STRING, GimpParamSpecString)) -#define GIMP_IS_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_STRING)) - -typedef struct _GimpParamSpecString GimpParamSpecString; - -struct _GimpParamSpecString -{ - GParamSpecString parent_instance; - - guint allow_non_utf8 : 1; - guint non_empty : 1; -}; - -GType gimp_param_string_get_type (void) G_GNUC_CONST; - -GParamSpec * gimp_param_spec_string (const gchar *name, - const gchar *nick, - const gchar *blurb, - gboolean allow_non_utf8, - gboolean null_ok, - gboolean non_empty, - const gchar *default_value, - GParamFlags flags); - - /* * GIMP_TYPE_ARRAY */ diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c index 3add813851..01f8c3b180 100644 --- a/libgimpbase/gimpprotocol.c +++ b/libgimpbase/gimpprotocol.c @@ -1043,6 +1043,11 @@ _gp_param_def_read (GIOChannel *channel, user_data)) return FALSE; + if (! _gimp_wire_read_int32 (channel, + ¶m_def->flags, 1, + user_data)) + return FALSE; + switch (param_def->param_def_type) { case GP_PARAM_DEF_TYPE_DEFAULT: @@ -1105,16 +1110,7 @@ _gp_param_def_read (GIOChannel *channel, break; case GP_PARAM_DEF_TYPE_STRING: - if (! _gimp_wire_read_int32 (channel, - (guint32 *) ¶m_def->meta.m_string.allow_non_utf8, 1, - user_data) || - ! _gimp_wire_read_int32 (channel, - (guint32 *) ¶m_def->meta.m_string.null_ok, 1, - user_data) || - ! _gimp_wire_read_int32 (channel, - (guint32 *) ¶m_def->meta.m_string.non_empty, 1, - user_data) || - ! _gimp_wire_read_string (channel, + if (! _gimp_wire_read_string (channel, ¶m_def->meta.m_string.default_val, 1, user_data)) return FALSE; @@ -1325,6 +1321,11 @@ _gp_param_def_write (GIOChannel *channel, user_data)) return FALSE; + if (! _gimp_wire_write_int32 (channel, + ¶m_def->flags, 1, + user_data)) + return FALSE; + switch (param_def->param_def_type) { case GP_PARAM_DEF_TYPE_DEFAULT: @@ -1387,16 +1388,7 @@ _gp_param_def_write (GIOChannel *channel, break; case GP_PARAM_DEF_TYPE_STRING: - if (! _gimp_wire_write_int32 (channel, - (guint32 *) ¶m_def->meta.m_string.allow_non_utf8, 1, - user_data) || - ! _gimp_wire_write_int32 (channel, - (guint32 *) ¶m_def->meta.m_string.null_ok, 1, - user_data) || - ! _gimp_wire_write_int32 (channel, - (guint32 *) ¶m_def->meta.m_string.non_empty, 1, - user_data) || - ! _gimp_wire_write_string (channel, + if (! _gimp_wire_write_string (channel, ¶m_def->meta.m_string.default_val, 1, user_data)) return FALSE; diff --git a/libgimpbase/gimpprotocol.h b/libgimpbase/gimpprotocol.h index effb494616..a7051ea3ae 100644 --- a/libgimpbase/gimpprotocol.h +++ b/libgimpbase/gimpprotocol.h @@ -26,7 +26,7 @@ G_BEGIN_DECLS /* Increment every time the protocol changes */ -#define GIMP_PROTOCOL_VERSION 0x0108 +#define GIMP_PROTOCOL_VERSION 0x0109 enum @@ -175,9 +175,6 @@ struct _GPParamDefFloat struct _GPParamDefString { - gint32 allow_non_utf8; - gint32 null_ok; - gint32 non_empty; gchar *default_val; }; @@ -204,6 +201,7 @@ struct _GPParamDef gchar *name; gchar *nick; gchar *blurb; + guint flags; union { diff --git a/plug-ins/common/file-gbr.c b/plug-ins/common/file-gbr.c index 38b490c530..03c5f9d84b 100644 --- a/plug-ins/common/file-gbr.c +++ b/plug-ins/common/file-gbr.c @@ -161,14 +161,11 @@ gbr_create_procedure (GimpPlugIn *plug_in, 1, 1000, 10, GIMP_PARAM_READWRITE); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("description", - "Description", - "Short description " - "of the brush", - FALSE, FALSE, TRUE, - "GIMP Brush", - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "description", + "Description", + "Short description of the brush", + "GIMP Brush", + GIMP_PARAM_READWRITE); } return procedure; diff --git a/plug-ins/common/file-gif-load.c b/plug-ins/common/file-gif-load.c index dad1594023..33097d9750 100644 --- a/plug-ins/common/file-gif-load.c +++ b/plug-ins/common/file-gif-load.c @@ -208,14 +208,12 @@ gif_create_procedure (GimpPlugIn *plug_in, "Sven Neumann", "2006"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("filename", - "Filename", - "Name of the file " - "to load", - FALSE, TRUE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); + GIMP_PROC_ARG_INT (procedure, "thumb-size", "Thumb Size", "Preferred thumbnail size", @@ -305,16 +303,16 @@ gif_load_thumb (GimpProcedure *procedure, gpointer run_data) { GimpValueArray *return_vals; - const gchar *filename; + GFile *file; gint32 image_id; GError *error = NULL; INIT_I18N (); gegl_init (NULL, NULL); - filename = g_value_get_string (gimp_value_array_index (args, 0)); + file = g_file_new_for_uri (g_value_get_string (gimp_value_array_index (args, 0))); - image_id = load_image (filename, TRUE, &error); + image_id = load_image (g_file_get_path (file), TRUE, &error); if (image_id < 1) return gimp_procedure_new_return_values (procedure, diff --git a/plug-ins/common/file-gih.c b/plug-ins/common/file-gih.c index c7a0871b35..8c66f65b77 100644 --- a/plug-ins/common/file-gih.c +++ b/plug-ins/common/file-gih.c @@ -204,14 +204,12 @@ gih_create_procedure (GimpPlugIn *plug_in, 1, 1000, 10, GIMP_PARAM_READWRITE); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("description", - "Description", - "Short description " - "of the gihtern", - FALSE, TRUE, FALSE, - "GIMP Gihtern", - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "description", + "Description", + "Short description of the gihtern", + "GIMP Gihtern", + GIMP_PARAM_READWRITE); + GIMP_PROC_ARG_INT (procedure, "cell-width", "Cell width", "Width of the brush cells", diff --git a/plug-ins/common/file-pat.c b/plug-ins/common/file-pat.c index 71ae52fbc3..97caf64194 100644 --- a/plug-ins/common/file-pat.c +++ b/plug-ins/common/file-pat.c @@ -127,14 +127,11 @@ pat_create_procedure (GimpPlugIn *plug_in, gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure), TRUE); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("description", - "Description", - "Short description " - "of the pattern", - FALSE, TRUE, FALSE, - "GIMP Pattern", - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "description", + "Description", + "Short description of the pattern", + "GIMP Pattern", + GIMP_PARAM_READWRITE); } return procedure; diff --git a/plug-ins/common/file-ps.c b/plug-ins/common/file-ps.c index c6cb821643..c41c02cdfd 100644 --- a/plug-ins/common/file-ps.c +++ b/plug-ins/common/file-ps.c @@ -473,14 +473,12 @@ ps_create_procedure (GimpPlugIn *plug_in, "Peter Kirchgessner", dversion); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("filename", - "Filename", - "Name of the file " - "to load", - FALSE, TRUE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); + GIMP_PROC_ARG_INT (procedure, "thumb-size", "Thumb Size", "Preferred thumbnail size", @@ -693,7 +691,7 @@ ps_load_thumb (GimpProcedure *procedure, gpointer run_data) { GimpValueArray *return_vals; - const gchar *filename; + GFile *file; gint size; gint32 image_id; GError *error = NULL; @@ -701,8 +699,9 @@ ps_load_thumb (GimpProcedure *procedure, INIT_I18N (); gegl_init (NULL, NULL); - filename = g_value_get_string (gimp_value_array_index (args, 0)); - size = g_value_get_int (gimp_value_array_index (args, 1)); + file = g_file_new_for_uri (g_value_get_string (gimp_value_array_index (args, 0))); + + size = g_value_get_int (gimp_value_array_index (args, 1)); /* We should look for an embedded preview but for now we * just load the document at a small resolution and the @@ -715,7 +714,7 @@ ps_load_thumb (GimpProcedure *procedure, check_load_vals (); - image_id = load_image (filename, &error); + image_id = load_image (g_file_get_path (file), &error); if (image_id < 1) return gimp_procedure_new_return_values (procedure, diff --git a/plug-ins/common/file-svg.c b/plug-ins/common/file-svg.c index 2edf5cbb16..ccccda04e8 100644 --- a/plug-ins/common/file-svg.c +++ b/plug-ins/common/file-svg.c @@ -216,14 +216,11 @@ svg_create_procedure (GimpPlugIn *plug_in, "Dom Lachowicz ", SVG_VERSION); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("filename", - "Filename", - "Name of the file " - "to load", - FALSE, TRUE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); GIMP_PROC_ARG_INT (procedure, "thumb-size", "Thumb Size", @@ -332,7 +329,7 @@ svg_load_thumb (GimpProcedure *procedure, gpointer run_data) { GimpValueArray *return_vals; - const gchar *filename; + GFile *file; gint width = 0; gint height = 0; gint32 image_id; @@ -341,9 +338,10 @@ svg_load_thumb (GimpProcedure *procedure, INIT_I18N (); gegl_init (NULL, NULL); - filename = g_value_get_string (gimp_value_array_index (args, 0)); + file = g_file_new_for_uri (g_value_get_string (gimp_value_array_index (args, 0))); - if (load_rsvg_size (filename, &load_vals, NULL)) + if (load_rsvg_size (g_file_get_path (file), + &load_vals, NULL)) { width = load_vals.width; height = load_vals.height; @@ -353,7 +351,8 @@ svg_load_thumb (GimpProcedure *procedure, load_vals.width = - g_value_get_int (gimp_value_array_index (args, 1)); load_vals.height = - g_value_get_int (gimp_value_array_index (args, 1)); - image_id = load_image (filename, &error); + image_id = load_image (g_file_get_path (file), + &error); if (image_id < 1) return gimp_procedure_new_return_values (procedure, diff --git a/plug-ins/file-ico/ico.c b/plug-ins/file-ico/ico.c index 8414eed516..d25ce4bec4 100644 --- a/plug-ins/file-ico/ico.c +++ b/plug-ins/file-ico/ico.c @@ -156,14 +156,12 @@ ico_create_procedure (GimpPlugIn *plug_in, "Sven Neumann ", "2005"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("filename", - "Filename", - "Name of the file " - "to load", - FALSE, TRUE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); + GIMP_PROC_ARG_INT (procedure, "thumb-size", "Thumb Size", "Preferred thumbnail size", diff --git a/plug-ins/file-psd/psd.c b/plug-ins/file-psd/psd.c index 076721023a..82f7c2c90c 100644 --- a/plug-ins/file-psd/psd.c +++ b/plug-ins/file-psd/psd.c @@ -186,14 +186,12 @@ psd_create_procedure (GimpPlugIn *plug_in, "John Marshall", "2007"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("filename", - "Filename", - "Name of the file " - "to load", - FALSE, TRUE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); + GIMP_PROC_ARG_INT (procedure, "thumb-size", "Thumb Size", "Preferred thumbnail size", diff --git a/plug-ins/file-raw/file-darktable.c b/plug-ins/file-raw/file-darktable.c index 894575815a..33b9696765 100644 --- a/plug-ins/file-raw/file-darktable.c +++ b/plug-ins/file-raw/file-darktable.c @@ -239,14 +239,11 @@ darktable_create_procedure (GimpPlugIn *plug_in, "Tobias Ellinghaus", "2016"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("filename", - "Filename", - "Name of the file " - "to load", - FALSE, TRUE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); GIMP_PROC_ARG_INT (procedure, "thumb-size", "Thumb Size", @@ -369,7 +366,7 @@ darktable_load_thumb (GimpProcedure *procedure, gpointer run_data) { GimpValueArray *return_vals; - const gchar *filename; + GFile *file; gint width; gint height; gint32 image_id; @@ -378,11 +375,13 @@ darktable_load_thumb (GimpProcedure *procedure, INIT_I18N (); - filename = g_value_get_string (gimp_value_array_index (args, 0)); - width = g_value_get_int (gimp_value_array_index (args, 1)); - height = width; + file = g_file_new_for_uri (g_value_get_string (gimp_value_array_index (args, 0))); - image_id = load_thumbnail_image (filename, width, &width, &height, &error); + width = g_value_get_int (gimp_value_array_index (args, 1)); + height = width; + + image_id = load_thumbnail_image (g_file_get_path (file), + width, &width, &height, &error); if (image_id < 1) return gimp_procedure_new_return_values (procedure, diff --git a/plug-ins/file-raw/file-rawtherapee.c b/plug-ins/file-raw/file-rawtherapee.c index 2dbdc33cf1..547cb76737 100644 --- a/plug-ins/file-raw/file-rawtherapee.c +++ b/plug-ins/file-raw/file-rawtherapee.c @@ -190,14 +190,12 @@ rawtherapee_create_procedure (GimpPlugIn *plug_in, "Alberto Griggio", "2017"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("filename", - "Filename", - "Name of the file " - "to load", - FALSE, TRUE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); + GIMP_PROC_ARG_STRING (procedure, "uri", + "URI", + "URI of the file to load", + NULL, + GIMP_PARAM_READWRITE); + GIMP_PROC_ARG_INT (procedure, "thumb-size", "Thumb Size", "Preferred thumbnail size", @@ -307,7 +305,7 @@ rawtherapee_load_thumb (GimpProcedure *procedure, gpointer run_data) { GimpValueArray *return_vals; - const gchar *filename; + GFile *file; gint size; gint32 image_id; GValue value = G_VALUE_INIT; @@ -315,10 +313,12 @@ rawtherapee_load_thumb (GimpProcedure *procedure, INIT_I18N (); - filename = g_value_get_string (gimp_value_array_index (args, 0)); - size = g_value_get_int (gimp_value_array_index (args, 1)); + file = g_file_new_for_uri (g_value_get_string (gimp_value_array_index (args, 0))); - image_id = load_thumbnail_image (filename, size, &error); + size = g_value_get_int (gimp_value_array_index (args, 1)); + + image_id = load_thumbnail_image (g_file_get_path (file), + size, &error); if (image_id < 1) return gimp_procedure_new_return_values (procedure, diff --git a/plug-ins/script-fu/script-fu-script.c b/plug-ins/script-fu/script-fu-script.c index 5e67c50831..95a800fa5b 100644 --- a/plug-ins/script-fu/script-fu-script.c +++ b/plug-ins/script-fu/script-fu-script.c @@ -303,66 +303,61 @@ script_fu_script_install_proc (GimpPlugIn *plug_in, break; case SF_FILENAME: - pspec = gimp_param_spec_string ("filename", - "Filename", - script->args[i].label, - TRUE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string ("filename", + "Filename", + script->args[i].label, + NULL, + G_PARAM_READWRITE | + GIMP_PARAM_NO_VALIDATE); break; case SF_DIRNAME: - pspec = gimp_param_spec_string ("dirname", - "Dirname", - script->args[i].label, - TRUE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string ("dirname", + "Dirname", + script->args[i].label, + NULL, + G_PARAM_READWRITE | + GIMP_PARAM_NO_VALIDATE); break; case SF_FONT: - pspec = gimp_param_spec_string ("Font", - "font", - script->args[i].label, - FALSE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string ("Font", + "font", + script->args[i].label, + NULL, + G_PARAM_READWRITE); break; case SF_PALETTE: - pspec = gimp_param_spec_string ("palette", - "Palette", - script->args[i].label, - FALSE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string ("palette", + "Palette", + script->args[i].label, + NULL, + G_PARAM_READWRITE); break; case SF_PATTERN: - pspec = gimp_param_spec_string ("pattern", - "Pattern", - script->args[i].label, - FALSE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string ("pattern", + "Pattern", + script->args[i].label, + NULL, + G_PARAM_READWRITE); break; case SF_BRUSH: - pspec = gimp_param_spec_string ("brush", - "Brush", - script->args[i].label, - FALSE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string ("brush", + "Brush", + script->args[i].label, + NULL, + G_PARAM_READWRITE); break; case SF_GRADIENT: - pspec = gimp_param_spec_string ("gradient", - "Gradient", - script->args[i].label, - FALSE, TRUE, FALSE, - NULL, - G_PARAM_READWRITE); + pspec = g_param_spec_string ("gradient", + "Gradient", + script->args[i].label, + NULL, + G_PARAM_READWRITE); break; case SF_OPTION: