[gnome-color-manager] Allow the user to choose the calibration precision using an interactive dialog



commit c3867ffbc3ed03865a764cb688a9203d24e11f58
Author: Richard Hughes <richard hughsie com>
Date:   Tue Mar 2 11:24:19 2010 +0000

    Allow the user to choose the calibration precision using an interactive dialog
    
    Note, this is only shown if 'ask' is the value of /apps/gnome-color-manager/calibration_length in GConf

 data/gcm-calibrate.ui               |  141 +++++++++++++++++++++++++++++++++++
 data/gnome-color-manager.schemas.in |    3 +-
 src/gcm-calibrate-argyll.c          |   72 ++++++------------
 src/gcm-calibrate-dialog.c          |   55 ++++++++++++++
 src/gcm-calibrate-dialog.h          |    1 +
 src/gcm-calibrate.c                 |  106 ++++++++++++++++++++++++++
 src/gcm-calibrate.h                 |    7 ++
 7 files changed, 334 insertions(+), 51 deletions(-)
---
diff --git a/data/gcm-calibrate.ui b/data/gcm-calibrate.ui
index f09e0ed..f79c110 100644
--- a/data/gcm-calibrate.ui
+++ b/data/gcm-calibrate.ui
@@ -713,6 +713,147 @@
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkVBox" id="vbox_precision">
+                            <property name="visible">True</property>
+                            <property name="border_width">9</property>
+                            <property name="orientation">vertical</property>
+                            <child>
+                              <object class="GtkHBox" id="hbox3">
+                                <property name="visible">True</property>
+                                <property name="spacing">6</property>
+                                <property name="homogeneous">True</property>
+                                <child>
+                                  <object class="GtkButton" id="button_precision_short">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <child>
+                                      <object class="GtkVBox" id="vbox10">
+                                        <property name="visible">True</property>
+                                        <property name="orientation">vertical</property>
+                                        <property name="spacing">6</property>
+                                        <child>
+                                          <object class="GtkImage" id="image7">
+                                            <property name="visible">True</property>
+                                            <property name="pixel_size">150</property>
+                                            <property name="icon_name">calibration-short</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label22">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes" comments="The length of the translation">Short</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkButton" id="button_precision_normal">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <child>
+                                      <object class="GtkVBox" id="vbox11">
+                                        <property name="visible">True</property>
+                                        <property name="orientation">vertical</property>
+                                        <property name="spacing">6</property>
+                                        <child>
+                                          <object class="GtkImage" id="image8">
+                                            <property name="visible">True</property>
+                                            <property name="pixel_size">150</property>
+                                            <property name="icon_name">calibration-normal</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label23">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes" comments="The length of the translation">Normal</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkButton" id="button_precision_long">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <child>
+                                      <object class="GtkVBox" id="vbox12">
+                                        <property name="visible">True</property>
+                                        <property name="orientation">vertical</property>
+                                        <property name="spacing">6</property>
+                                        <child>
+                                          <object class="GtkImage" id="image9">
+                                            <property name="visible">True</property>
+                                            <property name="pixel_size">150</property>
+                                            <property name="icon_name">calibration-long</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label24">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes" comments="The length of the translation">Long</property>
+                                          </object>
+                                          <packing>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">5</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <object class="GtkLabel" id="label21">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">precision</property>
+                          </object>
+                          <packing>
+                            <property name="position">5</property>
+                            <property name="tab_fill">False</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
diff --git a/data/gnome-color-manager.schemas.in b/data/gnome-color-manager.schemas.in
index 9fbca01..3285a0a 100644
--- a/data/gnome-color-manager.schemas.in
+++ b/data/gnome-color-manager.schemas.in
@@ -133,7 +133,7 @@
       <applyto>/apps/gnome-color-manager/calibration_length</applyto>
       <owner>gnome-color-manager</owner>
       <type>string</type>
-      <default>short</default>
+      <default>ask</default>
       <locale name="C">
         <short>The default calibration length.</short>
         <long>
@@ -141,6 +141,7 @@
           The option 'short' creates a quick profile, 'normal' a regular one,
           and 'long' takes a really long time, but is more precise and creates
           a better profile.
+          Use 'ask' if the want the user to choose.
         </long>
       </locale>
     </schema>
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index e71b78c..b4c288e 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -36,7 +36,6 @@
 #include <stdlib.h>
 #include <gtk/gtk.h>
 #include <vte/vte.h>
-#include <gconf/gconf-client.h>
 #include <canberra-gtk.h>
 
 #include "gcm-calibrate-argyll.h"
@@ -53,13 +52,6 @@ static void     gcm_calibrate_argyll_finalize	(GObject     *object);
 #define GCM_CALIBRATE_ARGYLL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_CALIBRATE_ARGYLL, GcmCalibrateArgyllPrivate))
 
 typedef enum {
-	GCM_CALIBRATE_ARGYLL_PRECISION_SHORT,
-	GCM_CALIBRATE_ARGYLL_PRECISION_NORMAL,
-	GCM_CALIBRATE_ARGYLL_PRECISION_LONG,
-	GCM_CALIBRATE_ARGYLL_PRECISION_LAST
-} GcmCalibrateArgyllPrecision;
-
-typedef enum {
 	GCM_CALIBRATE_ARGYLL_STATE_IDLE,
 	GCM_CALIBRATE_ARGYLL_STATE_WAITING_FOR_STDIN,
 	GCM_CALIBRATE_ARGYLL_STATE_WAITING_FOR_LOOP,
@@ -75,8 +67,6 @@ typedef enum {
 struct _GcmCalibrateArgyllPrivate
 {
 	guint				 display;
-	GConfClient			*gconf_client;
-	GcmCalibrateArgyllPrecision	 precision;
 	GMainLoop			*loop;
 	GtkWidget			*terminal;
 	GcmCalibrateDialog		*calibrate_dialog;
@@ -99,33 +89,18 @@ enum {
 G_DEFINE_TYPE (GcmCalibrateArgyll, gcm_calibrate_argyll, GCM_TYPE_CALIBRATE)
 
 /**
- * gcm_calibrate_argyll_precision_from_string:
- **/
-static GcmCalibrateArgyllPrecision
-gcm_calibrate_argyll_precision_from_string (const gchar *string)
-{
-	if (g_strcmp0 (string, "short") == 0)
-		return GCM_CALIBRATE_ARGYLL_PRECISION_SHORT;
-	if (g_strcmp0 (string, "normal") == 0)
-		return GCM_CALIBRATE_ARGYLL_PRECISION_NORMAL;
-	if (g_strcmp0 (string, "long") == 0)
-		return GCM_CALIBRATE_ARGYLL_PRECISION_LONG;
-	egg_warning ("failed to convert to precision: %s", string);
-	return GCM_CALIBRATE_ARGYLL_PRECISION_NORMAL;
-}
-
-/**
  * gcm_calibrate_argyll_get_quality_arg:
  **/
 static const gchar *
 gcm_calibrate_argyll_get_quality_arg (GcmCalibrateArgyll *calibrate_argyll)
 {
-	GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
 	GcmCalibrateReferenceKind reference_kind;
+	GcmCalibratePrecision precision;
 
 	/* get kind */
 	g_object_get (calibrate_argyll,
 		      "reference-kind", &reference_kind,
+		      "precision", &precision,
 		      NULL);
 
 	/* these have such low patch count, we only can do low quality */
@@ -134,11 +109,11 @@ gcm_calibrate_argyll_get_quality_arg (GcmCalibrateArgyll *calibrate_argyll)
 		return "-ql";
 
 	/* get the default precision */
-	if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_SHORT)
+	if (precision == GCM_CALIBRATE_PRECISION_SHORT)
 		return "-ql";
-	if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_NORMAL)
+	if (precision == GCM_CALIBRATE_PRECISION_NORMAL)
 		return "-qm";
-	if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_LONG)
+	if (precision == GCM_CALIBRATE_PRECISION_LONG)
 		return "-qh";
 	return "-qm";
 }
@@ -150,13 +125,18 @@ static guint
 gcm_calibrate_argyll_display_get_patches (GcmCalibrateArgyll *calibrate_argyll)
 {
 	guint patches = 250;
-	GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+	GcmCalibratePrecision precision;
 
-	if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_SHORT)
+	/* get kind */
+	g_object_get (calibrate_argyll,
+		      "precision", &precision,
+		      NULL);
+
+	if (precision == GCM_CALIBRATE_PRECISION_SHORT)
 		patches = 100;
-	else if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_NORMAL)
+	else if (precision == GCM_CALIBRATE_PRECISION_NORMAL)
 		patches = 250;
-	else if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_LONG)
+	else if (precision == GCM_CALIBRATE_PRECISION_LONG)
 		patches = 500;
 	return patches;
 }
@@ -169,16 +149,19 @@ gcm_calibrate_argyll_printer_get_patches (GcmCalibrateArgyll *calibrate_argyll)
 {
 	guint patches = 180;
 	GcmColorimeterKind colorimeter_kind;
-	GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+	GcmCalibratePrecision precision;
 
 	/* we care about the type */
-	g_object_get (calibrate_argyll, "colorimeter-kind", &colorimeter_kind, NULL);
+	g_object_get (calibrate_argyll,
+		      "colorimeter-kind", &colorimeter_kind,
+		      "precision", &precision,
+		      NULL);
 
-	if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_SHORT)
+	if (precision == GCM_CALIBRATE_PRECISION_SHORT)
 		patches = 90;
-	else if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_NORMAL)
+	else if (precision == GCM_CALIBRATE_PRECISION_NORMAL)
 		patches = 180;
-	else if (priv->precision == GCM_CALIBRATE_ARGYLL_PRECISION_LONG)
+	else if (precision == GCM_CALIBRATE_PRECISION_LONG)
 		patches = 360;
 
 	/* using double density, so we can double the patch count */
@@ -2639,8 +2622,6 @@ gcm_calibrate_argyll_class_init (GcmCalibrateArgyllClass *klass)
 static void
 gcm_calibrate_argyll_init (GcmCalibrateArgyll *calibrate_argyll)
 {
-	gchar *precision;
-
 	calibrate_argyll->priv = GCM_CALIBRATE_ARGYLL_GET_PRIVATE (calibrate_argyll);
 	calibrate_argyll->priv->child_pid = -1;
 	calibrate_argyll->priv->loop = g_main_loop_new (NULL, FALSE);
@@ -2655,9 +2636,6 @@ gcm_calibrate_argyll_init (GcmCalibrateArgyll *calibrate_argyll)
 	g_signal_connect (calibrate_argyll->priv->calibrate_dialog, "response",
 			  G_CALLBACK (gcm_calibrate_argyll_response_cb), calibrate_argyll);
 
-	/* use GConf to get defaults */
-	calibrate_argyll->priv->gconf_client = gconf_client_get_default ();
-
 	/* get screen */
 	calibrate_argyll->priv->screen = gcm_screen_new ();
 
@@ -2670,11 +2648,6 @@ gcm_calibrate_argyll_init (GcmCalibrateArgyll *calibrate_argyll)
 			  G_CALLBACK (gcm_calibrate_argyll_cursor_moved_cb), calibrate_argyll);
 	gcm_calibrate_dialog_pack_details (calibrate_argyll->priv->calibrate_dialog,
 					   calibrate_argyll->priv->terminal);
-
-	/* get default precision */
-	precision = gconf_client_get_string (calibrate_argyll->priv->gconf_client, GCM_SETTINGS_CALIBRATION_LENGTH, NULL);
-	calibrate_argyll->priv->precision = gcm_calibrate_argyll_precision_from_string (precision);
-	g_free (precision);
 }
 
 /**
@@ -2700,7 +2673,6 @@ gcm_calibrate_argyll_finalize (GObject *object)
 
 	g_main_loop_unref (priv->loop);
 	g_object_unref (priv->screen);
-	g_object_unref (priv->gconf_client);
 	g_object_unref (priv->calibrate_dialog);
 	g_object_unref (priv->print);
 
diff --git a/src/gcm-calibrate-dialog.c b/src/gcm-calibrate-dialog.c
index 1f54e06..3ae69c2 100644
--- a/src/gcm-calibrate-dialog.c
+++ b/src/gcm-calibrate-dialog.c
@@ -54,6 +54,7 @@ struct _GcmCalibrateDialogPrivate
 	GcmCalibrateDeviceKind		 device_kind;
 	GcmCalibratePrintKind		 print_kind;
 	GcmCalibrateReferenceKind	 reference_kind;
+	GcmCalibratePrecision		 precision;
 	GtkResponseType			 response;
 	GMainLoop			*loop;
 	gboolean			 move_window;
@@ -69,6 +70,7 @@ enum {
 	PROP_DEVICE_KIND,
 	PROP_PRINT_KIND,
 	PROP_REFERENCE_KIND,
+	PROP_PRECISION,
 	PROP_LAST
 };
 
@@ -160,6 +162,36 @@ gcm_calibrate_dialog_button_clicked_print_analyze_cb (GtkWidget *widget, GcmCali
 }
 
 /**
+ * gcm_calibrate_dialog_button_clicked_precision_short_cb:
+ **/
+static void
+gcm_calibrate_dialog_button_clicked_precision_short_cb (GtkWidget *widget, GcmCalibrateDialog *calibrate_dialog)
+{
+	calibrate_dialog->priv->precision = GCM_CALIBRATE_PRECISION_SHORT;
+	gcm_calibrate_dialog_emit_response (calibrate_dialog, GTK_RESPONSE_OK);
+}
+
+/**
+ * gcm_calibrate_dialog_button_clicked_precision_normal_cb:
+ **/
+static void
+gcm_calibrate_dialog_button_clicked_precision_normal_cb (GtkWidget *widget, GcmCalibrateDialog *calibrate_dialog)
+{
+	calibrate_dialog->priv->precision = GCM_CALIBRATE_PRECISION_NORMAL;
+	gcm_calibrate_dialog_emit_response (calibrate_dialog, GTK_RESPONSE_OK);
+}
+
+/**
+ * gcm_calibrate_dialog_button_clicked_precision_long_cb:
+ **/
+static void
+gcm_calibrate_dialog_button_clicked_precision_long_cb (GtkWidget *widget, GcmCalibrateDialog *calibrate_dialog)
+{
+	calibrate_dialog->priv->precision = GCM_CALIBRATE_PRECISION_LONG;
+	gcm_calibrate_dialog_emit_response (calibrate_dialog, GTK_RESPONSE_OK);
+}
+
+/**
  * gcm_calibrate_dialog_button_clicked_ok_cb:
  **/
 static void
@@ -331,6 +363,8 @@ gcm_calibrate_dialog_show (GcmCalibrateDialog		*calibrate_dialog,
 	gtk_widget_set_visible (widget, (tab == GCM_CALIBRATE_DIALOG_TAB_GENERIC));
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "vbox_print_mode"));
 	gtk_widget_set_visible (widget, (tab == GCM_CALIBRATE_DIALOG_TAB_PRINT_MODE));
+	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "vbox_precision"));
+	gtk_widget_set_visible (widget, (tab == GCM_CALIBRATE_DIALOG_TAB_PRECISION));
 
 	/* reset */
 	gcm_calibrate_dialog_set_image_filename (calibrate_dialog, NULL);
