[gnome-color-manager] Split the calibration bits up into sections so we can add the scanner calibration bits



commit 484b9fcec0fae096bfe71c8ec7947b44ce30a0ce
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 6 14:55:32 2009 +0000

    Split the calibration bits up into sections so we can add the scanner calibration bits

 src/gcm-calibrate.c |   86 +++++++++++++++++++++++----------------
 src/gcm-calibrate.h |   11 +++--
 src/gcm-prefs.c     |  114 +++++++++++++++++++++++++++++++++++----------------
 3 files changed, 135 insertions(+), 76 deletions(-)
---
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 89e43bc..03de478 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -180,10 +180,7 @@ gcm_calibrate_setup (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
 {
 	GtkWidget *widget;
 	GcmCalibratePrivate *priv = calibrate->priv;
-	GtkWidget *dialog;
-	GtkResponseType response;
 	gboolean ret = TRUE;
-	GString *string = NULL;
 
 	/* show main UI */
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "dialog_calibrate"));
@@ -196,6 +193,34 @@ gcm_calibrate_setup (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
 	/* TRANSLATORS: dialog message */
 	gcm_calibrate_set_message (calibrate, _("Setting up hardware device for use..."));
 
+	return ret;
+}
+
+/**
+ * gcm_calibrate_debug_argv:
+ **/
+static void
+gcm_calibrate_debug_argv (const gchar *program, gchar **argv)
+{
+	gchar *join;
+	join = g_strjoinv ("  ", argv);
+	egg_debug ("running %s  %s", program, join);
+	g_free (join);
+}
+
+/**
+ * gcm_calibrate_display_setup:
+ **/
+static gboolean
+gcm_calibrate_display_setup (GcmCalibrate *calibrate, GError **error)
+{
+	gboolean ret = TRUE;
+	GtkWidget *dialog;
+	GtkResponseType response;
+	GString *string = NULL;
+	GcmCalibratePrivate *priv = calibrate->priv;
+	GtkWidget *widget;
+
 	/* this wasn't previously set */
 	if (!priv->is_lcd && !priv->is_crt) {
 		dialog = gtk_message_dialog_new (GTK_WINDOW(widget), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
@@ -270,9 +295,6 @@ gcm_calibrate_setup (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
 			goto out;
 		}
 	}
-
-	/* success */
-	ret = TRUE;
 out:
 	if (string != NULL)
 		g_string_free (string, TRUE);
@@ -280,22 +302,10 @@ out:
 }
 
 /**
- * gcm_calibrate_debug_argv:
- **/
-static void
-gcm_calibrate_debug_argv (const gchar *program, gchar **argv)
-{
-	gchar *join;
-	join = g_strjoinv ("  ", argv);
-	egg_debug ("running %s  %s", program, join);
-	g_free (join);
-}
-
-/**
- * gcm_calibrate_task_neutralise:
+ * gcm_calibrate_display_neutralise:
  **/
 static gboolean
-gcm_calibrate_task_neutralise (GcmCalibrate *calibrate, GError **error)
+gcm_calibrate_display_neutralise (GcmCalibrate *calibrate, GError **error)
 {
 	gboolean ret = FALSE;
 	GcmCalibratePrivate *priv = calibrate->priv;
@@ -437,10 +447,10 @@ gcm_calibrate_timeout_cb (GcmCalibrate *calibrate)
 }
 
 /**
- * gcm_calibrate_task_generate_patches:
+ * gcm_calibrate_display_generate_patches:
  **/
 static gboolean
-gcm_calibrate_task_generate_patches (GcmCalibrate *calibrate, GError **error)
+gcm_calibrate_display_generate_patches (GcmCalibrate *calibrate, GError **error)
 {
 	gboolean ret = TRUE;
 	GcmCalibratePrivate *priv = calibrate->priv;
@@ -492,10 +502,10 @@ out:
 }
 
 /**
- * gcm_calibrate_task_draw_and_measure:
+ * gcm_calibrate_display_draw_and_measure:
  **/
 static gboolean
-gcm_calibrate_task_draw_and_measure (GcmCalibrate *calibrate, GError **error)
+gcm_calibrate_display_draw_and_measure (GcmCalibrate *calibrate, GError **error)
 {
 	gboolean ret = TRUE;
 	GcmCalibratePrivate *priv = calibrate->priv;
@@ -553,10 +563,10 @@ out:
 }
 
 /**
- * gcm_calibrate_task_generate_profile:
+ * gcm_calibrate_display_generate_profile:
  **/
 static gboolean
-gcm_calibrate_task_generate_profile (GcmCalibrate *calibrate, GError **error)
+gcm_calibrate_display_generate_profile (GcmCalibrate *calibrate, GError **error)
 {
 	gboolean ret = TRUE;
 	GcmCalibratePrivate *priv = calibrate->priv;
@@ -654,7 +664,7 @@ out:
 }
 
 /**
- * gcm_calibrate_task:
+ * gcm_calibrate_display:
  **/
 gboolean
 gcm_calibrate_task (GcmCalibrate *calibrate, GcmCalibrateTask task, GError **error)
@@ -664,20 +674,24 @@ gcm_calibrate_task (GcmCalibrate *calibrate, GcmCalibrateTask task, GError **err
 	g_return_val_if_fail (GCM_IS_CALIBRATE (calibrate), FALSE);
 
 	/* each option */
-	if (task == GCM_CALIBRATE_TASK_NEUTRALISE) {
-		ret = gcm_calibrate_task_neutralise (calibrate, error);
+	if (task == GCM_CALIBRATE_TASK_DISPLAY_SETUP) {
+		ret = gcm_calibrate_display_setup (calibrate, error);
+		goto out;
+	}
+	if (task == GCM_CALIBRATE_TASK_DISPLAY_NEUTRALISE) {
+		ret = gcm_calibrate_display_neutralise (calibrate, error);
 		goto out;
 	}
-	if (task == GCM_CALIBRATE_TASK_GENERATE_PATCHES) {
-		ret = gcm_calibrate_task_generate_patches (calibrate, error);
+	if (task == GCM_CALIBRATE_TASK_DISPLAY_GENERATE_PATCHES) {
+		ret = gcm_calibrate_display_generate_patches (calibrate, error);
 		goto out;
 	}
-	if (task == GCM_CALIBRATE_TASK_DRAW_AND_MEASURE) {
-		ret = gcm_calibrate_task_draw_and_measure (calibrate, error);
+	if (task == GCM_CALIBRATE_TASK_DISPLAY_DRAW_AND_MEASURE) {
+		ret = gcm_calibrate_display_draw_and_measure (calibrate, error);
 		goto out;
 	}
-	if (task == GCM_CALIBRATE_TASK_GENERATE_PROFILE) {
-		ret = gcm_calibrate_task_generate_profile (calibrate, error);
+	if (task == GCM_CALIBRATE_TASK_DISPLAY_GENERATE_PROFILE) {
+		ret = gcm_calibrate_display_generate_profile (calibrate, error);
 		goto out;
 	}
 out:
@@ -905,6 +919,7 @@ gcm_calibrate_init (GcmCalibrate *calibrate)
 	if (retval == 0) {
 		egg_warning ("failed to load ui: %s", error->message);
 		g_error_free (error);
+		return;
 	}
 
 	/* get screen */
@@ -912,6 +927,7 @@ gcm_calibrate_init (GcmCalibrate *calibrate)
 	if (calibrate->priv->rr_screen == NULL) {
 		egg_warning ("failed to get rr screen: %s", error->message);
 		g_error_free (error);
+		return;
 	}
 
 	/* get edid parser */
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index c663cee..5209ff5 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -55,11 +55,12 @@ struct _GcmCalibrateClass
 };
 
 typedef enum {
-	GCM_CALIBRATE_TASK_NEUTRALISE,
-	GCM_CALIBRATE_TASK_GENERATE_PATCHES,
-	GCM_CALIBRATE_TASK_DRAW_AND_MEASURE,
-	GCM_CALIBRATE_TASK_GENERATE_PROFILE,
-	GCM_CALIBRATE_TASK_UNKNOWN,
+	GCM_CALIBRATE_TASK_DISPLAY_SETUP,
+	GCM_CALIBRATE_TASK_DISPLAY_NEUTRALISE,
+	GCM_CALIBRATE_TASK_DISPLAY_GENERATE_PATCHES,
+	GCM_CALIBRATE_TASK_DISPLAY_DRAW_AND_MEASURE,
+	GCM_CALIBRATE_TASK_DISPLAY_GENERATE_PROFILE,
+	GCM_CALIBRATE_TASK_DISPLAY_UNKNOWN,
 } GcmCalibrateTask;
 
 GType		 gcm_calibrate_get_type		  	(void);
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index e5408c7..bce81bc 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -81,21 +81,15 @@ gcm_prefs_help_cb (GtkWidget *widget, gpointer data)
 }
 
 /**
- * gcm_prefs_calibrate_cb:
+ * gcm_prefs_calibrate_display:
  **/
 static void
-gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
+gcm_prefs_calibrate_display (GcmCalibrate *calib)
 {
-	GcmCalibrate *calib = NULL;
 	GcmBrightness *brightness = NULL;
 	gboolean ret;
 	GError *error = NULL;
-	GtkWindow *window;
 	gchar *output_name = NULL;
-	const gchar *name;
-	gchar *filename = NULL;
-	gchar *destination = NULL;
-	guint i;
 	guint percentage = G_MAXUINT;
 
 	/* get the device */
@@ -108,7 +102,6 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* create new calibration and brightness objects */
-	calib = gcm_calibrate_new ();
 	brightness = gcm_brightness_new ();
 
 	/* set the proper output name */
@@ -116,15 +109,6 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 		      "output-name", output_name,
 		      NULL);
 
-	/* run each task in order */
-	window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_prefs"));
-	ret = gcm_calibrate_setup (calib, window, &error);
-	if (!ret) {
-		egg_warning ("failed to setup: %s", error->message);
-		g_error_free (error);
-		goto finish_calibrate;
-	}
-
 	/* if we are an internal LCD, we need to set the brightness to maximum */
 	ret = gcm_utils_output_is_lcd_internal (output_name);
 	if (ret) {
@@ -148,7 +132,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* step 1 */
-	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_NEUTRALISE, &error);
+	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_DISPLAY_NEUTRALISE, &error);
 	if (!ret) {
 		egg_warning ("failed to calibrate: %s", error->message);
 		g_error_free (error);
@@ -156,7 +140,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* step 2 */
-	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_GENERATE_PATCHES, &error);
+	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_DISPLAY_GENERATE_PATCHES, &error);
 	if (!ret) {
 		egg_warning ("failed to calibrate: %s", error->message);
 		g_error_free (error);
@@ -164,7 +148,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* step 3 */
-	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_DRAW_AND_MEASURE, &error);
+	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_DISPLAY_DRAW_AND_MEASURE, &error);
 	if (!ret) {
 		egg_warning ("failed to calibrate: %s", error->message);
 		g_error_free (error);
@@ -172,7 +156,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* step 4 */
-	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_GENERATE_PROFILE, &error);
+	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_DISPLAY_GENERATE_PROFILE, &error);
 	if (!ret) {
 		egg_warning ("failed to calibrate: %s", error->message);
 		g_error_free (error);
@@ -180,6 +164,14 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 finish_calibrate:
+	/* need to set the gamma back to the default after calibration */
+	error = NULL;
+	ret = gcm_utils_set_gamma_for_device (current_device, &error);
+	if (!ret) {
+		egg_warning ("failed to set output gamma: %s", error->message);
+		g_error_free (error);
+	}
+
 	/* restore brightness */
 	if (percentage != G_MAXUINT) {
 		/* set the new brightness */
@@ -191,8 +183,69 @@ finish_calibrate:
 			error = NULL;
 		}
 	}
