[gnome-color-manager/colord: 52/72] Assign profiles with EDID_md5 metadata to thier correct devices automatically
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager/colord: 52/72] Assign profiles with EDID_md5 metadata to thier correct devices automatically
- Date: Tue, 8 Mar 2011 11:27:43 +0000 (UTC)
commit caea46746c88627c92e5892201dc6803c7822000
Author: Richard Hughes <richard hughsie com>
Date: Tue Feb 8 11:37:09 2011 +0000
Assign profiles with EDID_md5 metadata to thier correct devices automatically
src/gcm-session.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/gcm-x11-screen.c | 48 ++++++++++++++++++++++++++++++
src/gcm-x11-screen.h | 3 ++
3 files changed, 127 insertions(+), 2 deletions(-)
---
diff --git a/src/gcm-session.c b/src/gcm-session.c
index 131ef2d..ca8a7c8 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -222,6 +222,79 @@ out:
}
/**
+ * gcm_session_profile_added_notify_cb:
+ **/
+static void
+gcm_session_profile_added_notify_cb (CdClient *client_,
+ CdProfile *profile,
+ gpointer user_data)
+{
+ GHashTable *metadata;
+ const gchar *edid_md5;
+ GcmX11Output *output = NULL;
+ GError *error = NULL;
+ CdDevice *device = NULL;
+ gboolean ret;
+
+ /* does the profile have EDID metadata? */
+ metadata = cd_profile_get_metadata (profile);
+ edid_md5 = g_hash_table_lookup (metadata, "EDID_md5");
+ if (edid_md5 == NULL)
+ goto out;
+
+ /* get the GcmX11Output for the edid */
+ output = gcm_x11_screen_get_output_by_edid (x11_screen,
+ edid_md5,
+ &error);
+ if (output == NULL) {
+ g_debug ("edid hash %s ignored: %s",
+ edid_md5,
+ error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* get the CdDevice for this ID */
+ device = cd_client_find_device_sync (client,
+ gcm_x11_output_get_name (output),
+ NULL,
+ &error);
+ if (device == NULL) {
+ g_error ("not found device %s which should have been added: %s",
+ gcm_x11_output_get_name (output),
+ error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* add the profile to the device */
+ ret = cd_device_add_profile_sync (device,
+ profile,
+ NULL,
+ &error);
+ if (!ret) {
+ /* this will fail if the profile is already added */
+ g_debug ("failed to assign auto-edid profile to device %s: %s",
+ gcm_x11_output_get_name (output),
+ error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* phew! */
+ g_debug ("successfully assigned %s to %s",
+ cd_profile_get_object_path (profile),
+ cd_device_get_object_path (device));
+out:
+ if (metadata != NULL)
+ g_hash_table_unref (metadata);
+ if (output != NULL)
+ g_object_unref (output);
+ if (device != NULL)
+ g_object_unref (device);
+}
+
+/**
* gcm_apply_create_icc_profile_for_edid:
**/
static gboolean
@@ -431,8 +504,6 @@ gcm_session_device_assign (CdDevice *device)
error->message);
g_clear_error (&error);
}
-
- /* FIXME: assign profile to device */
}
/* get the default profile for the device */
@@ -1162,6 +1233,9 @@ main (int argc, char *argv[])
g_signal_connect (client, "device-added",
G_CALLBACK (gcm_session_device_added_notify_cb),
NULL);
+ g_signal_connect (client, "profile-added",
+ G_CALLBACK (gcm_session_profile_added_notify_cb),
+ NULL);
g_signal_connect (client, "device-added",
G_CALLBACK (gcm_session_device_added_assign_cb),
NULL);
diff --git a/src/gcm-x11-screen.c b/src/gcm-x11-screen.c
index 088c95d..ef1087e 100644
--- a/src/gcm-x11-screen.c
+++ b/src/gcm-x11-screen.c
@@ -385,6 +385,54 @@ gcm_x11_screen_get_output_by_name (GcmX11Screen *screen,
}
/**
+ * gcm_x11_screen_get_output_by_name:
+ * @screen: a valid %GcmX11Screen instance
+ * @edid_md5: an output hash
+ * @error: a %GError or %NULL
+ *
+ * Gets a specified output.
+ *
+ * Return value: A #GcmX11Output, or %NULL if nothing matched.
+ **/
+GcmX11Output *
+gcm_x11_screen_get_output_by_edid (GcmX11Screen *screen,
+ const gchar *edid_md5,
+ GError **error)
+{
+ guint i;
+ GcmX11Output *output_tmp;
+ GcmX11Output *output = NULL;
+ GcmEdid *edid;
+ GcmX11ScreenPrivate *priv = screen->priv;
+
+ /* not set the display */
+ if (priv->gdk_screen == NULL) {
+ g_set_error_literal (error,
+ GCM_X11_SCREEN_ERROR, GCM_X11_SCREEN_ERROR_INTERNAL,
+ "no display set, use gcm_x11_screen_assign()");
+ return NULL;
+ }
+
+ /* find the output */
+ for (i=0; i<priv->outputs->len; i++) {
+ output_tmp = g_ptr_array_index (priv->outputs, i);
+ edid = gcm_x11_output_get_edid (output_tmp, NULL);
+ if (edid == NULL)
+ continue;
+ if (g_strcmp0 (gcm_edid_get_checksum (edid), edid_md5) == 0)
+ output = g_object_ref (output_tmp);
+ g_object_unref (edid);
+ if (output != NULL)
+ goto out;
+ }
+ g_set_error_literal (error,
+ GCM_X11_SCREEN_ERROR, GCM_X11_SCREEN_ERROR_INTERNAL,
+ "no connected output with that eidd hash");
+out:
+ return output;
+}
+
+/**
* cd_x11_screen_get_output_coverage:
**/
static gfloat
diff --git a/src/gcm-x11-screen.h b/src/gcm-x11-screen.h
index d366b25..4945d3e 100644
--- a/src/gcm-x11-screen.h
+++ b/src/gcm-x11-screen.h
@@ -69,6 +69,9 @@ GPtrArray *gcm_x11_screen_get_outputs (GcmX11Screen *screen,
GcmX11Output *gcm_x11_screen_get_output_by_name (GcmX11Screen *screen,
const gchar *name,
GError **error);
+GcmX11Output *gcm_x11_screen_get_output_by_edid (GcmX11Screen *screen,
+ const gchar *edid_md5,
+ GError **error);
GcmX11Output *cd_x11_screen_get_output_by_window (GcmX11Screen *screen,
GdkWindow *window);
gboolean gcm_x11_screen_get_profile_data (GcmX11Screen *screen,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]