colord/colord-upstream-fixes.patch

237 lines
6.6 KiB
Diff

diff --git a/src/cd-main.c b/src/cd-main.c
index a5e0ff6..ce4de30 100644
--- a/src/cd-main.c
+++ b/src/cd-main.c
@@ -265,25 +265,16 @@ out:
}
/**
- * cd_main_device_auto_add_profile_md:
+ * cd_main_auto_add_from_md:
**/
static gboolean
-cd_main_device_auto_add_profile_md (CdDevice *device, CdProfile *profile)
+cd_main_auto_add_from_md (CdMainPrivate *priv,
+ CdDevice *device,
+ CdProfile *profile)
{
- const gchar *device_id;
gboolean ret = FALSE;
GError *error = NULL;
- /* does the profile have device metadata */
- device_id = cd_profile_get_metadata_item (profile,
- CD_PROFILE_METADATA_MAPPING_DEVICE_ID);
- if (device_id == NULL)
- goto out;
-
- /* does this device match? */
- if (g_strcmp0 (cd_device_get_id (device), device_id) != 0)
- goto out;
-
/* auto-add soft relationship */
g_debug ("CdMain: Automatically MD add %s to %s",
cd_profile_get_id (profile),
@@ -307,12 +298,12 @@ out:
}
/**
- * cd_main_device_auto_add_profile_db:
+ * cd_main_auto_add_from_db:
**/
static gboolean
-cd_main_device_auto_add_profile_db (CdMainPrivate *priv,
- CdDevice *device,
- CdProfile *profile)
+cd_main_auto_add_from_db (CdMainPrivate *priv,
+ CdDevice *device,
+ CdProfile *profile)
{
gboolean ret = FALSE;
GError *error = NULL;
@@ -350,36 +341,37 @@ out:
}
/**
- * cd_main_device_auto_add_profile:
+ * cd_main_device_auto_add_from_md:
**/
-static gboolean
-cd_main_device_auto_add_profile (CdMainPrivate *priv,
- CdDevice *device,
- CdProfile *profile)
+static void
+cd_main_device_auto_add_from_md (CdMainPrivate *priv,
+ CdDevice *device)
{
- gboolean ret;
-
- /* try adding devices from the mapping db -- we do this first
- * as the database entries might be hard */
- ret = cd_main_device_auto_add_profile_db (priv, device, profile);
- if (ret)
- goto out;
+ CdProfile *profile_tmp;
+ GPtrArray *array;
+ guint i;
- /* first try finding profile metadata to the device,
- * which will be added soft */
- ret = cd_main_device_auto_add_profile_md (device, profile);
- if (ret)
+ /* get all the profiles, and check to see if any of them contain
+ * MAPPING_device_id that matches the device */
+ array = cd_profile_array_get_by_metadata (priv->profiles_array,
+ CD_PROFILE_METADATA_MAPPING_DEVICE_ID,
+ cd_device_get_id (device));
+ if (array == NULL)
goto out;
+ for (i = 0; i < array->len; i++) {
+ profile_tmp = g_ptr_array_index (array, i);
+ cd_main_auto_add_from_md (priv, device, profile_tmp);
+ }
out:
- return ret;
+ if (array != NULL)
+ g_ptr_array_unref (array);
}
/**
- * cd_main_device_auto_add_profiles:
+ * cd_main_device_auto_add_from_db:
**/
static void
-cd_main_device_auto_add_profiles (CdMainPrivate *priv,
- CdDevice *device)
+cd_main_device_auto_add_from_db (CdMainPrivate *priv, CdDevice *device)
{
CdProfile *profile_tmp;
const gchar *object_id_tmp;
@@ -404,15 +396,15 @@ cd_main_device_auto_add_profiles (CdMainPrivate *priv,
profile_tmp = cd_profile_array_get_by_id_owner (priv->profiles_array,
object_id_tmp,
cd_device_get_owner (device));
- if (profile_tmp != NULL) {
- cd_main_device_auto_add_profile (priv,
- device,
- profile_tmp);
- g_object_unref (profile_tmp);
- } else {
- g_debug ("CdMain: profile %s is not (yet) available",
- object_id_tmp);
+ if (profile_tmp == NULL) {
+ g_debug ("CdMain: profile %s with owner %i is not (yet) available",
+ object_id_tmp, cd_device_get_owner (device));
+ continue;
}
+
+ /* does the profile have the correct device metadata */
+ cd_main_auto_add_from_db (priv, device, profile_tmp);
+ g_object_unref (profile_tmp);
}
out:
if (array != NULL)
@@ -493,8 +485,9 @@ cd_main_device_add (CdMainPrivate *priv,
/* add to array */
cd_device_array_add (priv->devices_array, device);
- /* auto add profiles from the database */
- cd_main_device_auto_add_profiles (priv, device);
+ /* auto add profiles from the database and metadata */
+ cd_main_device_auto_add_from_db (priv, device);
+ cd_main_device_auto_add_from_md (priv, device);
out:
return ret;
}
@@ -656,11 +649,11 @@ cd_main_sensor_array_to_variant (GPtrArray *array)
}
/**
- * cd_main_profile_auto_add_to_device:
+ * cd_main_profile_auto_add_from_db:
**/
static void
-cd_main_profile_auto_add_to_device (CdMainPrivate *priv,
- CdProfile *profile)
+cd_main_profile_auto_add_from_db (CdMainPrivate *priv,
+ CdProfile *profile)
{
CdDevice *device_tmp;
const gchar *device_id_tmp;
@@ -692,15 +685,12 @@ cd_main_profile_auto_add_to_device (CdMainPrivate *priv,
device_tmp = cd_device_array_get_by_id_owner (priv->devices_array,
device_id_tmp,
cd_profile_get_owner (profile));
- if (device_tmp != NULL) {
- cd_main_device_auto_add_profile (priv,
- device_tmp,
- profile);
- g_object_unref (device_tmp);
- } else {
- g_debug ("CdMain: device %s is not (yet) available",
- device_id_tmp);
- }
+ if (device_tmp == NULL)
+ continue;
+
+ /* hard add */
+ cd_main_auto_add_from_db (priv, device_tmp, profile);
+ g_object_unref (device_tmp);
}
out:
if (array != NULL)
@@ -708,6 +698,32 @@ out:
}
/**
+ * cd_main_profile_auto_add_from_md:
+ **/
+static void
+cd_main_profile_auto_add_from_md (CdMainPrivate *priv,
+ CdProfile *profile)
+{
+ CdDevice *device = NULL;
+ const gchar *device_id;
+
+ /* does the device exists that matches the md */
+ device_id = cd_profile_get_metadata_item (profile,
+ CD_PROFILE_METADATA_MAPPING_DEVICE_ID);
+ if (device_id == NULL)
+ goto out;
+ device = cd_device_array_get_by_id_owner (priv->devices_array,
+ device_id,
+ cd_profile_get_owner (profile));
+ if (device == NULL)
+ goto out;
+ cd_main_auto_add_from_md (priv, device, profile);
+out:
+ if (device != NULL)
+ g_object_unref (device);
+}
+
+/**
* cd_main_profile_register_on_bus:
**/
static gboolean
@@ -1375,9 +1391,6 @@ cd_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
goto out;
}
- /* auto add profiles from the database */
- cd_main_profile_auto_add_to_device (priv, profile);
-
/* get any file descriptor in the message */
message = g_dbus_method_invocation_get_message (invocation);
fd_list = g_dbus_message_get_unix_fd_list (message);
@@ -1421,6 +1434,10 @@ cd_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
}
}
+ /* auto add profiles from the database and metadata */
+ cd_main_profile_auto_add_from_db (priv, profile);
+ cd_main_profile_auto_add_from_md (priv, profile);
+
/* register on bus */
ret = cd_main_profile_register_on_bus (priv, profile, &error);
if (!ret) {