[libgda/LIBGDA_4.2] Added the GdaReportEngine::output-directory property
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.2] Added the GdaReportEngine::output-directory property
- Date: Tue, 24 Jan 2012 18:06:32 +0000 (UTC)
commit d935884f3dca378fe4837e133ab2cfdc546506e2
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue Jan 24 18:29:14 2012 +0100
Added the GdaReportEngine::output-directory property
to specify a directory in which generated files wil be saved
libgda-report/engine/gda-report-engine.c | 31 ++++++++++++++--
libgda-report/engine/rt-parser.c | 57 ++++++++++++++++++++----------
libgda-report/engine/rt-parser.h | 5 ++-
libgda-report/engine/test-rt-parser.c | 2 +-
4 files changed, 69 insertions(+), 26 deletions(-)
---
diff --git a/libgda-report/engine/gda-report-engine.c b/libgda-report/engine/gda-report-engine.c
index 60242fa..e3b2361 100644
--- a/libgda-report/engine/gda-report-engine.c
+++ b/libgda-report/engine/gda-report-engine.c
@@ -44,6 +44,7 @@ struct _GdaReportEnginePrivate {
xmlNodePtr spec;
xmlNodePtr result;
GHashTable *objects;
+ gchar *output_dir;
};
/* properties */
@@ -52,7 +53,8 @@ enum
PROP_0,
PROP_SPEC_NODE,
PROP_SPEC_STRING,
- PROP_SPEC_FILE
+ PROP_SPEC_FILE,
+ PROP_OUTPUT_DIR
};
static void gda_report_engine_class_init (GdaReportEngineClass *klass);
@@ -92,6 +94,17 @@ gda_report_engine_class_init (GdaReportEngineClass *klass)
g_param_spec_string ("spec-string", NULL, NULL, NULL, G_PARAM_WRITABLE));
g_object_class_install_property (object_class, PROP_SPEC_FILE,
g_param_spec_string ("spec-filename", NULL, NULL, NULL, G_PARAM_WRITABLE));
+ /**
+ * GdaReportEngine::output-directory:
+ *
+ * Defines the directory in which any file generated by the report engine will be stored;
+ * if not specified the current working directory is used.
+ *
+ * Since: 5.0.3
+ */
+ g_object_class_install_property (object_class, PROP_OUTPUT_DIR,
+ g_param_spec_string ("output-directory", NULL, NULL,
+ NULL, G_PARAM_WRITABLE | G_PARAM_READABLE));
}
static void
@@ -99,6 +112,7 @@ gda_report_engine_init (GdaReportEngine *eng, G_GNUC_UNUSED GdaReportEngineClass
{
eng->priv = g_new0 (GdaReportEnginePrivate, 1);
eng->priv->objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ eng->priv->output_dir = NULL;
}
static void
@@ -125,6 +139,8 @@ gda_report_engine_dispose (GObject *object)
eng->priv->spec = NULL;
}
+ g_free (eng->priv->output_dir);
+
g_free (eng->priv);
eng->priv = NULL;
}
@@ -210,6 +226,10 @@ gda_report_engine_set_property (GObject *object,
}
break;
}
+ case PROP_OUTPUT_DIR:
+ g_free (eng->priv->output_dir);
+ eng->priv->output_dir = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -231,6 +251,9 @@ gda_report_engine_get_property (GObject *object,
case PROP_SPEC_NODE:
g_value_set_pointer (value, eng->priv->spec);
break;
+ case PROP_OUTPUT_DIR:
+ g_value_set_string (value, eng->priv->output_dir);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -1176,7 +1199,7 @@ gtype_equal (gconstpointer a, gconstpointer b)
* Converts @value to a string
*/
static xmlNodePtr
-value_to_node (G_GNUC_UNUSED GdaReportEngine *engine, G_GNUC_UNUSED RunContext *context, const GValue *value, GdaSet *options)
+value_to_node (GdaReportEngine *engine, G_GNUC_UNUSED RunContext *context, const GValue *value, GdaSet *options)
{
xmlNodePtr retnode = NULL;
GdaHolder *converter = NULL;
@@ -1236,12 +1259,12 @@ value_to_node (G_GNUC_UNUSED GdaReportEngine *engine, G_GNUC_UNUSED RunContext *
if (array[0] && !strcmp (array[0], "richtext")) {
if (array[1] && !strcmp (array[1], "docbook")) {
retnode = xmlNewNode (NULL, BAD_CAST "para");
- parse_rich_text_to_docbook (retnode, str);
+ parse_rich_text_to_docbook (engine, retnode, str);
converted = TRUE;
}
else if (array[1] && !strcmp (array[1], "html")) {
retnode = xmlNewNode (NULL, BAD_CAST "p");
- parse_rich_text_to_html (retnode, str);
+ parse_rich_text_to_html (engine, retnode, str);
converted = TRUE;
}
}
diff --git a/libgda-report/engine/rt-parser.c b/libgda-report/engine/rt-parser.c
index f88a16a..afcd366 100644
--- a/libgda-report/engine/rt-parser.c
+++ b/libgda-report/engine/rt-parser.c
@@ -1283,20 +1283,34 @@ rich_text_node_to_docbook (RenderingContext *context, xmlNodePtr top_parent, RtN
}
void
-parse_rich_text_to_docbook (xmlNodePtr top, const gchar *text)
+parse_rich_text_to_docbook (GdaReportEngine *eng, xmlNodePtr top, const gchar *text)
{
RtNode *rtnode;
RenderingContext context;
+ g_return_if_fail (!eng || GDA_IS_REPORT_ENGINE (eng));
context.hash = g_hash_table_new (NULL, NULL);
context.file_path = ".";
+ if (eng)
+ g_object_get (eng, "output-directory", &context.file_path, NULL);
context.file_prefix = "IMG";
-
rtnode = rt_parse_text (text);
/*rt_dump_tree (rtnode);*/
rich_text_node_to_docbook (&context, top, rtnode, top);
g_hash_table_destroy (context.hash);
rt_free_node (rtnode);
+
+ if (eng)
+ g_free (context.file_path);
+}
+
+static xmlNodePtr
+new_html_child (xmlNodePtr parent, const gchar *ns, const gchar *name, const gchar *contents)
+{
+ if (!parent || (parent->name && (*parent->name != 'h')))
+ return xmlNewChild (parent, NULL, BAD_CAST name, BAD_CAST contents);
+ else
+ return new_html_child (parent->parent, ns, name, contents);
}
/*
@@ -1338,26 +1352,26 @@ rich_text_node_to_html (RenderingContext *context, xmlNodePtr top_parent, RtNode
}
break;
case RT_MARKUP_BOLD:
- cattach = xmlNewChild (parent, NULL, BAD_CAST "b", BAD_CAST realtext);
+ cattach = new_html_child (parent, NULL, "b", realtext);
break;
case RT_MARKUP_PARA:
pattach = parent;
if ((parent != top_parent) &&
! strcmp ((gchar*) parent->name, "p"))
pattach = parent->parent;
- cattach = xmlNewChild (pattach, NULL, BAD_CAST "p", BAD_CAST realtext);
+ cattach = new_html_child (pattach, NULL, "p", realtext);
parent = cattach;
break;
case RT_MARKUP_TT:
case RT_MARKUP_VERBATIM:
case RT_MARKUP_ITALIC:
- cattach = xmlNewChild (parent, NULL, BAD_CAST "i", BAD_CAST realtext);
+ cattach = new_html_child (parent, NULL, "i", realtext);
break;
case RT_MARKUP_STRIKE:
- cattach = xmlNewChild (parent, NULL, BAD_CAST "del", BAD_CAST realtext);
+ cattach = new_html_child (parent, NULL, "del", realtext);
break;
case RT_MARKUP_UNDERLINE:
- cattach = xmlNewChild (parent, NULL, BAD_CAST "ins", BAD_CAST realtext);
+ cattach = new_html_child (parent, NULL, "ins", realtext);
break;
case RT_MARKUP_PICTURE: {
gboolean saved = FALSE;
@@ -1405,16 +1419,16 @@ rich_text_node_to_html (RenderingContext *context, xmlNodePtr top_parent, RtNode
else {
switch (type) {
case 0:
- pattach = xmlNewChild (parent, NULL, BAD_CAST "img",
+ pattach = new_html_child (parent, NULL, "img",
NULL);
- xmlSetProp (cattach, BAD_CAST "src", BAD_CAST file);
+ xmlSetProp (pattach, BAD_CAST "src", BAD_CAST file);
break;
case 1:
xmlNodeAddContent (parent, BAD_CAST (rtnode->text));
break;
case 2:
- cattach = xmlNewChild (parent, NULL, BAD_CAST "ulink",
- BAD_CAST _("link"));
+ cattach = new_html_child (parent, NULL, "ulink",
+ _("link"));
xmlSetProp (cattach, BAD_CAST "url", BAD_CAST file);
break;
default:
@@ -1430,7 +1444,7 @@ rich_text_node_to_html (RenderingContext *context, xmlNodePtr top_parent, RtNode
if (!strcmp ((gchar*) parent->name, "para"))
pattach = parent->parent;
sect = g_strdup_printf ("h%d", rtnode->offset + 1);
- cattach = xmlNewChild (pattach, NULL, BAD_CAST sect, BAD_CAST realtext);
+ cattach = new_html_child (pattach, NULL, sect, realtext);
g_free (sect);
break;
}
@@ -1445,14 +1459,14 @@ rich_text_node_to_html (RenderingContext *context, xmlNodePtr top_parent, RtNode
g_assert (!strcmp ((gchar*) tmp->name, "ul"));
g_assert (rtnode->prev->offset == rtnode->offset);
g_hash_table_insert (context->hash, rtnode, tmp);
- tmp = xmlNewChild (tmp, NULL, BAD_CAST "li", NULL);
- cattach = xmlNewChild (tmp, NULL, BAD_CAST "p", BAD_CAST realtext);
+ tmp = new_html_child (tmp, NULL, "li", NULL);
+ cattach = new_html_child (tmp, NULL, "p", realtext);
}
else {
- pattach = xmlNewChild (parent, NULL, BAD_CAST "ul", NULL);
+ pattach = new_html_child (parent, NULL, "ul", NULL);
g_hash_table_insert (context->hash, rtnode, pattach);
- pattach = xmlNewChild (pattach, NULL, BAD_CAST "li", NULL);
- cattach = xmlNewChild (pattach, NULL, BAD_CAST "p", BAD_CAST realtext);
+ pattach = new_html_child (pattach, NULL, "li", NULL);
+ cattach = new_html_child (pattach, NULL, "p", realtext);
}
break;
}
@@ -1474,18 +1488,23 @@ rich_text_node_to_html (RenderingContext *context, xmlNodePtr top_parent, RtNode
}
void
-parse_rich_text_to_html (xmlNodePtr top, const gchar *text)
+parse_rich_text_to_html (GdaReportEngine *eng, xmlNodePtr top, const gchar *text)
{
RtNode *rtnode;
RenderingContext context;
+ g_return_if_fail (!eng || GDA_IS_REPORT_ENGINE (eng));
context.hash = g_hash_table_new (NULL, NULL);
context.file_path = ".";
+ if (eng)
+ g_object_get (eng, "output-directory", &context.file_path, NULL);
context.file_prefix = "IMG";
-
rtnode = rt_parse_text (text);
/*rt_dump_tree (rtnode);*/
rich_text_node_to_html (&context, top, rtnode, top);
g_hash_table_destroy (context.hash);
rt_free_node (rtnode);
+
+ if (eng)
+ g_free (context.file_path);
}
diff --git a/libgda-report/engine/rt-parser.h b/libgda-report/engine/rt-parser.h
index 7b8da38..a2ce58f 100644
--- a/libgda-report/engine/rt-parser.h
+++ b/libgda-report/engine/rt-parser.h
@@ -28,6 +28,7 @@
#include <libxml/tree.h>
#include <glib.h>
#include <gda-value.h>
+#include "gda-report-engine.h"
G_BEGIN_DECLS
@@ -63,8 +64,8 @@ void rt_free_node (RtNode *node);
void rt_dump_tree (RtNode *tree);
gchar *rt_dump_to_string (RtNode *tree);
-void parse_rich_text_to_docbook (xmlNodePtr top, const gchar *text);
-void parse_rich_text_to_html (xmlNodePtr top, const gchar *text);
+void parse_rich_text_to_docbook (GdaReportEngine *eng, xmlNodePtr top, const gchar *text);
+void parse_rich_text_to_html (GdaReportEngine *eng, xmlNodePtr top, const gchar *text);
G_END_DECLS
diff --git a/libgda-report/engine/test-rt-parser.c b/libgda-report/engine/test-rt-parser.c
index a10973d..6b96e7c 100644
--- a/libgda-report/engine/test-rt-parser.c
+++ b/libgda-report/engine/test-rt-parser.c
@@ -100,7 +100,7 @@ main ()
xmlNodePtr node;
xmlKeepBlanksDefault(0);
node = xmlNewNode (NULL, BAD_CAST "top");
- parse_rich_text_to_docbook (node, test->in);
+ parse_rich_text_to_docbook (NULL, node, test->in);
xmlBufferPtr buf;
buf = xmlBufferCreate ();
xmlNodeDump (buf, NULL, node, 1, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]