summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2011-01-10 06:56:07 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2011-01-10 06:56:07 +0100
commit01d771403e3a0b20bd39186b079294e60307ee56 (patch)
treeb84ecd78130e9095a219d5d09e3d795456ef2d51
parentd7c22f10d544bc6ba3a34eab160e934941041888 (diff)
downloadlogdiag-01d771403e3a0b20bd39186b079294e60307ee56.tar.gz
logdiag-01d771403e3a0b20bd39186b079294e60307ee56.tar.xz
logdiag-01d771403e3a0b20bd39186b079294e60307ee56.zip
Write a signature to diagram files.
-rw-r--r--src/ld-diagram.c58
1 files changed, 51 insertions, 7 deletions
diff --git a/src/ld-diagram.c b/src/ld-diagram.c
index 49bfc9e..7a6694c 100644
--- a/src/ld-diagram.c
+++ b/src/ld-diagram.c
@@ -54,6 +54,8 @@ static void ld_diagram_set_property (GObject *object, guint property_id,
static void ld_diagram_dispose (GObject *gobject);
static void ld_diagram_finalize (GObject *gobject);
+static gboolean write_signature (GOutputStream *stream, GError **error);
+
static void ld_diagram_real_changed (LdDiagram *self);
static void ld_diagram_clear_internal (LdDiagram *self);
static void ld_diagram_unselect_all_internal (LdDiagram *self);
@@ -279,13 +281,37 @@ gboolean
ld_diagram_save_to_file (LdDiagram *self,
const gchar *filename, GError **error)
{
+ GFile *file;
+ GFileOutputStream *file_stream;
JsonGenerator *generator;
JsonNode *root;
- GError *json_error;
+ GError *local_error;
g_return_val_if_fail (LD_IS_DIAGRAM (self), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
+ file = g_file_new_for_path (filename);
+
+ local_error = NULL;
+ file_stream = g_file_replace (file, NULL, FALSE,
+ G_FILE_CREATE_NONE, NULL, &local_error);
+ g_object_unref (file);
+
+ if (local_error)
+ {
+ g_propagate_error (error, local_error);
+ return FALSE;
+ }
+
+ local_error = NULL;
+ write_signature (G_OUTPUT_STREAM (file_stream), &local_error);
+ if (local_error)
+ {
+ g_object_unref (file_stream);
+ g_propagate_error (error, local_error);
+ return FALSE;
+ }
+
/* TODO: Implement saving for real. This is just a stub. */
generator = json_generator_new ();
g_object_set (generator, "pretty", TRUE, NULL);
@@ -295,15 +321,33 @@ ld_diagram_save_to_file (LdDiagram *self,
json_generator_set_root (generator, root);
json_node_free (root);
- json_error = NULL;
- json_generator_to_file (generator, filename, &json_error);
- if (json_error)
+ local_error = NULL;
+ json_generator_to_stream (generator, G_OUTPUT_STREAM (file_stream),
+ NULL, &local_error);
+ g_object_unref (file_stream);
+ g_object_unref (generator);
+
+ if (local_error)
{
- g_propagate_error (error, json_error);
- g_object_unref (generator);
+ g_propagate_error (error, local_error);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean
+write_signature (GOutputStream *stream, GError **error)
+{
+ static const gchar signature[] = "/* logdiag diagram */\n";
+ GError *local_error = NULL;
+
+ g_output_stream_write (stream, signature, sizeof (signature) - 1,
+ NULL, &local_error);
+ if (local_error)
+ {
+ g_propagate_error (error, local_error);
return FALSE;
}
- g_object_unref (generator);
return TRUE;
}