[gthumb] metadata provider: pass the file_data as well to can_read if available



commit ac456611405ee4ad186b05a3c3ff9b5c9c5794ba
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Aug 1 12:20:27 2021 +0200

    metadata provider: pass the file_data as well to can_read if available
    
    This allows the provider to determine if the metadata is readable based
    on the file_data information as well.

 .../comments/gth-metadata-provider-comment.c       |   8 +-
 .../exiv2_tools/gth-metadata-provider-exiv2.c      |   1 +
 .../gth-metadata-provider-gstreamer.c              |   5 +-
 .../image_viewer/gth-metadata-provider-image.c     |   5 +-
 extensions/raw_files/gth-metadata-provider-raw.c   |   5 +-
 .../selections/gth-metadata-provider-selections.c  |   7 +-
 gthumb/gth-main.c                                  |   4 +-
 gthumb/gth-metadata-provider-file.c                |   3 +-
 gthumb/gth-metadata-provider.c                     |  11 ++-
 gthumb/gth-metadata-provider.h                     | 106 +++++++++++----------
 10 files changed, 86 insertions(+), 69 deletions(-)
---
diff --git a/extensions/comments/gth-metadata-provider-comment.c 
b/extensions/comments/gth-metadata-provider-comment.c
index 6720783f..74adecc9 100644
--- a/extensions/comments/gth-metadata-provider-comment.c
+++ b/extensions/comments/gth-metadata-provider-comment.c
@@ -30,9 +30,11 @@ G_DEFINE_TYPE (GthMetadataProviderComment, gth_metadata_provider_comment, GTH_TY
 
 
 static gboolean
-gth_metadata_provider_comment_can_read (GthMetadataProvider  *self,
-                                       const char           *mime_type,
-                                       char                **attribute_v)
+gth_metadata_provider_comment_can_read (GthMetadataProvider  *base,
+                                       GthFileData          *file_data,
+                                       const char           *mime_type,
+                                       char                **attribute_v)
+
 {
        return _g_file_attributes_matches_any_v ("comment::*,"
                                                 "general::datetime,"
diff --git a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c 
b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
index 22be118b..a09e9104 100644
--- a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
+++ b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
@@ -54,6 +54,7 @@ gth_metadata_provider_exiv2_finalize (GObject *object)
 
 static gboolean
 gth_metadata_provider_exiv2_can_read (GthMetadataProvider  *self,
+                                     GthFileData          *file_data,
                                      const char           *mime_type,
                                      char                **attribute_v)
 {
diff --git a/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c 
b/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c
index 2a3b95de..dcfd79c0 100644
--- a/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c
+++ b/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c
@@ -31,8 +31,9 @@ G_DEFINE_TYPE (GthMetadataProviderGstreamer, gth_metadata_provider_gstreamer, GT
 
 static gboolean
 gth_metadata_provider_gstreamer_can_read (GthMetadataProvider  *self,
-                                         const char           *mime_type,
-                                         char                **attribute_v)
+                                         GthFileData          *file_data,
+                                         const char           *mime_type,
+                                         char                **attribute_v)
 {
        if (! g_str_equal (mime_type, "*")
            && ! _g_content_type_is_a (mime_type, "audio/*")
diff --git a/extensions/image_viewer/gth-metadata-provider-image.c 
b/extensions/image_viewer/gth-metadata-provider-image.c
index eb5d01ef..9dc5b680 100644
--- a/extensions/image_viewer/gth-metadata-provider-image.c
+++ b/extensions/image_viewer/gth-metadata-provider-image.c
@@ -44,16 +44,17 @@ G_DEFINE_TYPE (GthMetadataProviderImage, gth_metadata_provider_image, GTH_TYPE_M
 
 static gboolean
 gth_metadata_provider_image_can_read (GthMetadataProvider  *self,
+                                     GthFileData          *file_data,
                                      const char           *mime_type,
                                      char                **attribute_v)
 {
        return _g_file_attributes_matches_any_v ("general::format,"
-                                                "general::dimensions,"
+                                                "general::dimensions,"
                                                 "image::width,"
                                                 "image::height,"
                                                 "frame::width,"
                                                 "frame::height",
-                                                attribute_v);
+                                                attribute_v);
 }
 
 
diff --git a/extensions/raw_files/gth-metadata-provider-raw.c 
b/extensions/raw_files/gth-metadata-provider-raw.c
index 77870bad..2d9f5020 100644
--- a/extensions/raw_files/gth-metadata-provider-raw.c
+++ b/extensions/raw_files/gth-metadata-provider-raw.c
@@ -31,16 +31,17 @@ G_DEFINE_TYPE (GthMetadataProviderRaw, gth_metadata_provider_raw, GTH_TYPE_METAD
 
 static gboolean
 gth_metadata_provider_raw_can_read (GthMetadataProvider  *self,
+                                   GthFileData          *file_data,
                                    const char           *mime_type,
                                    char                **attribute_v)
 {
        return _g_file_attributes_matches_any_v ("general::format,"
-                                                "general::dimensions,"
+                                                "general::dimensions,"
                                                 "image::width,"
                                                 "image::height,"
                                                 "frame::width,"
                                                 "frame::height",
-                                                attribute_v);
+                                                attribute_v);
 }
 
 
diff --git a/extensions/selections/gth-metadata-provider-selections.c 
b/extensions/selections/gth-metadata-provider-selections.c
index 62b46379..5f4ed29f 100644
--- a/extensions/selections/gth-metadata-provider-selections.c
+++ b/extensions/selections/gth-metadata-provider-selections.c
@@ -31,11 +31,12 @@ G_DEFINE_TYPE (GthMetadataProviderSelections, gth_metadata_provider_selections,
 
 static gboolean
 gth_metadata_provider_selections_can_read (GthMetadataProvider  *self,
-                                          const char           *mime_type,
-                                          char                **attribute_v)
+                                          GthFileData          *file_data,
+                                          const char           *mime_type,
+                                          char                **attribute_v)
 {
        return _g_file_attributes_matches_any_v (GTH_FILE_ATTRIBUTE_EMBLEMS,
-                                                attribute_v);
+                                                attribute_v);
 }
 
 
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index ca8f7ba4..8109a0d5 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -566,7 +566,7 @@ gth_main_get_metadata_reader (const char *id,
        for (scan = Main->priv->metadata_provider; scan; scan = scan->next) {
                GthMetadataProvider *registered_metadata = scan->data;
 
-               if (gth_metadata_provider_can_read (registered_metadata, mime_type, (char **)attribute_v)) {
+               if (gth_metadata_provider_can_read (registered_metadata, NULL, mime_type, (char 
**)attribute_v)) {
                        metadata = g_object_new (G_OBJECT_TYPE (registered_metadata), NULL);
                        break;
                }
@@ -1503,7 +1503,7 @@ attribute_list_reload_required (const char *old_attributes,
 
                                attr_v[0] = new_attributes_v[j];
                                attr_v[1] = NULL;
-                               if (gth_metadata_provider_can_read (provider, "*", attr_v)) {
+                               if (gth_metadata_provider_can_read (provider, NULL, "*", attr_v)) {
                                        g_free (new_attributes_v[j]);
                                        new_attributes_v[j] = NULL;
                                }
diff --git a/gthumb/gth-metadata-provider-file.c b/gthumb/gth-metadata-provider-file.c
index 2f90a200..51e71464 100644
--- a/gthumb/gth-metadata-provider-file.c
+++ b/gthumb/gth-metadata-provider-file.c
@@ -30,6 +30,7 @@ G_DEFINE_TYPE (GthMetadataProviderFile, gth_metadata_provider_file, GTH_TYPE_MET
 
 static gboolean
 gth_metadata_provider_file_can_read (GthMetadataProvider  *self,
+                                    GthFileData          *file_data,
                                     const char           *mime_type,
                                     char                **attribute_v)
 {
@@ -38,7 +39,7 @@ gth_metadata_provider_file_can_read (GthMetadataProvider  *self,
                                                 "gth::file::content-type,"
                                                 "gth::file::is-modified,"
                                                 "gth::file::full-name",
-                                                attribute_v);
+                                                attribute_v);
 }
 
 
diff --git a/gthumb/gth-metadata-provider.c b/gthumb/gth-metadata-provider.c
index 166123ad..8b538630 100644
--- a/gthumb/gth-metadata-provider.c
+++ b/gthumb/gth-metadata-provider.c
@@ -34,6 +34,7 @@ G_DEFINE_TYPE (GthMetadataProvider, gth_metadata_provider, G_TYPE_OBJECT)
 
 static gboolean
 gth_metadata_provider_real_can_read (GthMetadataProvider  *self,
+                                    GthFileData          *file_data,
                                     const char           *mime_type,
                                     char                **attribute_v)
 {
@@ -90,10 +91,11 @@ gth_metadata_provider_init (GthMetadataProvider *self)
 
 gboolean
 gth_metadata_provider_can_read (GthMetadataProvider  *self,
+                               GthFileData          *file_data,
                                const char           *mime_type,
                                char                **attribute_v)
 {
-       return GTH_METADATA_PROVIDER_GET_CLASS (self)->can_read (self, mime_type, attribute_v);
+       return GTH_METADATA_PROVIDER_GET_CLASS (self)->can_read (self, file_data, mime_type, attribute_v);
 }
 
 
@@ -205,8 +207,13 @@ _g_query_metadata_async_thread (GTask        *task,
                for (scan_providers = providers; scan_providers; scan_providers = scan_providers->next) {
                        GthMetadataProvider *metadata_provider = scan_providers->data;
 
-                       if (gth_metadata_provider_can_read (metadata_provider, gth_file_data_get_mime_type 
(file_data), qmd->attributes_v))
+                       if (gth_metadata_provider_can_read (metadata_provider,
+                                                           file_data,
+                                                           gth_file_data_get_mime_type (file_data),
+                                                           qmd->attributes_v))
+                       {
                                gth_metadata_provider_read (metadata_provider, file_data, qmd->attributes, 
cancellable);
+                       }
                }
        }
 
diff --git a/gthumb/gth-metadata-provider.h b/gthumb/gth-metadata-provider.h
index f75c9a61..d40ee0f1 100644
--- a/gthumb/gth-metadata-provider.h
+++ b/gthumb/gth-metadata-provider.h
@@ -50,60 +50,62 @@ struct _GthMetadataProvider {
 
 struct _GthMetadataProviderClass {
        GObjectClass parent_class;
-       gboolean  (*can_read)  (GthMetadataProvider    *self,
-                               const char             *mime_type,
-                               char                  **attribute_v);
-       gboolean  (*can_write) (GthMetadataProvider    *self,
-                               const char             *mime_type,
-                               char                  **attribute_v);
-       void      (*read)      (GthMetadataProvider    *self,
-                               GthFileData            *file_data,
-                               const char             *attributes,
-                               GCancellable           *cancellable);
-       void      (*write)     (GthMetadataProvider    *self,
-                               GthMetadataWriteFlags   flags,
-                               GthFileData            *file_data,
-                               const char             *attributes,
-                               GCancellable           *cancellable);
+       gboolean  (*can_read)           (GthMetadataProvider    *self,
+                                        GthFileData            *file_data,
+                                        const char             *mime_type,
+                                        char                  **attribute_v);
+       gboolean  (*can_write)          (GthMetadataProvider    *self,
+                                        const char             *mime_type,
+                                        char                  **attribute_v);
+       void      (*read)               (GthMetadataProvider    *self,
+                                        GthFileData            *file_data,
+                                        const char             *attributes,
+                                        GCancellable           *cancellable);
+       void      (*write)              (GthMetadataProvider    *self,
+                                        GthMetadataWriteFlags   flags,
+                                        GthFileData            *file_data,
+                                        const char             *attributes,
+                                        GCancellable           *cancellable);
 };
 
-GType      gth_metadata_provider_get_type   (void);
-gboolean   gth_metadata_provider_can_read   (GthMetadataProvider    *self,
-                                            const char             *mime_type,
-                                            char                  **attribute_v);
-gboolean   gth_metadata_provider_can_write  (GthMetadataProvider    *self,
-                                            const char             *mime_type,
-                                            char                  **attribute_v);
-void       gth_metadata_provider_read       (GthMetadataProvider    *self,
-                                            GthFileData            *file_data,
-                                            const char             *attributes,
-                                            GCancellable           *cancellable);
-void       gth_metadata_provider_write      (GthMetadataProvider    *self,
-                                            GthMetadataWriteFlags   flags,
-                                            GthFileData            *file_data,
-                                            const char             *attributes,
-                                            GCancellable           *cancellable);
-void       _g_query_metadata_async          (GList                  *files,       /* GthFileData * list */
-                                            const char             *attributes,
-                                            GCancellable           *cancellable,
-                                            GAsyncReadyCallback     callback,
-                                            gpointer                user_data);
-GList *    _g_query_metadata_finish         (GAsyncResult           *result,
-                                            GError                **error);
-void       _g_write_metadata_async          (GList                  *files, /* GthFileData * list */
-                                            GthMetadataWriteFlags   flags,
-                                            const char             *attributes,
-                                            GCancellable           *cancellable,
-                                            GAsyncReadyCallback     callback,
-                                            gpointer                user_data);
-gboolean   _g_write_metadata_finish         (GAsyncResult           *result,
-                                            GError                **error);
-void       _g_query_all_metadata_async      (GList                  *files, /* GFile * list */
-                                            GthListFlags            flags,
-                                            const char             *attributes,
-                                            GCancellable           *cancellable,
-                                            InfoReadyCallback       ready_func,
-                                            gpointer                user_data);
+GType      gth_metadata_provider_get_type      (void);
+gboolean   gth_metadata_provider_can_read      (GthMetadataProvider    *self,
+                                                GthFileData            *file_data,
+                                                const char             *mime_type,
+                                                char                  **attribute_v);
+gboolean   gth_metadata_provider_can_write     (GthMetadataProvider    *self,
+                                                const char             *mime_type,
+                                                char                  **attribute_v);
+void       gth_metadata_provider_read          (GthMetadataProvider    *self,
+                                                GthFileData            *file_data,
+                                                const char             *attributes,
+                                                GCancellable           *cancellable);
+void       gth_metadata_provider_write         (GthMetadataProvider    *self,
+                                                GthMetadataWriteFlags   flags,
+                                                GthFileData            *file_data,
+                                                const char             *attributes,
+                                                GCancellable           *cancellable);
+void       _g_query_metadata_async             (GList                  *files,       /* GthFileData * list */
+                                                const char             *attributes,
+                                                GCancellable           *cancellable,
+                                                GAsyncReadyCallback     callback,
+                                                gpointer                user_data);
+GList *    _g_query_metadata_finish            (GAsyncResult           *result,
+                                                GError                **error);
+void       _g_write_metadata_async             (GList                  *files, /* GthFileData * list */
+                                                GthMetadataWriteFlags   flags,
+                                                const char             *attributes,
+                                                GCancellable           *cancellable,
+                                                GAsyncReadyCallback     callback,
+                                                gpointer                user_data);
+gboolean   _g_write_metadata_finish            (GAsyncResult           *result,
+                                                GError                **error);
+void       _g_query_all_metadata_async         (GList                  *files, /* GFile * list */
+                                                GthListFlags            flags,
+                                                const char             *attributes,
+                                                GCancellable           *cancellable,
+                                                InfoReadyCallback       ready_func,
+                                                gpointer                user_data);
 
 G_END_DECLS
 


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