[gnome-color-manager: 69/80] trivial: move the per-sensor state data from GcmColorimeter to GcmSensor



commit c4d336d00874e25a2925cb3e49dbb3ee3bf59e76
Author: Richard Hughes <richard hughsie com>
Date:   Sun Jul 18 14:03:25 2010 +0100

    trivial: move the per-sensor state data from GcmColorimeter to GcmSensor

 libcolor-glib/gcm-self-test.c |    2 +
 libcolor-glib/gcm-sensor.c    |  243 ++++++++++++++++++++++++++++++++++-
 libcolor-glib/gcm-sensor.h    |   57 ++++++---
 src/cc-color-panel.c          |    2 +-
 src/gcm-calibrate-argyll.c    |   48 ++++----
 src/gcm-calibrate.c           |   20 ++-
 src/gcm-colorimeter.c         |  291 ++++++-----------------------------------
 src/gcm-colorimeter.h         |   26 +----
 src/gcm-picker.c              |   16 ++-
 9 files changed, 378 insertions(+), 327 deletions(-)
---
diff --git a/libcolor-glib/gcm-self-test.c b/libcolor-glib/gcm-self-test.c
index e7adac0..124163f 100644
--- a/libcolor-glib/gcm-self-test.c
+++ b/libcolor-glib/gcm-self-test.c
@@ -29,8 +29,10 @@
 #include "gcm-ddc-client.h"
 #include "gcm-ddc-device.h"
 #include "gcm-edid.h"
+#include "gcm-brightness.h"
 #include "gcm-tables.h"
 #include "gcm-profile.h"
+#include "gcm-profile-store.h"
 #include "gcm-clut.h"
 #include "gcm-xyz.h"
 #include "gcm-dmi.h"
diff --git a/libcolor-glib/gcm-sensor.c b/libcolor-glib/gcm-sensor.c
index 4db1e62..f64b368 100644
--- a/libcolor-glib/gcm-sensor.c
+++ b/libcolor-glib/gcm-sensor.c
@@ -43,12 +43,26 @@ static void     gcm_sensor_finalize	(GObject     *object);
  **/
 struct _GcmSensorPrivate
 {
-	gchar				*device;
+	GcmSensorKind			 kind;
 	GcmSensorOutputType		 output_type;
+	gboolean			 supports_display;
+	gboolean			 supports_projector;
+	gboolean			 supports_printer;
+	gboolean			 supports_spot;
+	gchar				*vendor;
+	gchar				*model;
+	gchar				*device;
 };
 
 enum {
 	PROP_0,
+	PROP_VENDOR,
+	PROP_MODEL,
+	PROP_KIND,
+	PROP_SUPPORTS_DISPLAY,
+	PROP_SUPPORTS_PROJECTOR,
+	PROP_SUPPORTS_PRINTER,
+	PROP_SUPPORTS_SPOT,
 	PROP_DEVICE,
 	PROP_LAST
 };
@@ -56,6 +70,69 @@ enum {
 G_DEFINE_TYPE (GcmSensor, gcm_sensor, G_TYPE_OBJECT)
 
 /**
+ * gcm_sensor_get_model:
+ **/
+const gchar *
+gcm_sensor_get_model (GcmSensor *sensor)
+{
+	return sensor->priv->model;
+}
+
+/**
+ * gcm_sensor_get_vendor:
+ **/
+const gchar *
+gcm_sensor_get_vendor (GcmSensor *sensor)
+{
+	return sensor->priv->vendor;
+}
+
+/**
+ * gcm_sensor_supports_display:
+ **/
+gboolean
+gcm_sensor_supports_display (GcmSensor *sensor)
+{
+	return sensor->priv->supports_display;
+}
+
+/**
+ * gcm_sensor_supports_projector:
+ **/
+gboolean
+gcm_sensor_supports_projector (GcmSensor *sensor)
+{
+	return sensor->priv->supports_projector;
+}
+
+/**
+ * gcm_sensor_supports_printer:
+ **/
+gboolean
+gcm_sensor_supports_printer (GcmSensor *sensor)
+{
+	return sensor->priv->supports_printer;
+}
+
+/**
+ * gcm_sensor_supports_spot:
+ **/
+gboolean
+gcm_sensor_supports_spot (GcmSensor *sensor)
+{
+	return sensor->priv->supports_spot;
+}
+
+/**
+ * gcm_sensor_get_kind:
+ **/
+GcmSensorKind
+gcm_sensor_get_kind (GcmSensor *sensor)
+{
+	return sensor->priv->kind;
+}
+
+/**
  * gcm_sensor_set_output_type:
  **/
 void
@@ -170,6 +247,64 @@ out:
 }
 
 /**
+ * gcm_sensor_kind_to_string:
+ **/
+const gchar *
+gcm_sensor_kind_to_string (GcmSensorKind sensor_kind)
+{
+	if (sensor_kind == GCM_SENSOR_KIND_HUEY)
+		return "huey";
+	if (sensor_kind == GCM_SENSOR_KIND_COLOR_MUNKI)
+		return "color-munki";
+	if (sensor_kind == GCM_SENSOR_KIND_SPYDER)
+		return "spyder";
+	if (sensor_kind == GCM_SENSOR_KIND_DTP20)
+		return "dtp20";
+	if (sensor_kind == GCM_SENSOR_KIND_DTP22)
+		return "dtp22";
+	if (sensor_kind == GCM_SENSOR_KIND_DTP41)
+		return "dtp41";
+	if (sensor_kind == GCM_SENSOR_KIND_DTP51)
+		return "dtp51";
+	if (sensor_kind == GCM_SENSOR_KIND_SPECTRO_SCAN)
+		return "spectro-scan";
+	if (sensor_kind == GCM_SENSOR_KIND_I1_PRO)
+		return "i1-pro";
+	if (sensor_kind == GCM_SENSOR_KIND_COLORIMTRE_HCFR)
+		return "colorimtre-hcfr";
+	return "unknown";
+}
+
+/**
+ * gcm_sensor_kind_from_string:
+ **/
+GcmSensorKind
+gcm_sensor_kind_from_string (const gchar *sensor_kind)
+{
+	if (g_strcmp0 (sensor_kind, "huey") == 0)
+		return GCM_SENSOR_KIND_HUEY;
+	if (g_strcmp0 (sensor_kind, "color-munki") == 0)
+		return GCM_SENSOR_KIND_COLOR_MUNKI;
+	if (g_strcmp0 (sensor_kind, "spyder") == 0)
+		return GCM_SENSOR_KIND_SPYDER;
+	if (g_strcmp0 (sensor_kind, "dtp20") == 0)
+		return GCM_SENSOR_KIND_DTP20;
+	if (g_strcmp0 (sensor_kind, "dtp22") == 0)
+		return GCM_SENSOR_KIND_DTP22;
+	if (g_strcmp0 (sensor_kind, "dtp41") == 0)
+		return GCM_SENSOR_KIND_DTP41;
+	if (g_strcmp0 (sensor_kind, "dtp51") == 0)
+		return GCM_SENSOR_KIND_DTP51;
+	if (g_strcmp0 (sensor_kind, "spectro-scan") == 0)
+		return GCM_SENSOR_KIND_SPECTRO_SCAN;
+	if (g_strcmp0 (sensor_kind, "i1-pro") == 0)
+		return GCM_SENSOR_KIND_I1_PRO;
+	if (g_strcmp0 (sensor_kind, "colorimtre-hcfr") == 0)
+		return GCM_SENSOR_KIND_COLORIMTRE_HCFR;
+	return GCM_SENSOR_KIND_UNKNOWN;
+}
+
+/**
  * gcm_sensor_get_property:
  **/
 static void
@@ -179,6 +314,27 @@ gcm_sensor_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
 	GcmSensorPrivate *priv = sensor->priv;
 
 	switch (prop_id) {
+	case PROP_VENDOR:
+		g_value_set_string (value, priv->vendor);
+		break;
+	case PROP_MODEL:
+		g_value_set_string (value, priv->model);
+		break;
+	case PROP_KIND:
+		g_value_set_boolean (value, priv->kind);
+		break;
+	case PROP_SUPPORTS_DISPLAY:
+		g_value_set_boolean (value, priv->supports_display);
+		break;
+	case PROP_SUPPORTS_PROJECTOR:
+		g_value_set_boolean (value, priv->supports_projector);
+		break;
+	case PROP_SUPPORTS_PRINTER:
+		g_value_set_boolean (value, priv->supports_printer);
+		break;
+	case PROP_SUPPORTS_SPOT:
+		g_value_set_boolean (value, priv->supports_spot);
+		break;
 	case PROP_DEVICE:
 		g_value_set_string (value, priv->device);
 		break;
@@ -200,7 +356,30 @@ gcm_sensor_set_property (GObject *object, guint prop_id, const GValue *value, GP
 	switch (prop_id) {
 	case PROP_DEVICE:
 		g_free (priv->device);
-		priv->device = g_strdup (g_value_get_string (value));
+		priv->device = g_value_dup_string (value);
+		break;
+	case PROP_VENDOR:
+		g_free (priv->vendor);
+		priv->vendor = g_value_dup_string (value);
+		break;
+	case PROP_MODEL:
+		g_free (priv->model);
+		priv->model = g_value_dup_string (value);
+		break;
+	case PROP_KIND:
+		priv->kind = g_value_get_uint (value);
+		break;
+	case PROP_SUPPORTS_DISPLAY:
+		priv->supports_display = g_value_get_boolean (value);
+		break;
+	case PROP_SUPPORTS_PROJECTOR:
+		priv->supports_projector = g_value_get_boolean (value);
+		break;
+	case PROP_SUPPORTS_PRINTER:
+		priv->supports_printer = g_value_get_boolean (value);
+		break;
+	case PROP_SUPPORTS_SPOT:
+		priv->supports_spot = g_value_get_boolean (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -221,6 +400,63 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	object_class->set_property = gcm_sensor_set_property;
 
 	/**
+	 * GcmSensor:vendor:
+	 */
+	pspec = g_param_spec_string ("vendor", NULL, NULL,
+				     NULL,
+				     G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_VENDOR, pspec);
+
+	/**
+	 * GcmSensor:model:
+	 */
+	pspec = g_param_spec_string ("model", NULL, NULL,
+				     NULL,
+				     G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_MODEL, pspec);
+
+	/**
+	 * GcmSensor:kind:
+	 */
+	pspec = g_param_spec_uint ("kind", NULL, NULL,
+				   0, G_MAXUINT, GCM_SENSOR_KIND_UNKNOWN,
+				   G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_KIND, pspec);
+
+	/**
+	 * GcmSensor:supports-display:
+	 */
+	pspec = g_param_spec_boolean ("supports-display", NULL, NULL,
+				      FALSE,
+				      G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_SUPPORTS_DISPLAY, pspec);
+
+	/**
+	 * GcmSensor:supports-projector:
+	 */
+	pspec = g_param_spec_boolean ("supports-projector", NULL, NULL,
+				      FALSE,
+				      G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_SUPPORTS_PROJECTOR, pspec);
+
+
+	/**
+	 * GcmSensor:supports-printer:
+	 */
+	pspec = g_param_spec_boolean ("supports-printer", NULL, NULL,
+				      FALSE,
+				      G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_SUPPORTS_PRINTER, pspec);
+
+	/**
+	 * GcmSensor:supports-spot:
+	 */
+	pspec = g_param_spec_boolean ("supports-spot", NULL, NULL,
+				      FALSE,
+				      G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_SUPPORTS_SPOT, pspec);
+
+	/**
 	 * GcmSensor:device:
 	 */
 	pspec = g_param_spec_string ("device", NULL, NULL,
@@ -239,6 +475,7 @@ gcm_sensor_init (GcmSensor *sensor)
 {
 	sensor->priv = GCM_SENSOR_GET_PRIVATE (sensor);
 	sensor->priv->device = NULL;
+	sensor->priv->kind = GCM_SENSOR_KIND_UNKNOWN;
 }
 
 /**
@@ -251,6 +488,8 @@ gcm_sensor_finalize (GObject *object)
 	GcmSensorPrivate *priv = sensor->priv;
 
 	g_free (priv->device);
+	g_free (priv->vendor);
+	g_free (priv->model);
 
 	G_OBJECT_CLASS (gcm_sensor_parent_class)->finalize (object);
 }
diff --git a/libcolor-glib/gcm-sensor.h b/libcolor-glib/gcm-sensor.h
index aacae2c..54a0186 100644
--- a/libcolor-glib/gcm-sensor.h
+++ b/libcolor-glib/gcm-sensor.h
@@ -86,26 +86,49 @@ typedef enum {
 	GCM_SENSOR_OUTPUT_TYPE_PROJECTOR
 } GcmSensorOutputType;
 
+typedef enum {
+	GCM_SENSOR_KIND_HUEY,
+	GCM_SENSOR_KIND_COLOR_MUNKI,
+	GCM_SENSOR_KIND_SPYDER,
+	GCM_SENSOR_KIND_DTP20,
+	GCM_SENSOR_KIND_DTP22,
+	GCM_SENSOR_KIND_DTP41,
+	GCM_SENSOR_KIND_DTP51,
+	GCM_SENSOR_KIND_SPECTRO_SCAN,
+	GCM_SENSOR_KIND_I1_PRO,
+	GCM_SENSOR_KIND_COLORIMTRE_HCFR,
+	GCM_SENSOR_KIND_UNKNOWN
+} GcmSensorKind;
+
 /* dummy */
 #define GCM_SENSOR_ERROR	1
 
-GType		 gcm_sensor_get_type			(void);
-GcmSensor	*gcm_sensor_new				(void);
-
-gboolean	 gcm_sensor_get_ambient			(GcmSensor	*sensor,
-							 gdouble	*value,
-							 GError		**error);
-gboolean	 gcm_sensor_set_leds			(GcmSensor	*sensor,
-							 guint8		 value,
-							 GError		**error);
-gboolean	 gcm_sensor_sample			(GcmSensor	*sensor,
-							 GcmColorXYZ	*value,
-							 GError		**error);
-gboolean	 gcm_sensor_startup			(GcmSensor	*sensor,
-							 GError		**error);
-void		 gcm_sensor_set_output_type		(GcmSensor	*sensor,
-							 GcmSensorOutputType output_type);
-GcmSensorOutputType  gcm_sensor_get_output_type		(GcmSensor	*sensor);
+GType			 gcm_sensor_get_type		(void);
+GcmSensor		*gcm_sensor_new			(void);
+
+gboolean		 gcm_sensor_get_ambient		(GcmSensor		*sensor,
+							gdouble			*value,
+							GError			**error);
+gboolean		 gcm_sensor_set_leds		(GcmSensor		*sensor,
+							guint8			 value,
+							GError			**error);
+gboolean		 gcm_sensor_sample		(GcmSensor		*sensor,
+							GcmColorXYZ		*value,
+							GError			**error);
+gboolean		 gcm_sensor_startup		(GcmSensor		*sensor,
+							GError			**error);
+void			 gcm_sensor_set_output_type	(GcmSensor		*sensor,
+							 GcmSensorOutputType	 output_type);
+GcmSensorOutputType	 gcm_sensor_get_output_type	(GcmSensor		*sensor);
+const gchar		*gcm_sensor_get_model		(GcmSensor		*sensor);
+const gchar		*gcm_sensor_get_vendor		(GcmSensor		*sensor);
+GcmSensorKind		 gcm_sensor_get_kind		(GcmSensor		*sensor);
+gboolean		 gcm_sensor_supports_display	(GcmSensor 		*sensor);
+gboolean		 gcm_sensor_supports_projector	(GcmSensor 		*sensor);
+gboolean		 gcm_sensor_supports_printer	(GcmSensor		*sensor);
+gboolean		 gcm_sensor_supports_spot	(GcmSensor		*sensor);
+const gchar		*gcm_sensor_kind_to_string	(GcmSensorKind		 sensor_kind);
+GcmSensorKind		 gcm_sensor_kind_from_string	(const gchar		*sensor_kind);
 
 G_END_DECLS
 
diff --git a/src/cc-color-panel.c b/src/cc-color-panel.c
index 31a4649..3972d17 100644
--- a/src/cc-color-panel.c
+++ b/src/cc-color-panel.c
@@ -1441,7 +1441,7 @@ cc_color_panel_set_calibrate_button_sensitivity (CcColorPanel *panel)
 		}
 
 		/* find whether we have hardware installed */
-		ret = gcm_colorimeter_supports_printer (panel->priv->colorimeter);
+		ret = gcm_sensor_supports_printer (gcm_colorimeter_get_sensor (panel->priv->colorimeter));
 		if (!ret) {
 			/* TRANSLATORS: this is when the button is insensitive */
 			tooltip = _("Cannot create profile: The measuring instrument does not support printer profiling");
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index 10b19ce..fa3e5c0 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -158,7 +158,7 @@ static guint
 gcm_calibrate_argyll_printer_get_patches (GcmCalibrateArgyll *calibrate_argyll)
 {
 	guint patches = 180;
-	GcmColorimeterKind colorimeter_kind;
+	GcmSensorKind colorimeter_kind;
 	GcmCalibratePrecision precision;
 
 	/* we care about the kind */
@@ -176,8 +176,8 @@ gcm_calibrate_argyll_printer_get_patches (GcmCalibrateArgyll *calibrate_argyll)
 
 #ifdef USE_DOUBLE_DENSITY
 	/* using double density, so we can double the patch count */
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLOR_MUNKI ||
-	    colorimeter_kind == GCM_COLORIMETER_KIND_SPECTRO_SCAN) {
+	if (colorimeter_kind == GCM_SENSOR_KIND_COLOR_MUNKI ||
+	    colorimeter_kind == GCM_SENSOR_KIND_SPECTRO_SCAN) {
 		patches *= 2;
 	}
 #endif
@@ -192,18 +192,18 @@ gcm_calibrate_argyll_printer_get_patches (GcmCalibrateArgyll *calibrate_argyll)
 static const gchar *
 gcm_calibrate_argyll_get_colorimeter_image_attach (GcmCalibrateArgyll *calibrate_argyll)
 {
-	GcmColorimeterKind colorimeter_kind;
+	GcmSensorKind colorimeter_kind;
 
 	g_object_get (calibrate_argyll, "colorimeter-kind", &colorimeter_kind, NULL);
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_HUEY)
+	if (colorimeter_kind == GCM_SENSOR_KIND_HUEY)
 		return "huey-attach.svg";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLOR_MUNKI)
+	if (colorimeter_kind == GCM_SENSOR_KIND_COLOR_MUNKI)
 		return "munki-attach.svg";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_SPYDER)
+	if (colorimeter_kind == GCM_SENSOR_KIND_SPYDER)
 		return "spyder-attach.svg";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLORIMTRE_HCFR)
+	if (colorimeter_kind == GCM_SENSOR_KIND_COLORIMTRE_HCFR)
 		return "hcfr-attach.svg";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_I1_PRO)
+	if (colorimeter_kind == GCM_SENSOR_KIND_I1_PRO)
 		return "i1-attach.svg";
 	return NULL;
 }
@@ -214,10 +214,10 @@ gcm_calibrate_argyll_get_colorimeter_image_attach (GcmCalibrateArgyll *calibrate
 static const gchar *
 gcm_calibrate_argyll_get_colorimeter_image_calibrate (GcmCalibrateArgyll *calibrate_argyll)
 {
-	GcmColorimeterKind colorimeter_kind;
+	GcmSensorKind colorimeter_kind;
 
 	g_object_get (calibrate_argyll, "colorimeter-kind", &colorimeter_kind, NULL);
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLOR_MUNKI)
+	if (colorimeter_kind == GCM_SENSOR_KIND_COLOR_MUNKI)
 		return "munki-calibrate.svg";
 	return NULL;
 }
@@ -228,10 +228,10 @@ gcm_calibrate_argyll_get_colorimeter_image_calibrate (GcmCalibrateArgyll *calibr
 static const gchar *
 gcm_calibrate_argyll_get_colorimeter_image_screen (GcmCalibrateArgyll *calibrate_argyll)
 {
-	GcmColorimeterKind colorimeter_kind;
+	GcmSensorKind colorimeter_kind;
 
 	g_object_get (calibrate_argyll, "colorimeter-kind", &colorimeter_kind, NULL);
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLOR_MUNKI)
+	if (colorimeter_kind == GCM_SENSOR_KIND_COLOR_MUNKI)
 		return "munki-screen.svg";
 	return NULL;
 }
@@ -1558,25 +1558,25 @@ out:
 static const gchar *
 gcm_calibrate_argyll_get_colorimeter_target (GcmCalibrateArgyll *calibrate_argyll)
 {
-	GcmColorimeterKind colorimeter_kind;
+	GcmSensorKind colorimeter_kind;
 
 	g_object_get (calibrate_argyll,
 		      "colorimeter-kind", &colorimeter_kind,
 		      NULL);
 
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP20)
+	if (colorimeter_kind == GCM_SENSOR_KIND_DTP20)
 		return "20";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP22)
+	if (colorimeter_kind == GCM_SENSOR_KIND_DTP22)
 		return "22";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP41)
+	if (colorimeter_kind == GCM_SENSOR_KIND_DTP41)
 		return "41";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP51)
+	if (colorimeter_kind == GCM_SENSOR_KIND_DTP51)
 		return "51";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_SPECTRO_SCAN)
+	if (colorimeter_kind == GCM_SENSOR_KIND_SPECTRO_SCAN)
 		return "SS";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_I1_PRO)
+	if (colorimeter_kind == GCM_SENSOR_KIND_I1_PRO)
 		return "i1";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLOR_MUNKI)
+	if (colorimeter_kind == GCM_SENSOR_KIND_COLOR_MUNKI)
 		return "CM";
 	return NULL;
 }
@@ -1595,7 +1595,7 @@ gcm_calibrate_argyll_display_generate_targets (GcmCalibrateArgyll *calibrate_arg
 	gchar *basename = NULL;
 	const gchar *title;
 	const gchar *message;
-	GcmColorimeterKind colorimeter_kind;
+	GcmSensorKind colorimeter_kind;
 
 	/* get shared data */
 	g_object_get (calibrate_argyll,
@@ -1635,8 +1635,8 @@ gcm_calibrate_argyll_display_generate_targets (GcmCalibrateArgyll *calibrate_arg
 
 #ifdef USE_DOUBLE_DENSITY
 	/* use double density */
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLOR_MUNKI ||
-	    colorimeter_kind == GCM_COLORIMETER_KIND_SPECTRO_SCAN) {
+	if (colorimeter_kind == GCM_SENSOR_KIND_COLOR_MUNKI ||
+	    colorimeter_kind == GCM_SENSOR_KIND_SPECTRO_SCAN) {
 		g_ptr_array_add (array, g_strdup ("-h"));
 	}
 #endif
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 3658584..6f9be4b 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -60,7 +60,7 @@ struct _GcmCalibratePrivate
 	GcmCalibrateDeviceKind		 calibrate_device_kind;
 	GcmCalibratePrintKind		 print_kind;
 	GcmCalibratePrecision		 precision;
-	GcmColorimeterKind		 colorimeter_kind;
+	GcmSensorKind		 colorimeter_kind;
 	GcmCalibrateDialog		*calibrate_dialog;
 	GcmDeviceKind			 device_kind;
 	GcmXyz				*xyz;
@@ -418,7 +418,7 @@ gcm_calibrate_get_display_kind (GcmCalibrate *calibrate, GtkWindow *window, GErr
 
 	/* can this device support projectors? */
 	if (priv->calibrate_device_kind == GCM_CALIBRATE_DEVICE_KIND_PROJECTOR &&
-	    !gcm_colorimeter_supports_projector (priv->colorimeter)) {
+	    !gcm_sensor_supports_projector (gcm_colorimeter_get_sensor (priv->colorimeter))) {
 		/* TRANSLATORS: title, the hardware calibration device does not support projectors */
 		title = _("Could not calibrate and profile using this color measuring instrument");
 
@@ -594,7 +594,7 @@ gcm_calibrate_display (GcmCalibrate *calibrate, GtkWindow *window, GError **erro
 	}
 
 	/* get calibration device model */
-	hardware_device = gcm_colorimeter_get_model (priv->colorimeter);
+	hardware_device = gcm_sensor_get_model (gcm_colorimeter_get_sensor (priv->colorimeter));
 
 	/* get device, harder */
 	if (hardware_device == NULL) {
@@ -1272,7 +1272,11 @@ gcm_calibrate_guess_kind (GcmCalibrate *calibrate)
 static void
 gcm_prefs_colorimeter_changed_cb (GcmColorimeter *_colorimeter, GcmCalibrate *calibrate)
 {
-	calibrate->priv->colorimeter_kind = gcm_colorimeter_get_kind (_colorimeter);
+	GcmSensor *sensor;
+	calibrate->priv->colorimeter_kind = GCM_SENSOR_KIND_UNKNOWN;
+	sensor = gcm_colorimeter_get_sensor (_colorimeter);
+	if (sensor != NULL)
+		calibrate->priv->colorimeter_kind = gcm_sensor_get_kind (sensor);
 	g_object_notify (G_OBJECT (calibrate), "colorimeter-kind");
 }
 
@@ -1511,6 +1515,8 @@ gcm_calibrate_class_init (GcmCalibrateClass *klass)
 static void
 gcm_calibrate_init (GcmCalibrate *calibrate)
 {
+	GcmSensor *sensor;
+
 	calibrate->priv = GCM_CALIBRATE_GET_PRIVATE (calibrate);
 	calibrate->priv->output_name = NULL;
 	calibrate->priv->filename_source = NULL;
@@ -1539,7 +1545,11 @@ gcm_calibrate_init (GcmCalibrate *calibrate)
 	calibrate->priv->settings = g_settings_new (GCM_SETTINGS_SCHEMA);
 
 	/* coldplug, and watch for changes */
-	calibrate->priv->colorimeter_kind = gcm_colorimeter_get_kind (calibrate->priv->colorimeter);
+	calibrate->priv->colorimeter_kind = GCM_SENSOR_KIND_UNKNOWN;
+	sensor = gcm_colorimeter_get_sensor (calibrate->priv->colorimeter);
+	if (sensor != NULL)
+		calibrate->priv->colorimeter_kind = gcm_sensor_get_kind (sensor);
+
 	g_signal_connect (calibrate->priv->colorimeter, "changed", G_CALLBACK (gcm_prefs_colorimeter_changed_cb), calibrate);
 }
 
diff --git a/src/gcm-colorimeter.c b/src/gcm-colorimeter.c
index ec25437..c628c16 100644
--- a/src/gcm-colorimeter.c
+++ b/src/gcm-colorimeter.c
@@ -49,26 +49,13 @@ static void     gcm_colorimeter_finalize	(GObject     *object);
 struct _GcmColorimeterPrivate
 {
 	gboolean			 present;
-	gboolean			 supports_display;
-	gboolean			 supports_projector;
-	gboolean			 supports_printer;
-	gboolean			 supports_spot;
-	gchar				*vendor;
-	gchar				*model;
 	GUdevClient			*client;
-	GcmColorimeterKind		 colorimeter_kind;
+	GcmSensor			*sensor;
 };
 
 enum {
 	PROP_0,
 	PROP_PRESENT,
-	PROP_VENDOR,
-	PROP_MODEL,
-	PROP_COLORIMETER_KIND,
-	PROP_SUPPORTS_DISPLAY,
-	PROP_SUPPORTS_PROJECTOR,
-	PROP_SUPPORTS_PRINTER,
-	PROP_SUPPORTS_SPOT,
 	PROP_LAST
 };
 
@@ -83,78 +70,6 @@ static gpointer gcm_colorimeter_object = NULL;
 G_DEFINE_TYPE (GcmColorimeter, gcm_colorimeter, G_TYPE_OBJECT)
 
 /**
- * gcm_colorimeter_get_model:
- **/
-const gchar *
-gcm_colorimeter_get_model (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->model;
-}
-
-/**
- * gcm_colorimeter_get_vendor:
- **/
-const gchar *
-gcm_colorimeter_get_vendor (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->vendor;
-}
-
-/**
- * gcm_colorimeter_get_present:
- **/
-gboolean
-gcm_colorimeter_get_present (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->present;
-}
-
-/**
- * gcm_colorimeter_supports_display:
- **/
-gboolean
-gcm_colorimeter_supports_display (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->supports_display;
-}
-
-/**
- * gcm_colorimeter_supports_projector:
- **/
-gboolean
-gcm_colorimeter_supports_projector (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->supports_projector;
-}
-
-/**
- * gcm_colorimeter_supports_printer:
- **/
-gboolean
-gcm_colorimeter_supports_printer (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->supports_printer;
-}
-
-/**
- * gcm_colorimeter_supports_spot:
- **/
-gboolean
-gcm_colorimeter_supports_spot (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->supports_spot;
-}
-
-/**
- * gcm_colorimeter_get_kind:
- **/
-GcmColorimeterKind
-gcm_colorimeter_get_kind (GcmColorimeter *colorimeter)
-{
-	return colorimeter->priv->colorimeter_kind;
-}
-
-/**
  * gcm_colorimeter_get_property:
  **/
 static void
@@ -167,27 +82,6 @@ gcm_colorimeter_get_property (GObject *object, guint prop_id, GValue *value, GPa
 	case PROP_PRESENT:
 		g_value_set_boolean (value, priv->present);
 		break;
-	case PROP_VENDOR:
-		g_value_set_string (value, priv->vendor);
-		break;
-	case PROP_MODEL:
-		g_value_set_string (value, priv->model);
-		break;
-	case PROP_COLORIMETER_KIND:
-		g_value_set_uint (value, priv->colorimeter_kind);
-		break;
-	case PROP_SUPPORTS_DISPLAY:
-		g_value_set_uint (value, priv->supports_display);
-		break;
-	case PROP_SUPPORTS_PROJECTOR:
-		g_value_set_uint (value, priv->supports_projector);
-		break;
-	case PROP_SUPPORTS_PRINTER:
-		g_value_set_uint (value, priv->supports_printer);
-		break;
-	case PROP_SUPPORTS_SPOT:
-		g_value_set_uint (value, priv->supports_spot);
-		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -228,63 +122,6 @@ gcm_colorimeter_class_init (GcmColorimeterClass *klass)
 	g_object_class_install_property (object_class, PROP_PRESENT, pspec);
 
 	/**
-	 * GcmColorimeter:vendor:
-	 */
-	pspec = g_param_spec_string ("vendor", NULL, NULL,
-				     NULL,
-				     G_PARAM_READABLE);
-	g_object_class_install_property (object_class, PROP_VENDOR, pspec);
-
-	/**
-	 * GcmColorimeter:model:
-	 */
-	pspec = g_param_spec_string ("model", NULL, NULL,
-				     NULL,
-				     G_PARAM_READABLE);
-	g_object_class_install_property (object_class, PROP_MODEL, pspec);
-
-	/**
-	 * GcmColorimeter:colorimeter-kind:
-	 */
-	pspec = g_param_spec_uint ("colorimeter-kind", NULL, NULL,
-				   0, G_MAXUINT, GCM_COLORIMETER_KIND_UNKNOWN,
-				   G_PARAM_READABLE);
-	g_object_class_install_property (object_class, PROP_COLORIMETER_KIND, pspec);
-
-	/**
-	 * GcmColorimeter:supports-display:
-	 */
-	pspec = g_param_spec_boolean ("supports-display", NULL, NULL,
-				      FALSE,
-				      G_PARAM_READABLE);
-	g_object_class_install_property (object_class, PROP_SUPPORTS_DISPLAY, pspec);
-
-	/**
-	 * GcmColorimeter:supports-projector:
-	 */
-	pspec = g_param_spec_boolean ("supports-projector", NULL, NULL,
-				      FALSE,
-				      G_PARAM_READABLE);
-	g_object_class_install_property (object_class, PROP_SUPPORTS_PROJECTOR, pspec);
-
-
-	/**
-	 * GcmColorimeter:supports-printer:
-	 */
-	pspec = g_param_spec_boolean ("supports-printer", NULL, NULL,
-				      FALSE,
-				      G_PARAM_READABLE);
-	g_object_class_install_property (object_class, PROP_SUPPORTS_PRINTER, pspec);
-
-	/**
-	 * GcmColorimeter:supports-spot:
-	 */
-	pspec = g_param_spec_boolean ("supports-spot", NULL, NULL,
-				      FALSE,
-				      G_PARAM_READABLE);
-	g_object_class_install_property (object_class, PROP_SUPPORTS_SPOT, pspec);
-
-	/**
 	 * GcmColorimeter::changed:
 	 **/
 	signals[SIGNAL_CHANGED] =
@@ -298,61 +135,21 @@ gcm_colorimeter_class_init (GcmColorimeterClass *klass)
 }
 
 /**
- * gcm_colorimeter_kind_to_string:
+ * gcm_colorimeter_get_sensor:
  **/
-const gchar *
-gcm_colorimeter_kind_to_string (GcmColorimeterKind colorimeter_kind)
+GcmSensor *
+gcm_colorimeter_get_sensor (GcmColorimeter *colorimeter)
 {
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_HUEY)
-		return "huey";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLOR_MUNKI)
-		return "color-munki";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_SPYDER)
-		return "spyder";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP20)
-		return "dtp20";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP22)
-		return "dtp22";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP41)
-		return "dtp41";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_DTP51)
-		return "dtp51";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_SPECTRO_SCAN)
-		return "spectro-scan";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_I1_PRO)
-		return "i1-pro";
-	if (colorimeter_kind == GCM_COLORIMETER_KIND_COLORIMTRE_HCFR)
-		return "colorimtre-hcfr";
-	return "unknown";
+	return colorimeter->priv->sensor;
 }
 
 /**
- * gcm_colorimeter_kind_from_string:
+ * gcm_colorimeter_get_present:
  **/
-GcmColorimeterKind
-gcm_colorimeter_kind_from_string (const gchar *colorimeter_kind)
+gboolean
+gcm_colorimeter_get_present (GcmColorimeter *colorimeter)
 {
-	if (g_strcmp0 (colorimeter_kind, "huey") == 0)
-		return GCM_COLORIMETER_KIND_HUEY;
-	if (g_strcmp0 (colorimeter_kind, "color-munki") == 0)
-		return GCM_COLORIMETER_KIND_COLOR_MUNKI;
-	if (g_strcmp0 (colorimeter_kind, "spyder") == 0)
-		return GCM_COLORIMETER_KIND_SPYDER;
-	if (g_strcmp0 (colorimeter_kind, "dtp20") == 0)
-		return GCM_COLORIMETER_KIND_DTP20;
-	if (g_strcmp0 (colorimeter_kind, "dtp22") == 0)
-		return GCM_COLORIMETER_KIND_DTP22;
-	if (g_strcmp0 (colorimeter_kind, "dtp41") == 0)
-		return GCM_COLORIMETER_KIND_DTP41;
-	if (g_strcmp0 (colorimeter_kind, "dtp51") == 0)
-		return GCM_COLORIMETER_KIND_DTP51;
-	if (g_strcmp0 (colorimeter_kind, "spectro-scan") == 0)
-		return GCM_COLORIMETER_KIND_SPECTRO_SCAN;
-	if (g_strcmp0 (colorimeter_kind, "i1-pro") == 0)
-		return GCM_COLORIMETER_KIND_I1_PRO;
-	if (g_strcmp0 (colorimeter_kind, "colorimtre-hcfr") == 0)
-		return GCM_COLORIMETER_KIND_COLORIMTRE_HCFR;
-	return GCM_COLORIMETER_KIND_UNKNOWN;
+	return colorimeter->priv->present;
 }
 
 /**
@@ -361,6 +158,9 @@ gcm_colorimeter_kind_from_string (const gchar *colorimeter_kind)
 static gboolean
 gcm_colorimeter_device_add (GcmColorimeter *colorimeter, GUdevDevice *device)
 {
+	const gchar *vendor;
+	const gchar *model;
+	GcmSensorKind colorimeter_kind;
 	gboolean ret;
 	const gchar *kind_str;
 	GcmColorimeterPrivate *priv = colorimeter->priv;
@@ -373,34 +173,37 @@ gcm_colorimeter_device_add (GcmColorimeter *colorimeter, GUdevDevice *device)
 	/* get data */
 	egg_debug ("adding color management device: %s", g_udev_device_get_sysfs_path (device));
 	priv->present = TRUE;
