[gnome-color-manager] trivial: switch GcmDevice to using multiple pre-parsed profiles by default



commit f05fce880fc84091e6f44d7ea99d027aeb5bb3ff
Author: Richard Hughes <richard hughsie com>
Date:   Wed May 26 13:35:26 2010 +0100

    trivial: switch GcmDevice to using multiple pre-parsed profiles by default
    
    This speeds up requests to the DBus interface by an order of magnitude or more.

 src/gcm-client.c    |    2 +-
 src/gcm-device.c    |  147 ++++++++++++++++++++++++++++++++++----------------
 src/gcm-device.h    |    6 +-
 src/gcm-self-test.c |   96 +++++++++++++++++++++------------
 src/gcm-session.c   |   62 ++--------------------
 5 files changed, 169 insertions(+), 144 deletions(-)
---
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 2c85540..dc395b4 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -1164,7 +1164,7 @@ gcm_client_add_device (GcmClient *client, GcmDevice *device, GError **error)
 	device_tmp = gcm_client_get_device_by_id (client, device_id);
 	if (device_tmp != NULL) {
 		egg_debug ("already exists, copy settings and remove old device: %s", device_id);
-		gcm_device_set_profile_filenames (device, gcm_device_get_profile_filenames (device_tmp));
+		gcm_device_set_profiles (device, gcm_device_get_profiles (device_tmp));
 		gcm_device_set_saved (device, gcm_device_get_saved (device_tmp));
 		ret = gcm_client_remove_device_internal (client, device_tmp, FALSE, error);
 		if (!ret)
diff --git a/src/gcm-device.c b/src/gcm-device.c
index 0b5d89a..bff4e7c 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -58,7 +58,7 @@ struct _GcmDevicePrivate
 	gchar			*serial;
 	gchar			*manufacturer;
 	gchar			*model;
-	gchar			**profile_filenames;
+	GPtrArray		*profiles;
 	gchar			*title;
 	GSettings		*settings;
 	GcmColorspace		 colorspace;
@@ -79,7 +79,7 @@ enum {
 	PROP_GAMMA,
 	PROP_BRIGHTNESS,
 	PROP_CONTRAST,
-	PROP_PROFILE_FILENAME,
+	PROP_PROFILES,
 	PROP_TITLE,
 	PROP_COLORSPACE,
 	PROP_LAST
@@ -179,25 +179,23 @@ static gboolean
 gcm_device_load_from_default_profile (GcmDevice *device, GError **error)
 {
 	gboolean ret = TRUE;
+	GcmProfile *profile;
 	GcmDevicePrivate *priv = device->priv;
 
 	g_return_val_if_fail (GCM_IS_DEVICE (device), FALSE);
 
 	/* no profile to load */
-	if (priv->profile_filenames == NULL)
+	if (priv->profiles->len == 0)
 		goto out;
 
-	/* load the profile if it's set */
-	if (priv->profile_filenames != NULL) {
-
-		/* if the profile was deleted */
-		ret = g_file_test (priv->profile_filenames[0], G_FILE_TEST_EXISTS);
-		if (!ret) {
-			egg_warning ("the file was deleted and can't be loaded: %s", priv->profile_filenames[0]);
-			/* this is not fatal */
-			ret = TRUE;
-			goto out;
-		}
+	/* if the profile was deleted */
+	profile = g_ptr_array_index (priv->profiles, 0);
+	ret = g_file_test (gcm_profile_get_filename (profile), G_FILE_TEST_EXISTS);
+	if (!ret) {
+		egg_warning ("the file was deleted and can't be loaded: %s", gcm_profile_get_filename (profile));
+		/* this is not fatal */
+		ret = TRUE;
+		goto out;
 	}
 out:
 	return ret;
@@ -486,26 +484,28 @@ gcm_device_set_title (GcmDevice *device, const gchar *title)
 }
 
 /**
- * gcm_device_get_profile_filenames:
+ * gcm_device_get_profiles:
  *
- * Return value: the filenames. Do not free this value
+ * Return value: the profiles. Do not unref this value
  **/
-gchar **
-gcm_device_get_profile_filenames (GcmDevice *device)
+GPtrArray *
+gcm_device_get_profiles (GcmDevice *device)
 {
 	g_return_val_if_fail (GCM_IS_DEVICE (device), NULL);
-	return device->priv->profile_filenames;
+	return device->priv->profiles;
 }
 
 /**
- * gcm_device_set_profile_filenames:
+ * gcm_device_set_profiles:
  **/
 void
-gcm_device_set_profile_filenames (GcmDevice *device, gchar **profile_filenames)
+gcm_device_set_profiles (GcmDevice *device, GPtrArray *profiles)
 {
 	g_return_if_fail (GCM_IS_DEVICE (device));
-	g_strfreev (device->priv->profile_filenames);
-	device->priv->profile_filenames = g_strdupv (profile_filenames);
+	g_return_if_fail (profiles != NULL);
+
+	g_ptr_array_unref (device->priv->profiles);
+	device->priv->profiles = g_ptr_array_ref (profiles);
 	gcm_device_changed (device);
 }
 
@@ -515,10 +515,12 @@ gcm_device_set_profile_filenames (GcmDevice *device, gchar **profile_filenames)
 const gchar *
 gcm_device_get_default_profile_filename (GcmDevice *device)
 {
+	GcmProfile *profile;
 	g_return_val_if_fail (GCM_IS_DEVICE (device), NULL);
-	if (device->priv->profile_filenames == NULL)
+	if (device->priv->profiles->len == 0)
 		return NULL;
-	return device->priv->profile_filenames[0];
+	profile = g_ptr_array_index (device->priv->profiles, 0);
+	return gcm_profile_get_filename (profile);
 }
 
 /**
@@ -527,12 +529,34 @@ gcm_device_get_default_profile_filename (GcmDevice *device)
 void
 gcm_device_set_default_profile_filename (GcmDevice *device, const gchar *profile_filename)
 {
+	GcmProfile *profile;
+	GPtrArray *array;
+	gboolean ret;
+	GFile *file;
+	GError *error = NULL;
+
 	g_return_if_fail (GCM_IS_DEVICE (device));
-	g_strfreev (device->priv->profile_filenames);
+
+	/* create new list */
+	array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+	profile = gcm_profile_default_new ();
+
+	/* TODO: parse here? */
+	file = g_file_new_for_path (profile_filename);
+	ret = gcm_profile_parse (profile, file, &error);
+	if (!ret) {
+		egg_warning ("failed to parse: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
 
 	/* FIXME: don't just nuke the list */
-	device->priv->profile_filenames = g_strsplit (profile_filename, ";", 1);
-	gcm_device_changed (device);
+	g_ptr_array_add (array, g_object_ref (profile));
+	gcm_device_set_profiles (device, array);
+out:
+	g_ptr_array_unref (array);
+	g_object_unref (profile);
+	g_object_unref (file);
 }
 
 /**
@@ -557,6 +581,10 @@ gcm_device_load (GcmDevice *device, GError **error)
 	gchar *filename = NULL;
 	GTimeVal timeval;
 	gchar *iso_date = NULL;
+	gchar **profile_filenames = NULL;
+	guint i;
+	GcmProfile *profile;
+	GFile *file_tmp;
 	GcmDevicePrivate *priv = device->priv;
 
 	g_return_val_if_fail (GCM_IS_DEVICE (device), FALSE);
@@ -597,8 +625,24 @@ gcm_device_load (GcmDevice *device, GError **error)
 	gcm_device_set_saved (device, TRUE);
 
 	/* load data */
-	g_strfreev (priv->profile_filenames);
-	priv->profile_filenames = g_key_file_get_string_list (file, priv->id, "profile", NULL, NULL);
+	g_ptr_array_set_size (priv->profiles, 0);
+
+	/* parse filenames to object, skipping entries that fail to parse */
+	profile_filenames = g_key_file_get_string_list (file, priv->id, "profile", NULL, NULL);
+	for (i=0; profile_filenames[i] != NULL; i++) {
+		file_tmp = g_file_new_for_path (profile_filenames[i]);
+		profile = gcm_profile_default_new ();
+		ret = gcm_profile_parse (profile, file_tmp, &error_local);
+		if (ret) {
+			g_ptr_array_add (priv->profiles, g_object_ref (profile));
+		} else {
+			egg_warning ("failed to parse %s: %s", profile_filenames[i], error_local->message);
+			g_clear_error (&error_local);
+		}
+		g_object_unref (profile);
+		g_object_unref (file_tmp);
+	}
+
 	if (priv->serial == NULL)
 		priv->serial = g_key_file_get_string (file, priv->id, "serial", NULL);
 	if (priv->model == NULL)
@@ -642,15 +686,15 @@ gcm_device_load (GcmDevice *device, GError **error)
 	if (!ret) {
 
 		/* just print a warning, this is not fatal */
-		egg_warning ("failed to load profile %s: %s", priv->profile_filenames[0], error_local->message);
+		egg_warning ("failed to load profile %s", error_local->message);
 		g_error_free (error_local);
 
 		/* recover as the file might have been corrupted */
-		g_strfreev (priv->profile_filenames);
-		priv->profile_filenames = NULL;
+		g_ptr_array_set_size (priv->profiles, 0);
 		ret = TRUE;
 	}
 out:
+	g_strfreev (profile_filenames);
 	g_free (iso_date);
 	g_free (filename);
 	if (file != NULL)
@@ -665,14 +709,17 @@ gboolean
 gcm_device_save (GcmDevice *device, GError **error)
 {
 	GKeyFile *keyfile = NULL;
+	guint i;
 	gboolean ret;
 	gchar *data = NULL;
 	gchar *dirname;
 	GFile *file = NULL;
 	gchar *filename = NULL;
 	gchar *timespec = NULL;
+	gchar **profile_filenames;
 	GError *error_local = NULL;
 	GTimeVal timeval;
+	GcmProfile *profile;
 	GcmDevicePrivate *priv = device->priv;
 
 	g_return_val_if_fail (GCM_IS_DEVICE (device), FALSE);
@@ -733,12 +780,19 @@ gcm_device_save (GcmDevice *device, GError **error)
 	g_key_file_set_string (keyfile, priv->id, "modified", timespec);
 
 	/* save data */
-	if (priv->profile_filenames == NULL)
+	if (priv->profiles->len == 0)
 		g_key_file_remove_key (keyfile, priv->id, "profile", NULL);
-	else
+	else {
+		profile_filenames = g_new0 (gchar *, priv->profiles->len + 1);
+		for (i=0; i<priv->profiles->len; i++) {
+			profile = g_ptr_array_index (priv->profiles, i);
+			profile_filenames[i] = g_strdup (gcm_profile_get_filename (profile));
+		}
 		g_key_file_set_string_list (keyfile, priv->id, "profile",
-					    (const gchar * const*) priv->profile_filenames,
-					    g_strv_length (priv->profile_filenames));
+					    (const gchar * const*) profile_filenames,
+					    priv->profiles->len);
+		g_strfreev (profile_filenames);
+	}
 
 	/* save device specific data */
 	if (priv->serial == NULL)
@@ -879,8 +933,8 @@ gcm_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
 	case PROP_CONTRAST:
 		g_value_set_float (value, priv->contrast);
 		break;
-	case PROP_PROFILE_FILENAME:
-		g_value_set_boxed (value, priv->profile_filenames);
+	case PROP_PROFILES:
+		g_value_set_pointer (value, priv->profiles);
 		break;
 	case PROP_TITLE:
 		g_value_set_string (value, priv->title);
@@ -930,8 +984,8 @@ gcm_device_set_property (GObject *object, guint prop_id, const GValue *value, GP
 	case PROP_TITLE:
 		gcm_device_set_title (device, g_value_get_string (value));
 		break;
-	case PROP_PROFILE_FILENAME:
-		gcm_device_set_profile_filenames (device, (gchar**)g_value_get_boxed (value));
+	case PROP_PROFILES:
+		gcm_device_set_profiles (device, g_value_get_pointer (value));
 		break;
 	case PROP_GAMMA:
 		gcm_device_set_gamma (device, g_value_get_float (value));
@@ -1054,10 +1108,9 @@ gcm_device_class_init (GcmDeviceClass *klass)
 	/**
 	 * GcmDevice:profile-filename:
 	 */
-	pspec = g_param_spec_boxed ("profile-filename", NULL, NULL,
-				    G_TYPE_STRV,
-				    G_PARAM_READWRITE);
-	g_object_class_install_property (object_class, PROP_PROFILE_FILENAME, pspec);
+	pspec = g_param_spec_pointer ("profile-filename", NULL, NULL,
+				      G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_PROFILES, pspec);
 
 	/**
 	 * GcmDevice:title:
@@ -1103,7 +1156,7 @@ gcm_device_init (GcmDevice *device)
 	device->priv->serial = NULL;
 	device->priv->manufacturer = NULL;
 	device->priv->model = NULL;
-	device->priv->profile_filenames = NULL;
+	device->priv->profiles = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
 	device->priv->modified_time = 0;
 	device->priv->settings = g_settings_new (GCM_SETTINGS_SCHEMA);
 	device->priv->gamma = g_settings_get_double (device->priv->settings, GCM_SETTINGS_DEFAULT_GAMMA);
@@ -1132,7 +1185,7 @@ gcm_device_finalize (GObject *object)
 	g_free (priv->serial);
 	g_free (priv->manufacturer);
 	g_free (priv->model);
-	g_strfreev (priv->profile_filenames);
+	g_ptr_array_unref (priv->profiles);
 	g_object_unref (priv->settings);
 
 	G_OBJECT_CLASS (gcm_device_parent_class)->finalize (object);
diff --git a/src/gcm-device.h b/src/gcm-device.h
index f35bb65..006a98f 100644
--- a/src/gcm-device.h
+++ b/src/gcm-device.h
@@ -107,9 +107,9 @@ void			 gcm_device_set_model			(GcmDevice	*device,
 const gchar		*gcm_device_get_title			(GcmDevice	*device);
 void			 gcm_device_set_title			(GcmDevice	*device,
 								 const gchar 	*title);
-gchar			**gcm_device_get_profile_filenames	(GcmDevice	*device);
-void			 gcm_device_set_profile_filenames	(GcmDevice	*device,
-								 gchar 		**profile_filenames);
+GPtrArray		*gcm_device_get_profiles		(GcmDevice	*device);
+void			 gcm_device_set_profiles		(GcmDevice	*device,
+								 GPtrArray	*profiles);
 glong			 gcm_device_get_modified_time		(GcmDevice	*device);
 
 /* helpers */
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index a5565aa..8efe043 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -64,28 +64,28 @@ gcm_test_get_data_file (const gchar *filename)
 		return full;
 	g_free (full);
 
-	/* check to see if we are being run in the build root */
-	full = g_build_filename ("..", "..", "data", "tests", filename, NULL);
-	ret = g_file_test (full, G_FILE_TEST_EXISTS);
-	if (ret)
-		return full;
-	g_free (full);
-
 	/* check to see if we are being run in make check */
 	full = g_build_filename ("..", "..", "data", "tests", filename, NULL);
 	ret = g_file_test (full, G_FILE_TEST_EXISTS);
 	if (ret)
 		return full;
 	g_free (full);
-	full = g_build_filename ("..", "..", "..", "data", "tests", filename, NULL);
-	ret = g_file_test (full, G_FILE_TEST_EXISTS);
-	if (ret)
-		return full;
-	g_free (full);
 	return NULL;
 }
 
 static void
+gcm_test_assert_basename (const gchar *filename1, const gchar *filename2)
+{
+	gchar *basename1;
+	gchar *basename2;
+	basename1 = g_path_get_basename (filename1);
+	basename2 = g_path_get_basename (filename2);
+	g_assert_cmpstr (basename1, ==, basename2);
+	g_free (basename1);
+	g_free (basename2);
+}
+
+static void
 gcm_test_brightness_func (void)
 {
 	GcmBrightness *brightness;
@@ -348,10 +348,18 @@ gcm_test_device_func (void)
 	gboolean ret;
 	GError *error = NULL;
 	gchar *filename;
-	const gchar *profile;
-	gchar **profiles;
+	GcmProfile *profile;
+	const gchar *profile_filename;
+	GPtrArray *profiles;
 	gchar *data;
 	gchar **split;
+	gchar *contents;
+	gchar *icc_filename1;
+	gchar *icc_filename2;
+
+	/* get test files */
+	icc_filename1 = gcm_test_get_data_file ("bluish.icc");
+	icc_filename2 = gcm_test_get_data_file ("AdobeGammaTest.icm");
 
 	device = gcm_device_udev_new ();
 	g_assert (device != NULL);
@@ -410,11 +418,12 @@ gcm_test_device_func (void)
 	g_assert (ret);
 
 	/* set default file */
-	g_file_set_contents (filename,
-			     "[sysfs_dummy_device]\n"
-			     "title=Canon - CanoScan\n"
-			     "type=scanner\n"
-			     "profile=/srv/sysfs_canon_canoscan.icc;/home/generic.icc\n", -1, NULL);
+	contents = g_strdup_printf ("[sysfs_dummy_device]\n"
+				    "title=Canon - CanoScan\n"
+				    "type=scanner\n"
+				    "profile=%s;%s\n",
+				    icc_filename1, icc_filename2);
+	g_file_set_contents (filename, contents, -1, NULL);
 
 	ret = gcm_device_load (device, &error);
 	g_assert_no_error (error);
@@ -427,15 +436,21 @@ gcm_test_device_func (void)
 	g_assert_cmpint (_changes, ==, 3);
 
 	/* get some properties */
-	profile = gcm_device_get_default_profile_filename (device);
-	g_assert_cmpstr (profile, ==, "/srv/sysfs_canon_canoscan.icc");
-	profiles = gcm_device_get_profile_filenames (device);
-	g_assert_cmpstr (profiles[0], ==, "/srv/sysfs_canon_canoscan.icc");
-	g_assert_cmpstr (profiles[1], ==, "/home/generic.icc");
-	g_assert_cmpstr (profiles[2], ==, NULL);
+	profile_filename = gcm_device_get_default_profile_filename (device);
+	gcm_test_assert_basename (profile_filename, icc_filename1);
+	profiles = gcm_device_get_profiles (device);
+	g_assert_cmpint (profiles->len, ==, 2);
+
+	profile = g_ptr_array_index (profiles, 0);
+	g_assert (profile != NULL);
+	gcm_test_assert_basename (gcm_profile_get_filename (profile), icc_filename1);
+
+	profile = g_ptr_array_index (profiles, 1);
+	g_assert (profile != NULL);
+	gcm_test_assert_basename (gcm_profile_get_filename (profile), icc_filename2);
 
 	/* set some properties */
-	gcm_device_set_default_profile_filename (device, "/srv/sysfs_canon_canoscan.icc");
+	gcm_device_set_default_profile_filename (device, icc_filename1);
 
 	/* ensure the file is nuked, again */
 	g_unlink (filename);
@@ -450,7 +465,6 @@ gcm_test_device_func (void)
 
 	split = g_strsplit (data, "\n", -1);
 	g_assert_cmpstr (split[1], ==, "[sysfs_dummy_device]");
-	g_assert_cmpstr (split[4], ==, "profile=/srv/sysfs_canon_canoscan.icc;");
 	g_assert_cmpstr (split[5], ==, "serial=0123456789");
 	g_assert_cmpstr (split[6], ==, "type=scanner");
 	g_assert_cmpstr (split[7], ==, "colorspace=rgb");
@@ -461,6 +475,9 @@ gcm_test_device_func (void)
 	g_unlink (filename);
 	g_main_loop_unref (_loop);
 	g_free (filename);
+	g_free (icc_filename1);
+	g_free (icc_filename2);
+	g_free (contents);
 
 	g_object_unref (device);
 }
@@ -1062,9 +1079,14 @@ gcm_test_client_func (void)
 	gboolean ret;
 	GPtrArray *array;
 	GcmDevice *device;
+	gchar *contents;
 	gchar *filename;
+	gchar *icc_filename;
 	gchar *data = NULL;
 
+	/* get test file */
+	icc_filename = gcm_test_get_data_file ("bluish.icc");
+
 	client = gcm_client_new ();
 	g_assert (client != NULL);
 
@@ -1079,16 +1101,17 @@ gcm_test_client_func (void)
 	g_assert (ret);
 
 	array = gcm_client_get_devices (client);
+	g_assert (array != NULL);
 	g_assert_cmpint (array->len, ==, 0);
 	g_ptr_array_unref (array);
 
 	/* ensure we get one device */
-	ret = g_file_set_contents (filename,
-				   "[xrandr_goldstar]\n"
-				   "profile=dave.icc\n"
-				   "title=Goldstar\n"
-				   "type=display\n"
-				   "colorspace=rgb\n", -1, &error);
+	contents = g_strdup_printf ("[xrandr_goldstar]\n"
+				    "profile=%s\n"
+				    "title=Goldstar\n"
+				    "type=display\n"
+				    "colorspace=rgb\n", icc_filename);
+	ret = g_file_set_contents (filename, contents, -1, &error);
 	g_assert_no_error (error);
 	g_assert (ret);
 
@@ -1097,11 +1120,12 @@ gcm_test_client_func (void)
 	g_assert (ret);
 
 	array = gcm_client_get_devices (client);
+	g_assert (array != NULL);
 	g_assert_cmpint (array->len, ==, 1);
 	device = g_ptr_array_index (array, 0);
 	g_assert_cmpstr (gcm_device_get_id (device), ==, "xrandr_goldstar");
 	g_assert_cmpstr (gcm_device_get_title (device), ==, "Goldstar");
-	g_assert_cmpstr (gcm_device_get_default_profile_filename (device), ==, "dave.icc");
+	gcm_test_assert_basename (gcm_device_get_default_profile_filename (device), icc_filename);
 	g_assert (gcm_device_get_saved (device));
 	g_assert (!gcm_device_get_connected (device));
 	g_assert (GCM_IS_DEVICE_XRANDR (device));
@@ -1121,7 +1145,7 @@ gcm_test_client_func (void)
 	device = g_ptr_array_index (array, 0);
 	g_assert_cmpstr (gcm_device_get_id (device), ==, "xrandr_goldstar");
 	g_assert_cmpstr (gcm_device_get_title (device), ==, "Slightly different");
-	g_assert_cmpstr (gcm_device_get_default_profile_filename (device), ==, "dave.icc");
+	gcm_test_assert_basename (gcm_device_get_default_profile_filename (device), icc_filename);
 	g_assert (gcm_device_get_saved (device));
 	g_assert (gcm_device_get_connected (device));
 	g_assert (GCM_IS_DEVICE_UDEV (device));
@@ -1146,7 +1170,9 @@ gcm_test_client_func (void)
 	g_object_unref (client);
 	g_object_unref (device);
 	g_unlink (filename);
+	g_free (contents);
 	g_free (filename);
+	g_free (icc_filename);
 	g_free (data);
 }
 
diff --git a/src/gcm-session.c b/src/gcm-session.c
index c498e3f..d7e2838 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -317,9 +317,6 @@ gcm_session_get_profiles_for_file (const gchar *filename, GError **error)
 	GPtrArray *array = NULL;
 	GPtrArray *array_devices;
 	GFile *file;
-	GFile *file_tmp;
-	GcmProfile *profile;
-	GError *error_local = NULL;
 
 	/* get file type */
 	exif = gcm_exif_new ();
@@ -328,9 +325,6 @@ gcm_session_get_profiles_for_file (const gchar *filename, GError **error)
 	if (!ret)
 		goto out;
 
-	/* create a temp array */
-	array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
-
 	/* get list */
 	egg_debug ("query=%s", filename);
 	array_devices = gcm_client_get_devices (client);
@@ -341,28 +335,8 @@ gcm_session_get_profiles_for_file (const gchar *filename, GError **error)
 		if (g_strcmp0 (gcm_device_get_manufacturer (device), gcm_exif_get_manufacturer (exif)) == 0 &&
 		    g_strcmp0 (gcm_device_get_model (device), gcm_exif_get_model (exif)) == 0 &&
 		    g_strcmp0 (gcm_device_get_serial (device), gcm_exif_get_serial (exif)) == 0) {
-
-			/* TODO: get an array of GcmProfiles */
-			filename = gcm_device_get_default_profile_filename (device);
-			if (filename == NULL) {
-				egg_warning ("%s does not have a profile set", gcm_device_get_id (device));
-				continue;
-			}
-
-			/* open and parse filename */
-			profile = gcm_profile_default_new ();
-			file_tmp = g_file_new_for_path (filename);
-			ret = gcm_profile_parse (profile, file_tmp, &error_local);
-			if (!ret) {
-				egg_warning ("failed to parse %s: %s", filename, error_local->message);
-				g_clear_error (&error_local);
-			} else {
-				g_ptr_array_add (array, g_object_ref (profile));
-			}
-
-			/* unref */
-			g_object_unref (file_tmp);
-			g_object_unref (profile);
+			array = gcm_device_get_profiles (device);
+			break;
 		}
 	}
 
@@ -380,16 +354,11 @@ out:
 static GPtrArray *
 gcm_session_get_profiles_for_device (const gchar *device_id_with_prefix, GError **error)
 {
-	gboolean ret;
-	const gchar *filename;
 	const gchar *device_id;
 	const gchar *device_id_tmp;
 	guint i;
 	gboolean use_native_device = FALSE;
 	GcmDevice *device;
-	GcmProfile *profile;
-	GFile *file;
-	GError *error_local = NULL;
 	GPtrArray *array;
 	GPtrArray *array_devices;
 
@@ -406,9 +375,6 @@ gcm_session_get_profiles_for_device (const gchar *device_id_with_prefix, GError
 	if (g_str_has_prefix (device_id_with_prefix, "/"))
 		use_native_device = TRUE;
 
-	/* create a temp array */
-	array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
-
 	/* get list */
 	egg_debug ("query=%s [%s] %i", device_id_with_prefix, device_id, use_native_device);
 	array_devices = gcm_client_get_devices (client);
@@ -429,28 +395,8 @@ gcm_session_get_profiles_for_device (const gchar *device_id_with_prefix, GError
 		/* compare what we have against what we were given */
 		egg_debug ("comparing %s with %s", device_id_tmp, device_id);
 		if (g_strcmp0 (device_id_tmp, device_id) == 0) {
-
-			/* TODO: get an array of GcmProfiles */
-			filename = gcm_device_get_default_profile_filename (device);
-			if (filename == NULL) {
-				egg_warning ("%s does not have a profile set", device_id);
-				continue;
-			}
-
-			/* open and parse filename */
-			profile = gcm_profile_default_new ();
-			file = g_file_new_for_path (filename);
-			ret = gcm_profile_parse (profile, file, &error_local);
-			if (!ret) {
-				egg_warning ("failed to parse %s: %s", filename, error_local->message);
-				g_clear_error (&error_local);
-			} else {
-				g_ptr_array_add (array, g_object_ref (profile));
-			}
-
-			/* unref */
-			g_object_unref (file);
-			g_object_unref (profile);
+			array = gcm_device_get_profiles (device);
+			break;
 		}
 	}
 



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