[gnome-color-manager] Save the EDID MD5 hash to device-profiles.conf for virtual devices



commit d22f9c2a567eef04a72cabf1125fe02c3d79efb1
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jun 16 15:04:38 2010 +0100

    Save the EDID MD5 hash to device-profiles.conf for virtual devices

 src/gcm-device-xrandr.c |   37 +++++++++++++++++++++++++++++++++++++
 src/gcm-device-xrandr.h |    1 +
 src/gcm-device.c        |   19 +++++++++++++++++++
 src/gcm-device.h        |    1 +
 4 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/gcm-device-xrandr.c b/src/gcm-device-xrandr.c
index 485fdce..88bef21 100644
--- a/src/gcm-device-xrandr.c
+++ b/src/gcm-device-xrandr.c
@@ -51,6 +51,7 @@ struct _GcmDeviceXrandrPrivate
 {
 	gchar				*native_device;
 	gchar				*eisa_id;
+	gchar				*edid_md5;
 	guint				 gamma_size;
 	GcmEdid				*edid;
 	GcmDmi				*dmi;
@@ -66,6 +67,7 @@ enum {
 	PROP_NATIVE_DEVICE,
 	PROP_XRANDR_FALLBACK,
 	PROP_EISA_ID,
+	PROP_EDID_MD5,
 	PROP_LAST
 };
 
@@ -93,6 +95,15 @@ gcm_device_xrandr_get_eisa_id (GcmDeviceXrandr *device_xrandr)
 }
 
 /**
+ * gcm_device_xrandr_get_edid_md5:
+ **/
+const gchar *
+gcm_device_xrandr_get_edid_md5 (GcmDeviceXrandr *device_xrandr)
+{
+	return device_xrandr->priv->edid_md5;
+}
+
+/**
  * gcm_device_xrandr_get_fallback:
  **/
 gboolean
@@ -261,6 +272,7 @@ gcm_device_xrandr_set_from_output (GcmDevice *device, GnomeRROutput *output, GEr
 	manufacturer = gcm_edid_get_vendor_name (priv->edid);
 	serial = gcm_edid_get_serial_number (priv->edid);
 	priv->eisa_id = g_strdup (gcm_edid_get_eisa_id (priv->edid));
+	priv->edid_md5 = g_strdup (gcm_edid_get_checksum (priv->edid));
 
 	/* refine data if it's missing */
 	output_name = gnome_rr_output_get_name (output);
@@ -446,6 +458,17 @@ gcm_device_xrandr_set_remove_atom (GcmDeviceXrandr *device_xrandr, gboolean remo
 }
 
 /**
+ * gcm_device_xrandr_get_config_data:
+ **/
+static gchar *
+gcm_device_xrandr_get_config_data (GcmDevice *device)
+{
+	GcmDeviceXrandr *device_xrandr = GCM_DEVICE_XRANDR (device);
+	GcmDeviceXrandrPrivate *priv = device_xrandr->priv;
+	return g_strdup_printf ("edid-hash=%s", priv->edid_md5);
+}
+
+/**
  * gcm_device_xrandr_apply:
  *
  * Return value: %TRUE for success;
@@ -631,6 +654,9 @@ gcm_device_xrandr_get_property (GObject *object, guint prop_id, GValue *value, G
 	case PROP_EISA_ID:
 		g_value_set_string (value, priv->eisa_id);
 		break;
+	case PROP_EDID_MD5:
+		g_value_set_string (value, priv->edid_md5);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -672,6 +698,7 @@ gcm_device_xrandr_class_init (GcmDeviceXrandrClass *klass)
 	object_class->set_property = gcm_device_xrandr_set_property;
 
 	device_class->apply = gcm_device_xrandr_apply;
+	device_class->get_config_data = gcm_device_xrandr_get_config_data;
 
 	/**
 	 * GcmDeviceXrandr:native-device:
@@ -697,6 +724,14 @@ gcm_device_xrandr_class_init (GcmDeviceXrandrClass *klass)
 				     G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_EISA_ID, pspec);
 
+	/**
+	 * GcmDeviceXrandr:edid-md5:
+	 */
+	pspec = g_param_spec_string ("edid-md", NULL, NULL,
+				     NULL,
+				     G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_EDID_MD5, pspec);
+
 	g_type_class_add_private (klass, sizeof (GcmDeviceXrandrPrivate));
 }
 
@@ -709,6 +744,7 @@ gcm_device_xrandr_init (GcmDeviceXrandr *device_xrandr)
 	device_xrandr->priv = GCM_DEVICE_XRANDR_GET_PRIVATE (device_xrandr);
 	device_xrandr->priv->native_device = NULL;
 	device_xrandr->priv->eisa_id = NULL;
+	device_xrandr->priv->edid_md5 = NULL;
 	device_xrandr->priv->xrandr_fallback = FALSE;
 	device_xrandr->priv->remove_atom = TRUE;
 	device_xrandr->priv->gamma_size = 0;
@@ -730,6 +766,7 @@ gcm_device_xrandr_finalize (GObject *object)
 
 	g_free (priv->native_device);
 	g_free (priv->eisa_id);
+	g_free (priv->edid_md5);
 	g_object_unref (priv->edid);
 	g_object_unref (priv->dmi);
 	g_object_unref (priv->settings);
diff --git a/src/gcm-device-xrandr.h b/src/gcm-device-xrandr.h
index 6f008df..9c37437 100644
--- a/src/gcm-device-xrandr.h
+++ b/src/gcm-device-xrandr.h
@@ -57,6 +57,7 @@ void		 gcm_device_xrandr_set_remove_atom	(GcmDeviceXrandr	*device_xrandr,
 							 gboolean		 remove_atom);
 const gchar	*gcm_device_xrandr_get_native_device	(GcmDeviceXrandr	*device_xrandr);
 const gchar	*gcm_device_xrandr_get_eisa_id		(GcmDeviceXrandr	*device_xrandr);
+const gchar	*gcm_device_xrandr_get_edid_md5		(GcmDeviceXrandr	*device_xrandr);
 gboolean	 gcm_device_xrandr_get_fallback		(GcmDeviceXrandr	*device_xrandr);
 
 G_END_DECLS
diff --git a/src/gcm-device.c b/src/gcm-device.c
index 60ca19e..4a2933d 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -733,10 +733,13 @@ gcm_device_save (GcmDevice *device, GError **error)
 	gchar *filename = NULL;
 	gchar *timespec = NULL;
 	gchar **profile_filenames;
+	gchar *config_data = NULL;
+	gchar **config_items = NULL;
 	GError *error_local = NULL;
 	GTimeVal timeval;
 	GcmProfile *profile;
 	GcmDevicePrivate *priv = device->priv;
+	GcmDeviceClass *klass = GCM_DEVICE_GET_CLASS (device);
 
 	g_return_val_if_fail (GCM_IS_DEVICE (device), FALSE);
 	g_return_val_if_fail (priv->id != NULL, FALSE);
@@ -854,6 +857,20 @@ gcm_device_save (GcmDevice *device, GError **error)
 	if (priv->virtual)
 		g_key_file_set_boolean (keyfile, priv->id, "virtual", TRUE);
 
+	/* get extra, device specific config data */
+	if (klass->get_config_data != NULL) {
+		config_data = klass->get_config_data (device);
+		config_items = g_strsplit (config_data, "=", 2);
+		if (g_strv_length (config_items) != 2) {
+			ret = FALSE;
+			g_set_error (error, 1, 0, "failed to get device specific config data for: %s", priv->id);
+			goto out;
+		}
+
+		/* save unstructured data to the keyfile */
+		g_key_file_set_string (keyfile, priv->id, config_items[0], config_items[1]);
+	}
+
 	/* convert to string */
 	data = g_key_file_to_data (keyfile, NULL, &error_local);
 	if (data == NULL) {
@@ -874,6 +891,8 @@ gcm_device_save (GcmDevice *device, GError **error)
 	/* update status */
 	gcm_device_set_saved (device, TRUE);
 out:
+	g_strfreev (config_items);
+	g_free (config_data);
 	g_free (timespec);
 	g_free (data);
 	g_free (filename);
diff --git a/src/gcm-device.h b/src/gcm-device.h
index ecd88a1..2a79888 100644
--- a/src/gcm-device.h
+++ b/src/gcm-device.h
@@ -52,6 +52,7 @@ struct _GcmDeviceClass
 	void		 (*changed)			(GcmDevice		*device);
 	gboolean	 (*apply)			(GcmDevice		*device,
 							 GError			**error);
+	gchar		*(*get_config_data)		(GcmDevice		*device);
 	/* padding for future expansion */
 	void (*_gcm_reserved1) (void);
 	void (*_gcm_reserved2) (void);



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