Commit 526ee018 authored by Paolo Bacchilega's avatar Paolo Bacchilega

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

parent 8cf51a7b
......@@ -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;
}
......
......@@ -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 */
......@@ -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);
......
......@@ -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;
......
......@@ -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,
......
......@@ -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 ();
......
......@@ -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/*"))
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
}
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment