[gnome-photos] Implicitly process the pipeline during add, remove and revert
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Implicitly process the pipeline during add, remove and revert
- Date: Tue, 28 Jun 2016 16:21:58 +0000 (UTC)
commit 2cb929646ec1df696c30bc3733e85fac2682d199
Author: Rafael Fonseca <r4f4rfs gmail com>
Date: Fri Apr 15 22:14:23 2016 +0200
Implicitly process the pipeline during add, remove and revert
The photos_base_item_operation_add/remove/revert calls are inevitably
followed by photos_base_item_process_async. Make it simpler by calling
photos_base_item_process_async from inside those functions and remove
it from the public API.
https://bugzilla.gnome.org/show_bug.cgi?id=765105
src/photos-application.c | 9 +-
src/photos-base-item.c | 198 ++++++++++++++++++++++++++++++----------
src/photos-base-item.h | 35 +++++--
src/photos-done-notification.c | 12 +--
src/photos-preview-view.c | 64 ++++++++++----
src/photos-tool-crop.c | 9 +-
6 files changed, 238 insertions(+), 89 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index de42521..7598282 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -748,7 +748,7 @@ photos_application_edit_cancel_process (GObject *source_object, GAsyncResult *re
GError *error = NULL;
PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
- if (!photos_base_item_process_finish (item, res, &error))
+ if (!photos_base_item_operations_revert_finish (item, res, &error))
{
g_warning ("Unable to process item: %s", error->message);
g_error_free (error);
@@ -768,10 +768,11 @@ photos_application_edit_cancel (PhotosApplication *self)
item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->state->item_mngr));
g_return_if_fail (item != NULL);
- photos_base_item_operations_revert (item);
-
g_application_hold (G_APPLICATION (self));
- photos_base_item_process_async (item, NULL, photos_application_edit_cancel_process, self);
+ photos_base_item_operations_revert_async (item,
+ NULL,
+ photos_application_edit_cancel_process,
+ self);
}
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index af00b24..5f94198 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -929,6 +929,66 @@ photos_base_item_process_idle (gpointer user_data)
}
+static void
+photos_base_item_process_async (PhotosBaseItem *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ PhotosBaseItemPrivate *priv;
+ GTask *task;
+
+ g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
+ priv = self->priv;
+
+ g_return_if_fail (!priv->collection);
+
+ g_clear_object (&priv->processor);
+ priv->processor = photos_pipeline_new_processor (priv->pipeline);
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_base_item_process_async);
+ g_task_set_task_data (task, g_object_ref (priv->processor), g_object_unref);
+
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, photos_base_item_process_idle, g_object_ref (task),
g_object_unref);
+ g_object_unref (task);
+}
+
+
+static gboolean
+photos_base_item_process_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
+{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_process_async, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (task, error);
+}
+
+
+static void
+photos_base_item_common_process (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
+ GTask *task = G_TASK (user_data);
+ GError *error = NULL;
+
+ if (!photos_base_item_process_finish (self, res, &error))
+ {
+ g_task_return_error (task, error);
+ goto out;
+ }
+
+ g_task_return_boolean (task, TRUE);
+
+ out:
+ g_object_unref (task);
+}
+
+
static GeglBuffer *
photos_base_item_load_buffer (PhotosBaseItem *self, GCancellable *cancellable, GError **error)
{
@@ -2371,9 +2431,16 @@ photos_base_item_open (PhotosBaseItem *self, GdkScreen *screen, guint32 timestam
void
-photos_base_item_operation_add (PhotosBaseItem *self, const gchar *operation, const gchar
*first_property_name, ...)
+photos_base_item_operation_add_async (PhotosBaseItem *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data,
+ const gchar *operation,
+ const gchar *first_property_name,
+ ...)
{
PhotosBaseItemPrivate *priv;
+ GTask *task;
va_list ap;
g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
@@ -2384,6 +2451,27 @@ photos_base_item_operation_add (PhotosBaseItem *self, const gchar *operation, co
va_start (ap, first_property_name);
photos_pipeline_add (priv->pipeline, operation, first_property_name, ap);
va_end (ap);
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_base_item_operation_add_async);
+
+ photos_base_item_process_async (self, cancellable, photos_base_item_common_process, g_object_ref (task));
+
+ g_object_unref (task);
+}
+
+
+gboolean
+photos_base_item_operation_add_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
+{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_operation_add_async, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (task, error);
}
@@ -2407,24 +2495,59 @@ photos_base_item_operation_get (PhotosBaseItem *self, const gchar *operation, co
}
-gboolean
-photos_base_item_operation_remove (PhotosBaseItem *self, const gchar *operation)
+void
+photos_base_item_operation_remove_async (PhotosBaseItem *self,
+ const gchar *operation,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
PhotosBaseItemPrivate *priv;
+ GTask *task;
- g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+ g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
priv = self->priv;
- g_return_val_if_fail (!priv->collection, FALSE);
+ g_return_if_fail (!priv->collection);
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_base_item_operation_remove_async);
+
+ if (!photos_pipeline_remove (priv->pipeline, operation))
+ {
+ g_task_return_new_error (task, PHOTOS_ERROR, 0, "Failed to find a GeglNode for %s", operation);
+ goto out;
+ }
+
+ photos_base_item_process_async (self, cancellable, photos_base_item_common_process, g_object_ref (task));
+
+ out:
+ g_object_unref (task);
+}
+
+
+gboolean
+photos_base_item_operation_remove_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
+{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_operation_remove_async, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return photos_pipeline_remove (priv->pipeline, operation);
+ return g_task_propagate_boolean (task, error);
}
void
-photos_base_item_operations_revert (PhotosBaseItem *self)
+photos_base_item_operations_revert_async (PhotosBaseItem *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
PhotosBaseItemPrivate *priv;
+ GTask *task;
g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
priv = self->priv;
@@ -2432,6 +2555,27 @@ photos_base_item_operations_revert (PhotosBaseItem *self)
g_return_if_fail (!priv->collection);
photos_pipeline_revert (priv->pipeline);
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_base_item_operations_revert_async);
+
+ photos_base_item_process_async (self, cancellable, photos_base_item_common_process, g_object_ref (task));
+
+ g_object_unref (task);
+}
+
+
+gboolean
+photos_base_item_operations_revert_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
+{
+ GTask *task = G_TASK (res);
+
+ g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_operations_revert_async, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (task, error);
}
@@ -2503,46 +2647,6 @@ photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel)
void
-photos_base_item_process_async (PhotosBaseItem *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- PhotosBaseItemPrivate *priv;
- GTask *task;
-
- g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
- priv = self->priv;
-
- g_return_if_fail (!priv->collection);
-
- g_clear_object (&priv->processor);
- priv->processor = photos_pipeline_new_processor (priv->pipeline);
-
- task = g_task_new (self, cancellable, callback, user_data);
- g_task_set_source_tag (task, photos_base_item_process_async);
- g_task_set_task_data (task, g_object_ref (priv->processor), g_object_unref);
-
- g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, photos_base_item_process_idle, g_object_ref (task),
g_object_unref);
- g_object_unref (task);
-}
-
-
-gboolean
-photos_base_item_process_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
-{
- GTask *task = G_TASK (res);
-
- g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
- g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
- g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_process_async, FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- return g_task_propagate_boolean (task, error);
-}
-
-
-void
photos_base_item_refresh (PhotosBaseItem *self)
{
GApplication *app;
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index eab854c..86593a4 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -197,42 +197,55 @@ void photos_base_item_open (PhotosBaseItem *se
GdkScreen *screen,
guint32 timestamp);
-void photos_base_item_operation_add (PhotosBaseItem *self,
+void photos_base_item_operation_add_async (PhotosBaseItem *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data,
const gchar *operation,
const gchar *first_property_name,
...) G_GNUC_NULL_TERMINATED;
+gboolean photos_base_item_operation_add_finish (PhotosBaseItem *self,
+ GAsyncResult *res,
+ GError **error);
+
gboolean photos_base_item_operation_get (PhotosBaseItem *self,
const gchar *operation,
const gchar *first_property_name,
...) G_GNUC_NULL_TERMINATED
G_GNUC_WARN_UNUSED_RESULT;
-gboolean photos_base_item_operation_remove (PhotosBaseItem *self, const gchar *operation);
-
-void photos_base_item_operations_revert (PhotosBaseItem *self);
-
-void photos_base_item_pipeline_save_async (PhotosBaseItem *self,
+void photos_base_item_operation_remove_async (PhotosBaseItem *self,
+ const gchar *operation,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean photos_base_item_pipeline_save_finish (PhotosBaseItem *self,
+gboolean photos_base_item_operation_remove_finish (PhotosBaseItem *self,
GAsyncResult *res,
GError **error);
-void photos_base_item_pipeline_snapshot (PhotosBaseItem *self);
+void photos_base_item_operations_revert_async (PhotosBaseItem *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
-void photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel);
+gboolean photos_base_item_operations_revert_finish(PhotosBaseItem *self,
+ GAsyncResult *res,
+ GError **error);
-void photos_base_item_process_async (PhotosBaseItem *self,
+void photos_base_item_pipeline_save_async (PhotosBaseItem *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean photos_base_item_process_finish (PhotosBaseItem *self,
+gboolean photos_base_item_pipeline_save_finish (PhotosBaseItem *self,
GAsyncResult *res,
GError **error);
+void photos_base_item_pipeline_snapshot (PhotosBaseItem *self);
+
+void photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel);
+
void photos_base_item_refresh (PhotosBaseItem *self);
void photos_base_item_save_async (PhotosBaseItem *self,
diff --git a/src/photos-done-notification.c b/src/photos-done-notification.c
index ab494f5..c6d34ad 100644
--- a/src/photos-done-notification.c
+++ b/src/photos-done-notification.c
@@ -121,7 +121,7 @@ photos_done_notification_edit_undo_process (GObject *source_object, GAsyncResult
app = g_application_get_default ();
- if (!photos_base_item_process_finish (item, res, &error))
+ if (!photos_base_item_operations_revert_finish (item, res, &error))
{
g_warning ("Unable to process item: %s", error->message);
g_error_free (error);
@@ -147,15 +147,13 @@ photos_done_notification_undo_clicked (PhotosDoneNotification *self)
{
GApplication *app;
- photos_base_item_operations_revert (self->item);
-
app = g_application_get_default ();
g_application_hold (app);
- photos_base_item_process_async (self->item,
- NULL,
- photos_done_notification_edit_undo_process,
- g_object_ref (self));
+ photos_base_item_operations_revert_async (self->item,
+ NULL,
+ photos_done_notification_edit_undo_process,
+ g_object_ref (self));
photos_done_notification_destroy (self);
}
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 73caaf0..641b5b2 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -276,7 +276,7 @@ photos_preview_view_process (GObject *source_object, GAsyncResult *res, gpointer
GError *error = NULL;
PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
- photos_base_item_process_finish (item, res, &error);
+ photos_base_item_operation_add_finish (item, res, &error);
if (error != NULL)
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
@@ -323,12 +323,14 @@ photos_preview_view_brightness_contrast (PhotosPreviewView *self, GVariant *para
g_return_if_fail (brightness > -G_MAXDOUBLE);
g_return_if_fail (contrast > -G_MAXDOUBLE);
- photos_base_item_operation_add (item,
- "gegl:brightness-contrast",
- "brightness", brightness,
- "contrast", contrast,
- NULL);
- photos_base_item_process_async (item, self->cancellable, photos_preview_view_process, self);
+ photos_base_item_operation_add_async (item,
+ self->cancellable,
+ photos_preview_view_process,
+ self,
+ "gegl:brightness-contrast",
+ "brightness", brightness,
+ "contrast", contrast,
+ NULL);
}
@@ -366,8 +368,16 @@ photos_preview_view_crop (PhotosPreviewView *self, GVariant *parameter)
g_return_if_fail (x >= 0.0);
g_return_if_fail (y >= 0.0);
- photos_base_item_operation_add (item, "gegl:crop", "height", height, "width", width, "x", x, "y", y, NULL);
- photos_base_item_process_async (item, self->cancellable, photos_preview_view_process, self);
+ photos_base_item_operation_add_async (item,
+ self->cancellable,
+ photos_preview_view_process,
+ self,
+ "gegl:crop",
+ "height", height,
+ "width", width,
+ "x", x,
+ "y", y,
+ NULL);
}
@@ -382,8 +392,13 @@ photos_preview_view_denoise (PhotosPreviewView *self, GVariant *parameter)
return;
iterations = g_variant_get_uint16 (parameter);
- photos_base_item_operation_add (item, "gegl:noise-reduction", "iterations", (gint) iterations, NULL);
- photos_base_item_process_async (item, self->cancellable, photos_preview_view_process, self);
+ photos_base_item_operation_add_async (item,
+ self->cancellable,
+ photos_preview_view_process,
+ self,
+ "gegl:noise-reduction",
+ "iterations", (gint) iterations,
+ NULL);
}
@@ -410,8 +425,13 @@ photos_preview_view_insta (PhotosPreviewView *self, GVariant *parameter)
return;
preset = (PhotosOperationInstaPreset) g_variant_get_int16 (parameter);
- photos_base_item_operation_add (item, "photos:insta-filter", "preset", preset, NULL);
- photos_base_item_process_async (item, self->cancellable, photos_preview_view_process, self);
+ photos_base_item_operation_add_async (item,
+ self->cancellable,
+ photos_preview_view_process,
+ self,
+ "photos:insta-filter",
+ "preset", preset,
+ NULL);
}
@@ -426,8 +446,13 @@ photos_preview_view_saturation (PhotosPreviewView *self, GVariant *parameter)
return;
scale = g_variant_get_double (parameter);
- photos_base_item_operation_add (item, "photos:saturation", "scale", scale, NULL);
- photos_base_item_process_async (item, self->cancellable, photos_preview_view_process, self);
+ photos_base_item_operation_add_async (item,
+ self->cancellable,
+ photos_preview_view_process,
+ self,
+ "photos:saturation",
+ "scale", scale,
+ NULL);
}
@@ -442,8 +467,13 @@ photos_preview_view_sharpen (PhotosPreviewView *self, GVariant *parameter)
return;
scale = g_variant_get_double (parameter);
- photos_base_item_operation_add (item, "gegl:unsharp-mask", "scale", scale, NULL);
- photos_base_item_process_async (item, self->cancellable, photos_preview_view_process, self);
+ photos_base_item_operation_add_async (item,
+ self->cancellable,
+ photos_preview_view_process,
+ self,
+ "gegl:unsharp-mask",
+ "scale", scale,
+ NULL);
}
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index 5f5d24c..81177a5 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -893,7 +893,7 @@ photos_tool_crop_process (GObject *source_object, GAsyncResult *res, gpointer us
gfloat zoom;
guint active;
- photos_base_item_process_finish (item, res, &error);
+ photos_base_item_operation_remove_finish (item, res, &error);
if (error != NULL)
{
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
@@ -976,8 +976,11 @@ photos_tool_crop_activate (PhotosTool *tool, PhotosBaseItem *item, PhotosImageVi
self->crop_x = x;
self->crop_y = y;
- photos_base_item_operation_remove (item, "gegl:crop");
- photos_base_item_process_async (item, self->cancellable, photos_tool_crop_process, self);
+ photos_base_item_operation_remove_async (item,
+ "gegl:crop",
+ self->cancellable,
+ photos_tool_crop_process,
+ self);
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]