+	priv->sensor = gcm_sensor_new ();
 
 	/* vendor */
-	g_free (priv->vendor);
-	priv->vendor = g_strdup (g_udev_device_get_property (device, "ID_VENDOR_FROM_DATABASE"));
-	if (priv->vendor == NULL)
-		priv->vendor = g_strdup (g_udev_device_get_property (device, "ID_VENDOR"));
-	if (priv->vendor == NULL)
-		priv->vendor = g_strdup (g_udev_device_get_sysfs_attr (device, "manufacturer"));
+	vendor = g_udev_device_get_property (device, "ID_VENDOR_FROM_DATABASE");
+	if (vendor == NULL)
+		vendor = g_udev_device_get_property (device, "ID_VENDOR");
+	if (vendor == NULL)
+		vendor = g_udev_device_get_sysfs_attr (device, "manufacturer");
 
 	/* model */
-	g_free (priv->model);
-	priv->model = g_strdup (g_udev_device_get_property (device, "ID_MODEL_FROM_DATABASE"));
-	if (priv->model == NULL)
-		priv->model = g_strdup (g_udev_device_get_property (device, "ID_MODEL"));
-	if (priv->model == NULL)
-		priv->model = g_strdup (g_udev_device_get_sysfs_attr (device, "product"));
-
-	/* device support */
-	priv->supports_display = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_DISPLAY");
-	priv->supports_projector = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PROJECTOR");
-	priv->supports_printer = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PRINTER");
-	priv->supports_spot = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_SPOT");
+	model = g_udev_device_get_property (device, "ID_MODEL_FROM_DATABASE");
+	if (model == NULL)
+		model = g_udev_device_get_property (device, "ID_MODEL");
+	if (model == NULL)
+		model = g_udev_device_get_sysfs_attr (device, "product");
 
 	/* try to get type */
 	kind_str = g_udev_device_get_property (device, "GCM_KIND");
