Commit 64fb1845 authored by Michael Natterer's avatar Michael Natterer 😴

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.
parent ce27a627
......@@ -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.
......@@ -834,6 +846,38 @@ gimp_config_deserialize_unit (GValue *value,
return token;
}
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,
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment