summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2013-02-04 09:38:34 +0000
committerRichard Hughes <richard@hughsie.com>2013-02-04 11:03:42 +0000
commit4052d9ae3b435b658caa85214aa3c911e4e69a8d (patch)
treed4743e6cc3cb2775ebc4c266df4662972c65d281
parent8476dfd9cf6fa7212bacec67d161a6f47b6bfe9b (diff)
downloadcolord-4052d9ae3b435b658caa85214aa3c911e4e69a8d.tar.gz
Allow profiles to have a 'score' which affects which get chosen as a specific standard space
Like before, prefer system profiles over user profiles.
-rw-r--r--src/cd-main.c19
-rw-r--r--src/cd-profile.c23
-rw-r--r--src/cd-profile.h1
-rw-r--r--src/cd-self-test.c5
4 files changed, 42 insertions, 6 deletions
diff --git a/src/cd-main.c b/src/cd-main.c
index 59f6a64..920d44c 100644
--- a/src/cd-main.c
+++ b/src/cd-main.c
@@ -815,26 +815,33 @@ static CdProfile *
cd_main_get_standard_space_metadata (CdMainPrivate *priv,
const gchar *standard_space)
{
+ CdProfile *profile_best = NULL;
CdProfile *profile = NULL;
CdProfile *profile_tmp;
- gboolean ret;
GPtrArray *array;
guint i;
+ guint score_best = 0;
+ guint score_tmp;
/* get all the profiles with this metadata */
array = cd_profile_array_get_by_metadata (priv->profiles_array,
CD_PROFILE_METADATA_STANDARD_SPACE,
standard_space);
- /* just use the first system-wide profile */
+ /* use the profile with the largest score */
for (i = 0; i < array->len; i++) {
profile_tmp = g_ptr_array_index (array, i);
- ret = cd_profile_get_is_system_wide (profile_tmp);
- if (ret) {
- profile = g_object_ref (profile_tmp);
- goto out;
+ score_tmp = cd_profile_get_score (profile_tmp);
+ if (score_tmp > score_best) {
+ score_best = score_tmp;
+ profile_best = profile_tmp;
}
}
+ if (profile_best == NULL)
+ goto out;
+
+ /* success */
+ profile = g_object_ref (profile_best);
out:
g_ptr_array_unref (array);
return profile;
diff --git a/src/cd-profile.c b/src/cd-profile.c
index 786331e..3751241 100644
--- a/src/cd-profile.c
+++ b/src/cd-profile.c
@@ -63,6 +63,7 @@ struct _CdProfilePrivate
guint owner;
gchar **warnings;
GMappedFile *mapped_file;
+ guint score;
};
enum {
@@ -150,6 +151,9 @@ cd_profile_set_is_system_wide (CdProfile *profile, gboolean is_system_wide)
{
g_return_if_fail (CD_IS_PROFILE (profile));
profile->priv->is_system_wide = is_system_wide;
+
+ /* by default, prefer systemwide profiles over user profiles */
+ profile->priv->score += 1;
}
/**
@@ -239,6 +243,9 @@ cd_profile_set_id (CdProfile *profile, const gchar *id)
g_free (profile->priv->id);
profile->priv->id = g_strdup (id);
+ /* all profiles have a score initially */
+ profile->priv->score = 1;
+
/* now calculate this again */
cd_profile_set_object_path (profile);
}
@@ -1629,6 +1636,22 @@ cd_profile_get_metadata_item (CdProfile *profile, const gchar *key)
}
/**
+ * cd_profile_get_score:
+ *
+ * Profiles from official vendors such as http://www.color.org/ should be
+ * more important than profiles generated from source data.
+ *
+ * Return value: A number which corresponds to the importance of the profile,
+ * where larger numbers have more importance than lower numbers.
+ **/
+guint
+cd_profile_get_score (CdProfile *profile)
+{
+ g_return_val_if_fail (CD_IS_PROFILE (profile), 0);
+ return profile->priv->score;
+}
+
+/**
* cd_profile_get_kind:
**/
CdProfileKind
diff --git a/src/cd-profile.h b/src/cd-profile.h
index 1aae777..098a6a7 100644
--- a/src/cd-profile.h
+++ b/src/cd-profile.h
@@ -92,6 +92,7 @@ GHashTable *cd_profile_get_metadata (CdProfile *profile);
const gchar *cd_profile_get_metadata_item (CdProfile *profile,
const gchar *key);
CdProfileKind cd_profile_get_kind (CdProfile *profile);
+guint cd_profile_get_score (CdProfile *profile);
CdColorspace cd_profile_get_colorspace (CdProfile *profile);
gboolean cd_profile_get_has_vcgt (CdProfile *profile);
void cd_profile_watch_sender (CdProfile *profile,
diff --git a/src/cd-self-test.c b/src/cd-self-test.c
index f9ca87e..ec4d9d9 100644
--- a/src/cd-self-test.c
+++ b/src/cd-self-test.c
@@ -45,6 +45,11 @@ colord_profile_func (void)
cd_profile_set_id (profile, "dave");
g_assert_cmpstr (cd_profile_get_id (profile), ==, "dave");
+ g_assert_cmpint (cd_profile_get_score (profile), ==, 1);
+
+ /* system-wide profiles have a larger importance */
+ cd_profile_set_is_system_wide (profile, TRUE);
+ g_assert_cmpint (cd_profile_get_score (profile), ==, 2);
g_object_unref (profile);
}