[gimp] libgimpconfig: add support for (de)serializing GFile properties
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpconfig: add support for (de)serializing GFile properties
- Date: Sun, 8 May 2016 21:13:41 +0000 (UTC)
commit 64fb18453c8075dcbdd6611ec39f1ef9f845ec92
Author: Michael Natterer <mitch gimp org>
Date: Sun May 8 22:21:15 2016 +0200
libgimpconfig: add support for (de)serializing GFile properties
Use g_file_get_parse_name() and g_file_parse_name() in order to turn
them into strings and back. Not really sure if we will end up needing
this, but I need it for current hacking. It's clean code and easy
enough to revert, so no harm done in either case.
libgimpconfig/gimpconfig-deserialize.c | 56 ++++++++++++++++++++++++++++---
libgimpconfig/gimpconfig-serialize.c | 27 +++++++++++++++-
2 files changed, 76 insertions(+), 7 deletions(-)
---
diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c
index 7a3114e..25f21d7 100644
--- a/libgimpconfig/gimpconfig-deserialize.c
+++ b/libgimpconfig/gimpconfig-deserialize.c
@@ -91,6 +91,9 @@ static GTokenType gimp_config_deserialize_value_array (GValue *value,
static GTokenType gimp_config_deserialize_unit (GValue *value,
GParamSpec *prop_spec,
GScanner *scanner);
+static GTokenType gimp_config_deserialize_file_value (GValue *value,
+ GParamSpec *prop_spec,
+ GScanner *scanner);
static GTokenType gimp_config_deserialize_any (GValue *value,
GParamSpec *prop_spec,
GScanner *scanner);
@@ -290,13 +293,18 @@ gimp_config_deserialize_property (GimpConfig *config,
}
else
{
- if (G_VALUE_HOLDS_OBJECT (&value))
- token = gimp_config_deserialize_object (&value,
- config, prop_spec,
- scanner, nest_level);
+ if (G_VALUE_HOLDS_OBJECT (&value) &&
+ G_VALUE_TYPE (&value) != G_TYPE_FILE)
+ {
+ token = gimp_config_deserialize_object (&value,
+ config, prop_spec,
+ scanner, nest_level);
+ }
else
- token = gimp_config_deserialize_value (&value,
- config, prop_spec, scanner);
+ {
+ token = gimp_config_deserialize_value (&value,
+ config, prop_spec, scanner);
+ }
}
if (token == G_TOKEN_RIGHT_PAREN &&
@@ -363,6 +371,10 @@ gimp_config_deserialize_value (GValue *value,
{
return gimp_config_deserialize_unit (value, prop_spec, scanner);
}
+ else if (prop_spec->value_type == G_TYPE_FILE)
+ {
+ return gimp_config_deserialize_file_value (value, prop_spec, scanner);
+ }
/* This fallback will only work for value_types that
* can be transformed from a string value.
@@ -835,6 +847,38 @@ gimp_config_deserialize_unit (GValue *value,
}
static GTokenType
+gimp_config_deserialize_file_value (GValue *value,
+ GParamSpec *prop_spec,
+ GScanner *scanner)
+{
+ GTokenType token;
+
+ token = g_scanner_peek_next_token (scanner);
+
+ if (token != G_TOKEN_IDENTIFIER &&
+ token != G_TOKEN_STRING)
+ {
+ return G_TOKEN_STRING;
+ }
+
+ g_scanner_get_next_token (scanner);
+
+ if (token == G_TOKEN_IDENTIFIER)
+ {
+ /* this is supposed to parse a literal "NULL" only, but so what... */
+ g_value_set_object (value, NULL);
+ }
+ else
+ {
+ GFile *file = g_file_parse_name (scanner->value.v_string);
+
+ g_value_take_object (value, file);
+ }
+
+ return G_TOKEN_RIGHT_PAREN;
+}
+
+static GTokenType
gimp_config_deserialize_any (GValue *value,
GParamSpec *prop_spec,
GScanner *scanner)
diff --git a/libgimpconfig/gimpconfig-serialize.c b/libgimpconfig/gimpconfig-serialize.c
index 55e5eb5..56bf3c1 100644
--- a/libgimpconfig/gimpconfig-serialize.c
+++ b/libgimpconfig/gimpconfig-serialize.c
@@ -236,7 +236,8 @@ gimp_config_serialize_property (GimpConfig *config,
if (! success)
{
- if (G_VALUE_HOLDS_OBJECT (&value))
+ if (G_VALUE_HOLDS_OBJECT (&value) &&
+ G_VALUE_TYPE (&value) != G_TYPE_FILE)
{
GimpConfigInterface *config_iface = NULL;
GimpConfig *prop_object;
@@ -484,6 +485,30 @@ gimp_config_serialize_value (const GValue *value,
return TRUE;
}
+ if (G_VALUE_TYPE (value) == G_TYPE_FILE)
+ {
+ GFile *file = g_value_get_object (value);
+
+ if (file)
+ {
+ gchar *parse_name = g_file_get_parse_name (file);
+
+ if (escaped)
+ gimp_config_string_append_escaped (str, parse_name);
+ else
+ g_string_append (str, parse_name);
+
+ g_free (parse_name);
+ g_object_unref (file);
+ }
+ else
+ {
+ g_string_append (str, "NULL");
+ }
+
+ return TRUE;
+ }
+
if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
{
GValue tmp_value = G_VALUE_INIT;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]