@@ -624,6 +658,9 @@ gcm_calibrate_dialog_get_property (GObject *object, guint prop_id, GValue *value
 	case PROP_PRINT_KIND:
 		g_value_set_uint (value, priv->print_kind);
 		break;
+	case PROP_PRECISION:
+		g_value_set_uint (value, priv->precision);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -680,6 +717,14 @@ gcm_calibrate_dialog_class_init (GcmCalibrateDialogClass *klass)
 	g_object_class_install_property (object_class, PROP_PRINT_KIND, pspec);
 
 	/**
+	 * GcmCalibrateDialog:precision:
+	 */
+	pspec = g_param_spec_uint ("precision", NULL, NULL,
+				   0, G_MAXUINT, 0,
+				   G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_PRECISION, pspec);
+
+	/**
 	 * GcmCalibrateDialog::response:
 	 **/
 	signals[SIGNAL_RESPONSE] =
@@ -708,6 +753,7 @@ gcm_calibrate_dialog_init (GcmCalibrateDialog *calibrate_dialog)
 	calibrate_dialog->priv->device_kind = GCM_CALIBRATE_DEVICE_KIND_UNKNOWN;
 	calibrate_dialog->priv->print_kind = GCM_CALIBRATE_PRINT_KIND_UNKNOWN;
 	calibrate_dialog->priv->reference_kind = GCM_CALIBRATE_REFERENCE_KIND_UNKNOWN;
+	calibrate_dialog->priv->precision = GCM_CALIBRATE_PRECISION_UNKNOWN;
 	calibrate_dialog->priv->move_window = FALSE;
 	calibrate_dialog->priv->loop = g_main_loop_new (NULL, FALSE);
 	calibrate_dialog->priv->cached_dialogs = g_ptr_array_new_with_free_func ((GDestroyNotify)gcm_calibrate_dialog_dialog_free);
@@ -747,6 +793,15 @@ gcm_calibrate_dialog_init (GcmCalibrateDialog *calibrate_dialog)
 	widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_print_analyze"));
 	g_signal_connect (widget, "clicked",
 			  G_CALLBACK (gcm_calibrate_dialog_button_clicked_print_analyze_cb), calibrate_dialog);
+	widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_precision_short"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_calibrate_dialog_button_clicked_precision_short_cb), calibrate_dialog);
+	widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_precision_normal"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_calibrate_dialog_button_clicked_precision_normal_cb), calibrate_dialog);
+	widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "button_precision_long"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_calibrate_dialog_button_clicked_precision_long_cb), calibrate_dialog);
 
 	widget = GTK_WIDGET (gtk_builder_get_object (calibrate_dialog->priv->builder, "image_target"));
 	gtk_widget_set_size_request (widget, 200, 140);
diff --git a/src/gcm-calibrate-dialog.h b/src/gcm-calibrate-dialog.h
index 8787548..088e4e3 100644
--- a/src/gcm-calibrate-dialog.h
+++ b/src/gcm-calibrate-dialog.h
@@ -59,6 +59,7 @@ typedef enum {
 	GCM_CALIBRATE_DIALOG_TAB_MANUAL,
 	GCM_CALIBRATE_DIALOG_TAB_GENERIC,
 	GCM_CALIBRATE_DIALOG_TAB_PRINT_MODE,
+	GCM_CALIBRATE_DIALOG_TAB_PRECISION,
 	GCM_CALIBRATE_DIALOG_TAB_LAST
 } GcmCalibrateDialogTab;
 
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 44f866c..ff49c0f 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -32,6 +32,7 @@
 #include <gtk/gtk.h>
 #include <tiff.h>
 #include <tiffio.h>
+#include <gconf/gconf-client.h>
 
 #include "gcm-calibrate.h"
 #include "gcm-utils.h"
@@ -56,6 +57,7 @@ struct _GcmCalibratePrivate
 	GcmCalibrateReferenceKind	 reference_kind;
 	GcmCalibrateDeviceKind		 device_kind;
 	GcmCalibratePrintKind		 print_kind;
+	GcmCalibratePrecision		 precision;
 	GcmColorimeterKind		 colorimeter_kind;
 	GcmCalibrateDialog		*calibrate_dialog;
 	GcmDeviceTypeEnum		 device_type;
@@ -70,6 +72,7 @@ struct _GcmCalibratePrivate
 	gchar				*serial;
 	gchar				*device;
 	gchar				*working_path;
