[gnome-color-manager] trivial: add the concept of multiple profiles for a device



commit 0c1aafa5abf56bb1adee838e38c741d58b1463dc
Author: Richard Hughes <richard hughsie com>
Date:   Wed May 26 12:19:06 2010 +0100

    trivial: add the concept of multiple profiles for a device

 src/gcm-client.c        |    2 +-
 src/gcm-device-sane.c   |    2 +-
 src/gcm-device-xrandr.c |    2 +-
 src/gcm-device.c        |   88 +++++++++++++++++++++++++++++++---------------
 src/gcm-device.h        |   11 ++++--
 src/gcm-prefs.c         |   10 +++---
 src/gcm-self-test.c     |   21 +++++++----
 src/gcm-session.c       |   12 +++---
 8 files changed, 94 insertions(+), 54 deletions(-)
---
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 9cb10ad..2c85540 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_filename (device, gcm_device_get_profile_filename (device_tmp));
+		gcm_device_set_profile_filenames (device, gcm_device_get_profile_filenames (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-sane.c b/src/gcm-device-sane.c
index 35e036e..f9672f8 100644
--- a/src/gcm-device-sane.c
+++ b/src/gcm-device-sane.c
@@ -285,7 +285,7 @@ gcm_device_sane_apply_device (GcmDeviceSane *device_sane, GError **error)
 	/* get properties from device */
 	model = gcm_device_get_model (device);
 	manufacturer = gcm_device_get_manufacturer (device);
-	profile_filename = gcm_device_get_profile_filename (device);
+	profile_filename = gcm_device_get_default_profile_filename (device);
 	profile_filename_quoted = g_strdup_printf ("\"%s\"", profile_filename);
 
 	device_filename = g_strdup_printf ("%s:%s.drc", manufacturer, model);
diff --git a/src/gcm-device-xrandr.c b/src/gcm-device-xrandr.c
index 4eb8b05..b0cd672 100644
--- a/src/gcm-device-xrandr.c
+++ b/src/gcm-device-xrandr.c
@@ -479,7 +479,7 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
 
 	/* if not saved, try to find default filename */
 	saved = gcm_device_get_saved (device);
-	filename = gcm_device_get_profile_filename (device);
+	filename = gcm_device_get_default_profile_filename (device);
 	if (!saved && filename == NULL) {
 		filename_systemwide = g_strdup_printf ("%s/%s.icc", GCM_SYSTEM_PROFILES_DIR, id);
 		ret = g_file_test (filename_systemwide, G_FILE_TEST_EXISTS);
diff --git a/src/gcm-device.c b/src/gcm-device.c
index 71b6b2b..0b5d89a 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_filename;
+	gchar			**profile_filenames;
 	gchar			*title;
 	GSettings		*settings;
 	GcmColorspace		 colorspace;
@@ -173,10 +173,10 @@ gcm_device_kind_to_string (GcmDeviceKind kind)
 }
 
 /**
- * gcm_device_load_from_profile:
+ * gcm_device_load_from_default_profile:
  **/
 static gboolean
-gcm_device_load_from_profile (GcmDevice *device, GError **error)
+gcm_device_load_from_default_profile (GcmDevice *device, GError **error)
 {
 	gboolean ret = TRUE;
 	GcmDevicePrivate *priv = device->priv;
@@ -184,16 +184,16 @@ gcm_device_load_from_profile (GcmDevice *device, GError **error)
 	g_return_val_if_fail (GCM_IS_DEVICE (device), FALSE);
 
 	/* no profile to load */
-	if (priv->profile_filename == NULL)
+	if (priv->profile_filenames == NULL)
 		goto out;
 
 	/* load the profile if it's set */
-	if (priv->profile_filename != NULL) {
+	if (priv->profile_filenames != NULL) {
 
 		/* if the profile was deleted */
-		ret = g_file_test (priv->profile_filename, G_FILE_TEST_EXISTS);
+		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_filename);
+			egg_warning ("the file was deleted and can't be loaded: %s", priv->profile_filenames[0]);
 			/* this is not fatal */
 			ret = TRUE;
 			goto out;
@@ -486,24 +486,52 @@ gcm_device_set_title (GcmDevice *device, const gchar *title)
 }
 
 /**
- * gcm_device_get_profile_filename:
+ * gcm_device_get_profile_filenames:
+ *
+ * Return value: the filenames. Do not free this value
+ **/
+gchar **
+gcm_device_get_profile_filenames (GcmDevice *device)
+{
+	g_return_val_if_fail (GCM_IS_DEVICE (device), NULL);
+	return device->priv->profile_filenames;
+}
+
+/**
+ * gcm_device_set_profile_filenames:
+ **/
+void
+gcm_device_set_profile_filenames (GcmDevice *device, gchar **profile_filenames)
+{
+	g_return_if_fail (GCM_IS_DEVICE (device));
+	g_strfreev (device->priv->profile_filenames);
+	device->priv->profile_filenames = g_strdupv (profile_filenames);
+	gcm_device_changed (device);
+}
+
+/**
+ * gcm_device_get_default_profile_filename:
  **/
 const gchar *
-gcm_device_get_profile_filename (GcmDevice *device)
+gcm_device_get_default_profile_filename (GcmDevice *device)
 {
 	g_return_val_if_fail (GCM_IS_DEVICE (device), NULL);
-	return device->priv->profile_filename;
+	if (device->priv->profile_filenames == NULL)
+		return NULL;
+	return device->priv->profile_filenames[0];
 }
 
 /**
- * gcm_device_set_profile_filename:
+ * gcm_device_set_default_profile_filename:
  **/
 void
-gcm_device_set_profile_filename (GcmDevice *device, const gchar *profile_filename)
+gcm_device_set_default_profile_filename (GcmDevice *device, const gchar *profile_filename)
 {
 	g_return_if_fail (GCM_IS_DEVICE (device));
-	g_free (device->priv->profile_filename);
-	device->priv->profile_filename = g_strdup (profile_filename);
+	g_strfreev (device->priv->profile_filenames);
+
+	/* FIXME: don't just nuke the list */
+	device->priv->profile_filenames = g_strsplit (profile_filename, ";", 1);
 	gcm_device_changed (device);
 }
 
@@ -569,8 +597,8 @@ gcm_device_load (GcmDevice *device, GError **error)
 	gcm_device_set_saved (device, TRUE);
 
 	/* load data */
-	g_free (priv->profile_filename);
-	priv->profile_filename = g_key_file_get_string (file, priv->id, "profile", NULL);
+	g_strfreev (priv->profile_filenames);
+	priv->profile_filenames = g_key_file_get_string_list (file, priv->id, "profile", NULL, NULL);
 	if (priv->serial == NULL)
 		priv->serial = g_key_file_get_string (file, priv->id, "serial", NULL);
 	if (priv->model == NULL)
@@ -610,16 +638,16 @@ gcm_device_load (GcmDevice *device, GError **error)
 	priv->modified_time = timeval.tv_sec;
 
 	/* load this */
-	ret = gcm_device_load_from_profile (device, &error_local);
+	ret = gcm_device_load_from_default_profile (device, &error_local);
 	if (!ret) {
 
 		/* just print a warning, this is not fatal */
-		egg_warning ("failed to load profile %s: %s", priv->profile_filename, error_local->message);
+		egg_warning ("failed to load profile %s: %s", priv->profile_filenames[0], error_local->message);
 		g_error_free (error_local);
 
 		/* recover as the file might have been corrupted */
-		g_free (priv->profile_filename);
-		priv->profile_filename = NULL;
+		g_strfreev (priv->profile_filenames);
+		priv->profile_filenames = NULL;
 		ret = TRUE;
 	}
 out:
@@ -705,10 +733,12 @@ gcm_device_save (GcmDevice *device, GError **error)
 	g_key_file_set_string (keyfile, priv->id, "modified", timespec);
 
 	/* save data */
-	if (priv->profile_filename == NULL)
+	if (priv->profile_filenames == NULL)
 		g_key_file_remove_key (keyfile, priv->id, "profile", NULL);
 	else
-		g_key_file_set_string (keyfile, priv->id, "profile", priv->profile_filename);
+		g_key_file_set_string_list (keyfile, priv->id, "profile",
+					    (const gchar * const*) priv->profile_filenames,
+					    g_strv_length (priv->profile_filenames));
 
 	/* save device specific data */
 	if (priv->serial == NULL)
@@ -850,7 +880,7 @@ gcm_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
 		g_value_set_float (value, priv->contrast);
 		break;
 	case PROP_PROFILE_FILENAME:
-		g_value_set_string (value, priv->profile_filename);
+		g_value_set_boxed (value, priv->profile_filenames);
 		break;
 	case PROP_TITLE:
 		g_value_set_string (value, priv->title);
@@ -901,7 +931,7 @@ gcm_device_set_property (GObject *object, guint prop_id, const GValue *value, GP
 		gcm_device_set_title (device, g_value_get_string (value));
 		break;
 	case PROP_PROFILE_FILENAME:
-		gcm_device_set_profile_filename (device, g_value_get_string (value));
+		gcm_device_set_profile_filenames (device, (gchar**)g_value_get_boxed (value));
 		break;
 	case PROP_GAMMA:
 		gcm_device_set_gamma (device, g_value_get_float (value));
@@ -1024,9 +1054,9 @@ gcm_device_class_init (GcmDeviceClass *klass)
 	/**
 	 * GcmDevice:profile-filename:
 	 */
-	pspec = g_param_spec_string ("profile-filename", NULL, NULL,
-				     NULL,
-				     G_PARAM_READWRITE);
+	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);
 
 	/**
@@ -1073,7 +1103,7 @@ gcm_device_init (GcmDevice *device)
 	device->priv->serial = NULL;
 	device->priv->manufacturer = NULL;
 	device->priv->model = NULL;
-	device->priv->profile_filename = NULL;
+	device->priv->profile_filenames = NULL;
 	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);
@@ -1102,7 +1132,7 @@ gcm_device_finalize (GObject *object)
 	g_free (priv->serial);
 	g_free (priv->manufacturer);
 	g_free (priv->model);
-	g_free (priv->profile_filename);
+	g_strfreev (priv->profile_filenames);
 	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 9c6b235..f35bb65 100644
--- a/src/gcm-device.h
+++ b/src/gcm-device.h
@@ -107,11 +107,16 @@ 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);
-const gchar		*gcm_device_get_profile_filename	(GcmDevice	*device);
-void			 gcm_device_set_profile_filename	(GcmDevice	*device,
-								 const gchar 	*profile_filename);
+gchar			**gcm_device_get_profile_filenames	(GcmDevice	*device);
+void			 gcm_device_set_profile_filenames	(GcmDevice	*device,
+								 gchar 		**profile_filenames);
 glong			 gcm_device_get_modified_time		(GcmDevice	*device);
 
+/* helpers */
+const gchar		*gcm_device_get_default_profile_filename (GcmDevice	*device);
+void			 gcm_device_set_default_profile_filename (GcmDevice	*device,
+								 const gchar 	*profile_filename);
+
 G_END_DECLS
 
 #endif /* __GCM_DEVICE_H */
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index b741902..0e1d104 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -139,7 +139,7 @@ gcm_prefs_set_default (GcmDevice *device)
 
 	/* nothing set */
 	id = gcm_device_get_id (device);
-	filename = gcm_device_get_profile_filename (device);
+	filename = gcm_device_get_default_profile_filename (device);
 	if (filename == NULL) {
 		egg_debug ("no filename for %s", id);
 		goto out;
@@ -956,7 +956,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 		egg_debug ("adding: %s", destination);
 
 		/* set this default */
-		gcm_device_set_profile_filename (current_device, destination);
+		gcm_device_set_default_profile_filename (current_device, destination);
 		ret = gcm_device_save (current_device, &error);
 		if (!ret) {
 			egg_warning ("failed to save default: %s", error->message);
@@ -1525,7 +1525,7 @@ gcm_prefs_devices_treeview_clicked_cb (GtkTreeSelection *selection, gpointer use
 
 	/* add profiles of the right kind */
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_profile"));
-	profile_filename = gcm_device_get_profile_filename (current_device);
+	profile_filename = gcm_device_get_default_profile_filename (current_device);
 	gcm_prefs_add_profiles_suitable_for_devices (widget, profile_filename);
 
 	/* make sure selectable */
@@ -2055,7 +2055,7 @@ gcm_prefs_profile_combo_changed_cb (GtkWidget *widget, gpointer data)
 	}
 
 	/* see if it's changed */
-	profile_old = gcm_device_get_profile_filename (current_device);
+	profile_old = gcm_device_get_default_profile_filename (current_device);
 	egg_debug ("old: %s, new:%s", profile_old, filename);
 	changed = ((g_strcmp0 (profile_old, filename) != 0));
 
@@ -2063,7 +2063,7 @@ gcm_prefs_profile_combo_changed_cb (GtkWidget *widget, gpointer data)
 	if (changed) {
 
 		/* save new profile */
-		gcm_device_set_profile_filename (current_device, filename);
+		gcm_device_set_default_profile_filename (current_device, filename);
 		ret = gcm_device_save (current_device, &error);
 		if (!ret) {
 			egg_warning ("failed to save config: %s", error->message);
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 0fb874b..a5565aa 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -349,6 +349,7 @@ gcm_test_device_func (void)
 	GError *error = NULL;
 	gchar *filename;
 	const gchar *profile;
+	gchar **profiles;
 	gchar *data;
 	gchar **split;
 
@@ -398,7 +399,7 @@ gcm_test_device_func (void)
 	g_assert_no_error (error);
 	g_assert (ret);
 
-	g_assert_cmpstr (gcm_device_get_profile_filename (device), ==, NULL);
+	g_assert_cmpstr (gcm_device_get_default_profile_filename (device), ==, NULL);
 
 	/* empty file that exists */
 	g_file_set_contents (filename, "", -1, NULL);
@@ -413,24 +414,28 @@ gcm_test_device_func (void)
 			     "[sysfs_dummy_device]\n"
 			     "title=Canon - CanoScan\n"
 			     "type=scanner\n"
-			     "profile=/srv/sysfs_canon_canoscan.icc\n", -1, NULL);
+			     "profile=/srv/sysfs_canon_canoscan.icc;/home/generic.icc\n", -1, NULL);
 
 	ret = gcm_device_load (device, &error);
 	g_assert_no_error (error);
 	g_assert (ret);
 
-	/* get some properties */
-	profile = gcm_device_get_profile_filename (device);
 
 	g_main_loop_run (_loop);
 	/* TODO: time out of loop */
 
 	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);
 
 	/* set some properties */
-	gcm_device_set_profile_filename (device, "/srv/sysfs_canon_canoscan.icc");
+	gcm_device_set_default_profile_filename (device, "/srv/sysfs_canon_canoscan.icc");
 
 	/* ensure the file is nuked, again */
 	g_unlink (filename);
@@ -445,7 +450,7 @@ 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[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");
@@ -1096,7 +1101,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), ==, "Goldstar");
-	g_assert_cmpstr (gcm_device_get_profile_filename (device), ==, "dave.icc");
+	g_assert_cmpstr (gcm_device_get_default_profile_filename (device), ==, "dave.icc");
 	g_assert (gcm_device_get_saved (device));
 	g_assert (!gcm_device_get_connected (device));
 	g_assert (GCM_IS_DEVICE_XRANDR (device));
@@ -1116,7 +1121,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_profile_filename (device), ==, "dave.icc");
+	g_assert_cmpstr (gcm_device_get_default_profile_filename (device), ==, "dave.icc");
 	g_assert (gcm_device_get_saved (device));
 	g_assert (gcm_device_get_connected (device));
 	g_assert (GCM_IS_DEVICE_UDEV (device));
diff --git a/src/gcm-session.c b/src/gcm-session.c
index 6a0dff2..c498e3f 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -180,7 +180,7 @@ gcm_session_added_cb (GcmClient *client_, GcmDevice *device, gpointer user_data)
 		return;
 
 	/* ensure we have a profile */
-	profile = gcm_device_get_profile_filename (device);
+	profile = gcm_device_get_default_profile_filename (device);
 	if (profile == NULL) {
 		egg_debug ("no profile set for %s", gcm_device_get_id (device));
 		goto out;
@@ -231,7 +231,7 @@ gcm_session_get_profile_for_window (guint xid, GError **error)
 	}
 
 	/* get the data */
-	filename = gcm_device_get_profile_filename (device);
+	filename = gcm_device_get_default_profile_filename (device);
 	if (filename == NULL) {
 		g_set_error (error, 1, 0, "no profiles found for xid %i", xid);
 		goto out;
@@ -342,8 +342,8 @@ gcm_session_get_profiles_for_file (const gchar *filename, GError **error)
 		    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) {
 
-			/* we have a profile? */
-			filename = gcm_device_get_profile_filename (device);
+			/* 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;
@@ -430,8 +430,8 @@ gcm_session_get_profiles_for_device (const gchar *device_id_with_prefix, GError
 		egg_debug ("comparing %s with %s", device_id_tmp, device_id);
 		if (g_strcmp0 (device_id_tmp, device_id) == 0) {
 
-			/* we have a profile? */
-			filename = gcm_device_get_profile_filename (device);
+			/* 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;



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