[gnome-color-manager] trivial: add gcm_client_add_device() for a way to manually add virtual devices to the array



commit 1f388238d5fdcfe42e31ceb39c5450d0ef2757a0
Author: Richard Hughes <richard hughsie com>
Date:   Wed Feb 24 09:52:03 2010 +0000

    trivial: add gcm_client_add_device() for a way to manually add virtual devices to the array

 src/gcm-client.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcm-client.h |    3 +++
 2 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/src/gcm-client.c b/src/gcm-client.c
index b487f7b..6f3c4e2 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -811,6 +811,58 @@ out:
 }
 
 /**
+ * gcm_client_add_device:
+ **/
+gboolean
+gcm_client_add_device (GcmClient *client, GcmDevice *device, GError **error)
+{
+	gboolean ret = FALSE;
+	gchar *id = NULL;
+	gboolean virtual;
+	GcmDevice *device_tmp = NULL;
+
+	g_return_val_if_fail (GCM_IS_CLIENT (client), FALSE);
+	g_return_val_if_fail (GCM_IS_DEVICE (device), FALSE);
+
+	/* check removable */
+	g_object_get (device,
+		      "virtual", &virtual,
+		      "id", &id,
+		      NULL);
+	if (!virtual) {
+		g_set_error_literal (error, 1, 0, "cannot add non-virtual devices");
+		goto out;
+	}
+
+	/* look to see if device already exists */
+	device_tmp = gcm_client_get_device_by_id (client, id);
+	if (device_tmp != NULL) {
+		g_set_error_literal (error, 1, 0, "already found in device array");
+		goto out;
+	}
+
+	/* add to the array */
+	g_ptr_array_add (client->priv->array, g_object_ref (device));
+
+	/* update status */
+	g_object_set (device,
+		      "saved", FALSE,
+		      NULL);
+
+	/* emit a signal */
+	egg_debug ("emit added: %s", id);
+	g_signal_emit (client, signals[SIGNAL_ADDED], 0, device);
+
+	/* all okay */
+	ret = TRUE;
+out:
+	g_free (id);
+	if (device_tmp != NULL)
+		g_object_unref (device_tmp);
+	return ret;
+}
+
+/**
  * gcm_client_delete_device:
  **/
 gboolean
diff --git a/src/gcm-client.h b/src/gcm-client.h
index 147a753..0b1e9a1 100644
--- a/src/gcm-client.h
+++ b/src/gcm-client.h
@@ -66,6 +66,9 @@ GcmDevice	*gcm_client_get_device_by_id			(GcmClient		*client,
 								 const gchar		*id);
 GcmDevice	*gcm_client_get_device_by_window		(GcmClient		*client,
 								 GdkWindow		*window);
+gboolean	 gcm_client_add_device				(GcmClient		*client,
+								 GcmDevice		*device,
+								 GError			**error);
 gboolean	 gcm_client_delete_device			(GcmClient		*client,
 								 GcmDevice		*device,
 								 GError			**error);



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