[gthumb] added a description property to GthTask to simplify the code



commit 465a36493c89b068a209058415305ff6dca9139c
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Aug 19 12:22:43 2012 +0200

    added a description property to GthTask to simplify the code

 extensions/file_tools/gth-file-tool-resize.c |   12 +----
 gthumb/gth-async-task.c                      |    2 +-
 gthumb/gth-image-list-task.c                 |    2 +-
 gthumb/gth-image-task.c                      |   12 +----
 gthumb/gth-image-task.h                      |    1 -
 gthumb/gth-task.c                            |   69 ++++++++++++++++++++++++++
 6 files changed, 74 insertions(+), 24 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-resize.c b/extensions/file_tools/gth-file-tool-resize.c
index aaa67ed..64dc686 100644
--- a/extensions/file_tools/gth-file-tool-resize.c
+++ b/extensions/file_tools/gth-file-tool-resize.c
@@ -111,14 +111,6 @@ update_dimensione_info_label (GthFileToolResize *self,
 }
 
 
-static void
-resize_task_init (GthAsyncTask *task,
-	          gpointer      user_data)
-{
-	gth_task_progress (GTH_TASK (task), _("Resizing images"), NULL, TRUE, 0.0);
-}
-
-
 static gpointer
 resize_task_exec (GthAsyncTask *task,
 		  gpointer      user_data)
@@ -185,8 +177,8 @@ update_pixbuf_size (GthFileToolResize *self)
 
 	_cairo_clear_surface (&self->priv->new_image);
 
-	resize_task = gth_image_task_new (NULL,
-					  resize_task_init,
+	resize_task = gth_image_task_new (_("Resizing images"),
+					  NULL,
 					  resize_task_exec,
 					  resize_task_completed,
 					  self,
diff --git a/gthumb/gth-async-task.c b/gthumb/gth-async-task.c
index 4ca4963..79d5109 100644
--- a/gthumb/gth-async-task.c
+++ b/gthumb/gth-async-task.c
@@ -35,7 +35,7 @@ enum {
         PROP_THREAD_FUNC,
         PROP_AFTER_THREAD,
         PROP_USER_DATA,
-        PROP_USER_DATA_DESTROY_FUNC,
+        PROP_USER_DATA_DESTROY_FUNC
 };
 
 
diff --git a/gthumb/gth-image-list-task.c b/gthumb/gth-image-list-task.c
index ffad44f..3241094 100644
--- a/gthumb/gth-image-list-task.c
+++ b/gthumb/gth-image-list-task.c
@@ -251,7 +251,7 @@ image_task_progress_cb (GthTask    *task,
 	}
 
 	gth_task_progress (GTH_TASK (self),
-			   gth_image_task_get_description (GTH_IMAGE_TASK (task)),
+			   description,
 			   details,
 			   FALSE,
 			   total_fraction + (file_fraction / (self->priv->n_files + 1)));
diff --git a/gthumb/gth-image-task.c b/gthumb/gth-image-task.c
index effe1b0..7b4cf3d 100644
--- a/gthumb/gth-image-task.c
+++ b/gthumb/gth-image-task.c
@@ -27,7 +27,6 @@
 struct _GthImageTaskPrivate {
 	GthImage *source;
 	GthImage *destination;
-	char     *description;
 };
 
 
@@ -44,7 +43,6 @@ gth_image_task_finalize (GObject *object)
 	self = GTH_IMAGE_TASK (object);
 	_g_object_unref (self->priv->source);
 	_g_object_unref (self->priv->destination);
-	g_free (self->priv->description);
 
 	G_OBJECT_CLASS (gth_image_task_parent_class)->finalize (object);
 }
@@ -68,7 +66,6 @@ gth_image_task_init (GthImageTask *self)
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_IMAGE_TASK, GthImageTaskPrivate);
 	self->priv->source = NULL;
 	self->priv->destination = NULL;
-	self->priv->description = NULL;
 }
 
 
@@ -88,8 +85,8 @@ gth_image_task_new (const char         *description,
 					      "after-thread", after_func,
 					      "user-data", user_data,
 					      "user-data-destroy-func", user_data_destroy_func,
+					      "description", description,
 					      NULL);
-	self->priv->description = g_strdup (description);
 
 	return (GthTask *) self;
 }