+	GConfClient			*gconf_client;
 };
 
 enum {
@@ -90,6 +93,7 @@ enum {
 	PROP_FILENAME_REFERENCE,
 	PROP_FILENAME_RESULT,
 	PROP_WORKING_PATH,
+	PROP_PRECISION,
 	PROP_LAST
 };
 
@@ -834,6 +838,78 @@ out:
 }
 
 /**
+ * gcm_calibrate_get_precision:
+ **/
+static GcmCalibratePrecision
+gcm_calibrate_get_precision (GcmCalibrate *calibrate, GError **error)
+{
+	GcmCalibratePrecision precision = GCM_CALIBRATE_PRECISION_UNKNOWN;
+	const gchar *title;
+	GString *string;
+	GtkResponseType response;
+	GcmCalibratePrivate *priv = calibrate->priv;
+
+	string = g_string_new ("");
+
+	/* TRANSLATORS: dialog title */
+	title = _("Choose the precision of the profile");
+
+	/* TRANSLATORS: dialog message, suffix */
+	g_string_append_printf (string, "%s\n", _("Please choose the calibration precision."));
+
+	/* TRANSLATORS: this is the message body for the chart selection */
+	g_string_append_printf (string, "\n%s", _("Short profiles are quick and easy, long profiles take longer to complete but are more accurate."));
+
+	/* printer specific options */
+	if (priv->device_type == GCM_DEVICE_TYPE_ENUM_PRINTER) {
+		/* TRANSLATORS: dialog message, preface */
+		g_string_append_printf (string, "\n%s", _("The long calibration also uses up much more paper and ink."));
+	}
+
+	/* TRANSLATORS: this is the message body for the chart selection */
+	g_string_append_printf (string, "\n\n%s", _("For a typical color workflow, a normal precision profile is sufficient."));
+
+	/* push new messages into the UI */
+	gcm_calibrate_dialog_show (priv->calibrate_dialog, GCM_CALIBRATE_DIALOG_TAB_PRECISION, title, string->str);
+	gcm_calibrate_dialog_set_show_button_ok (priv->calibrate_dialog, FALSE);
+	gcm_calibrate_dialog_set_show_expander (priv->calibrate_dialog, FALSE);
+	response = gcm_calibrate_dialog_run (priv->calibrate_dialog);
+	if (response != GTK_RESPONSE_OK) {
+		gcm_calibrate_dialog_hide (priv->calibrate_dialog);
+		g_set_error_literal (error,
+				     GCM_CALIBRATE_ERROR,
+				     GCM_CALIBRATE_ERROR_USER_ABORT,
+				     "user did not choose precision type and ask is specified in GConf");
+		goto out;
+	}
+
+	/* copy */
+	g_object_get (priv->calibrate_dialog, "precision", &precision, NULL);
+out:
+	if (string != NULL)
+		g_string_free (string, TRUE);
+	return precision;
+}
+
+/**
+ * gcm_calibrate_precision_from_string:
+ **/
+static GcmCalibratePrecision
+gcm_calibrate_precision_from_string (const gchar *string)
+{
+	if (g_strcmp0 (string, "short") == 0)
+		return GCM_CALIBRATE_PRECISION_SHORT;
+	if (g_strcmp0 (string, "normal") == 0)
+		return GCM_CALIBRATE_PRECISION_NORMAL;
+	if (g_strcmp0 (string, "long") == 0)
+		return GCM_CALIBRATE_PRECISION_LONG;
+	if (g_strcmp0 (string, "ask") == 0)
+		return GCM_CALIBRATE_PRECISION_UNKNOWN;
+	egg_warning ("failed to convert to precision: %s", string);
+	return GCM_CALIBRATE_PRECISION_UNKNOWN;
+}
+
+/**
  * gcm_calibrate_device:
  **/
 gboolean