-	priv->colorimeter_kind = gcm_colorimeter_kind_from_string (kind_str);
-	if (priv->colorimeter_kind == GCM_COLORIMETER_KIND_UNKNOWN)
-		egg_warning ("Failed to recognize color device: %s", priv->model);
+	colorimeter_kind = gcm_sensor_kind_from_string (kind_str);
+	if (colorimeter_kind == GCM_SENSOR_KIND_UNKNOWN)
+		egg_warning ("Failed to recognize color device: %s", model);
+
+	g_object_set (priv->sensor,
+		      "vendor", vendor,
+		      "model", model,
+		      "supports-display", g_udev_device_get_property_as_boolean (device, "GCM_TYPE_DISPLAY"),
+		      "supports-projector",g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PROJECTOR"),
+		      "supports-printer", g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PRINTER"),
+		      "supports-spot", g_udev_device_get_property_as_boolean (device, "GCM_TYPE_SPOT"),
+		      "kind", colorimeter_kind,
+		      NULL);
 
 	/* signal the addition */
 	egg_debug ("emit: changed");
@@ -426,18 +229,9 @@ gcm_colorimeter_device_remove (GcmColorimeter *colorimeter, GUdevDevice *device)
 	/* get data */
 	egg_debug ("removing color management device: %s", g_udev_device_get_sysfs_path (device));
 	priv->present = FALSE;