@@ -141,10 +138,3 @@ gth_image_task_copy_source_to_destination (GthImageTask *self)
 	_g_object_unref (self->priv->destination);
 	self->priv->destination = gth_image_copy (self->priv->source);
 }
-
-
-const char *
-gth_image_task_get_description (GthImageTask *self)
-{
-	return self->priv->description;
-}
diff --git a/gthumb/gth-image-task.h b/gthumb/gth-image-task.h
index d06fd9f..c084f9e 100644
--- a/gthumb/gth-image-task.h
+++ b/gthumb/gth-image-task.h
@@ -63,7 +63,6 @@ void          gth_image_task_set_destination (GthImageTask       *self,
 GthImage *    gth_image_task_get_destination (GthImageTask       *self);
 void          gth_image_task_copy_source_to_destination
 					     (GthImageTask       *self);
-const char *  gth_image_task_get_description (GthImageTask       *self);
 
 G_END_DECLS
 
diff --git a/gthumb/gth-task.c b/gthumb/gth-task.c
index 261a13c..6136c19 100644
--- a/gthumb/gth-task.c
+++ b/gthumb/gth-task.c
@@ -26,6 +26,13 @@
 #include "gth-task.h"
 
 
+/* Properties */
+enum {
+        PROP_0,
+        PROP_DESCRIPTION
+};
+
+
 /* Signals */
 enum {
 	COMPLETED,
@@ -36,6 +43,7 @@ enum {
 
 struct _GthTaskPrivate
 {
+	char         *description;
 	gboolean      running;
 	GCancellable *cancellable;
 	gulong        cancellable_cancelled;
@@ -67,6 +75,8 @@ gth_task_finalize (GObject *object)
 		g_object_unref (task->priv->cancellable);
 	}
 
+	g_free (task->priv->description);
+
 	G_OBJECT_CLASS (gth_task_parent_class)->finalize (object);
 }
 
@@ -86,6 +96,48 @@ base_cancelled (GthTask *task)
 
 
 static void
+gth_task_set_property (GObject      *object,
+		       guint         property_id,
+		       const GValue *value,
+		       GParamSpec   *pspec)
+{
+	GthTask *self;
+
+	self = GTH_TASK (object);
+
+	switch (property_id) {
+	case PROP_DESCRIPTION:
+		g_free (self->priv->description);
+		self->priv->description = g_strdup (g_value_get_string (value));
+		break;
+	default:
+		break;
+	}
+}
+
+
+static void
+gth_task_get_property (GObject    *object,
+		       guint       property_id,
+		       GValue     *value,
+		       GParamSpec *pspec)
+{
+	GthTask *self;
+
+	self = GTH_TASK (object);
+
+	switch (property_id) {
+	case PROP_DESCRIPTION:
+		g_value_set_string (value, self->priv->description);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+		break;
+	}
+}
+
+
+static void
 gth_task_class_init (GthTaskClass *class)
 {
 	GObjectClass *object_class;
@@ -93,11 +145,23 @@ gth_task_class_init (GthTaskClass *class)
 	g_type_class_add_private (class, sizeof (GthTaskPrivate));
 
 	object_class = (GObjectClass*) class;
+	object_class->set_property = gth_task_set_property;
+	object_class->get_property = gth_task_get_property;
 	object_class->finalize = gth_task_finalize;
 
 	class->exec = base_exec;
 	class->cancelled = base_cancelled;
 
+	/* properties */
+
+	g_object_class_install_property (object_class,
+					 PROP_DESCRIPTION,
+					 g_param_spec_string ("description",
+							      "Description",
+							      "The task description to be displayed in the progress dialog",
+							      NULL,
+							      G_PARAM_READWRITE));
+
 	/* signals */
 
 	gth_task_signals[COMPLETED] =
@@ -146,6 +210,7 @@ gth_task_init (GthTask *self)
 	self->priv->running = FALSE;
 	self->priv->cancellable = NULL;
 	self->priv->cancellable_cancelled = 0;
+	self->priv->description = NULL;
 }
 
 
@@ -179,6 +244,10 @@ gth_task_exec (GthTask      *task,
 								   G_CALLBACK (cancellable_cancelled_cb),
 							           task,
 							           NULL);
+
+	if (task->priv->description != NULL)
+		gth_task_progress (task, task->priv->description, NULL, TRUE, 0.0);
+
 	task->priv->running = TRUE;
 	GTH_TASK_GET_CLASS (task)->exec (task);
 }



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