[gnome-color-manager] Support spotreading in GcmCalibrate



commit bf1cfb0ae851512fd3f101b7a5b6afce7d7a5f12
Author: Richard Hughes <richard hughsie com>
Date:   Fri Apr 23 10:52:56 2010 +0100

    Support spotreading in GcmCalibrate

 src/gcm-calibrate-argyll.c |  135 +++++++++++++++++++++++++++++++++++++++++++-
 src/gcm-calibrate.c        |   30 ++++++++++
 src/gcm-calibrate.h        |    6 ++
 3 files changed, 168 insertions(+), 3 deletions(-)
---
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index 94d694d..8163e19 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -1379,6 +1379,134 @@ out:
 }
 
 /**
+ * gcm_calibrate_argyll_spotread_read_chart:
+ **/
+static gboolean
+gcm_calibrate_argyll_spotread_read_chart (GcmCalibrateArgyll *calibrate_argyll, GError **error)
+{
+	gboolean ret = TRUE;
+	GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+	gchar *command = NULL;
+	gchar **argv = NULL;
+	GPtrArray *array = NULL;
+	gchar *basename = NULL;
+	gchar *working_path = NULL;
+	const gchar *title;
+	const gchar *message;
+
+	/* get shared data */
+	g_object_get (calibrate_argyll,
+		      "basename", &basename,
+		      "working-path", &working_path,
+		      NULL);
+
+	/* get correct name of the command */
+	command = gcm_calibrate_argyll_get_tool_filename ("spotread", error);
+	if (command == NULL) {
+		ret = FALSE;
+		goto out;
+	}
+
+	/* TRANSLATORS: title, patches are specific colours used in calibration */
+	title = _("Reading the patches");
+	/* TRANSLATORS: dialog message */
+	message = _("Reading the patches using the color measuring instrument.");
+
+	/* push new messages into the UI */
+	gcm_calibrate_dialog_show (priv->calibrate_dialog, GCM_CALIBRATE_DIALOG_TAB_GENERIC, title, message);
+	gcm_calibrate_dialog_set_show_button_ok (priv->calibrate_dialog, FALSE);
+	gcm_calibrate_dialog_set_show_expander (priv->calibrate_dialog, TRUE);
+
+	/* argument array */
+	array = g_ptr_array_new_with_free_func (g_free);
+
+	/* setup the command */
+	g_ptr_array_add (array, g_strdup ("-v9"));
+	if (priv->done_calibrate)
+		g_ptr_array_add (array, g_strdup ("-N"));
+	g_ptr_array_add (array, g_strdup (basename));
+	argv = gcm_utils_ptr_array_to_strv (array);
+	gcm_calibrate_argyll_debug_argv (command, argv);
+
+	/* start up the command */
+	priv->state = GCM_CALIBRATE_ARGYLL_STATE_RUNNING;
+	vte_terminal_reset (VTE_TERMINAL(priv->terminal), TRUE, FALSE);
+	priv->child_pid = vte_terminal_fork_command (VTE_TERMINAL(priv->terminal), command, argv, NULL, working_path, FALSE, FALSE, FALSE);
+
+	/* wait until finished */
+	g_main_loop_run (priv->loop);
+
+	/* get result */
+	if (priv->response == GTK_RESPONSE_CANCEL) {
+		g_set_error_literal (error,
+				     GCM_CALIBRATE_ERROR,
+				     GCM_CALIBRATE_ERROR_USER_ABORT,
+				     "calibration was cancelled");
+		ret = FALSE;
+		goto out;
+	}
+	if (priv->response == GTK_RESPONSE_REJECT) {
+		gchar *vte_text;
+		vte_text = vte_terminal_get_text (VTE_TERMINAL(priv->terminal), NULL, NULL, NULL);
+		g_set_error (error,
+			     GCM_CALIBRATE_ERROR,
+			     GCM_CALIBRATE_ERROR_INTERNAL,
+			     "command failed to run successfully: %s", vte_text);
+		g_free (vte_text);
+		ret = FALSE;
+		goto out;
+	}
+out:
+	if (array != NULL)
+		g_ptr_array_unref (array);
+	g_free (working_path);
+	g_free (basename);
+	g_free (command);
+	g_strfreev (argv);
+	return ret;
+}
+
+/**
+ * gcm_calibrate_argyll_spotread:
+ **/
+static gboolean
+gcm_calibrate_argyll_spotread (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
+{
+	GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL(calibrate);
+	GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+	gboolean ret;
+	const gchar *title;
+	const gchar *message;
+
+	/* set modal windows up correctly */
+	gcm_calibrate_dialog_set_move_window (priv->calibrate_dialog, TRUE);
+	gcm_calibrate_dialog_set_window (priv->calibrate_dialog, window);
+
+	/* TRANSLATORS: title, color spot is the color we are trying to measure */
+	title = _("Sampling the color spot");
+
+	/* TRANSLATORS: dialog message */
+	message = _("Setting up display device for useâ?¦");
+
+	/* push new messages into the UI */
+	gcm_calibrate_dialog_show (priv->calibrate_dialog, GCM_CALIBRATE_DIALOG_TAB_GENERIC, title, message);
+	gcm_calibrate_dialog_set_show_button_ok (priv->calibrate_dialog, FALSE);
+	gcm_calibrate_dialog_set_show_expander (priv->calibrate_dialog, FALSE);
+
+	/* step 3 */
+	ret = gcm_calibrate_argyll_spotread_read_chart (calibrate_argyll, error);
+	if (!ret)
+		goto out;
+
+	/* step 5 */
+	ret = gcm_calibrate_argyll_remove_temp_files (calibrate_argyll, error);
+	if (!ret)
+		goto out;
+out:
+	return ret;
+}
+
+/**
  * gcm_calibrate_argyll_get_colorimeter_target:
  **/
 static const gchar *
@@ -2188,6 +2316,9 @@ gcm_calibrate_argyll_interaction_calibrate (GcmCalibrateArgyll *calibrate_argyll
 	/* assume it's no longer on the window */
 	priv->already_on_window = FALSE;
 
+	/* assume it was done correctly */
+	priv->done_calibrate = TRUE;
+
 	/* set state */
 	priv->argyllcms_ok = " ";
 	priv->state = GCM_CALIBRATE_ARGYLL_STATE_WAITING_FOR_STDIN;
@@ -2240,9 +2371,6 @@ gcm_calibrate_argyll_interaction_surface (GcmCalibrateArgyll *calibrate_argyll)
 	/* assume it's no longer on the window */
 	priv->already_on_window = FALSE;
 
-	/* assume it was done correctly */
-	priv->done_calibrate = TRUE;
-
 	/* set state */
 	priv->argyllcms_ok = " ";
 	priv->state = GCM_CALIBRATE_ARGYLL_STATE_WAITING_FOR_STDIN;
@@ -2696,6 +2824,7 @@ gcm_calibrate_argyll_class_init (GcmCalibrateArgyllClass *klass)
 	parent_class->calibrate_display = gcm_calibrate_argyll_display;
 	parent_class->calibrate_device = gcm_calibrate_argyll_device;
 	parent_class->calibrate_printer = gcm_calibrate_argyll_printer;
+	parent_class->calibrate_spotread = gcm_calibrate_argyll_spotread;
 
 	g_type_class_add_private (klass, sizeof (GcmCalibrateArgyllPrivate));
 }
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 1162c7e..508978c 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -508,6 +508,36 @@ out:
 }
 
 /**
+ * gcm_calibrate_spotread:
+ **/
+gboolean
+gcm_calibrate_spotread (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
+{
+	GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
+	gboolean ret;
+
+	/* set the per-profile filename */
+	ret = gcm_calibrate_set_working_path (calibrate, error);
+	if (!ret)
+		goto out;
+
+	/* coldplug source */
+	if (klass->calibrate_spotread == NULL) {
+		ret = FALSE;
+		g_set_error_literal (error,
+				     GCM_CALIBRATE_ERROR,
+				     GCM_CALIBRATE_ERROR_INTERNAL,
+				     "no klass support");
+		goto out;
+	}
+
+	/* proxy */
+	ret = klass->calibrate_spotread (calibrate, window, error);
+out:
+	return ret;
+}
+
+/**
  * gcm_calibrate_display:
  **/
 gboolean
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index 7bf8bca..11791de 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -58,6 +58,9 @@ struct _GcmCalibrateClass
 	gboolean	 (*calibrate_printer)		(GcmCalibrate	*calibrate,
 							 GtkWindow	*window,
 							 GError		**error);
+	gboolean	 (*calibrate_spotread)		(GcmCalibrate	*calibrate,
+							 GtkWindow	*window,
+							 GError		**error);
 	/* padding for future expansion */
 	void (*_gcm_reserved1) (void);
 	void (*_gcm_reserved2) (void);
@@ -123,6 +126,9 @@ gboolean	 gcm_calibrate_device			(GcmCalibrate	*calibrate,
 gboolean	 gcm_calibrate_printer			(GcmCalibrate	*calibrate,
 							 GtkWindow	*window,
 							 GError		**error);
+gboolean	 gcm_calibrate_spotread			(GcmCalibrate	*calibrate,
+							 GtkWindow	*window,
+							 GError		**error);
 gboolean	 gcm_calibrate_set_from_device		(GcmCalibrate	*calibrate,
 							 GcmDevice	*device,
 							 GError		**error);



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