[tepl] FileMetadata: start to rework the API
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] FileMetadata: start to rework the API
- Date: Sat, 18 Apr 2020 17:15:08 +0000 (UTC)
commit f447d201ea2b531395473db24063aed649d4d103
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Apr 2 07:48:19 2020 +0200
FileMetadata: start to rework the API
This is an API break, so the Tepl API/major version will be bumped in a
forthcoming commit.
GLib 2.64 is required for g_warning_once().
Make TeplFileMetadata independent of TeplFile, to make it more
re-usable. The goal is to expose TeplFileMetadata in the gedit plugin
API.
As a first step, do not care about the fallback to TeplMetadataStore.
Care about GVfs only, and test it well. The integration with
TeplMetadataStore will be done in a later commit.
Remove tepl_file_get_file_metadata(), I prefer not to mix TeplFile with
TeplFileMetadata. The TeplFile* classes are already complex enough. File
metadata will be seen as a separate entity (for now at least, I have the
intention to review the TeplFile API later). TeplFileMetadata will maybe
be associated with TeplBuffer instead (maybe). But there is a desire to
integrate TeplFileMetadata into the framework, somehow; I will do that
later.
Disable the TeplFileMetadata unit tests for now, they will be ported to
the new API in a later commit.
docs/reference/api-breaks.xml | 28 +++
docs/reference/tepl-sections.txt | 4 -
meson.build | 2 +-
tepl/meson.build | 1 -
tepl/tepl-file-metadata.c | 498 ++++++---------------------------------
tepl/tepl-file-metadata.h | 19 +-
tepl/tepl-file.c | 27 +--
tepl/tepl-file.h | 5 +-
tepl/tepl-tab.c | 37 +--
tepl/tepl-types.h | 35 ---
tepl/tepl.h | 1 -
testsuite/meson.build | 2 +-
12 files changed, 112 insertions(+), 547 deletions(-)
---
diff --git a/docs/reference/api-breaks.xml b/docs/reference/api-breaks.xml
index 98a933c..aa3905c 100644
--- a/docs/reference/api-breaks.xml
+++ b/docs/reference/api-breaks.xml
@@ -120,4 +120,32 @@
</listitem>
</itemizedlist>
</chapter>
+
+ <chapter id="api-breaks-4-to-5-tepl">
+ <title>Tepl 4 -> Tepl 5</title>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ The <link linkend="TeplFileMetadata">TeplFileMetadata</link> API has
+ been re-worked to no longer depend on
+ <link linkend="TeplFile">TeplFile</link>, and to no longer do
+ synchronous I/O, only the async API has been kept.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The <code>tepl_file_get_file_metadata()</code> function has been
+ removed.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The <link linkend="tepl-tab-load-file">tepl_tab_load_file()</link>
+ function no longer loads the file metadata (but it was anyway an
+ implementation detail).
+ </para>
+ </listitem>
+ </itemizedlist>
+ </chapter>
</part>
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index a705151..810272a 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -141,7 +141,6 @@ TeplCompressionType
TeplMountOperationFactory
<SUBSECTION>
tepl_file_new
-tepl_file_get_file_metadata
tepl_file_get_location
tepl_file_set_location
tepl_file_get_short_name
@@ -168,13 +167,10 @@ tepl_compression_type_get_type
<FILE>file-metadata</FILE>
TeplFileMetadata
tepl_file_metadata_new
-tepl_file_metadata_get_file
tepl_file_metadata_get
tepl_file_metadata_set
-tepl_file_metadata_load
tepl_file_metadata_load_async
tepl_file_metadata_load_finish
-tepl_file_metadata_save
tepl_file_metadata_save_async
tepl_file_metadata_save_finish
<SUBSECTION Standard>
diff --git a/meson.build b/meson.build
index 8a913f6..f004e19 100644
--- a/meson.build
+++ b/meson.build
@@ -42,7 +42,7 @@ TEPL_LT_VERSION = '@0@.@1@.@2@'.format(lt_current, lt_revision, lt_age)
TEPL_API_VERSION = '4'
TEPL_PUBLIC_DEPS = [
- dependency('gio-2.0', version: '>= 2.56'),
+ dependency('gio-2.0', version: '>= 2.64'),
dependency('gtk+-3.0', version: '>= 3.22'),
dependency('gtksourceview-4', version: '>= 4.0'),
dependency('amtk-5', version: '>= 5.0')
diff --git a/tepl/meson.build b/tepl/meson.build
index 4f11758..345e0bc 100644
--- a/tepl/meson.build
+++ b/tepl/meson.build
@@ -23,7 +23,6 @@ tepl_public_headers = [
'tepl-tab.h',
'tepl-tab-group.h',
'tepl-tab-label.h',
- 'tepl-types.h',
'tepl-utils.h',
'tepl-view.h'
]
diff --git a/tepl/tepl-file-metadata.c b/tepl/tepl-file-metadata.c
index 5b88c7b..3085f91 100644
--- a/tepl/tepl-file-metadata.c
+++ b/tepl/tepl-file-metadata.c
@@ -1,7 +1,7 @@
/*
* This file is part of Tepl, a text editor library.
*
- * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2016-2020 - Sébastien Wilmet <swilmet gnome org>
*
* Tepl is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -17,32 +17,24 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
#include "tepl-file-metadata.h"
-#include <glib/gi18n-lib.h>
-#include "tepl-file.h"
-#include "tepl-metadata-manager.h"
/**
* SECTION:file-metadata
* @Short_description: File metadata
* @Title: TeplFileMetadata
*
- * A #TeplFileMetadata object stores the metadata of a #TeplFile. You need to
- * call tepl_metadata_manager_init() and tepl_metadata_manager_shutdown() in
- * your application, in case GVfs metadata are not supported.
+ * A #TeplFileMetadata object stores the metadata of a #GFile.
+ *
+ * You need to load and save the #TeplMetadataStore in your application, it is
+ * used as a fallback in #TeplFileMetadata in the case where GVfs metadata is
+ * not supported. TODO: update.
*
* The tepl_file_metadata_get() and tepl_file_metadata_set() functions don't
- * load or save the metadata on disk. They only access the metadata stored in
+ * load or save the metadata on disk, they only access the metadata stored in
* the #TeplFileMetadata object memory. To load the metadata from disk, call
- * tepl_file_metadata_load() or its async variant. Likewise, to save the
- * metadata on disk, call tepl_file_metadata_save() or its async variant. When
- * loading or saving metadata, the file at #TeplFile:location, if non-%NULL,
- * must exist on the filesystem, otherwise an error is returned.
- *
- * When the #TeplFile:location changes, the metadata are still kept in the
- * #TeplFileMetadata object memory. But the metadata are
- * <emphasis>not</emphasis> automatically saved for the new location.
+ * tepl_file_metadata_load_async(). Likewise, to save the
+ * metadata on disk, call tepl_file_metadata_save_async().
*/
/* TODO Better test how it works with remote files, with various protocols.
@@ -51,32 +43,22 @@
* automatically call the TeplFile mount operation factory method.
*
* On Linux, is the metadata supported for all GVfs backends? (the custom
- * metadata that we set). Does it fallback to the metadata manager even on
- * Linux?
+ * metadata that we set). Does it fallback to TeplMetadataStore even on Linux
+ * and even when GVfs is well installed?
*/
typedef struct _TeplFileMetadataPrivate TeplFileMetadataPrivate;
struct _TeplFileMetadataPrivate
{
- /* Weak ref */
- TeplFile *file;
-
/* Never NULL */
GFileInfo *file_info;
+#if 0
guint use_gvfs_metadata : 1;
+#endif
};
-enum
-{
- PROP_0,
- PROP_FILE,
- N_PROPERTIES
-};
-
-static GParamSpec *properties[N_PROPERTIES];
-
G_DEFINE_TYPE_WITH_PRIVATE (TeplFileMetadata, tepl_file_metadata, G_TYPE_OBJECT)
#define METADATA_PREFIX "metadata::"
@@ -89,96 +71,12 @@ get_metadata_attribute_key (const gchar *key)
}
static void
-print_fallback_to_metadata_manager_warning (void)
-{
- static gboolean warning_printed = FALSE;
-
- if (G_LIKELY (warning_printed))
- {
- return;
- }
-
- g_warning ("GVfs metadata is not supported. Fallback to TeplMetadataManager. "
- "Either GVfs is not correctly installed or GVfs metadata are "
- "not supported on this platform. In the latter case, you should "
- "configure Tepl with --disable-gvfs-metadata.");
-
- warning_printed = TRUE;
-}
-
-static void
-set_file (TeplFileMetadata *metadata,
- TeplFile *file)
+print_fallback_to_metadata_store_warning (void)
{
- TeplFileMetadataPrivate *priv = tepl_file_metadata_get_instance_private (metadata);
-
- g_return_if_fail (TEPL_IS_FILE (file));
-
- g_assert (priv->file == NULL);
- priv->file = file;
-
- g_object_add_weak_pointer (G_OBJECT (priv->file),
- (gpointer *) &priv->file);
-
- g_object_notify_by_pspec (G_OBJECT (metadata), properties[PROP_FILE]);
-}
-
-static void
-tepl_file_metadata_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- TeplFileMetadata *metadata = TEPL_FILE_METADATA (object);
-
- switch (prop_id)
- {
- case PROP_FILE:
- g_value_set_object (value, tepl_file_metadata_get_file (metadata));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-tepl_file_metadata_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- TeplFileMetadata *metadata = TEPL_FILE_METADATA (object);
-
- switch (prop_id)
- {
- case PROP_FILE:
- set_file (metadata, g_value_get_object (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-tepl_file_metadata_dispose (GObject *object)
-{
- TeplFileMetadataPrivate *priv;
-
- priv = tepl_file_metadata_get_instance_private (TEPL_FILE_METADATA (object));
-
- if (priv->file != NULL)
- {
- g_object_remove_weak_pointer (G_OBJECT (priv->file),
- (gpointer *) &priv->file);
-
- priv->file = NULL;
- }
-
- G_OBJECT_CLASS (tepl_file_metadata_parent_class)->dispose (object);
+ g_warning_once ("GVfs metadata is not supported. Fallback to TeplMetadataStore. "
+ "Either GVfs is not correctly installed or GVfs metadata are "
+ "not supported on this platform. In the latter case, you should "
+ "configure Tepl with -Dgvfs_metadata=false.");
}
static void
@@ -198,28 +96,7 @@ tepl_file_metadata_class_init (TeplFileMetadataClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->get_property = tepl_file_metadata_get_property;
- object_class->set_property = tepl_file_metadata_set_property;
- object_class->dispose = tepl_file_metadata_dispose;
object_class->finalize = tepl_file_metadata_finalize;
-
- /**
- * TeplFileMetadata:file:
- *
- * The #TeplFile that the metadata belong to.
- *
- * Since: 1.0
- */
- properties[PROP_FILE] =
- g_param_spec_object ("file",
- "File",
- "",
- TEPL_TYPE_FILE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
static void
@@ -229,46 +106,26 @@ tepl_file_metadata_init (TeplFileMetadata *metadata)
priv->file_info = g_file_info_new ();
+#if 0
+/* TODO change the #ifdef to an #if. */
#ifdef ENABLE_GVFS_METADATA
priv->use_gvfs_metadata = TRUE;
#else
priv->use_gvfs_metadata = FALSE;
#endif
+#endif
}
/**
* tepl_file_metadata_new:
- * @file: the #TeplFile that the metadata will belong to.
*
* Returns: a new #TeplFileMetadata object.
- * Since: 1.0
+ * Since: 5.0
*/
TeplFileMetadata *
-tepl_file_metadata_new (TeplFile *file)
+tepl_file_metadata_new (void)
{
- g_return_val_if_fail (TEPL_IS_FILE (file), NULL);
-
- return g_object_new (TEPL_TYPE_FILE_METADATA,
- "file", file,
- NULL);
-}
-
-/**
- * tepl_file_metadata_get_file:
- * @metadata: a #TeplFileMetadata object.
- *
- * Returns: (transfer none): the #TeplFile that the metadata belong to.
- * Since: 1.0
- */
-TeplFile *
-tepl_file_metadata_get_file (TeplFileMetadata *metadata)
-{
- TeplFileMetadataPrivate *priv;
-
- g_return_val_if_fail (TEPL_IS_FILE_METADATA (metadata), NULL);
-
- priv = tepl_file_metadata_get_instance_private (metadata);
- return priv->file;
+ return g_object_new (TEPL_TYPE_FILE_METADATA, NULL);
}
/**
@@ -314,7 +171,9 @@ tepl_file_metadata_get (TeplFileMetadata *metadata,
* @value: (nullable): the value of the metadata, or %NULL to unset.
*
* Sets the value of a metadata. It's preferable that @key starts with a
- * namespace, to not get metadata conflicts between applications.
+ * namespace, to not get metadata conflicts between applications. For example a
+ * good @key name for the gedit application is
+ * `"gedit-spell-checking-language"`.
*
* This function just stores the new metadata value in the @metadata object
* memory.
@@ -354,93 +213,6 @@ tepl_file_metadata_set (TeplFileMetadata *metadata,
g_free (attribute_key);
}
-/**
- * tepl_file_metadata_load:
- * @metadata: a #TeplFileMetadata.
- * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
- * @error: location to a %NULL #GError, or %NULL.
- *
- * Loads synchronously the metadata from #TeplFile:location. The loaded
- * metadata values can then be accessed with tepl_file_metadata_get().
- *
- * If the metadata are loaded successfully, this function deletes all previous
- * metadata stored in the @metadata object memory.
- *
- * The file at #TeplFile:location, if non-%NULL, must exist on the
- * filesystem, otherwise an error is returned.
- *
- * If #TeplFile:location is %NULL, %FALSE is simply returned.
- *
- * Returns: whether the metadata was loaded successfully.
- * Since: 1.0
- */
-gboolean
-tepl_file_metadata_load (TeplFileMetadata *metadata,
- GCancellable *cancellable,
- GError **error)
-{
- TeplFileMetadataPrivate *priv;
- GFile *location;
- GFileInfo *file_info;
-
- g_return_val_if_fail (TEPL_IS_FILE_METADATA (metadata), FALSE);
- g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- priv = tepl_file_metadata_get_instance_private (metadata);
-
- if (priv->file == NULL)
- {
- return FALSE;
- }
-
- location = tepl_file_get_location (priv->file);
- if (location == NULL)
- {
- return FALSE;
- }
-
- if (priv->use_gvfs_metadata)
- {
- GError *my_error = NULL;
-
- file_info = g_file_query_info (location,
- METADATA_QUERY_ATTRIBUTES,
- G_FILE_QUERY_INFO_NONE,
- cancellable,
- &my_error);
-
- if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
- {
- print_fallback_to_metadata_manager_warning ();
- priv->use_gvfs_metadata = FALSE;
-
- g_clear_error (&my_error);
- g_clear_object (&file_info);
- }
- else if (my_error != NULL)
- {
- g_propagate_error (error, my_error);
- my_error = NULL;
- }
- }
-
- if (!priv->use_gvfs_metadata)
- {
- file_info = _tepl_metadata_manager_get_all_metadata_for_location (location);
- }
-
- if (file_info == NULL)
- {
- return FALSE;
- }
-
- g_object_unref (priv->file_info);
- priv->file_info = file_info;
-
- return TRUE;
-}
-
static void
load_metadata_async_cb (GObject *source_object,
GAsyncResult *result,
@@ -460,13 +232,14 @@ load_metadata_async_cb (GObject *source_object,
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
{
- print_fallback_to_metadata_manager_warning ();
- priv->use_gvfs_metadata = FALSE;
+ print_fallback_to_metadata_store_warning ();
+ //priv->use_gvfs_metadata = FALSE;
g_clear_error (&error);
- g_clear_object (&metadata);
+ g_clear_object (&file_info);
- file_info = _tepl_metadata_manager_get_all_metadata_for_location (location);
+ /* TODO: load from TeplMetadataStore. */
+ file_info = NULL;
}
if (error != NULL)
@@ -479,13 +252,13 @@ load_metadata_async_cb (GObject *source_object,
if (file_info == NULL)
{
+ /* FIXME: return TRUE instead? */
g_task_return_boolean (task, FALSE);
g_object_unref (task);
return;
}
- g_object_unref (priv->file_info);
- priv->file_info = file_info;
+ g_set_object (&priv->file_info, file_info);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
@@ -494,6 +267,7 @@ load_metadata_async_cb (GObject *source_object,
/**
* tepl_file_metadata_load_async:
* @metadata: a #TeplFileMetadata.
+ * @location: a #GFile.
* @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.
@@ -501,67 +275,41 @@ load_metadata_async_cb (GObject *source_object,
* satisfied.
* @user_data: user data to pass to @callback.
*
- * The asynchronous version of tepl_file_metadata_load().
+ * Loads asynchronously the metadata for @location.
*
- * If the metadata is loaded from the metadata manager (i.e. not with GVfs),
- * this function loads the metadata synchronously. A future version might fix
- * this.
+ * If the metadata are loaded successfully, this function deletes all previous
+ * metadata stored in the @metadata object memory.
+ *
+ * @location must exist on the filesystem, otherwise an error is returned.
*
* See the #GAsyncResult documentation to know how to use this function.
*
- * Since: 1.0
+ * Since: 5.0
*/
void
tepl_file_metadata_load_async (TeplFileMetadata *metadata,
+ GFile *location,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- TeplFileMetadataPrivate *priv;
GTask *task;
- GFile *location;
g_return_if_fail (TEPL_IS_FILE_METADATA (metadata));
+ g_return_if_fail (G_IS_FILE (location));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- priv = tepl_file_metadata_get_instance_private (metadata);
-
task = g_task_new (metadata, cancellable, callback, user_data);
-
- if (priv->file == NULL)
- {
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- return;
- }
-
- location = tepl_file_get_location (priv->file);
- if (location == NULL)
- {
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- return;
- }
-
- if (priv->use_gvfs_metadata)
- {
- g_file_query_info_async (location,
- METADATA_QUERY_ATTRIBUTES,
- G_FILE_QUERY_INFO_NONE,
- io_priority,
- cancellable,
- load_metadata_async_cb,
- task);
- }
- else
- {
- gboolean ok;
-
- ok = tepl_file_metadata_load (metadata, cancellable, NULL);
- g_task_return_boolean (task, ok);
- g_object_unref (task);
- }
+ g_task_set_priority (task, io_priority);
+
+ g_file_query_info_async (location,
+ METADATA_QUERY_ATTRIBUTES,
+ G_FILE_QUERY_INFO_NONE,
+ io_priority,
+ cancellable,
+ load_metadata_async_cb,
+ task);
}
/**
@@ -587,83 +335,6 @@ tepl_file_metadata_load_finish (TeplFileMetadata *metadata,
return g_task_propagate_boolean (G_TASK (result), error);
}
-/**
- * tepl_file_metadata_save:
- * @metadata: a #TeplFileMetadata.
- * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
- * @error: location to a %NULL #GError, or %NULL.
- *
- * Saves synchronously the metadata for #TeplFile:location.
- *
- * The file at #TeplFile:location, if non-%NULL, must exist on the
- * filesystem, otherwise an error is returned.
- *
- * If #TeplFile:location is %NULL, %FALSE is simply returned.
- *
- * Returns: whether the metadata was saved successfully.
- * Since: 1.0
- */
-gboolean
-tepl_file_metadata_save (TeplFileMetadata *metadata,
- GCancellable *cancellable,
- GError **error)
-{
- TeplFileMetadataPrivate *priv;
- GFile *location;
-
- g_return_val_if_fail (TEPL_IS_FILE_METADATA (metadata), FALSE);
- g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- priv = tepl_file_metadata_get_instance_private (metadata);
-
- if (priv->file == NULL)
- {
- return FALSE;
- }
-
- location = tepl_file_get_location (priv->file);
- if (location == NULL)
- {
- return FALSE;
- }
-
- if (priv->use_gvfs_metadata)
- {
- GError *my_error = NULL;
- gboolean ok;
-
- ok = g_file_set_attributes_from_info (location,
- priv->file_info,
- G_FILE_QUERY_INFO_NONE,
- cancellable,
- &my_error);
-
- if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
- {
- print_fallback_to_metadata_manager_warning ();
- priv->use_gvfs_metadata = FALSE;
-
- g_clear_error (&my_error);
- }
- else if (my_error != NULL)
- {
- g_propagate_error (error, my_error);
- return ok;
- }
- else
- {
- return ok;
- }
- }
-
- g_assert (!priv->use_gvfs_metadata);
-
- _tepl_metadata_manager_set_metadata_for_location (location, priv->file_info);
-
- return TRUE;
-}
-
static void
save_metadata_async_cb (GObject *source_object,
GAsyncResult *result,
@@ -671,23 +342,14 @@ save_metadata_async_cb (GObject *source_object,
{
GFile *location = G_FILE (source_object);
GTask *task = G_TASK (user_data);
- TeplFileMetadata *metadata;
- TeplFileMetadataPrivate *priv;
GError *error = NULL;
- metadata = g_task_get_source_object (task);
- priv = tepl_file_metadata_get_instance_private (metadata);
-
g_file_set_attributes_finish (location, result, NULL, &error);
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
{
- print_fallback_to_metadata_manager_warning ();
- priv->use_gvfs_metadata = FALSE;
-
+ print_fallback_to_metadata_store_warning ();
g_clear_error (&error);
-
- _tepl_metadata_manager_set_metadata_for_location (location, priv->file_info);
}
if (error != NULL)
@@ -704,6 +366,7 @@ save_metadata_async_cb (GObject *source_object,
/**
* tepl_file_metadata_save_async:
* @metadata: a #TeplFileMetadata.
+ * @location: a #GFile.
* @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.
@@ -711,17 +374,17 @@ save_metadata_async_cb (GObject *source_object,
* satisfied.
* @user_data: user data to pass to @callback.
*
- * The asynchronous version of tepl_file_metadata_save().
+ * Saves asynchronously the metadata for @location.
*
- * If the metadata is saved with the metadata manager (i.e. not with GVfs), this
- * function saves the metadata synchronously. A future version might fix this.
+ * @location must exist on the filesystem, otherwise an error is returned.
*
* See the #GAsyncResult documentation to know how to use this function.
*
- * Since: 1.0
+ * Since: 5.0
*/
void
tepl_file_metadata_save_async (TeplFileMetadata *metadata,
+ GFile *location,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -729,46 +392,23 @@ tepl_file_metadata_save_async (TeplFileMetadata *metadata,
{
TeplFileMetadataPrivate *priv;
GTask *task;
- GFile *location;
g_return_if_fail (TEPL_IS_FILE_METADATA (metadata));
+ g_return_if_fail (G_IS_FILE (location));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
priv = tepl_file_metadata_get_instance_private (metadata);
task = g_task_new (metadata, cancellable, callback, user_data);
-
- if (priv->file == NULL)
- {
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- return;
- }
-
- location = tepl_file_get_location (priv->file);
- if (location == NULL)
- {
- g_task_return_boolean (task, FALSE);
- g_object_unref (task);
- return;
- }
-
- if (priv->use_gvfs_metadata)
- {
- g_file_set_attributes_async (location,
- priv->file_info,
- G_FILE_QUERY_INFO_NONE,
- io_priority,
- cancellable,
- save_metadata_async_cb,
- task);
- }
- else
- {
- _tepl_metadata_manager_set_metadata_for_location (location, priv->file_info);
- g_task_return_boolean (task, TRUE);
- g_object_unref (task);
- }
+ g_task_set_priority (task, io_priority);
+
+ g_file_set_attributes_async (location,
+ priv->file_info,
+ G_FILE_QUERY_INFO_NONE,
+ io_priority,
+ cancellable,
+ save_metadata_async_cb,
+ task);
}
/**
@@ -794,6 +434,7 @@ tepl_file_metadata_save_finish (TeplFileMetadata *metadata,
return g_task_propagate_boolean (G_TASK (result), error);
}
+#if 0
/* For unit tests. */
void
_tepl_file_metadata_set_use_gvfs_metadata (TeplFileMetadata *metadata,
@@ -807,3 +448,4 @@ _tepl_file_metadata_set_use_gvfs_metadata (TeplFileMetadata *metadata,
priv->use_gvfs_metadata = use_gvfs_metadata != FALSE;
}
+#endif
diff --git a/tepl/tepl-file-metadata.h b/tepl/tepl-file-metadata.h
index cdf4c4c..83f0ffb 100644
--- a/tepl/tepl-file-metadata.h
+++ b/tepl/tepl-file-metadata.h
@@ -1,7 +1,7 @@
/*
* This file is part of Tepl, a text editor library.
*
- * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2016-2020 - Sébastien Wilmet <swilmet gnome org>
*
* Tepl is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -25,7 +25,6 @@
#endif
#include <gio/gio.h>
-#include <tepl/tepl-types.h>
G_BEGIN_DECLS
@@ -41,9 +40,7 @@ struct _TeplFileMetadataClass
gpointer padding[12];
};
-TeplFileMetadata * tepl_file_metadata_new (TeplFile *file);
-
-TeplFile * tepl_file_metadata_get_file (TeplFileMetadata *metadata);
+TeplFileMetadata * tepl_file_metadata_new (void);
gchar * tepl_file_metadata_get (TeplFileMetadata *metadata,
const gchar *key);
@@ -52,11 +49,8 @@ void tepl_file_metadata_set (TeplFileMetadata
*metadata,
const gchar *key,
const gchar *value);
-gboolean tepl_file_metadata_load (TeplFileMetadata *metadata,
- GCancellable *cancellable,
- GError **error);
-
void tepl_file_metadata_load_async (TeplFileMetadata *metadata,
+ GFile *location,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -66,11 +60,8 @@ gboolean tepl_file_metadata_load_finish (TeplFileMetadata
*metadata,
GAsyncResult *result,
GError **error);
-gboolean tepl_file_metadata_save (TeplFileMetadata *metadata,
- GCancellable *cancellable,
- GError **error);
-
void tepl_file_metadata_save_async (TeplFileMetadata *metadata,
+ GFile *location,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -80,9 +71,11 @@ gboolean tepl_file_metadata_save_finish (TeplFileMetadata
*metadata,
GAsyncResult *result,
GError **error);
+#if 0
G_GNUC_INTERNAL
void _tepl_file_metadata_set_use_gvfs_metadata (TeplFileMetadata *metadata,
gboolean use_gvfs_metadata);
+#endif
G_END_DECLS
diff --git a/tepl/tepl-file.c b/tepl/tepl-file.c
index 3aceaee..e3ca6bb 100644
--- a/tepl/tepl-file.c
+++ b/tepl/tepl-file.c
@@ -1,7 +1,7 @@
/*
* This file is part of Tepl, a text editor library.
*
- * Copyright 2016, 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2016-2020 - Sébastien Wilmet <swilmet gnome org>
*
* Tepl is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -27,7 +27,7 @@
* SECTION:file
* @Short_description: On-disk representation of a TeplBuffer
* @Title: TeplFile
- * @See_also: #TeplFileLoader, #TeplFileSaver, #TeplFileMetadata
+ * @See_also: #TeplFileLoader, #TeplFileSaver
*
* A #TeplFile object is the on-disk representation of a #TeplBuffer.
*
@@ -50,8 +50,6 @@ typedef struct _TeplFilePrivate TeplFilePrivate;
struct _TeplFilePrivate
{
- TeplFileMetadata *metadata;
-
GFile *location;
TeplEncoding *encoding;
TeplNewlineType newline_type;
@@ -208,7 +206,6 @@ tepl_file_dispose (GObject *object)
{
TeplFilePrivate *priv = tepl_file_get_instance_private (TEPL_FILE (object));
- g_clear_object (&priv->metadata);
g_clear_object (&priv->location);
if (priv->mount_operation_notify != NULL)
@@ -449,8 +446,6 @@ tepl_file_init (TeplFile *file)
{
TeplFilePrivate *priv = tepl_file_get_instance_private (file);
- priv->metadata = tepl_file_metadata_new (file);
-
priv->encoding = NULL;
priv->newline_type = TEPL_NEWLINE_TYPE_LF;
priv->compression_type = TEPL_COMPRESSION_TYPE_NONE;
@@ -470,24 +465,6 @@ tepl_file_new (void)
return g_object_new (TEPL_TYPE_FILE, NULL);
}
-/**
- * tepl_file_get_file_metadata:
- * @file: a #TeplFile.
- *
- * Returns: (transfer none): the associated #TeplFileMetadata.
- * Since: 1.0
- */
-TeplFileMetadata *
-tepl_file_get_file_metadata (TeplFile *file)
-{
- TeplFilePrivate *priv;
-
- g_return_val_if_fail (TEPL_IS_FILE (file), NULL);
-
- priv = tepl_file_get_instance_private (file);
- return priv->metadata;
-}
-
/**
* tepl_file_set_location:
* @file: a #TeplFile.
diff --git a/tepl/tepl-file.h b/tepl/tepl-file.h
index 45d4016..f1d4e52 100644
--- a/tepl/tepl-file.h
+++ b/tepl/tepl-file.h
@@ -24,9 +24,8 @@
#error "Only <tepl/tepl.h> can be included directly."
#endif
-#include <gtksourceview/gtksource.h>
+#include <gio/gio.h>
#include <tepl/tepl-encoding.h>
-#include <tepl/tepl-file-metadata.h>
G_BEGIN_DECLS
@@ -99,8 +98,6 @@ typedef enum
TeplFile * tepl_file_new (void);
-TeplFileMetadata * tepl_file_get_file_metadata (TeplFile *file);
-
GFile * tepl_file_get_location (TeplFile *file);
void tepl_file_set_location (TeplFile *file,
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index 0ecd5a7..696677b 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -1,7 +1,7 @@
/*
* This file is part of Tepl, a text editor library.
*
- * Copyright 2016, 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2016-2020 - Sébastien Wilmet <swilmet gnome org>
*
* Tepl is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -22,7 +22,6 @@
#include <glib/gi18n-lib.h>
#include "tepl-close-confirm-dialog-single.h"
#include "tepl-file-loader.h"
-#include "tepl-file-metadata.h"
#include "tepl-file-saver.h"
#include "tepl-info-bar.h"
#include "tepl-tab-group.h"
@@ -475,26 +474,6 @@ tepl_tab_add_info_bar (TeplTab *tab,
TEPL_TAB_GET_CLASS (tab)->pack_info_bar (tab, info_bar);
}
-static void
-load_metadata_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- TeplFileMetadata *metadata = TEPL_FILE_METADATA (source_object);
- TeplTab *tab = TEPL_TAB (user_data);
- GError *error = NULL;
-
- tepl_file_metadata_load_finish (metadata, result, &error);
-
- if (error != NULL)
- {
- g_warning ("Error when loading metadata: %s", error->message);
- g_clear_error (&error);
- }
-
- g_object_unref (tab);
-}
-
static void
load_file_content_cb (GObject *source_object,
GAsyncResult *result,
@@ -502,26 +481,16 @@ load_file_content_cb (GObject *source_object,
{
TeplFileLoader *loader = TEPL_FILE_LOADER (source_object);
TeplTab *tab = TEPL_TAB (user_data);
- TeplBuffer *buffer;
GError *error = NULL;
- buffer = tepl_tab_get_buffer (tab);
-
if (tepl_file_loader_load_finish (loader, result, &error))
{
+ TeplBuffer *buffer;
TeplFile *file;
- TeplFileMetadata *metadata;
+ buffer = tepl_tab_get_buffer (tab);
file = tepl_buffer_get_file (buffer);
tepl_file_add_uri_to_recent_manager (file);
-
- metadata = tepl_file_get_file_metadata (file);
-
- tepl_file_metadata_load_async (metadata,
- G_PRIORITY_DEFAULT,
- NULL,
- load_metadata_cb,
- g_object_ref (tab));
}
if (error != NULL)
diff --git a/tepl/tepl.h b/tepl/tepl.h
index a00c99a..95d7c43 100644
--- a/tepl/tepl.h
+++ b/tepl/tepl.h
@@ -24,7 +24,6 @@
#include <amtk/amtk.h>
-#include <tepl/tepl-types.h>
#include <tepl/tepl-enum-types.h>
#include <tepl/tepl-abstract-factory.h>
diff --git a/testsuite/meson.build b/testsuite/meson.build
index b978ee0..30012cb 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -5,7 +5,7 @@ unit_tests = [
'test-file',
'test-file-content',
'test-file-loader',
- 'test-file-metadata',
+ #'test-file-metadata',
'test-file-saver',
'test-fold-region',
'test-info-bar',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]