-	priv->supports_display = FALSE;
-	priv->supports_projector = FALSE;
-	priv->supports_printer = FALSE;
-	priv->supports_spot = FALSE;
-
-	/* vendor */
-	g_free (priv->vendor);
-	priv->vendor = NULL;
-
-	/* model */
-	g_free (priv->model);
-	priv->model = NULL;
+	if (priv->sensor != NULL)
+		g_object_unref (priv->sensor);
+	priv->sensor = NULL;
 
 	/* signal the removal */
 	egg_debug ("emit: changed");
@@ -495,9 +289,6 @@ gcm_colorimeter_init (GcmColorimeter *colorimeter)
 	const gchar *subsystems[] = {"usb", NULL};
 
 	colorimeter->priv = GCM_COLORIMETER_GET_PRIVATE (colorimeter);
-	colorimeter->priv->vendor = NULL;
-	colorimeter->priv->model = NULL;
-	colorimeter->priv->colorimeter_kind = GCM_COLORIMETER_KIND_UNKNOWN;
 
 	/* use GUdev to find the calibration device */
 	colorimeter->priv->client = g_udev_client_new (subsystems);
@@ -518,8 +309,8 @@ gcm_colorimeter_finalize (GObject *object)
 	GcmColorimeterPrivate *priv = colorimeter->priv;
 
 	g_object_unref (priv->client);
