[libgsf] Fix read/write of GSF_DOCPROP_VECTOR_TYPE meta data [Part of #672716]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsf] Fix read/write of GSF_DOCPROP_VECTOR_TYPE meta data [Part of #672716]
- Date: Sat, 31 Mar 2012 18:40:28 +0000 (UTC)
commit 71354b11f9d0810cb9ca31f730cd6e1ca840e9d4
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Sat Mar 31 12:39:54 2012 -0600
Fix read/write of GSF_DOCPROP_VECTOR_TYPE meta data [Part of #672716]
2012-03-31 Andreas J. Guelzow <aguelzow pyrshep ca>
* gsf/gsf-opendoc-utils.c (od_meta_user_defined): default to
G_TYPE_NONE
(od_meta_user_defined_end): Check for "GSF_DOCPROP_VECTOR:" and
handle accordingly
(meta_write_props_user_defined): code extracted from
meta_write_props
(meta_write_props): use meta_write_props_user_defined and handle
GSF_DOCPROP_VECTOR_TYPE
ChangeLog | 11 ++++
NEWS | 3 +
gsf/gsf-opendoc-utils.c | 148 +++++++++++++++++++++++++++++++++-------------
3 files changed, 120 insertions(+), 42 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5487e16..6d33113 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-03-31 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * gsf/gsf-opendoc-utils.c (od_meta_user_defined): default to
+ G_TYPE_NONE
+ (od_meta_user_defined_end): Check for "GSF_DOCPROP_VECTOR:" and
+ handle accordingly
+ (meta_write_props_user_defined): code extracted from
+ meta_write_props
+ (meta_write_props): use meta_write_props_user_defined and handle
+ GSF_DOCPROP_VECTOR_TYPE
+
2012-03-25 Morten Welinder <terra gnome org>
* configure.in (test_python): Disable by default. Patch from
diff --git a/NEWS b/NEWS
index 76f1d37..cacf149 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
libgsf 1.14.23
+Andreas:
+ * Fix read/write of GSF_DOCPROP_VECTOR_TYPE meta data [Part of #672716]
+
Alan Knowles:
* Add gobject introspection support. [#610340]
diff --git a/gsf/gsf-opendoc-utils.c b/gsf/gsf-opendoc-utils.c
index 2df4daa..f57ab9d 100644
--- a/gsf/gsf-opendoc-utils.c
+++ b/gsf/gsf-opendoc-utils.c
@@ -213,7 +213,7 @@ static void
od_meta_user_defined (GsfXMLIn *xin, xmlChar const **attrs)
{
GsfOOMetaIn *mi = (GsfOOMetaIn *)xin->user_state;
- mi->typ = G_TYPE_STRING;
+ mi->typ = G_TYPE_NONE;
mi->name = NULL;
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
@@ -261,13 +261,49 @@ od_meta_user_defined_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
GType t = mi->typ;
if (t == G_TYPE_NONE) t = G_TYPE_STRING;
if (gsf_xml_gvalue_from_str (res, t, xin->content->str)) {
+ if (g_str_has_prefix (mi->name, "GSF_DOCPROP_VECTOR:")) {
+ gchar *true_name = strchr (mi->name + 19, ':');
+ if (true_name != NULL && *(++true_name) != 0) {
+ GsfDocProp *prop = gsf_doc_meta_data_lookup
+ (mi->md, true_name);
+ if (prop == NULL) {
+ GsfDocPropVector *vector = gsf_docprop_vector_new ();
+ GValue *val_vector = g_new0 (GValue, 1);
+ g_value_init (val_vector, GSF_DOCPROP_VECTOR_TYPE);
+ gsf_docprop_vector_append (vector, res);
+ g_value_set_object (val_vector, vector);
+ gsf_doc_meta_data_insert (mi->md, g_strdup (true_name),
+ val_vector);
+ g_value_unset (res);
+ g_free (res);
+ } else {
+ GValue const *old = gsf_doc_prop_get_val (prop);
+ if (G_VALUE_HOLDS (old, GSF_DOCPROP_VECTOR_TYPE)) {
+ GValue *new = g_new0 (GValue, 1);
+ GValueArray *vector;
+ g_value_init (new, GSF_DOCPROP_VECTOR_TYPE);
+ g_value_copy (old, new);
+ vector = gsf_value_get_docprop_varray (new);
+ g_value_array_append (vector, res);
+ gsf_doc_prop_set_val (prop, new);
+ } else
+ g_printerr (_("Property \"%s\" used for "
+ "multiple types!"), true_name);
+ g_value_unset (res);
+ g_free (res);
+ }
+
+ g_free (mi->name);
+ mi->name = NULL;
+ return;
+ }
+ }
gsf_doc_meta_data_insert (mi->md, mi->name, res);
- mi->name = NULL;
} else {
g_free (res);
g_free (mi->name);
- mi->name = NULL;
}
+ mi->name = NULL;
}
}
@@ -482,6 +518,53 @@ meta:object-count
#endif
static void
+meta_write_props_user_defined (char const *prop_name, GValue const *val, GsfXMLOut *output)
+{
+ GType t;
+ char const *type_name = NULL;
+
+ gsf_xml_out_start_element (output, "meta:user-defined");
+ gsf_xml_out_add_cstr (output, "meta:name", prop_name);
+
+ if (NULL == val) {
+ gsf_xml_out_end_element (output);
+ return;
+ }
+
+ t = G_VALUE_TYPE (val);
+ switch (t) {
+ case G_TYPE_CHAR:
+ case G_TYPE_UCHAR:
+ case G_TYPE_STRING:
+ case G_TYPE_ENUM:
+ case G_TYPE_FLAGS:
+ type_name = "string";
+ break;
+ case G_TYPE_BOOLEAN:
+ type_name = "boolean";
+ break;
+ case G_TYPE_INT:
+ case G_TYPE_UINT:
+ case G_TYPE_LONG:
+ case G_TYPE_ULONG:
+ case G_TYPE_FLOAT:
+ case G_TYPE_DOUBLE:
+ type_name = "float";
+ break;
+
+ default:
+ if (GSF_TIMESTAMP_TYPE == t)
+ type_name = "date";
+ }
+ if (NULL != type_name)
+ gsf_xml_out_add_cstr (output, "meta:value-type", type_name);
+ if (NULL != val)
+ gsf_xml_out_add_gvalue (output, NULL, val);
+ gsf_xml_out_end_element (output);
+}
+
+
+static void
meta_write_props (char const *prop_name, GsfDocProp *prop, GsfXMLOut *output)
{
char const *mapped_name;
@@ -516,46 +599,27 @@ meta_write_props (char const *prop_name, GsfDocProp *prop, GsfXMLOut *output)
}
if (NULL == (mapped_name = od_map_prop_name (prop_name))) {
- GType t;
- char const *type_name = NULL;
-
- gsf_xml_out_start_element (output, "meta:user-defined");
- gsf_xml_out_add_cstr (output, "meta:name", prop_name);
-
- if (NULL == val) {
- gsf_xml_out_end_element (output);
- return;
- }
+ if (GSF_DOCPROP_VECTOR_TYPE == G_VALUE_TYPE (val)) {
+ GValueArray *vector = gsf_value_get_docprop_varray (val);
+ guint i;
+ guint num_values = vector->n_values;
+
+ for (i = 0; i < num_values; i++) {
+ GValue *v;
+ char *new_name = g_strdup_printf
+ ("GSF_DOCPROP_VECTOR:%.4i:%s", i, prop_name);
+
+ v = g_value_array_get_nth (vector, i);
+ meta_write_props_user_defined (new_name, v, output);
+ g_free (new_name);
+ }
+ } else
+ meta_write_props_user_defined (prop_name, val, output);
+ return;
+ }
- t = G_VALUE_TYPE (val);
- switch (t) {
- case G_TYPE_CHAR:
- case G_TYPE_UCHAR:
- case G_TYPE_STRING:
- case G_TYPE_ENUM:
- case G_TYPE_FLAGS:
- type_name = "string";
- break;
- case G_TYPE_BOOLEAN:
- type_name = "boolean";
- break;
- case G_TYPE_INT:
- case G_TYPE_UINT:
- case G_TYPE_LONG:
- case G_TYPE_ULONG:
- case G_TYPE_FLOAT:
- case G_TYPE_DOUBLE:
- type_name = "float";
- break;
-
- default:
- if (GSF_TIMESTAMP_TYPE == t)
- type_name = "date";
- }
- if (NULL != type_name)
- gsf_xml_out_add_cstr (output, "meta:value-type", type_name);
- } else
- gsf_xml_out_start_element (output, mapped_name);
+ /* Standardized ODF meta items*/
+ gsf_xml_out_start_element (output, mapped_name);
if (NULL != val)
gsf_xml_out_add_gvalue (output, NULL, val);
gsf_xml_out_end_element (output);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]