[gnome-color-manager] Do not connect to sane in gcm-apply, we only need XRandR devices. Fixes rh#585723



commit 9908798169e030339df08df5b0efd4118c5654db
Author: Richard Hughes <richard hughsie com>
Date:   Thu Apr 29 15:56:52 2010 +0100

    Do not connect to sane in gcm-apply, we only need XRandR devices. Fixes rh#585723

 src/gcm-apply.c  |    2 +-
 src/gcm-client.c |  102 +++++++++++++++++++++++++++++++++++------------------
 src/gcm-client.h |   10 +++++
 src/gcm-dbus.c   |    2 +-
 src/gcm-prefs.c  |    2 +-
 5 files changed, 80 insertions(+), 38 deletions(-)
---
diff --git a/src/gcm-apply.c b/src/gcm-apply.c
index 5935421..dbf757d 100644
--- a/src/gcm-apply.c
+++ b/src/gcm-apply.c
@@ -63,7 +63,7 @@ main (int argc, char **argv)
 
 	/* get devices */
 	client = gcm_client_new ();
-	ret = gcm_client_add_connected (client, &error);
+	ret = gcm_client_add_connected (client, GCM_CLIENT_COLDPLUG_XRANDR, &error);
 	if (!ret) {
 		egg_warning ("failed to get devices: %s", error->message);
 		g_error_free (error);
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 630c2fa..993565b 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -140,6 +140,22 @@ gcm_client_done_loading (GcmClient *client)
 }
 
 /**
+ * gcm_client_add_loading:
+ **/
+static void
+gcm_client_add_loading (GcmClient *client)
+{
+	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+
+	/* decrement refcount, with a lock */
+	g_static_mutex_lock (&mutex);
+	client->priv->loading_refcount++;
+	if (client->priv->loading_refcount > 0)
+		gcm_client_set_loading (client, TRUE);
+	g_static_mutex_unlock (&mutex);
+}
+
+/**
  * gcm_client_get_devices:
  *
  * @client: a valid %GcmClient instance
@@ -662,6 +678,10 @@ gcm_client_add_connected_devices_xrandr (GcmClient *client, GError **error)
 		return FALSE;
 	for (i=0; outputs[i] != NULL; i++)
 		gcm_client_xrandr_add (client, outputs[i]);
+
+	/* inform the UI */
+	gcm_client_done_loading (client);
+
 	return TRUE;
 }
 
@@ -986,57 +1006,69 @@ out:
  * gcm_client_add_connected:
  **/
 gboolean
