[gnome-settings-daemon] color: Do not use sync methods in the color plugin



commit eb1533008523a1499ae0fe2b3d5997d18a2c1083
Author: Richard Hughes <richard hughsie com>
Date:   Mon May 30 22:30:16 2011 +0100

    color: Do not use sync methods in the color plugin

 plugins/color/gsd-color-manager.c |  114 +++++++++++++++++++++++++-----------
 1 files changed, 79 insertions(+), 35 deletions(-)
---
diff --git a/plugins/color/gsd-color-manager.c b/plugins/color/gsd-color-manager.c
index b3256de..6746ad1 100644
--- a/plugins/color/gsd-color-manager.c
+++ b/plugins/color/gsd-color-manager.c
@@ -270,45 +270,25 @@ gcm_session_notify_device (GsdColorManager *manager, CdDevice *device)
         g_free (message);
 }
 
+typedef struct {
+        GsdColorManager         *manager;
+        CdDevice                *device;
+} GsdColorManagerDeviceHelper;
+
 static void
-gcm_session_device_added_notify_cb (CdClient *client,
-                                    CdDevice *device,
-                                    GsdColorManager *manager)
+gcm_session_profile_connect_cb (GObject *object,
+                                GAsyncResult *res,
+                                gpointer user_data)
 {
-        CdDeviceKind kind;
-        CdProfile *profile;
         const gchar *filename;
-        gchar *basename = NULL;
         gboolean allow_notifications;
         gboolean ret;
+        gchar *basename = NULL;
         GError *error = NULL;
-        GsdColorManagerPrivate *priv = manager->priv;
+        CdProfile *profile = CD_PROFILE (object);
+        GsdColorManagerDeviceHelper *helper = (GsdColorManagerDeviceHelper *) user_data;
+        GsdColorManager *manager = GSD_COLOR_MANAGER (helper->manager);
 
-        /* connect to the device */
-        ret = cd_device_connect_sync (device,
-                                      NULL,
-                                      &error);
-        if (!ret) {
-                g_warning ("failed to connect to device: %s",
-                           error->message);
-                g_error_free (error);
-                goto out;
-        }
-
-        /* check we care */
-        kind = cd_device_get_kind (device);
-        if (kind != CD_DEVICE_KIND_DISPLAY &&
-            kind != CD_DEVICE_KIND_PRINTER)
-                return;
-
-        /* ensure we have a profile */
-        profile = cd_device_get_default_profile (device);
-        if (profile == NULL) {
-                g_debug ("no profile set for %s", cd_device_get_id (device));
-                goto out;
-        }
-
-        /* connect to the profile */
         ret = cd_profile_connect_sync (profile,
                                        NULL,
                                        &error);
@@ -324,22 +304,86 @@ gcm_session_device_added_notify_cb (CdClient *client,
         basename = g_path_get_basename (filename);
         if (!g_str_has_prefix (basename, "GCM")) {
                 g_debug ("not a GCM profile for %s: %s",
-                         cd_device_get_id (device), filename);
+                         cd_device_get_id (helper->device), filename);
                 goto out;
         }
 
         /* do we allow notifications */
-        allow_notifications = g_settings_get_boolean (priv->settings,
+        allow_notifications = g_settings_get_boolean (manager->priv->settings,
                                                       GCM_SETTINGS_SHOW_NOTIFICATIONS);
         if (!allow_notifications)
                 goto out;
 
         /* handle device */
-        gcm_session_notify_device (manager, device);
+        gcm_session_notify_device (manager, helper->device);
 out:
+        g_object_unref (helper->device);
+        g_object_unref (helper->manager);
+        g_free (helper);
         g_free (basename);
 }
 
+static void
+gcm_session_device_connect_cb (GObject *object,
+                               GAsyncResult *res,
+                               gpointer user_data)
+{
+        gboolean ret;
+        GError *error = NULL;
+        CdDeviceKind kind;
+        CdProfile *profile = NULL;
+        CdDevice *device = CD_DEVICE (object);
+        GsdColorManager *manager = GSD_COLOR_MANAGER (user_data);
+        GsdColorManagerDeviceHelper *helper;
+
+        ret = cd_device_connect_sync (device,
+                                      NULL,
+                                      &error);
+        if (!ret) {
+                g_warning ("failed to connect to device: %s",
+                           error->message);
+                g_error_free (error);
+                goto out;
+        }
+
+        /* check we care */
+        kind = cd_device_get_kind (device);
+        if (kind != CD_DEVICE_KIND_DISPLAY &&
+            kind != CD_DEVICE_KIND_PRINTER)
+                return;
+
+        /* ensure we have a profile */
+        profile = cd_device_get_default_profile (device);
+        if (profile == NULL) {
+                g_debug ("no profile set for %s", cd_device_get_id (device));
+                goto out;
+        }
+
+        /* connect to the profile */
+        helper = g_new0 (GsdColorManagerDeviceHelper, 1);
+        helper->manager = g_object_ref (manager);
+        helper->device = g_object_ref (device);
+        cd_profile_connect (profile,
+                            NULL,
+                            gcm_session_profile_connect_cb,
+                            helper);
+out:
+        if (profile != NULL)
+                g_object_unref (profile);
+}
+
+static void
+gcm_session_device_added_notify_cb (CdClient *client,
+                                    CdDevice *device,
+                                    GsdColorManager *manager)
+{
+        /* connect to the device to get properties */
+        cd_device_connect (device,
+                           NULL,
+                           gcm_session_device_connect_cb,
+                           manager);
+}
+
 #ifdef HAVE_LCMS
 static gchar *
 gcm_session_get_precooked_md5 (cmsHPROFILE lcms_profile)



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