@@ -848,6 +924,7 @@ gcm_calibrate_device (GcmCalibrate *calibrate, GtkWindow *window, GError **error
 	GString *string;
 	GtkResponseType response;
 	GtkWindow *window_tmp;
+	gchar *precision = NULL;
 #ifdef GCM_USE_PACKAGEKIT
 	GtkWidget *dialog;
 #endif
@@ -922,6 +999,7 @@ gcm_calibrate_device (GcmCalibrate *calibrate, GtkWindow *window, GError **error
 	g_string_append_printf (string, "\n%s\n", _("Please select the chart type which corresponds to your reference file."));
 
 	/* push new messages into the UI */
+	gcm_calibrate_dialog_set_window (priv->calibrate_dialog, window);
 	gcm_calibrate_dialog_show (priv->calibrate_dialog, GCM_CALIBRATE_DIALOG_TAB_TARGET_TYPE, title, string->str);
 	gcm_calibrate_dialog_set_show_button_ok (priv->calibrate_dialog, TRUE);
 	gcm_calibrate_dialog_set_show_expander (priv->calibrate_dialog, FALSE);
@@ -939,6 +1017,17 @@ gcm_calibrate_device (GcmCalibrate *calibrate, GtkWindow *window, GError **error
 	/* copy */
 	g_object_get (priv->calibrate_dialog, "reference-kind", &priv->reference_kind, NULL);
 
+	/* get default precision */
+	precision = gconf_client_get_string (priv->gconf_client, GCM_SETTINGS_CALIBRATION_LENGTH, NULL);
+	priv->precision = gcm_calibrate_precision_from_string (precision);
+	if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
+		priv->precision = gcm_calibrate_get_precision (calibrate, error);
+		if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
+			ret = FALSE;
+			goto out;
+		}
+	}
+
 	/* get scanned image */
 	directory = g_get_home_dir ();
 	window_tmp = gcm_calibrate_dialog_get_window (priv->calibrate_dialog);
@@ -1000,6 +1089,7 @@ gcm_calibrate_device (GcmCalibrate *calibrate, GtkWindow *window, GError **error
 out:
 	if (string != NULL)
 		g_string_free (string, TRUE);
+	g_free (precision);
 	g_free (device);
 	g_free (reference_image);
 	g_free (reference_data);
@@ -1064,6 +1154,9 @@ gcm_calibrate_get_property (GObject *object, guint prop_id, GValue *value, GPara
 	case PROP_WORKING_PATH:
 		g_value_set_string (value, priv->working_path);
 		break;
+	case PROP_PRECISION:
+		g_value_set_uint (value, priv->precision);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -1300,6 +1393,14 @@ gcm_calibrate_class_init (GcmCalibrateClass *klass)
 				     G_PARAM_READWRITE);
 	g_object_class_install_property (object_class, PROP_WORKING_PATH, pspec);
 
+	/**
+	 * GcmCalibrate:precision:
+	 */
+	pspec = g_param_spec_uint ("precision", NULL, NULL,
+				   0, G_MAXUINT, 0,
+				   G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_PRECISION, pspec);
+
 	g_type_class_add_private (klass, sizeof (GcmCalibratePrivate));
 }
 
@@ -1324,12 +1425,16 @@ gcm_calibrate_init (GcmCalibrate *calibrate)
 	calibrate->priv->device_kind = GCM_CALIBRATE_DEVICE_KIND_UNKNOWN;
 	calibrate->priv->print_kind = GCM_CALIBRATE_PRINT_KIND_UNKNOWN;
 	calibrate->priv->reference_kind = GCM_CALIBRATE_REFERENCE_KIND_UNKNOWN;
+	calibrate->priv->precision = GCM_CALIBRATE_PRECISION_UNKNOWN;
 	calibrate->priv->colorimeter = gcm_colorimeter_new ();
 	calibrate->priv->calibrate_dialog = gcm_calibrate_dialog_new ();
 
 	// FIXME: this has to be per-run specific
 	calibrate->priv->working_path = g_strdup ("/tmp");
 
+	/* use GConf to get defaults */
+	calibrate->priv->gconf_client = gconf_client_get_default ();
+
 	/* coldplug, and watch for changes */
 	calibrate->priv->colorimeter_kind = gcm_colorimeter_get_kind (calibrate->priv->colorimeter);
 	g_signal_connect (calibrate->priv->colorimeter, "changed", G_CALLBACK (gcm_prefs_colorimeter_changed_cb), calibrate);
@@ -1358,6 +1463,7 @@ gcm_calibrate_finalize (GObject *object)
 	g_signal_handlers_disconnect_by_func (calibrate->priv->colorimeter, G_CALLBACK (gcm_prefs_colorimeter_changed_cb), calibrate);
 	g_object_unref (priv->colorimeter);
 	g_object_unref (priv->calibrate_dialog);
+	g_object_unref (priv->gconf_client);
 
 	G_OBJECT_CLASS (gcm_calibrate_parent_class)->finalize (object);
 }
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index b65a934..1721d63 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -105,6 +105,13 @@ typedef enum {
 	GCM_CALIBRATE_PRINT_KIND_UNKNOWN
 } GcmCalibratePrintKind;
 
+typedef enum {
+	GCM_CALIBRATE_PRECISION_SHORT,
+	GCM_CALIBRATE_PRECISION_NORMAL,
+	GCM_CALIBRATE_PRECISION_LONG,
+	GCM_CALIBRATE_PRECISION_UNKNOWN
+} GcmCalibratePrecision;
+
 GType		 gcm_calibrate_get_type			(void);
 GcmCalibrate	*gcm_calibrate_new			(void);
 gboolean	 gcm_calibrate_display			(GcmCalibrate	*calibrate,



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