-gcm_client_add_connected (GcmClient *client, GError **error)
+gcm_client_add_connected (GcmClient *client, GcmClientColdplug coldplug, GError **error)
 {
 	gboolean ret;
 	GThread *thread;
 
 	g_return_val_if_fail (GCM_IS_CLIENT (client), FALSE);
 
-	/* XRandR */
-	ret = gcm_client_add_connected_devices_xrandr (client, error);
-	if (!ret)
-		goto out;
-
-	/* inform UI if we are loading devices still */
-	client->priv->loading_refcount = 2;
-#ifdef GCM_USE_SANE
-	client->priv->loading_refcount++;
-#endif
-	gcm_client_set_loading (client, TRUE);
+	/* reset */
+	client->priv->loading_refcount = 0;
 
-	/* UDEV */
-	if (client->priv->use_threads) {
-		thread = g_thread_create ((GThreadFunc) gcm_client_add_connected_devices_udev_thrd, client, FALSE, error);
-		if (thread == NULL)
-			goto out;
-	} else {
-		ret = gcm_client_add_connected_devices_udev (client, error);
+	/* XRandR */
+	if (!coldplug || coldplug & GCM_CLIENT_COLDPLUG_XRANDR) {
+		gcm_client_add_loading (client);
+		egg_debug ("adding devices of type XRandR");
+		ret = gcm_client_add_connected_devices_xrandr (client, error);
 		if (!ret)
 			goto out;
 	}
 
+	/* UDEV */
+	if (!coldplug || coldplug & GCM_CLIENT_COLDPLUG_UDEV) {
+		gcm_client_add_loading (client);
+		egg_debug ("adding devices of type UDEV");
+		if (client->priv->use_threads) {
+			thread = g_thread_create ((GThreadFunc) gcm_client_add_connected_devices_udev_thrd, client, FALSE, error);
+			if (thread == NULL)
+				goto out;
+		} else {
+			ret = gcm_client_add_connected_devices_udev (client, error);
+			if (!ret)
+				goto out;
+		}
+	}
+
 	/* CUPS */
-	if (client->priv->use_threads) {
-		thread = g_thread_create ((GThreadFunc) gcm_client_add_connected_devices_cups_thrd, client, FALSE, error);
-		if (thread == NULL)
-			goto out;
-	} else {
-		ret = gcm_client_add_connected_devices_cups (client, error);
-		if (!ret)
-			goto out;
+	if (!coldplug || coldplug & GCM_CLIENT_COLDPLUG_CUPS) {
+		gcm_client_add_loading (client);
+		egg_debug ("adding devices of type CUPS");
+		if (client->priv->use_threads) {
+			thread = g_thread_create ((GThreadFunc) gcm_client_add_connected_devices_cups_thrd, client, FALSE, error);
+			if (thread == NULL)
+				goto out;
+		} else {
+			ret = gcm_client_add_connected_devices_cups (client, error);
+			if (!ret)
+				goto out;
+		}
 	}
 
 #ifdef GCM_USE_SANE
 	/* SANE */
-	if (client->priv->use_threads) {
-		thread = g_thread_create ((GThreadFunc) gcm_client_add_connected_devices_sane_thrd, client, FALSE, error);
-		if (thread == NULL)
-			goto out;
-	} else {
-		ret = gcm_client_add_connected_devices_sane (client, error);
-		if (!ret)
-			goto out;
+	if (!coldplug || coldplug & GCM_CLIENT_COLDPLUG_SANE) {
+		gcm_client_add_loading (client);
+		egg_debug ("adding devices of type SANE");
+		if (client->priv->use_threads) {
+			thread = g_thread_create ((GThreadFunc) gcm_client_add_connected_devices_sane_thrd, client, FALSE, error);
+			if (thread == NULL)
+				goto out;
+		} else {
+			ret = gcm_client_add_connected_devices_sane (client, error);
+			if (!ret)
+				goto out;
+		}
 	}
 #endif
 out:
diff --git a/src/gcm-client.h b/src/gcm-client.h
index a9e7186..083cb5d 100644
--- a/src/gcm-client.h
+++ b/src/gcm-client.h
@@ -60,6 +60,15 @@ struct _GcmClientClass
 	void (*_gcm_reserved5) (void);
 };
 
+typedef enum {
+	GCM_CLIENT_COLDPLUG_ALL		= 0x00,
+	GCM_CLIENT_COLDPLUG_XRANDR	= 0x01,
+	GCM_CLIENT_COLDPLUG_CUPS	= 0x02,
+	GCM_CLIENT_COLDPLUG_SANE	= 0x04,
+	GCM_CLIENT_COLDPLUG_UDEV	= 0x08,
+	GCM_CLIENT_COLDPLUG_LAST,
+} GcmClientColdplug;
+
 GType		 gcm_client_get_type		  		(void);
 GcmClient	*gcm_client_new					(void);
 
@@ -74,6 +83,7 @@ gboolean	 gcm_client_delete_device			(GcmClient		*client,
 								 GcmDevice		*device,
 								 GError			**error);
 gboolean	 gcm_client_add_connected			(GcmClient		*client,
+								 GcmClientColdplug	 coldplug,
 								 GError			**error);
 gboolean	 gcm_client_add_saved				(GcmClient		*client,
 								 GError			**error);
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
index 85d961c..7ba4223 100644
--- a/src/gcm-dbus.c
+++ b/src/gcm-dbus.c
@@ -565,7 +565,7 @@ gcm_dbus_init (GcmDbus *dbus)
 	dbus->priv->colorspace_cmyk = gconf_client_get_string (dbus->priv->gconf_client, GCM_SETTINGS_COLORSPACE_CMYK, NULL);
 
 	/* get all devices */
-	ret = gcm_client_add_connected (dbus->priv->client, &error);
+	ret = gcm_client_add_connected (dbus->priv->client, GCM_CLIENT_COLDPLUG_ALL, &error);
 	if (!ret) {
 		egg_warning ("failed to coldplug: %s", error->message);
 		g_error_free (error);
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 32e952c..e20c434 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -2412,7 +2412,7 @@ gcm_prefs_startup_phase1_idle_cb (gpointer user_data)
 			  G_CALLBACK (gcm_prefs_renderer_combo_changed_cb), (gpointer) "softproof");
 
 	/* coldplug plugged in devices */
-	ret = gcm_client_add_connected (gcm_client, &error);
+	ret = gcm_client_add_connected (gcm_client, GCM_CLIENT_COLDPLUG_ALL, &error);
 	if (!ret) {
 		egg_warning ("failed to add connected devices: %s", error->message);
 		g_error_free (error);



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