[gtksourceview/wip/metadata: 7/8] FileLoader: add load_metadata(), sync and async versions
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/metadata: 7/8] FileLoader: add load_metadata(), sync and async versions
- Date: Sat, 30 Apr 2016 16:22:12 +0000 (UTC)
commit b3df2cf3c831ebb7b474c967ab59acc0369c6b90
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 30 15:00:37 2016 +0200
FileLoader: add load_metadata(), sync and async versions
docs/reference/gtksourceview-3.0-sections.txt | 3 +
gtksourceview/gtksourcefileloader.c | 148 ++++++++++++++++++++++++-
gtksourceview/gtksourcefileloader.h | 21 ++++-
3 files changed, 170 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 03fea7e..6bfacb1 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -291,6 +291,9 @@ gtk_source_file_loader_get_location
gtk_source_file_loader_get_input_stream
gtk_source_file_loader_load_async
gtk_source_file_loader_load_finish
+gtk_source_file_loader_load_metadata
+gtk_source_file_loader_load_metadata_async
+gtk_source_file_loader_load_metadata_finish
gtk_source_file_loader_get_encoding
gtk_source_file_loader_get_newline_type
gtk_source_file_loader_get_compression_type
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 118795f..c4597e2 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -77,6 +77,7 @@ enum
};
#define READ_CHUNK_SIZE 8192
+#define METADATA_QUERY_ATTRIBUTES "metadata::*"
#define LOADER_QUERY_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \
G_FILE_ATTRIBUTE_STANDARD_TYPE "," \
G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
@@ -751,7 +752,7 @@ query_info_cb (GFile *file,
}
g_file_query_info_async (file,
- "metadata::*",
+ METADATA_QUERY_ATTRIBUTES,
G_FILE_QUERY_INFO_NONE,
g_task_get_priority (loader->priv->task),
g_task_get_cancellable (loader->priv->task),
@@ -1228,6 +1229,151 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader *loader,
}
/**
+ * gtk_source_file_loader_load_metadata:
+ * @loader: a #GtkSourceFileLoader.
+ * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
+ * @error: location to a %NULL #GError, or %NULL.
+ *
+ * Loads synchronously the metadata.
+ *
+ * Returns: whether the metadata was loaded successfully.
+ * Since: 3.22
+ */
+gboolean
+gtk_source_file_loader_load_metadata (GtkSourceFileLoader *loader,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GFileInfo *metadata;
+ gboolean ok;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), FALSE);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (loader->priv->file == NULL ||
+ loader->priv->location == NULL)
+ {
+ return FALSE;
+ }
+
+ metadata = g_file_query_info (loader->priv->location,
+ METADATA_QUERY_ATTRIBUTES,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable,
+ error);
+
+ ok = metadata != NULL;
+
+ _gtk_source_file_set_metadata_info (loader->priv->file, metadata);
+ g_clear_object (&metadata);
+
+ return ok;
+}
+
+static void
+load_metadata_async_cb (GFile *location,
+ GAsyncResult *result,
+ GTask *task)
+{
+ GtkSourceFileLoader *loader;
+ GFileInfo *metadata;
+ GError *error = NULL;
+
+ DEBUG ({
+ g_print ("%s\n", G_STRFUNC);
+ });
+
+ metadata = g_file_query_info_finish (location, result, &error);
+
+ if (error != NULL)
+ {
+ g_task_return_error (task, error);
+ g_object_unref (task);
+ g_clear_object (&metadata);
+ return;
+ }
+
+ loader = g_task_get_source_object (task);
+ if (loader->priv->file != NULL)
+ {
+ _gtk_source_file_set_metadata_info (loader->priv->file, metadata);
+ }
+
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+ g_clear_object (&metadata);
+}
+
+/**
+ * gtk_source_file_loader_load_metadata_async:
+ * @loader: a #GtkSourceFileLoader.
+ * @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
+ * %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
+ * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is
+ * satisfied.
+ * @user_data: user data to pass to @callback.
+ *
+ * Loads asynchronously the metadata. See the #GAsyncResult documentation to
+ * know how to use this function.
+ *
+ * Since: 3.22
+ */
+void
+gtk_source_file_loader_load_metadata_async (GtkSourceFileLoader *loader,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ g_return_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+ if (loader->priv->file == NULL ||
+ loader->priv->location == NULL)
+ {
+ return;
+ }
+
+ task = g_task_new (loader, cancellable, callback, user_data);
+
+ g_file_query_info_async (loader->priv->location,
+ METADATA_QUERY_ATTRIBUTES,
+ G_FILE_QUERY_INFO_NONE,
+ io_priority,
+ cancellable,
+ (GAsyncReadyCallback) load_metadata_async_cb,
+ task);
+}
+
+/**
+ * gtk_source_file_loader_load_metadata_finish:
+ * @loader: a #GtkSourceFileLoader.
+ * @result: a #GAsyncResult.
+ * @error: location to a %NULL #GError, or %NULL.
+ *
+ * Finishes the metadata loading started with
+ * gtk_source_file_loader_load_metadata_async().
+ *
+ * Returns: whether the metadata was loaded successfully.
+ * Since: 3.22
+ */
+gboolean
+gtk_source_file_loader_load_metadata_finish (GtkSourceFileLoader *loader,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (g_task_is_valid (result, loader), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
+
+/**
* gtk_source_file_loader_get_encoding:
* @loader: a #GtkSourceFileLoader.
*
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index 3ff4851..fc139b6 100644
--- a/gtksourceview/gtksourcefileloader.h
+++ b/gtksourceview/gtksourcefileloader.h
@@ -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
@@ -121,6 +121,25 @@ gboolean gtk_source_file_loader_load_finish (GtkSourceFileLoader
*loader,
GAsyncResult *result,
GError **error);
+GTK_SOURCE_AVAILABLE_IN_3_22
+gboolean gtk_source_file_loader_load_metadata (GtkSourceFileLoader *loader,
+ GCancellable *cancellable,
+ GError **error);
+
+GTK_SOURCE_AVAILABLE_IN_3_22
+void gtk_source_file_loader_load_metadata_async
+ (GtkSourceFileLoader *loader,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GTK_SOURCE_AVAILABLE_IN_3_22
+gboolean gtk_source_file_loader_load_metadata_finish
+ (GtkSourceFileLoader *loader,
+ GAsyncResult *result,
+ GError **error);
+
GTK_SOURCE_AVAILABLE_IN_3_14
const GtkSourceEncoding *gtk_source_file_loader_get_encoding (GtkSourceFileLoader *loader);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]