[gtksourceview/wip/metadata] FileLoader: add flag to not load metadata
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/metadata] FileLoader: add flag to not load metadata
- Date: Sat, 30 Apr 2016 16:13:37 +0000 (UTC)
commit 090afa6f4c6ee397153b5b395d1e292d744ccf1c
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 30 17:53:02 2016 +0200
FileLoader: add flag to not load metadata
docs/reference/gtksourceview-3.0-sections.txt | 3 +
gtksourceview/gtksourcefileloader.c | 108 ++++++++++++++++++++++---
gtksourceview/gtksourcefileloader.h | 21 +++++
3 files changed, 120 insertions(+), 12 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 6bfacb1..37c1b28 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -281,6 +281,7 @@ gtk_source_file_get_type
GtkSourceFileLoader
GTK_SOURCE_FILE_LOADER_ERROR
GtkSourceFileLoaderError
+GtkSourceFileLoaderFlags
<SUBSECTION>
gtk_source_file_loader_new
gtk_source_file_loader_new_from_stream
@@ -289,6 +290,8 @@ gtk_source_file_loader_get_buffer
gtk_source_file_loader_get_file
gtk_source_file_loader_get_location
gtk_source_file_loader_get_input_stream
+gtk_source_file_loader_set_flags
+gtk_source_file_loader_get_flags
gtk_source_file_loader_load_async
gtk_source_file_loader_load_finish
gtk_source_file_loader_load_metadata
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 32370b6..f969025 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -73,7 +73,8 @@ enum
PROP_BUFFER,
PROP_FILE,
PROP_LOCATION,
- PROP_INPUT_STREAM
+ PROP_INPUT_STREAM,
+ PROP_FLAGS
};
#define READ_CHUNK_SIZE 8192
@@ -104,6 +105,7 @@ struct _GtkSourceFileLoaderPrivate
GInputStream *input_stream_property;
GSList *candidate_encodings;
+ GtkSourceFileLoaderFlags flags;
GFileInfo *info;
GFileInfo *metadata;
@@ -192,6 +194,10 @@ gtk_source_file_loader_set_property (GObject *object,
loader->priv->input_stream_property = g_value_dup_object (value);
break;
+ case PROP_FLAGS:
+ gtk_source_file_loader_set_flags (loader, g_value_get_flags (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -224,6 +230,10 @@ gtk_source_file_loader_get_property (GObject *object,
g_value_set_object (value, loader->priv->input_stream_property);
break;
+ case PROP_FLAGS:
+ g_value_set_flags (value, loader->priv->flags);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -436,6 +446,23 @@ gtk_source_file_loader_class_init (GtkSourceFileLoaderClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GtkSourceFileLoader:flags:
+ *
+ * File loading flags.
+ *
+ * Since: 3.22
+ */
+ g_object_class_install_property (object_class, PROP_FLAGS,
+ g_param_spec_flags ("flags",
+ "Flags",
+ "",
+ GTK_SOURCE_TYPE_FILE_LOADER_FLAGS,
+ GTK_SOURCE_FILE_LOADER_FLAGS_NONE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -721,6 +748,7 @@ query_info_cb (GFile *file,
GtkSourceFileLoader *loader)
{
GError *error = NULL;
+ gboolean load_metadata;
DEBUG ({
g_print ("%s\n", G_STRFUNC);
@@ -751,13 +779,22 @@ query_info_cb (GFile *file,
G_FILE_ATTRIBUTE_STANDARD_SIZE);
}
- g_file_query_info_async (file,
- METADATA_QUERY_ATTRIBUTES,
- G_FILE_QUERY_INFO_NONE,
- g_task_get_priority (loader->priv->task),
- g_task_get_cancellable (loader->priv->task),
- (GAsyncReadyCallback) query_metadata_cb,
- loader);
+ load_metadata = (loader->priv->flags & GTK_SOURCE_FILE_LOADER_FLAGS_DO_NOT_LOAD_METADATA) == 0;
+
+ if (load_metadata)
+ {
+ g_file_query_info_async (file,
+ METADATA_QUERY_ATTRIBUTES,
+ G_FILE_QUERY_INFO_NONE,
+ g_task_get_priority (loader->priv->task),
+ g_task_get_cancellable (loader->priv->task),
+ (GAsyncReadyCallback) query_metadata_cb,
+ loader);
+ }
+ else
+ {
+ create_input_stream (loader);
+ }
}
static void
@@ -1021,6 +1058,42 @@ gtk_source_file_loader_get_input_stream (GtkSourceFileLoader *loader)
}
/**
+ * gtk_source_file_loader_set_flags:
+ * @loader: a #GtkSourceFileLoader.
+ * @flags: the new flags.
+ *
+ * Since: 3.22
+ */
+void
+gtk_source_file_loader_set_flags (GtkSourceFileLoader *loader,
+ GtkSourceFileLoaderFlags flags)
+{
+ g_return_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader));
+ g_return_if_fail (loader->priv->task == NULL);
+
+ if (loader->priv->flags != flags)
+ {
+ loader->priv->flags = flags;
+ g_object_notify (G_OBJECT (loader), "flags");
+ }
+}
+
+/**
+ * gtk_source_file_loader_get_flags:
+ * @loader: a #GtkSourceFileLoader.
+ *
+ * Returns: the flags.
+ * Since: 3.22
+ */
+GtkSourceFileLoaderFlags
+gtk_source_file_loader_get_flags (GtkSourceFileLoader *loader)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), GTK_SOURCE_FILE_LOADER_FLAGS_NONE);
+
+ return loader->priv->flags;
+}
+
+/**
* gtk_source_file_loader_load_async:
* @loader: a #GtkSourceFileLoader.
* @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
@@ -1057,6 +1130,7 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader *loader,
gpointer user_data)
{
gboolean implicit_trailing_newline;
+ gboolean load_metadata;
g_return_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
@@ -1099,8 +1173,12 @@ 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);
+ load_metadata = (loader->priv->flags & GTK_SOURCE_FILE_LOADER_FLAGS_DO_NOT_LOAD_METADATA) == 0;
+ if (load_metadata)
+ {
+ /* 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);
@@ -1174,6 +1252,8 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader *loader,
if (update_file_properties && loader->priv->file != NULL)
{
+ gboolean metadata_loaded;
+
/* The location is already updated at the beginning of the
* operation.
*/
@@ -1190,8 +1270,12 @@ 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);
+ metadata_loaded = (loader->priv->flags & GTK_SOURCE_FILE_LOADER_FLAGS_DO_NOT_LOAD_METADATA)
== 0;
+ if (metadata_loaded)
+ {
+ _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))
{
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index fc139b6..fc4d9b6 100644
--- a/gtksourceview/gtksourcefileloader.h
+++ b/gtksourceview/gtksourcefileloader.h
@@ -59,6 +59,20 @@ typedef enum
GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK
} GtkSourceFileLoaderError;
+/**
+ * GtkSourceFileLoaderFlags:
+ * @GTK_SOURCE_FILE_LOADER_FLAGS_NONE: No flags.
+ * @GTK_SOURCE_FILE_LOADER_FLAGS_DO_NOT_LOAD_METADATA: Do not load metadata.
+ *
+ * Flags to define the behavior of a #GtkSourceFileLoader.
+ * Since: 3.22
+ */
+typedef enum
+{
+ GTK_SOURCE_FILE_LOADER_FLAGS_NONE = 0,
+ GTK_SOURCE_FILE_LOADER_FLAGS_DO_NOT_LOAD_METADATA = 1 << 0
+} GtkSourceFileLoaderFlags;
+
struct _GtkSourceFileLoader
{
GObject parent;
@@ -106,6 +120,13 @@ GTK_SOURCE_AVAILABLE_IN_3_14
GInputStream *gtk_source_file_loader_get_input_stream
(GtkSourceFileLoader *loader);
+GTK_SOURCE_AVAILABLE_IN_3_22
+void gtk_source_file_loader_set_flags (GtkSourceFileLoader *loader,
+ GtkSourceFileLoaderFlags flags);
+
+GTK_SOURCE_AVAILABLE_IN_3_22
+GtkSourceFileLoaderFlags gtk_source_file_loader_get_flags (GtkSourceFileLoader *loader);
+
GTK_SOURCE_AVAILABLE_IN_3_14
void gtk_source_file_loader_load_async (GtkSourceFileLoader *loader,
gint io_priority,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]