[gthumb] metadata-provider: added a cancellable argument to the read and write functions



commit 526ee018b975f8df14861fa45282bf017954cc66
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jul 17 16:28:12 2011 +0200

    metadata-provider: added a cancellable argument to the read and write functions

 extensions/comments/gth-comment.c                  |    7 +-
 extensions/comments/gth-comment.h                  |   65 ++++++++++----------
 .../comments/gth-metadata-provider-comment.c       |   10 ++-
 extensions/exiv2_tools/exiv2-utils.cpp             |    7 +-
 extensions/exiv2_tools/exiv2-utils.h               |    1 +
 .../exiv2_tools/gth-metadata-provider-exiv2.c      |   14 +++--
 .../gth-metadata-provider-gstreamer.c              |    3 +-
 .../image_viewer/gth-metadata-provider-image.c     |   13 ++--
 gthumb/gth-metadata-provider-file.c                |    3 +-
 gthumb/gth-metadata-provider.c                     |   20 ++++---
 gthumb/gth-metadata-provider.h                     |   12 +++-
 11 files changed, 87 insertions(+), 68 deletions(-)
---
diff --git a/extensions/comments/gth-comment.c b/extensions/comments/gth-comment.c
index b3a2afc..60e20d1 100644
--- a/extensions/comments/gth-comment.c
+++ b/extensions/comments/gth-comment.c
@@ -302,8 +302,9 @@ gth_comment_get_comment_file (GFile *file)
 
 
 GthComment *
