[gnome-photos/wip/rishi/guess-sizes: 3/3] base-item: Embed photo loading into guess_save_sizes_async



commit 481f7f428842959f1438df47ffe3b31dcdb98fc4
Author: Rafael Fonseca <r4f4rfs gmail com>
Date:   Fri Apr 1 22:26:02 2016 +0200

    base-item: Embed photo loading into guess_save_sizes_async
    
    The caller of guess_save_sizes_async should not worry about the BaseItem
    being loaded or not; the loading (if needed) should be transparent.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760839

 src/photos-base-item.c     |   56 ++++++++++++++++++++++++++++---------------
 src/photos-export-dialog.c |   47 +++---------------------------------
 2 files changed, 40 insertions(+), 63 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 36aad5c..fb09cbe 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -122,8 +122,11 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 static const gint PIXEL_SIZES[] = {2048, 1024};
 
+
 static void photos_base_item_filterable_iface_init (PhotosFilterableInterface *iface);
 
+static void photos_base_item_guess_save_sizes_in_thread_func (GTask *task, gpointer source_object,
+                                                              gpointer task_data, GCancellable *cancellable);
 
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PhotosBaseItem, photos_base_item, G_TYPE_OBJECT,
                                   G_ADD_PRIVATE (PhotosBaseItem)
@@ -850,6 +853,37 @@ photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpo
 
 
 static void
+photos_base_item_guess_save_sizes_do (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  GTask *task = G_TASK (user_data);
+  PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
+  PhotosBaseItemSaveData *data;
+  GeglBuffer *buffer;
+  GeglNode *graph = NULL;
+  GError *error = NULL;
+
+  graph = photos_base_item_load_finish (self, res, &error);
+  if (error != NULL)
+    {
+      g_task_return_error (task, error);
+      goto out;
+    }
+
+  buffer = photos_utils_create_buffer_from_node (graph);
+  data = photos_base_item_save_data_new (NULL, buffer, self->priv->mime_type);
+  g_task_set_task_data (task, data, (GDestroyNotify) photos_base_item_save_data_free);
+
+  g_task_run_in_thread (task, photos_base_item_guess_save_sizes_in_thread_func);
+
+  g_object_unref (buffer);
+
+ out:
+  g_clear_object (&graph);
+  g_object_unref (task);
+}
+
+
+static void
 photos_base_item_guess_save_sizes_from_buffer (GeglBuffer *buffer,
                                                const gchar *mime_type,
                                                gsize *full_size,
@@ -2297,34 +2331,16 @@ photos_base_item_guess_save_sizes_async (PhotosBaseItem *self,
                                          GAsyncReadyCallback callback,
                                          gpointer user_data)
 {
-  PhotosBaseItemPrivate *priv;
-  GeglBuffer *buffer;
-  GeglNode *graph;
   GTask *task;
-  PhotosBaseItemSaveData *data;
 
   g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
-  priv = self->priv;
-
-  g_return_if_fail (!priv->collection);
-  g_return_if_fail (priv->edit_graph != NULL);
-  g_return_if_fail (priv->load_graph != NULL);
-  g_return_if_fail (priv->pipeline != NULL);
-  g_return_if_fail (priv->processor != NULL);
-  g_return_if_fail (!gegl_processor_work (priv->processor, NULL));
-
-  graph = photos_pipeline_get_graph (priv->pipeline);
-  buffer = photos_utils_create_buffer_from_node (graph);
-
-  data = photos_base_item_save_data_new (NULL, buffer, priv->mime_type);
+  g_return_if_fail (!self->priv->collection);
 
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task, photos_base_item_guess_save_sizes_async);
-  g_task_set_task_data (task, data, (GDestroyNotify) photos_base_item_save_data_free);
 
-  g_task_run_in_thread (task, photos_base_item_guess_save_sizes_in_thread_func);
+  photos_base_item_load_async (self, cancellable, photos_base_item_guess_save_sizes_do, g_object_ref (task));
 
-  g_object_unref (buffer);
   g_object_unref (task);
 }
 
diff --git a/src/photos-export-dialog.c b/src/photos-export-dialog.c
index d664abb..ce343bd 100644
--- a/src/photos-export-dialog.c
+++ b/src/photos-export-dialog.c
@@ -181,48 +181,6 @@ photos_export_dialog_guess_sizes (GObject *source_object, GAsyncResult *res, gpo
 
 
 static void
-photos_export_dialog_load (GObject *source_object, GAsyncResult *result, gpointer user_data)
-{
-  PhotosExportDialog *self;
-  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
-  GError *error;
-  GeglNode *node = NULL;
-
-  error = NULL;
-  node = photos_base_item_load_finish (item, result, &error);
-  if (error != NULL)
-    {
-      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
-        {
-          g_error_free (error);
-          goto out;
-        }
-      else
-        {
-          g_warning ("Unable to load the item: %s", error->message);
-          g_error_free (error);
-        }
-    }
-
-  self = PHOTOS_EXPORT_DIALOG (user_data);
-
-  photos_export_dialog_show_size_options (self, FALSE, FALSE);
-
-  if (node != NULL)
-    {
-      photos_export_dialog_show_size_options (self, FALSE, TRUE);
-      photos_base_item_guess_save_sizes_async (self->item,
-                                               self->cancellable,
-                                               photos_export_dialog_guess_sizes,
-                                               self);
-    }
-
- out:
-  g_clear_object (&node);
-}
-
-
-static void
 photos_export_dialog_constructed (GObject *object)
 {
   PhotosExportDialog *self = PHOTOS_EXPORT_DIALOG (object);
@@ -251,7 +209,10 @@ photos_export_dialog_constructed (GObject *object)
       gtk_entry_set_text (GTK_ENTRY (self->dir_entry), now_str);
 
       photos_export_dialog_show_size_options (self, FALSE, TRUE);
-      photos_base_item_load_async (self->item, self->cancellable, photos_export_dialog_load, self);
+      photos_base_item_guess_save_sizes_async (self->item,
+                                               self->cancellable,
+                                               photos_export_dialog_guess_sizes,
+                                               self);
 
       g_date_time_unref (now);
       g_free (now_str);


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