[gtksourceview/wip/metadata: 2/5] FileLoader: load metadata



commit 5dd76aa512fe9072f60d29bfc13eea5762e47e99
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Apr 29 13:49:18 2016 +0200

    FileLoader: load metadata

 gtksourceview/gtksourcefile.c       |   15 ++++++++++++
 gtksourceview/gtksourcefile.h       |    4 +++
 gtksourceview/gtksourcefileloader.c |   42 +++++++++++++++++++++++++++++++++-
 3 files changed, 59 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 391b749..d43bbf4 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -746,3 +746,18 @@ gtk_source_file_set_metadata (GtkSourceFile *file,
 
        g_free (attribute_key);
 }
+
+void
+_gtk_source_file_set_metadata_info (GtkSourceFile *file,
+                                   GFileInfo     *metadata)
+{
+       g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+       g_return_if_fail (metadata == NULL || G_IS_FILE_INFO (metadata));
+
+       if (metadata == NULL)
+       {
+               metadata = g_file_info_new ();
+       }
+
+       g_set_object (&file->priv->metadata, metadata);
+}
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index 1685abe..ee814e9 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -154,6 +154,10 @@ G_GNUC_INTERNAL
 void            _gtk_source_file_set_readonly                  (GtkSourceFile *file,
                                                                 gboolean       readonly);
 
+G_GNUC_INTERNAL
+void            _gtk_source_file_set_metadata_info             (GtkSourceFile *file,
+                                                                GFileInfo     *metadata);
+
 G_END_DECLS
 
 #endif /* GTK_SOURCE_FILE_H */
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index e4c3278..d409b57 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -5,7 +5,7 @@
  * Copyright (C) 2005 - Paolo Maggi
  * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux
  * Copyright (C) 2008 - Jesse van den Kieboom
- * Copyright (C) 2014 - Sébastien Wilmet
+ * Copyright (C) 2014, 2016 - Sébastien Wilmet
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -105,6 +105,7 @@ struct _GtkSourceFileLoaderPrivate
        GSList *candidate_encodings;
 
        GFileInfo *info;
+       GFileInfo *metadata;
        const GtkSourceEncoding *auto_detected_encoding;
        GtkSourceNewlineType auto_detected_newline_type;
        GtkSourceCompressionType auto_detected_compression_type;
@@ -235,6 +236,7 @@ reset (GtkSourceFileLoader *loader)
        g_clear_object (&loader->priv->input_stream);
        g_clear_object (&loader->priv->output_stream);
        g_clear_object (&loader->priv->info);
+       g_clear_object (&loader->priv->metadata);
 
        if (loader->priv->progress_cb_notify != NULL)
        {
@@ -690,6 +692,29 @@ create_input_stream (GtkSourceFileLoader *loader)
 }
 
 static void
+query_metadata_cb (GFile               *file,
+                  GAsyncResult        *result,
+                  GtkSourceFileLoader *loader)
+{
+       GError *error = NULL;
+
+       DEBUG ({
+              g_print ("%s\n", G_STRFUNC);
+       });
+
+       g_clear_object (&loader->priv->metadata);
+       loader->priv->metadata = g_file_query_info_finish (file, result, &error);
+
+       if (error != NULL)
+       {
+               g_task_return_error (loader->priv->task, error);
+               return;
+       }
+
+       create_input_stream (loader);
+}
+
+static void
 query_info_cb (GFile               *file,
               GAsyncResult        *result,
               GtkSourceFileLoader *loader)
@@ -700,6 +725,7 @@ query_info_cb (GFile               *file,
               g_print ("%s\n", G_STRFUNC);
        });
 
+       g_clear_object (&loader->priv->info);
        loader->priv->info = g_file_query_info_finish (file, result, &error);
 
        if (error != NULL)
@@ -724,7 +750,13 @@ query_info_cb (GFile               *file,
                                                                             G_FILE_ATTRIBUTE_STANDARD_SIZE);
        }
 
-       create_input_stream (loader);
+       g_file_query_info_async (file,
+                                "metadata::*",
+                                G_FILE_QUERY_INFO_NONE,
+                                g_task_get_priority (loader->priv->task),
+                                g_task_get_cancellable (loader->priv->task),
+                                (GAsyncReadyCallback) query_metadata_cb,
+                                loader);
 }
 
 static void
@@ -1066,6 +1098,9 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
                                              loader->priv->location);
        }
 
+       /* The old metadata is no longer valid. */
+       _gtk_source_file_set_metadata_info (loader->priv->file, NULL);
+
        implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(loader->priv->source_buffer);
 
        /* The BufferOutputStream has a strong reference to the buffer.
@@ -1154,6 +1189,9 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
                _gtk_source_file_set_externally_modified (loader->priv->file, FALSE);
                _gtk_source_file_set_deleted (loader->priv->file, FALSE);
 
+               _gtk_source_file_set_metadata_info (loader->priv->file,
+                                                   loader->priv->metadata);
+
                if (g_file_info_has_attribute (loader->priv->info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
                {
                        GTimeVal modification_time;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]