-	g_free (priv->vendor);
-	g_free (priv->model);
+	if (priv->sensor != NULL)
+		g_object_unref (priv->sensor);
 
 	G_OBJECT_CLASS (gcm_colorimeter_parent_class)->finalize (object);
 }
diff --git a/src/gcm-colorimeter.h b/src/gcm-colorimeter.h
index 96bf9b5..5650d8b 100644
--- a/src/gcm-colorimeter.h
+++ b/src/gcm-colorimeter.h
@@ -24,6 +24,8 @@
 
 #include <glib-object.h>
 
+#include "gcm-sensor.h"
+
 G_BEGIN_DECLS
 
 #define GCM_TYPE_COLORIMETER		(gcm_colorimeter_get_type ())
@@ -55,34 +57,12 @@ struct _GcmColorimeterClass
 	void (*_gcm_reserved5) (void);
 };
 
-typedef enum {
-	GCM_COLORIMETER_KIND_HUEY,
-	GCM_COLORIMETER_KIND_COLOR_MUNKI,
-	GCM_COLORIMETER_KIND_SPYDER,
-	GCM_COLORIMETER_KIND_DTP20,
-	GCM_COLORIMETER_KIND_DTP22,
-	GCM_COLORIMETER_KIND_DTP41,
-	GCM_COLORIMETER_KIND_DTP51,
-	GCM_COLORIMETER_KIND_SPECTRO_SCAN,
-	GCM_COLORIMETER_KIND_I1_PRO,
-	GCM_COLORIMETER_KIND_COLORIMTRE_HCFR,
-	GCM_COLORIMETER_KIND_UNKNOWN
-} GcmColorimeterKind;
-
 GType			 gcm_colorimeter_get_type		(void);
 GcmColorimeter		*gcm_colorimeter_new			(void);
 
 /* accessors */
-const gchar		*gcm_colorimeter_get_model		(GcmColorimeter		*colorimeter);
-const gchar		*gcm_colorimeter_get_vendor		(GcmColorimeter		*colorimeter);
+GcmSensor		*gcm_colorimeter_get_sensor		(GcmColorimeter		*colorimeter);
 gboolean		 gcm_colorimeter_get_present		(GcmColorimeter		*colorimeter);
-GcmColorimeterKind	 gcm_colorimeter_get_kind		(GcmColorimeter		*colorimeter);
-gboolean		 gcm_colorimeter_supports_display	(GcmColorimeter 	*colorimeter);
-gboolean		 gcm_colorimeter_supports_projector	(GcmColorimeter 	*colorimeter);
-gboolean		 gcm_colorimeter_supports_printer	(GcmColorimeter		*colorimeter);
-gboolean		 gcm_colorimeter_supports_spot		(GcmColorimeter		*colorimeter);
-const gchar		*gcm_colorimeter_kind_to_string		(GcmColorimeterKind	 colorimeter_kind);
-GcmColorimeterKind	 gcm_colorimeter_kind_from_string	(const gchar		*colorimeter_kind);
 
 G_END_DECLS
 
diff --git a/src/gcm-picker.c b/src/gcm-picker.c
index 07a0c90..5049868 100644
--- a/src/gcm-picker.c
+++ b/src/gcm-picker.c
@@ -263,11 +263,19 @@ gcm_picker_colorimeter_setup_ui (GcmColorimeter *colorimeter)
 {
 	gboolean present;
 	gboolean supports_spot;
-	gboolean ret;
+	gboolean ret = FALSE;
 	GtkWidget *widget;
 
+	/* no present */
 	present = gcm_colorimeter_get_present (colorimeter);
-	supports_spot = gcm_colorimeter_supports_spot (colorimeter);
+	if (!present) {
+		/* TRANSLATORS: this is displayed the user has not got suitable hardware */
+		gtk_label_set_label (GTK_LABEL (info_bar_hardware_label), _("No colorimeter is attached."));
+		goto out;
+	}
+
+	/* no support */
+	supports_spot = gcm_sensor_supports_spot (gcm_colorimeter_get_sensor (colorimeter));
 	ret = (present && supports_spot);
 
 	/* change the label */
@@ -275,11 +283,9 @@ gcm_picker_colorimeter_setup_ui (GcmColorimeter *colorimeter)
 		/* TRANSLATORS: this is displayed the user has not got suitable hardware */
 		gtk_label_set_label (GTK_LABEL (info_bar_hardware_label), _("The attached colorimeter is not capable of reading a spot color."));
 	} else if (!present) {
-		/* TRANSLATORS: this is displayed the user has not got suitable hardware */
-		gtk_label_set_label (GTK_LABEL (info_bar_hardware_label), _("No colorimeter is attached."));
 	}
 
-	/* hide some stuff */
+out:
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_measure"));
 	gtk_widget_set_sensitive (widget, ret);
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "expander_results"));



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