[gnome-photos] delete-item-job: Convert to async API
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] delete-item-job: Convert to async API
- Date: Wed, 13 Apr 2016 15:49:39 +0000 (UTC)
commit 7350f87dc4425e042de343d47231a1a3382565f8
Author: Rafael Fonseca <r4f4rfs gmail com>
Date: Thu Mar 24 16:16:30 2016 +0100
delete-item-job: Convert to async API
https://bugzilla.gnome.org/show_bug.cgi?id=764086
src/photos-base-item.c | 2 +-
src/photos-delete-item-job.c | 50 ++++++++++++++++++++++++++---------------
src/photos-delete-item-job.h | 9 +++++--
3 files changed, 39 insertions(+), 22 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index e92591f..4a700f9 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -2669,6 +2669,6 @@ photos_base_item_trash (PhotosBaseItem *self)
PHOTOS_BASE_ITEM_GET_CLASS (self)->trash (self);
job = photos_delete_item_job_new (self->priv->id);
- photos_delete_item_job_run (job, NULL, NULL);
+ photos_delete_item_job_run (job, NULL, NULL, NULL);
g_object_unref (job);
}
diff --git a/src/photos-delete-item-job.c b/src/photos-delete-item-job.c
index 573d758..245f34a 100644
--- a/src/photos-delete-item-job.c
+++ b/src/photos-delete-item-job.c
@@ -39,10 +39,9 @@
struct _PhotosDeleteItemJob
{
GObject parent_instance;
- PhotosDeleteItemJobCallback callback;
+ GError *queue_error;
PhotosTrackerQueue *queue;
gchar *urn;
- gpointer user_data;
};
struct _PhotosDeleteItemJobClass
@@ -63,7 +62,7 @@ G_DEFINE_TYPE (PhotosDeleteItemJob, photos_delete_item_job, G_TYPE_OBJECT);
static void
photos_delete_item_job_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
- PhotosDeleteItemJob *self = PHOTOS_DELETE_ITEM_JOB (user_data);
+ GTask *task = G_TASK (user_data);
TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
GError *error;
@@ -71,14 +70,11 @@ photos_delete_item_job_query_executed (GObject *source_object, GAsyncResult *res
tracker_sparql_connection_update_finish (connection, res, &error);
if (error != NULL)
{
- g_warning ("Unable to delete item: %s", error->message);
- g_error_free (error);
- goto out;
+ g_task_return_error (task, error);
+ return;
}
- out:
- if (self->callback != NULL)
- (*self->callback) (self->user_data);
+ g_task_return_boolean (task, TRUE);
}
@@ -98,6 +94,7 @@ photos_delete_item_job_finalize (GObject *object)
{
PhotosDeleteItemJob *self = PHOTOS_DELETE_ITEM_JOB (object);
+ g_clear_error (&self->queue_error);
g_free (self->urn);
G_OBJECT_CLASS (photos_delete_item_job_parent_class)->finalize (object);
@@ -125,7 +122,7 @@ photos_delete_item_job_set_property (GObject *object, guint prop_id, const GValu
static void
photos_delete_item_job_init (PhotosDeleteItemJob *self)
{
- self->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
+ self->queue = photos_tracker_queue_dup_singleton (NULL, &self->queue_error);
}
@@ -155,25 +152,39 @@ photos_delete_item_job_new (const gchar *urn)
}
+gboolean
+photos_delete_item_job_finish (PhotosDeleteItemJob *self, GAsyncResult *res, GError **error)
+{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_delete_item_job_run, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (task, error);
+}
+
+
void
photos_delete_item_job_run (PhotosDeleteItemJob *self,
- PhotosDeleteItemJobCallback callback,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
gpointer user_data)
{
GApplication *app;
+ GTask *task;
PhotosQuery *query;
PhotosSearchContextState *state;
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_delete_item_job_run);
+
if (G_UNLIKELY (self->queue == NULL))
{
- if (callback != NULL)
- (*callback) (user_data);
- return;
+ g_task_return_error (task, g_error_copy (self->queue_error));
+ goto out;
}
- self->callback = callback;
- self->user_data = user_data;
-
app = g_application_get_default ();
state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
@@ -182,7 +193,10 @@ photos_delete_item_job_run (PhotosDeleteItemJob *self,
query->sparql,
NULL,
photos_delete_item_job_query_executed,
- g_object_ref (self),
+ g_object_ref (task),
g_object_unref);
photos_query_free (query);
+
+ out:
+ g_object_unref (task);
}
diff --git a/src/photos-delete-item-job.h b/src/photos-delete-item-job.h
index 177409b..63a14f8 100644
--- a/src/photos-delete-item-job.h
+++ b/src/photos-delete-item-job.h
@@ -39,8 +39,6 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
PHOTOS_TYPE_DELETE_ITEM_JOB))
-typedef void (*PhotosDeleteItemJobCallback) (gpointer);
-
typedef struct _PhotosDeleteItemJob PhotosDeleteItemJob;
typedef struct _PhotosDeleteItemJobClass PhotosDeleteItemJobClass;
@@ -49,9 +47,14 @@ GType photos_delete_item_job_get_type (void) G_GNUC_CON
PhotosDeleteItemJob *photos_delete_item_job_new (const gchar *urn);
void photos_delete_item_job_run (PhotosDeleteItemJob *self,
- PhotosDeleteItemJobCallback callback,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
gpointer user_data);
+gboolean photos_delete_item_job_finish (PhotosDeleteItemJob *self,
+ GAsyncResult *res,
+ GError **error);
+
G_END_DECLS
#endif /* PHOTOS_DELETE_ITEM_JOB_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]