[gthumb] comments: metadata is unreadable if the comment folder does not exist
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] comments: metadata is unreadable if the comment folder does not exist
- Date: Sun, 22 Aug 2021 05:31:43 +0000 (UTC)
commit 18a619d1a7f6dfe98c3fedc5386b10ffc6a911f8
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Aug 1 12:22:48 2021 +0200
comments: metadata is unreadable if the comment folder does not exist
Do not try to read the metadata if the comment folder does not exist.
Added a cache of the checked folders to speed-up folder loading on
remote/slow locations.
.../comments/gth-metadata-provider-comment.c | 89 +++++++++++++++++++---
.../comments/gth-metadata-provider-comment.h | 4 +-
2 files changed, 82 insertions(+), 11 deletions(-)
---
diff --git a/extensions/comments/gth-metadata-provider-comment.c
b/extensions/comments/gth-metadata-provider-comment.c
index 74adecc9..0dcad4b5 100644
--- a/extensions/comments/gth-metadata-provider-comment.c
+++ b/extensions/comments/gth-metadata-provider-comment.c
@@ -26,7 +26,15 @@
#include "gth-metadata-provider-comment.h"
-G_DEFINE_TYPE (GthMetadataProviderComment, gth_metadata_provider_comment, GTH_TYPE_METADATA_PROVIDER)
+struct _GthMetadataProviderCommentPrivate {
+ GHashTable *checked_folders;
+};
+
+
+G_DEFINE_TYPE_WITH_CODE (GthMetadataProviderComment,
+ gth_metadata_provider_comment,
+ GTH_TYPE_METADATA_PROVIDER,
+ G_ADD_PRIVATE (GthMetadataProviderComment))
static gboolean
@@ -36,14 +44,52 @@ gth_metadata_provider_comment_can_read (GthMetadataProvider *base,
char **attribute_v)
{
- return _g_file_attributes_matches_any_v ("comment::*,"
- "general::datetime,"
- "general::title,"
- "general::description,"
- "general::location,"
- "general::tags,"
- "general::rating",
- attribute_v);
+ GthMetadataProviderComment *self = GTH_METADATA_PROVIDER_COMMENT (base);
+ gboolean can_read;
+
+ can_read = _g_file_attributes_matches_any_v ("comment::*,"
+ "general::datetime,"
+ "general::title,"
+ "general::description,"
+ "general::location,"
+ "general::tags,"
+ "general::rating",
+ attribute_v);
+
+ if (! can_read)
+ return FALSE;
+
+ if (file_data != NULL) {
+ GFile *comment_file;
+ GFile *comment_folder;
+ gboolean comment_folder_exists;
+ gpointer value;
+
+ comment_file = gth_comment_get_comment_file (file_data->file);
+ if (comment_file == NULL)
+ return FALSE;
+
+ comment_folder = g_file_get_parent (comment_file);
+ if (comment_folder == NULL)
+ return FALSE;
+
+ value = g_hash_table_lookup (self->priv->checked_folders, comment_folder);
+ if (value == NULL) {
+ comment_folder_exists = g_file_query_exists (comment_folder, NULL);
+ g_hash_table_insert (self->priv->checked_folders,
+ g_object_ref (comment_folder),
+ GINT_TO_POINTER (comment_folder_exists ? 1 : 2));
+ }
+ else
+ comment_folder_exists = GPOINTER_TO_INT (value) == 1;
+
+ can_read = comment_folder_exists;
+
+ g_object_unref (comment_folder);
+ g_object_unref (comment_file);
+ }
+
+ return can_read;
}
@@ -222,11 +268,32 @@ gth_metadata_provider_comment_write (GthMetadataProvider *self,
}
+static void
+gth_metadata_provider_comment_finalize (GObject *object)
+{
+ GthMetadataProviderComment *self;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GTH_IS_METADATA_PROVIDER_COMMENT (object));
+
+ self = GTH_METADATA_PROVIDER_COMMENT (object);
+ g_hash_table_unref (self->priv->checked_folders);
+
+ /* Chain up */
+ G_OBJECT_CLASS (gth_metadata_provider_comment_parent_class)->finalize (object);
+}
+
+
static void
gth_metadata_provider_comment_class_init (GthMetadataProviderCommentClass *klass)
+
{
+ GObjectClass *gobject_class;
GthMetadataProviderClass *mp_class;
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = gth_metadata_provider_comment_finalize;
+
mp_class = GTH_METADATA_PROVIDER_CLASS (klass);
mp_class->can_read = gth_metadata_provider_comment_can_read;
mp_class->can_write = gth_metadata_provider_comment_can_write;
@@ -234,8 +301,10 @@ gth_metadata_provider_comment_class_init (GthMetadataProviderCommentClass *klass
mp_class->write = gth_metadata_provider_comment_write;
}
+
static void
gth_metadata_provider_comment_init (GthMetadataProviderComment *self)
{
- /* void */
+ self->priv = gth_metadata_provider_comment_get_instance_private (self);
+ self->priv->checked_folders = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
g_object_unref, NULL);
}
diff --git a/extensions/comments/gth-metadata-provider-comment.h
b/extensions/comments/gth-metadata-provider-comment.h
index 96c938f0..f706ad70 100644
--- a/extensions/comments/gth-metadata-provider-comment.h
+++ b/extensions/comments/gth-metadata-provider-comment.h
@@ -35,15 +35,17 @@
typedef struct _GthMetadataProviderComment GthMetadataProviderComment;
typedef struct _GthMetadataProviderCommentClass GthMetadataProviderCommentClass;
+typedef struct _GthMetadataProviderCommentPrivate GthMetadataProviderCommentPrivate;
struct _GthMetadataProviderComment
{
GthMetadataProvider __parent;
+ GthMetadataProviderCommentPrivate *priv;
};
struct _GthMetadataProviderCommentClass
{
- GthMetadataProviderClass __parent_class;
+ GthMetadataProviderClass __parent_class;
};
GType gth_metadata_provider_comment_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]