diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ld-document.c | 51 | ||||
-rw-r--r-- | src/ld-document.h | 4 |
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); |