aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2010-12-11 15:46:30 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2010-12-11 20:32:03 +0100
commitf9dbe12971960e35a0e5c6b701c6d83d4e199db5 (patch)
tree52fcca81353e20c2edabd0fdcfff4e76a7688ad9
parente364267010db1242757f67ad9c7aef5abc2c3103 (diff)
downloadlogdiag-f9dbe12971960e35a0e5c6b701c6d83d4e199db5.tar.gz
logdiag-f9dbe12971960e35a0e5c6b701c6d83d4e199db5.tar.xz
logdiag-f9dbe12971960e35a0e5c6b701c6d83d4e199db5.zip
Stubplement LdDocument file operations.
Prototypes for these functions were wrong; fixed.
-rw-r--r--src/ld-document.c51
-rw-r--r--src/ld-document.h4
2 files changed, 47 insertions, 8 deletions
diff --git a/src/ld-document.c b/src/ld-document.c
index 54c0ff9..d067d3b 100644
--- a/src/ld-document.c
+++ b/src/ld-document.c
@@ -229,12 +229,29 @@ ld_document_clear_internal (LdDocument *self)
*/
gboolean
ld_document_load_from_file (LdDocument *self,
- const gchar *filename, GError *error)
+ const gchar *filename, GError **error)
{
+ JsonParser *parser;
+ GError *json_error;
+
g_return_val_if_fail (LD_IS_DOCUMENT (self), FALSE);
+ g_return_val_if_fail (filename != NULL, FALSE);
+
+ /* TODO: Implement loading for real. This is just a stub. */
+ parser = json_parser_new ();
+
+ json_error = NULL;
+ json_parser_load_from_file (parser, filename, &json_error);
+ if (json_error)
+ {
+ g_propagate_error (error, json_error);
+ g_object_unref (parser);
+ return FALSE;
+ }
- /* TODO */
- return FALSE;
+ ld_document_clear (self);
+ g_object_unref (parser);
+ return TRUE;
}
/**
@@ -249,12 +266,34 @@ ld_document_load_from_file (LdDocument *self,
*/
gboolean
ld_document_save_to_file (LdDocument *self,
- const gchar *filename, GError *error)
+ const gchar *filename, GError **error)
{
+ JsonGenerator *generator;
+ JsonNode *root;
+ GError *json_error;
+
g_return_val_if_fail (LD_IS_DOCUMENT (self), FALSE);
+ g_return_val_if_fail (filename != NULL, FALSE);
+
+ /* TODO: Implement saving for real. This is just a stub. */
+ generator = json_generator_new ();
+ g_object_set (generator, "pretty", TRUE, NULL);
+
+ /* XXX: json-glib dislikes empty objects. */
+ root = json_node_new (JSON_NODE_OBJECT);
+ json_generator_set_root (generator, root);
+ json_node_free (root);
- /* TODO */
- return FALSE;
+ json_error = NULL;
+ json_generator_to_file (generator, filename, &json_error);
+ if (json_error)
+ {
+ g_propagate_error (error, json_error);
+ g_object_unref (generator);
+ return FALSE;
+ }
+ g_object_unref (generator);
+ return TRUE;
}
/**
diff --git a/src/ld-document.h b/src/ld-document.h
index a27fe23..13602aa 100644
--- a/src/ld-document.h
+++ b/src/ld-document.h
@@ -60,9 +60,9 @@ GType ld_document_get_type (void) G_GNUC_CONST;
LdDocument *ld_document_new (void);
void ld_document_clear (LdDocument *self);
gboolean ld_document_load_from_file (LdDocument *self,
- const gchar *filename, GError *error);
+ const gchar *filename, GError **error);
gboolean ld_document_save_to_file (LdDocument *self,
- const gchar *filename, GError *error);
+ const gchar *filename, GError **error);
gboolean ld_document_get_modified (LdDocument *self);
void ld_document_set_modified (LdDocument *self, gboolean value);