[gnome-photos] create-collection-icon-job: Convert to async API
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] create-collection-icon-job: Convert to async API
- Date: Fri, 22 Apr 2016 15:30:41 +0000 (UTC)
commit e86f0369f8e8fd77b1aa10c01f85338e06516c1d
Author: Rafael Fonseca <r4f4rfs gmail com>
Date: Thu Apr 21 14:30:45 2016 +0200
create-collection-icon-job: Convert to async API
https://bugzilla.gnome.org/show_bug.cgi?id=764086
src/photos-create-collection-icon-job.c | 46 +++++++++++++++++++------------
src/photos-create-collection-icon-job.h | 7 ++++-
src/photos-fetch-metas-job.c | 13 ++++++++-
3 files changed, 46 insertions(+), 20 deletions(-)
---
diff --git a/src/photos-create-collection-icon-job.c b/src/photos-create-collection-icon-job.c
index e247d14..500f87c 100644
--- a/src/photos-create-collection-icon-job.c
+++ b/src/photos-create-collection-icon-job.c
@@ -29,13 +29,14 @@
#include "photos-query-builder.h"
#include "photos-create-collection-icon-job.h"
#include "photos-tracker-queue.h"
+#include "photos-utils.h"
struct _PhotosCreateCollectionIconJob
{
GObject parent_instance;
+ GError *queue_error;
GIcon *icon;
- PhotosCreateCollectionIconJobCallback callback;
PhotosTrackerQueue *queue;
gchar *urn;
gpointer user_data;
@@ -57,16 +58,6 @@ G_DEFINE_TYPE (PhotosCreateCollectionIconJob, photos_create_collection_icon_job,
static void
-photos_create_collection_icon_job_emit_callback (PhotosCreateCollectionIconJob *self)
-{
- if (self->callback == NULL)
- return;
-
- (*self->callback) (self->icon, self->user_data);
-}
-
-
-static void
photos_create_collection_icon_job_dispose (GObject *object)
{
PhotosCreateCollectionIconJob *self = PHOTOS_CREATE_COLLECTION_ICON_JOB (object);
@@ -83,6 +74,7 @@ photos_create_collection_icon_job_finalize (GObject *object)
{
PhotosCreateCollectionIconJob *self = PHOTOS_CREATE_COLLECTION_ICON_JOB (object);
+ g_clear_error (&self->queue_error);
g_free (self->urn);
G_OBJECT_CLASS (photos_create_collection_icon_job_parent_class)->finalize (object);
@@ -113,7 +105,7 @@ photos_create_collection_icon_job_set_property (GObject *object,
static void
photos_create_collection_icon_job_init (PhotosCreateCollectionIconJob *self)
{
- self->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
+ self->queue = photos_tracker_queue_dup_singleton (NULL, &self->queue_error);
}
@@ -143,20 +135,38 @@ photos_create_collection_icon_job_new (const gchar *urn)
}
+GIcon *
+photos_create_collection_icon_job_finish (PhotosCreateCollectionIconJob *self, GAsyncResult *res, GError
**error)
+{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (g_task_is_valid (res, self), NULL);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_create_collection_icon_job_run, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return g_task_propagate_pointer (task, error);
+}
+
+
void
photos_create_collection_icon_job_run (PhotosCreateCollectionIconJob *self,
- PhotosCreateCollectionIconJobCallback callback,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
gpointer user_data)
{
+ GTask *task;
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_create_collection_icon_job_run);
+
if (G_UNLIKELY (self->queue == NULL))
{
- photos_create_collection_icon_job_emit_callback (self);
+ g_task_return_error (task, g_error_copy (self->queue_error));
return;
}
- self->callback = callback;
- self->user_data = user_data;
-
/* TODO: build collection icon query */
- photos_create_collection_icon_job_emit_callback (self);
+ g_task_return_new_error (task, PHOTOS_ERROR, 0, "Unable to create collection icon");
+
+ g_object_unref (task);
}
diff --git a/src/photos-create-collection-icon-job.h b/src/photos-create-collection-icon-job.h
index 2ced318..b64ec5e 100644
--- a/src/photos-create-collection-icon-job.h
+++ b/src/photos-create-collection-icon-job.h
@@ -48,8 +48,13 @@ GType photos_create_collection_icon_job_get_type (void
PhotosCreateCollectionIconJob *photos_create_collection_icon_job_new (const gchar *urn);
+GIcon *photos_create_collection_icon_job_finish (PhotosCreateCollectionIconJob
*self,
+ GAsyncResult *res,
+ GError **error);
+
void photos_create_collection_icon_job_run (PhotosCreateCollectionIconJob *self,
- PhotosCreateCollectionIconJobCallback
callback,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
gpointer user_data);
G_END_DECLS
diff --git a/src/photos-fetch-metas-job.c b/src/photos-fetch-metas-job.c
index 1205ad3..0e40bc6 100644
--- a/src/photos-fetch-metas-job.c
+++ b/src/photos-fetch-metas-job.c
@@ -100,15 +100,25 @@ photos_fetch_metas_job_collector (PhotosFetchMetasJob *self)
static void
-photos_fetch_metas_job_create_collection_icon_executed (GIcon *icon, gpointer user_data)
+photos_fetch_metas_job_create_collection_icon_executed (GObject *source_object, GAsyncResult *res, gpointer
user_data)
{
GTask *task = G_TASK (user_data);
+ GError *error = NULL;
+ GIcon *icon = NULL;
+ PhotosCreateCollectionIconJob *job = PHOTOS_CREATE_COLLECTION_ICON_JOB (source_object);
PhotosFetchMetasJob *self;
PhotosFetchMeta *meta;
self = PHOTOS_FETCH_METAS_JOB (g_task_get_source_object (task));
meta = (PhotosFetchMeta *) g_task_get_task_data (task);
+ icon = photos_create_collection_icon_job_finish (job, res, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to create collection icon: %s", error->message);
+ g_error_free (error);
+ }
+
if (icon != NULL)
{
g_clear_object (&meta->icon);
@@ -131,6 +141,7 @@ photos_fetch_metas_job_create_collection_pixbuf (PhotosFetchMetasJob *self, Phot
task = g_task_new (self, NULL, NULL, NULL);
g_task_set_task_data (task, meta, NULL);
photos_create_collection_icon_job_run (job,
+ NULL,
photos_fetch_metas_job_create_collection_icon_executed,
g_object_ref (task));
g_object_unref (task);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]