Commit c6aed42e authored by Rafael Fonseca dos Santos's avatar Rafael Fonseca dos Santos Committed by Debarshi Ray
Browse files

base-item, export-dialog: Transparently load item while guessing size

The caller of photos_base_item_guess_save_sizes_async should not have
to worry about the BaseItem being loaded or not; the loading (if
needed) should be transparent.

https://bugzilla.gnome.org/show_bug.cgi?id=760839
parent d059ee9d
......@@ -910,6 +910,37 @@ photos_base_item_guess_save_sizes_in_thread_func (GTask *task,
}
static void
photos_base_item_guess_save_sizes_load (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
GError *error;
GTask *task = G_TASK (user_data);
GeglBuffer *buffer = NULL;
GeglNode *graph = NULL;
PhotosBaseItemSaveData *data;
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);
out:
g_clear_object (&buffer);
g_clear_object (&graph);
g_object_unref (task);
}
static gboolean
photos_base_item_process_idle (gpointer user_data)
{
......@@ -2337,34 +2368,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_load, g_object_ref (task));
g_object_unref (buffer);
g_object_unref (task);
}
......
......@@ -180,48 +180,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)
{
......@@ -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);
......
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