[gthumb] resize tool: show a progress dialog if the resizing takes a lot of time



commit 13d279886cc1937f4cd93b6162ef708fcfc71cc6
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Aug 19 11:55:34 2012 +0200

    resize tool: show a progress dialog if the resizing takes a lot of time
    
    and allow to cancel the operation

 extensions/file_tools/gth-file-tool-resize.c |   77 +++++++++++++++++++++----
 1 files changed, 64 insertions(+), 13 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-resize.c b/extensions/file_tools/gth-file-tool-resize.c
index 369e197..aaa67ed 100644
--- a/extensions/file_tools/gth-file-tool-resize.c
+++ b/extensions/file_tools/gth-file-tool-resize.c
@@ -112,23 +112,55 @@ update_dimensione_info_label (GthFileToolResize *self,
 
 
 static void
-update_pixbuf_size (GthFileToolResize *self)
+resize_task_init (GthAsyncTask *task,
+	          gpointer      user_data)
 {
-	GtkWidget *window;
-	GtkWidget *viewer_page;
+	gth_task_progress (GTH_TASK (task), _("Resizing images"), NULL, TRUE, 0.0);
+}
 
-	cairo_surface_destroy (self->priv->new_image);
 
-	/*self->priv->new_image = _cairo_image_surface_scale_to (self->priv->original_image,
-							       self->priv->new_width,
-							       self->priv->new_height,
-							       self->priv->high_quality ? CAIRO_FILTER_GAUSSIAN : CAIRO_FILTER_NEAREST);*/
+static gpointer
+resize_task_exec (GthAsyncTask *task,
+		  gpointer      user_data)
+{
+	GthFileToolResize *self = user_data;
+	cairo_surface_t   *destination;
+	GthImage          *destination_image;
+
+	destination = _cairo_image_surface_scale (self->priv->original_image,
+			    	    	    	  self->priv->new_width,
+			    	    	    	  self->priv->new_height,
+			    	    	    	  (self->priv->high_quality ? SCALE_FILTER_BEST : SCALE_FILTER_FAST),
+			    	    	    	  task);
+	destination_image = gth_image_new_for_surface (destination);
+	gth_image_task_set_destination (GTH_IMAGE_TASK (task), destination_image);
+
+	_g_object_unref (destination_image);
+	cairo_surface_destroy (destination);
+
+	return NULL;
+}
+
+
+static void
+resize_task_completed (GthAsyncTask *task,
+		       GError       *error,
+		       gpointer      user_data)
+{
+	GthFileToolResize *self = user_data;
+	GthImage          *destination_image;
+	GtkWidget         *window;
+	GtkWidget         *viewer_page;
+
+	if (error != NULL)
+		return;
+
+	destination_image = gth_image_task_get_destination (GTH_IMAGE_TASK (task));
+	if (destination_image == NULL)
+		return;
+
+	self->priv->new_image = gth_image_get_cairo_surface (destination_image);
 
-	self->priv->new_image = _cairo_image_surface_scale (self->priv->original_image,
-							    self->priv->new_width,
-							    self->priv->new_height,
-							    (self->priv->high_quality ? SCALE_FILTER_BEST : SCALE_FILTER_FAST),
-							    NULL);
 	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
 	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
 	gth_image_viewer_page_set_image (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->new_image, FALSE);
@@ -147,6 +179,25 @@ update_pixbuf_size (GthFileToolResize *self)
 
 
 static void
+update_pixbuf_size (GthFileToolResize *self)
+{
+	GthTask *resize_task;
+
+	_cairo_clear_surface (&self->priv->new_image);
+
+	resize_task = gth_image_task_new (NULL,
+					  resize_task_init,
+					  resize_task_exec,
+					  resize_task_completed,
+					  self,
+					  NULL);
+	gth_browser_exec_task (GTH_BROWSER (gth_file_tool_get_window (GTH_FILE_TOOL (self))), resize_task, FALSE);
+
+	g_object_unref (resize_task);
+}
+
+
+static void
 selection_width_value_changed_cb (GtkSpinButton     *spin,
 				  GthFileToolResize *self)
 {



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