[gnome-color-manager] Add gcm_profile_get_checksum() so we can use this as a key to detect duplicates



commit 9c9ea2c5c60804e5a02420746b981fb1134604cf
Author: Richard Hughes <richard hughsie com>
Date:   Mon May 31 21:32:44 2010 +0100

    Add gcm_profile_get_checksum() so we can use this as a key to detect duplicates

 src/gcm-profile.c   |   53 ++++++++++++++++++++++++++++++++++++++++++++------
 src/gcm-profile.h   |    1 +
 src/gcm-self-test.c |    4 +++
 3 files changed, 51 insertions(+), 7 deletions(-)
---
diff --git a/src/gcm-profile.c b/src/gcm-profile.c
index 3cd3c33..162e05f 100644
--- a/src/gcm-profile.c
+++ b/src/gcm-profile.c
@@ -61,6 +61,7 @@ struct _GcmProfilePrivate
 	gchar			*manufacturer;
 	gchar			*model;
 	gchar			*datetime;
+	gchar			*checksum;
 	GcmXyz			*white;
 	GcmXyz			*black;
 	GcmXyz			*red;
@@ -75,6 +76,7 @@ enum {
 	PROP_MANUFACTURER,
 	PROP_MODEL,
 	PROP_DATETIME,
+	PROP_CHECKSUM,
 	PROP_DESCRIPTION,
 	PROP_FILENAME,
 	PROP_KIND,
@@ -131,7 +133,6 @@ gcm_profile_set_description (GcmProfile *profile, const gchar *description)
 	g_object_notify (G_OBJECT (profile), "description");
 }
 
-
 /**
  * gcm_profile_get_filename:
  **/
@@ -195,7 +196,6 @@ gcm_profile_set_filename (GcmProfile *profile, const gchar *filename)
 	g_object_notify (G_OBJECT (profile), "filename");
 }
 
-
 /**
  * gcm_profile_get_copyright:
  **/
@@ -223,7 +223,6 @@ gcm_profile_set_copyright (GcmProfile *profile, const gchar *copyright)
 	g_object_notify (G_OBJECT (profile), "copyright");
 }
 
-
 /**
  * gcm_profile_get_model:
  **/
@@ -278,7 +277,6 @@ gcm_profile_set_manufacturer (GcmProfile *profile, const gchar *manufacturer)
 	g_object_notify (G_OBJECT (profile), "manufacturer");
 }
 
-
 /**
  * gcm_profile_get_datetime:
  **/
@@ -304,6 +302,30 @@ gcm_profile_set_datetime (GcmProfile *profile, const gchar *datetime)
 	g_object_notify (G_OBJECT (profile), "datetime");
 }
 
+/**
+ * gcm_profile_get_checksum:
+ **/
+const gchar *
+gcm_profile_get_checksum (GcmProfile *profile)
+{
+	g_return_val_if_fail (GCM_IS_PROFILE (profile), NULL);
+	return profile->priv->checksum;
+}
+
+/**
+ * gcm_profile_set_checksum:
+ **/
+static void
+gcm_profile_set_checksum (GcmProfile *profile, const gchar *checksum)
+{
+	GcmProfilePrivate *priv = profile->priv;
+
+	g_return_if_fail (GCM_IS_PROFILE (profile));
+
+	g_free (priv->checksum);
+	priv->checksum = g_strdup (checksum);
+	g_object_notify (G_OBJECT (profile), "checksum");
+}
 
 /**
  * gcm_profile_get_size:
@@ -326,7 +348,6 @@ gcm_profile_set_size (GcmProfile *profile, guint size)
 	g_object_notify (G_OBJECT (profile), "size");
 }
 
-
 /**
  * gcm_profile_get_kind:
  **/
@@ -348,7 +369,6 @@ gcm_profile_set_kind (GcmProfile *profile, GcmProfileKind kind)
 	g_object_notify (G_OBJECT (profile), "kind");
 }
 
-
 /**
  * gcm_profile_get_colorspace:
  **/
@@ -370,7 +390,6 @@ gcm_profile_set_colorspace (GcmProfile *profile, GcmColorspace colorspace)
 	g_object_notify (G_OBJECT (profile), "colorspace");
 }
 
-
 /**
  * gcm_profile_get_has_vcgt:
  **/
@@ -399,6 +418,7 @@ gboolean
 gcm_profile_parse_data (GcmProfile *profile, const guint8 *data, gsize length, GError **error)
 {
 	gboolean ret = FALSE;
+	gchar *checksum = NULL;
 	GcmProfilePrivate *priv = profile->priv;
 	GcmProfileClass *klass = GCM_PROFILE_GET_CLASS (profile);
 
@@ -413,7 +433,14 @@ gcm_profile_parse_data (GcmProfile *profile, const guint8 *data, gsize length, G
 
 	/* proxy */
 	ret = klass->parse_data (profile, data, length, error);
+	if (!ret)
+		goto out;
+
+	/* generate and set checksum */
+	checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, (const guchar *) data, length);
+	gcm_profile_set_checksum (profile, checksum);
 out:
+	g_free (checksum);
 	return ret;
 }
 
@@ -565,6 +592,9 @@ gcm_profile_get_property (GObject *object, guint prop_id, GValue *value, GParamS
 	case PROP_DATETIME:
 		g_value_set_string (value, priv->datetime);
 		break;
+	case PROP_CHECKSUM:
+		g_value_set_string (value, priv->checksum);
+		break;
 	case PROP_DESCRIPTION:
 		g_value_set_string (value, priv->description);
 		break;
@@ -710,6 +740,14 @@ gcm_profile_class_init (GcmProfileClass *klass)
 	g_object_class_install_property (object_class, PROP_DATETIME, pspec);
 
 	/**
+	 * GcmProfile:checksum:
+	 */
+	pspec = g_param_spec_string ("checksum", NULL, NULL,
+				     NULL,
+				     G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_CHECKSUM, pspec);
+
+	/**
 	 * GcmProfile:description:
 	 */
 	pspec = g_param_spec_string ("description", NULL, NULL,
@@ -832,6 +870,7 @@ gcm_profile_finalize (GObject *object)
 	g_free (priv->manufacturer);
 	g_free (priv->model);
 	g_free (priv->datetime);
+	g_free (priv->checksum);
 	g_object_unref (priv->white);
 	g_object_unref (priv->black);
 	g_object_unref (priv->red);
diff --git a/src/gcm-profile.h b/src/gcm-profile.h
index 89a412b..afbe776 100644
--- a/src/gcm-profile.h
+++ b/src/gcm-profile.h
@@ -83,6 +83,7 @@ gboolean	 gcm_profile_parse_data			(GcmProfile	*profile,
 gboolean	 gcm_profile_save			(GcmProfile	*profile,
 							 const gchar	*filename,
 							 GError		**error);
+const gchar	*gcm_profile_get_checksum		(GcmProfile	*profile);
 GcmClut		*gcm_profile_generate_vcgt		(GcmProfile	*profile,
 							 guint		 size);
 GcmClut		*gcm_profile_generate_curve		(GcmProfile	*profile,
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 8efe043..69328f6 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -812,6 +812,7 @@ typedef struct {
 	const gchar *model;
 	const gchar *datetime;
 	const gchar *description;
+	const gchar *checksum;
 	GcmProfileKind kind;
 	GcmColorspace colorspace;
 	gfloat luminance;
@@ -845,6 +846,7 @@ gcm_test_profile_test_parse_file (const gchar *datafile, GcmProfileTestData *tes
 	g_assert_cmpstr (gcm_profile_get_model (profile_lcms1), ==, test_data->model);
 	g_assert_cmpstr (gcm_profile_get_datetime (profile_lcms1), ==, test_data->datetime);
 	g_assert_cmpstr (gcm_profile_get_description (profile_lcms1), ==, test_data->description);
+	g_assert_cmpstr (gcm_profile_get_checksum (profile_lcms1), ==, test_data->checksum);
 	g_assert_cmpint (gcm_profile_get_kind (profile_lcms1), ==, test_data->kind);
 	g_assert_cmpint (gcm_profile_get_colorspace (profile_lcms1), ==, test_data->colorspace);
 
@@ -873,6 +875,7 @@ gcm_test_profile_func (void)
 	test_data.colorspace = GCM_COLORSPACE_RGB;
 	test_data.luminance = 0.648454;
 	test_data.datetime = "February  9 1998, 06:49:00 AM";
+	test_data.checksum = "8e2aed5dac6f8b5d8da75610a65b7f27";
 	gcm_test_profile_test_parse_file ("bluish.icc", &test_data);
 
 	/* Adobe test */
@@ -884,6 +887,7 @@ gcm_test_profile_func (void)
 	test_data.colorspace = GCM_COLORSPACE_RGB;
 	test_data.luminance = 0.648446;
 	test_data.datetime = "August 16 2005, 09:49:54 PM";
+	test_data.checksum = "bd847723f676e2b846daaf6759330624";
 	gcm_test_profile_test_parse_file ("AdobeGammaTest.icm", &test_data);
 }
 



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