+out:
+	if (brightness != NULL)
+		g_object_unref (brightness);
+	g_free (output_name);
+}
 
-	/* step 4 */
+/**
+ * gcm_prefs_calibrate_scanner:
+ **/
+static void
+gcm_prefs_calibrate_scanner (GcmCalibrate *calib)
+{
+	// TODO: add something!
+}
+
+/**
+ * gcm_prefs_calibrate_cb:
+ **/
+static void
+gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
+{
+	GcmCalibrate *calib = NULL;
+	GcmDeviceType type;
+	gboolean ret;
+	GError *error = NULL;
+	GtkWindow *window;
+	gchar *filename = NULL;
+	guint i;
+	const gchar *name;
+	gchar *destination = NULL;
+
+	/* get the type */
+	g_object_get (current_device,
+		      "type", &type,
+		      NULL);
+
+	/* create new calibration object */
+	calib = gcm_calibrate_new ();
+
+	/* run each task in order */
+	window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_prefs"));
+	ret = gcm_calibrate_setup (calib, window, &error);
+	if (!ret) {
+		egg_warning ("failed to setup: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* choose the correct type of calibration */
+	switch (type) {
+	case GCM_DEVICE_TYPE_DISPLAY:
+		gcm_prefs_calibrate_display (calib);
+		break;
+	case GCM_DEVICE_TYPE_SCANNER:
+	case GCM_DEVICE_TYPE_CAMERA:
+		gcm_prefs_calibrate_scanner (calib);
+		break;
+	default:
+		egg_error ("calibration not supported for this device");
+		goto out;
+	}
+
+	/* finish */
 	filename = gcm_calibrate_finish (calib, &error);
 	if (filename == NULL) {
 		egg_warning ("failed to finish calibrate: %s", error->message);
@@ -231,22 +284,11 @@ finish_calibrate:
 
 	/* remove temporary file */
 	g_unlink (filename);
-
 out:
-	if (calib != NULL)
-		g_object_unref (calib);
-	if (brightness != NULL)
-		g_object_unref (brightness);
-
-	/* need to set the gamma back to the default after calibration */
-	ret = gcm_utils_set_gamma_for_device (current_device, &error);
-	if (!ret) {
-		egg_warning ("failed to set output gamma: %s", error->message);
-		g_error_free (error);
-	}
 	g_free (filename);
 	g_free (destination);
-	g_free (output_name);
+	if (calib != NULL)
+		g_object_unref (calib);
 }
 
 /**



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