-gth_comment_new_for_file (GFile   *file,
-			  GError **error)
+gth_comment_new_for_file (GFile         *file,
+			  GCancellable  *cancellable,
+			  GError       **error)
 {
 	GFile       *comment_file;
 	GthComment  *comment;
@@ -317,7 +318,7 @@ gth_comment_new_for_file (GFile   *file,
 	if (comment_file == NULL)
 		return NULL;
 
-	if (! g_load_file_in_buffer (comment_file, &zipped_buffer, &zipped_size, NULL, error)) {
+	if (! g_load_file_in_buffer (comment_file, &zipped_buffer, &zipped_size, cancellable, error)) {
 		g_object_unref (comment_file);
 		return NULL;
 	}
diff --git a/extensions/comments/gth-comment.h b/extensions/comments/gth-comment.h
index 716c5df..0995626 100644
--- a/extensions/comments/gth-comment.h
+++ b/extensions/comments/gth-comment.h
@@ -47,39 +47,40 @@ struct _GthCommentClass {
         GObjectClass parent_class;
 };
 
-GFile *           gth_comment_get_comment_file           (GFile       *file);
+GFile *           gth_comment_get_comment_file           (GFile         *file);
 GType             gth_comment_get_type                   (void);
 GthComment *      gth_comment_new                        (void);
-GthComment *      gth_comment_new_for_file               (GFile       *file,
-							  GError     **error);
-char *            gth_comment_to_data                    (GthComment  *comment,
-							  gsize       *length);
-GthComment *      gth_comment_dup                        (GthComment  *comment);
-void              gth_comment_reset                      (GthComment  *comment);
-void              gth_comment_set_caption                (GthComment  *comment,
-							  const char  *value);
-void              gth_comment_set_note                   (GthComment  *comment,
-							  const char  *value);
-void              gth_comment_set_place                  (GthComment  *comment,
-							  const char  *value);
-void              gth_comment_set_rating                 (GthComment  *comment,
-							  int          value);
-void              gth_comment_clear_categories           (GthComment  *comment);
-void              gth_comment_add_category               (GthComment  *comment,
-							  const char  *value);
-void              gth_comment_reset_time                 (GthComment  *comment);
-void              gth_comment_set_time_from_exif_format  (GthComment  *comment,
-							  const char  *value);
-void              gth_comment_set_time_from_time_t       (GthComment  *comment,
-							  time_t       value);
-const char *      gth_comment_get_caption                (GthComment  *comment);
-const char *      gth_comment_get_note                   (GthComment  *comment);
-const char *      gth_comment_get_place                  (GthComment  *comment);
-int               gth_comment_get_rating                 (GthComment  *comment);
-GPtrArray *       gth_comment_get_categories             (GthComment  *comment);
-GDate *           gth_comment_get_date                   (GthComment  *comment);
-GthTime *         gth_comment_get_time_of_day            (GthComment  *comment);
-char *            gth_comment_get_time_as_exif_format    (GthComment  *comment);
-void              gth_comment_update_general_attributes  (GthFileData *file_data);
+GthComment *      gth_comment_new_for_file               (GFile         *file,
+							  GCancellable  *cancellable,
+							  GError       **error);
+char *            gth_comment_to_data                    (GthComment    *comment,
+							  gsize         *length);
+GthComment *      gth_comment_dup                        (GthComment    *comment);
+void              gth_comment_reset                      (GthComment    *comment);
+void              gth_comment_set_caption                (GthComment    *comment,
+							  const char    *value);
+void              gth_comment_set_note                   (GthComment    *comment,
+							  const char    *value);
+void              gth_comment_set_place                  (GthComment    *comment,
+							  const char    *value);
+void              gth_comment_set_rating                 (GthComment    *comment,
+							  int            value);
+void              gth_comment_clear_categories           (GthComment    *comment);
+void              gth_comment_add_category               (GthComment    *comment,
+							  const char    *value);
+void              gth_comment_reset_time                 (GthComment    *comment);
+void              gth_comment_set_time_from_exif_format  (GthComment    *comment,
+							  const char    *value);
+void              gth_comment_set_time_from_time_t       (GthComment    *comment,
+							  time_t         value);
+const char *      gth_comment_get_caption                (GthComment    *comment);
+const char *      gth_comment_get_note                   (GthComment    *comment);
+const char *      gth_comment_get_place                  (GthComment    *comment);
+int               gth_comment_get_rating                 (GthComment    *comment);
+GPtrArray *       gth_comment_get_categories             (GthComment    *comment);
+GDate *           gth_comment_get_date                   (GthComment    *comment);
+GthTime *         gth_comment_get_time_of_day            (GthComment    *comment);
+char *            gth_comment_get_time_as_exif_format    (GthComment    *comment);
+void              gth_comment_update_general_attributes  (GthFileData   *file_data);
 
 #endif /* GTH_COMMENT_H */
diff --git a/extensions/comments/gth-metadata-provider-comment.c b/extensions/comments/gth-metadata-provider-comment.c
index ea082ec..d6aa343 100644
--- a/extensions/comments/gth-metadata-provider-comment.c
+++ b/extensions/comments/gth-metadata-provider-comment.c
@@ -64,7 +64,8 @@ gth_metadata_provider_comment_can_write (GthMetadataProvider  *self,
 static void
 gth_metadata_provider_comment_read (GthMetadataProvider *self,
 				    GthFileData         *file_data,
-				    const char          *attributes)
+				    const char          *attributes,
+				    GCancellable        *cancellable)
 {
 	GthComment            *comment;
 	GFileAttributeMatcher *matcher;
@@ -72,7 +73,7 @@ gth_metadata_provider_comment_read (GthMetadataProvider *self,
 	GPtrArray             *categories;
 	char                  *comment_time;
 
-	comment = gth_comment_new_for_file (file_data->file, NULL);
+	comment = gth_comment_new_for_file (file_data->file, cancellable, NULL);
 	if (comment == NULL)
 		return;
 
@@ -135,7 +136,8 @@ static void
 gth_metadata_provider_comment_write (GthMetadataProvider   *self,
 				     GthMetadataWriteFlags  flags,
 				     GthFileData           *file_data,
-				     const char            *attributes)
+				     const char            *attributes,
+				     GCancellable          *cancellable)
 {
 	GthComment    *comment;
 	GthMetadata   *metadata;
@@ -207,7 +209,7 @@ gth_metadata_provider_comment_write (GthMetadataProvider   *self,
 	comment_folder = g_file_get_parent (comment_file);
 
 	g_file_make_directory (comment_folder, NULL, NULL);
-	g_write_file (comment_file, FALSE, 0, data, length, NULL, NULL);
+	g_write_file (comment_file, FALSE, 0, data, length, cancellable, NULL);
 
 	g_object_unref (comment_folder);
 	g_object_unref (comment_file);
diff --git a/extensions/exiv2_tools/exiv2-utils.cpp b/extensions/exiv2_tools/exiv2-utils.cpp
index 32ed5e2..45f3513 100644
--- a/extensions/exiv2_tools/exiv2-utils.cpp
+++ b/extensions/exiv2_tools/exiv2-utils.cpp
@@ -663,9 +663,10 @@ exiv2_read_metadata (Exiv2::Image::AutoPtr  image,
  */
 extern "C"
 gboolean
-exiv2_read_metadata_from_file (GFile      *file,
-			       GFileInfo  *info,
-			       GError    **error)
+exiv2_read_metadata_from_file (GFile         *file,
+			       GFileInfo     *info,
+			       GCancellable  *cancellable,
+			       GError       **error)
 {
 	try {
 		char *path;
diff --git a/extensions/exiv2_tools/exiv2-utils.h b/extensions/exiv2_tools/exiv2-utils.h
index 4e9ef44..4a1595c 100644
--- a/extensions/exiv2_tools/exiv2-utils.h
+++ b/extensions/exiv2_tools/exiv2-utils.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 
 gboolean   exiv2_read_metadata_from_file    (GFile           *file,
 					     GFileInfo       *info,
+					     GCancellable    *cancellable,
 					     GError         **error);
 gboolean   exiv2_read_metadata_from_buffer  (void            *buffer,
 					     gsize            buffer_size,
diff --git a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
index f000e1c..b26aa79 100644
--- a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
+++ b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
@@ -78,7 +78,8 @@ gth_metadata_provider_exiv2_can_write (GthMetadataProvider  *self,
 static void
 gth_metadata_provider_exiv2_read (GthMetadataProvider *self,
 				  GthFileData         *file_data,
-				  const char          *attributes)
+				  const char          *attributes,
+				  GCancellable        *cancellable)
 {
 	GFile       *sidecar;
 	GthFileData *sidecar_file_data;
@@ -89,15 +90,15 @@ gth_metadata_provider_exiv2_read (GthMetadataProvider *self,
 	/* this function is executed in a secondary thread, so calling
 	 * slow sync functions is not a problem. */
 
-	exiv2_read_metadata_from_file (file_data->file, file_data->info, NULL);
+	exiv2_read_metadata_from_file (file_data->file, file_data->info, cancellable, NULL);
 
 	/* sidecar data */
 
 	sidecar = exiv2_get_sidecar (file_data->file);
 	sidecar_file_data = gth_file_data_new (sidecar, NULL);
-	if (g_file_query_exists (sidecar_file_data->file, NULL)) {
+	if (g_file_query_exists (sidecar_file_data->file, cancellable)) {
 		gth_file_data_update_info (sidecar_file_data, "time::*");
-		if (g_file_query_exists (sidecar_file_data->file, NULL))
+		if (g_file_query_exists (sidecar_file_data->file, cancellable))
 			exiv2_read_sidecar (sidecar_file_data->file, file_data->info);
 	}
 
@@ -110,7 +111,8 @@ static void
 gth_metadata_provider_exiv2_write (GthMetadataProvider   *self,
 				   GthMetadataWriteFlags  flags,
 				   GthFileData           *file_data,
-				   const char            *attributes)
+				   const char            *attributes,
+				   GCancellable          *cancellable)
 {
 	void    *buffer = NULL;
 	gsize    size;
@@ -237,7 +239,7 @@ gth_metadata_provider_exiv2_write (GthMetadataProvider   *self,
 			      G_FILE_CREATE_NONE,
 			      buffer,
 			      size,
-			      NULL,
+			      cancellable,
 			      &error);
 
 		tmp_info = g_file_info_new ();
diff --git a/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c b/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c
index f6401a5..8d2c26b 100644
--- a/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c
+++ b/extensions/gstreamer_tools/gth-metadata-provider-gstreamer.c
@@ -54,7 +54,8 @@ gth_metadata_provider_gstreamer_can_read (GthMetadataProvider  *self,
 static void
 gth_metadata_provider_gstreamer_read (GthMetadataProvider *self,
 				      GthFileData         *file_data,
-				      const char          *attributes)
+				      const char          *attributes,
+				      GCancellable        *cancellable)
 {
 	if (! g_content_type_is_a (gth_file_data_get_mime_type (file_data), "audio/*")
 	    && ! g_content_type_is_a (gth_file_data_get_mime_type (file_data), "video/*"))
diff --git a/extensions/image_viewer/gth-metadata-provider-image.c b/extensions/image_viewer/gth-metadata-provider-image.c
index 9567b6c..75fad87 100644
--- a/extensions/image_viewer/gth-metadata-provider-image.c
+++ b/extensions/image_viewer/gth-metadata-provider-image.c
@@ -54,7 +54,8 @@ gth_metadata_provider_image_can_read (GthMetadataProvider  *self,
 static void
 gth_metadata_provider_image_read (GthMetadataProvider *self,
 				  GthFileData         *file_data,
-				  const char          *attributes)
+				  const char          *attributes,
+				  GCancellable        *cancellable)
 {
 	gboolean          format_recognized;
 	GFileInputStream *stream;
@@ -65,7 +66,7 @@ gth_metadata_provider_image_read (GthMetadataProvider *self,
 
 	format_recognized = FALSE;
 
-	stream = g_file_read (file_data->file, NULL, NULL);
+	stream = g_file_read (file_data->file, cancellable, NULL);
 	if (stream != NULL) {
 		int     buffer_size;
 		guchar *buffer;
@@ -76,7 +77,7 @@ gth_metadata_provider_image_read (GthMetadataProvider *self,
 		size = g_input_stream_read (G_INPUT_STREAM (stream),
 					    buffer,
 					    buffer_size,
-					    NULL,
+					    cancellable,
 					    NULL);
 		if (size >= 0) {
 			if ((size >= 24)
@@ -120,18 +121,18 @@ gth_metadata_provider_image_read (GthMetadataProvider *self,
 				GthTransform orientation;
 
 				if (g_seekable_can_seek (G_SEEKABLE (stream))) {
-					g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL);
+					g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, cancellable, NULL);
 				}
 				else {
 					g_object_unref (stream);
-					stream = g_file_read (file_data->file, NULL, NULL);
+					stream = g_file_read (file_data->file, cancellable, NULL);
 				}
 
 				if (_jpeg_get_image_info (G_INPUT_STREAM (stream),
 							  &width,
 							  &height,
 							  &orientation,
-							  NULL,
+							  cancellable,
 							  NULL))
 				{
 					format_recognized = TRUE;
diff --git a/gthumb/gth-metadata-provider-file.c b/gthumb/gth-metadata-provider-file.c
index 05af456..a84841e 100644
--- a/gthumb/gth-metadata-provider-file.c
+++ b/gthumb/gth-metadata-provider-file.c
@@ -48,7 +48,8 @@ gth_metadata_provider_file_can_read (GthMetadataProvider  *self,
 static void
 gth_metadata_provider_file_read (GthMetadataProvider *self,
 				 GthFileData         *file_data,
-				 const char          *attributes)
+				 const char          *attributes,
+				 GCancellable        *cancellable)
 {
 	GFileAttributeMatcher *matcher;
 	char                  *value;
diff --git a/gthumb/gth-metadata-provider.c b/gthumb/gth-metadata-provider.c
index 4ce4f00..b6bd08e 100644
--- a/gthumb/gth-metadata-provider.c
+++ b/gthumb/gth-metadata-provider.c
@@ -53,7 +53,8 @@ gth_metadata_provider_real_can_write (GthMetadataProvider  *self,
 static void
 gth_metadata_provider_real_read (GthMetadataProvider *self,
 				 GthFileData         *file_data,
-				 const char          *attributes)
+				 const char          *attributes,
+				 GCancellable        *cancellable)
 {
 	/* void */
 }
@@ -63,7 +64,8 @@ static void
 gth_metadata_provider_real_write (GthMetadataProvider   *self,
 				  GthMetadataWriteFlags  flags,
 				  GthFileData           *file_data,
-				  const char            *attributes)
+				  const char            *attributes,
+				  GCancellable          *cancellable)
 {
 	/* void */
 }
@@ -125,9 +127,10 @@ gth_metadata_provider_can_write (GthMetadataProvider  *self,
 void
 gth_metadata_provider_read (GthMetadataProvider *self,
 			    GthFileData         *file_data,
-			    const char          *attributes)
+			    const char          *attributes,
+			    GCancellable        *cancellable)
 {
-	GTH_METADATA_PROVIDER_GET_CLASS (self)->read (self, file_data, attributes);
+	GTH_METADATA_PROVIDER_GET_CLASS (self)->read (self, file_data, attributes, cancellable);
 }
 
 
@@ -135,9 +138,10 @@ void
 gth_metadata_provider_write (GthMetadataProvider   *self,
 			     GthMetadataWriteFlags  flags,
 			     GthFileData           *file_data,
-			     const char            *attributes)
+			     const char            *attributes,
+			     GCancellable          *cancellable)
 {
-	GTH_METADATA_PROVIDER_GET_CLASS (self)->write (self, flags, file_data, attributes);
+	GTH_METADATA_PROVIDER_GET_CLASS (self)->write (self, flags, file_data, attributes, cancellable);
 }
 
 
@@ -193,7 +197,7 @@ _g_query_metadata_async_thread (GSimpleAsyncResult *result,
 			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))
-				gth_metadata_provider_read (metadata_provider, file_data, qmd->attributes);
+				gth_metadata_provider_read (metadata_provider, file_data, qmd->attributes, cancellable);
 		}
 	}
 
@@ -318,7 +322,7 @@ _g_write_metadata_async_thread (GSimpleAsyncResult *result,
 			GthMetadataProvider *metadata_provider = scan_providers->data;
 
 			if (gth_metadata_provider_can_write (metadata_provider, gth_file_data_get_mime_type (file_data), wmd->attributes_v))
-				gth_metadata_provider_write (metadata_provider, wmd->flags, file_data, wmd->attributes);
+				gth_metadata_provider_write (metadata_provider, wmd->flags, file_data, wmd->attributes, cancellable);
 		}
 	}
 
diff --git a/gthumb/gth-metadata-provider.h b/gthumb/gth-metadata-provider.h
index fbcf32b..f75c9a6 100644
--- a/gthumb/gth-metadata-provider.h
+++ b/gthumb/gth-metadata-provider.h
@@ -58,11 +58,13 @@ struct _GthMetadataProviderClass {
 			        char                  **attribute_v);
 	void      (*read)      (GthMetadataProvider    *self,
 		                GthFileData            *file_data,
-		                const char             *attributes);
+		                const char             *attributes,
+		                GCancellable           *cancellable);
 	void      (*write)     (GthMetadataProvider    *self,
 				GthMetadataWriteFlags   flags,
 			        GthFileData            *file_data,
-			        const char             *attributes);
+			        const char             *attributes,
+			        GCancellable           *cancellable);
 };
 
 GType      gth_metadata_provider_get_type   (void);
@@ -74,11 +76,13 @@ gboolean   gth_metadata_provider_can_write  (GthMetadataProvider    *self,
 					     char                  **attribute_v);
 void       gth_metadata_provider_read       (GthMetadataProvider    *self,
 					     GthFileData            *file_data,
-					     const char             *attributes);
+					     const char             *attributes,
+					     GCancellable           *cancellable);
 void       gth_metadata_provider_write      (GthMetadataProvider    *self,
 					     GthMetadataWriteFlags   flags,
 					     GthFileData            *file_data,
-					     const char             *attributes);
+					     const char             *attributes,
+					     GCancellable           *cancellable);
 void       _g_query_metadata_async          (GList                  *files,       /* GthFileData * list */
 					     const char             *attributes,
 					     GCancellable           *cancellable,



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