[gnome-color-manager] Add support for unconnected devices, as profiles are stuff useful for things like cameras
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add support for unconnected devices, as profiles are stuff useful for things like cameras
- Date: Wed, 18 Nov 2009 13:15:33 +0000 (UTC)
commit c7729de4530217cdbfa2f35f9214a6b934eccaf3
Author: Richard Hughes <richard hughsie com>
Date: Wed Nov 18 13:12:41 2009 +0000
Add support for unconnected devices, as profiles are stuff useful for things like cameras
src/gcm-apply.c | 2 +-
src/gcm-client.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++------
src/gcm-client.h | 4 +-
src/gcm-dbus.c | 2 +-
src/gcm-prefs.c | 82 +++++++++++++++++++----------
5 files changed, 193 insertions(+), 49 deletions(-)
---
diff --git a/src/gcm-apply.c b/src/gcm-apply.c
index 3c2b8b6..a7de7f3 100644
--- a/src/gcm-apply.c
+++ b/src/gcm-apply.c
@@ -62,7 +62,7 @@ main (int argc, char **argv)
/* get devices */
client = gcm_client_new ();
- ret = gcm_client_coldplug (client, &error);
+ ret = gcm_client_add_connected (client, &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 2d33e51..d8646ee 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -152,18 +152,30 @@ gcm_client_gudev_remove (GcmClient *client, GUdevDevice *udev_device)
{
GcmDevice *device;
gchar *id;
+ gboolean ret;
GcmClientPrivate *priv = client->priv;
/* generate id */
id = gcm_client_get_id_for_udev_device (udev_device);
+
+ /* do we have a device that matches */
device = gcm_client_get_device_by_id (client, id);
- if (device != NULL) {
- /* emit before we remove so the device is valid */
- egg_debug ("emit removed: %s", id);
- g_signal_emit (client, signals[SIGNAL_REMOVED], 0, device);
- g_ptr_array_remove (priv->array, device);
- g_object_unref (device);
+ if (device == NULL)
+ goto out;
+
+ /* remove device first as we hold a reference to it */
+ ret = g_ptr_array_remove (priv->array, device);
+ if (!ret) {
+ egg_warning ("failed to remove %s", id);
+ goto out;
}
+
+ /* emit a signal */
+ egg_debug ("emit removed: %s", id);
+ g_signal_emit (client, signals[SIGNAL_REMOVED], 0, device);
+out:
+ if (device != NULL)
+ g_object_unref (device);
g_free (id);
}
@@ -193,6 +205,13 @@ gcm_client_gudev_add_type (GcmClient *client, GUdevDevice *udev_device, GcmDevic
/* turn space delimiters into spaces */
g_strdelimit (title, "_", ' ');
+ /* we might have a previous saved device with this ID, in which case nuke it */
+ device = gcm_client_get_device_by_id (client, id);
+ if (device != NULL) {
+ g_ptr_array_remove (client->priv->array, device);
+ g_object_unref (device);
+ }
+
/* get sysfs path */
sysfs_path = g_udev_device_get_sysfs_path (udev_device);
@@ -276,10 +295,10 @@ gcm_client_uevent_cb (GUdevClient *gudev_client, const gchar *action, GUdevDevic
}
/**
- * gcm_client_coldplug_devices_usb:
+ * gcm_client_add_connected_devices_usb:
**/
static gboolean
-gcm_client_coldplug_devices_usb (GcmClient *client, GError **error)
+gcm_client_add_connected_devices_usb (GcmClient *client, GError **error)
{
GList *devices;
GList *l;
@@ -484,12 +503,11 @@ gcm_client_xrandr_add (GcmClient *client, GnomeRROutput *output)
/* get details */
id = gcm_client_get_id_for_xrandr_device (client, output);
- /* are we already in the list */
+ /* we might have a previous saved device with this ID, in which case nuke it */
device = gcm_client_get_device_by_id (client, id);
if (device != NULL) {
- egg_debug ("%s already added", id);
+ g_ptr_array_remove (client->priv->array, device);
g_object_unref (device);
- goto out;
}
/* parse the EDID to get a crtc-specific name, not an output specific name */
@@ -566,10 +584,10 @@ gcm_client_randr_event_cb (GnomeRRScreen *screen, GcmClient *client)
}
/**
- * gcm_client_coldplug_devices_xrandr:
+ * gcm_client_add_connected_devices_xrandr:
**/
static gboolean
-gcm_client_coldplug_devices_xrandr (GcmClient *client, GError **error)
+gcm_client_add_connected_devices_xrandr (GcmClient *client, GError **error)
{
GnomeRROutput **outputs;
guint i;
@@ -582,22 +600,122 @@ gcm_client_coldplug_devices_xrandr (GcmClient *client, GError **error)
}
/**
- * gcm_client_coldplug:
+ * gcm_client_add_unconnected_device:
+ **/
+static void
+gcm_client_add_unconnected_device (GcmClient *client, GKeyFile *keyfile, const gchar *id)
+{
+ gchar *title;
+ gchar *type_text;
+ GcmDeviceType type;
+ GcmDevice *device = NULL;
+ gboolean ret;
+ GError *error = NULL;
+ GcmClientPrivate *priv = client->priv;
+
+ /* add new device */
+ title = g_key_file_get_string (keyfile, id, "title", NULL);
+ if (title == NULL)
+ goto out;
+ type_text = g_key_file_get_string (keyfile, id, "type", NULL);
+ type = gcm_device_type_from_text (type_text);
+
+ /* create device */
+ device = gcm_device_new ();
+ g_object_set (device,
+ "type", type,
+ "id", id,
+ "connected", FALSE,
+ "title", title,
+ NULL);
+
+ /* load the device */
+ ret = gcm_device_load (device, &error);
+ if (!ret) {
+ egg_warning ("failed to load: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* add to list */
+ g_ptr_array_add (priv->array, g_object_ref (device));
+
+ /* signal the addition */
+ egg_debug ("emit: added %s to device list", id);
+ g_signal_emit (client, signals[SIGNAL_ADDED], 0, device);
+out:
+ if (device != NULL)
+ g_object_unref (device);
+ g_free (type_text);
+ g_free (title);
+}
+
+/**
+ * gcm_client_add_saved:
+ **/
+gboolean
+gcm_client_add_saved (GcmClient *client, GError **error)
+{
+ gboolean ret;
+ gchar *filename;
+ GKeyFile *keyfile;
+ gchar **groups = NULL;
+ guint i;
+ GcmDevice *device;
+
+ /* get the config file */
+ filename = gcm_utils_get_default_config_location ();
+ egg_debug ("using %s", filename);
+
+ /* load the config file */
+ keyfile = g_key_file_new ();
+ ret = g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, error);
+ if (!ret)
+ goto out;
+
+ /* get groups */
+ groups = g_key_file_get_groups (keyfile, NULL);
+ if (groups == NULL) {
+ ret = FALSE;
+ if (error != NULL)
+ *error = g_error_new (1, 0, "failed to get groups");
+ goto out;
+ }
+
+ /* add each device if it's not already connected */
+ for (i=0; groups[i] != NULL; i++) {
+ device = gcm_client_get_device_by_id (client, groups[i]);
+ if (device == NULL) {
+ egg_debug ("not found %s", groups[i]);
+ gcm_client_add_unconnected_device (client, keyfile, groups[i]);
+ } else {
+ egg_debug ("found already added %s", groups[i]);
+ }
+ }
+out:
+ g_strfreev (groups);
+ g_free (filename);
+ g_key_file_free (keyfile);
+ return ret;
+}
+
+/**
+ * gcm_client_add_connected:
**/
gboolean
-gcm_client_coldplug (GcmClient *client, GError **error)
+gcm_client_add_connected (GcmClient *client, GError **error)
{
gboolean ret;
g_return_val_if_fail (GCM_IS_CLIENT (client), FALSE);
/* usb */
- ret = gcm_client_coldplug_devices_usb (client, error);
+ ret = gcm_client_add_connected_devices_usb (client, error);
if (!ret)
goto out;
/* xorg */
- ret = gcm_client_coldplug_devices_xrandr (client, error);
+ ret = gcm_client_add_connected_devices_xrandr (client, error);
if (!ret)
goto out;
out:
diff --git a/src/gcm-client.h b/src/gcm-client.h
index 82dd1f1..7dc181b 100644
--- a/src/gcm-client.h
+++ b/src/gcm-client.h
@@ -63,7 +63,9 @@ GcmClient *gcm_client_new (void);
GcmDevice *gcm_client_get_device_by_id (GcmClient *client,
const gchar *id);
-gboolean gcm_client_coldplug (GcmClient *client,
+gboolean gcm_client_add_connected (GcmClient *client,
+ GError **error);
+gboolean gcm_client_add_saved (GcmClient *client,
GError **error);
GPtrArray *gcm_client_get_devices (GcmClient *client);
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
index e2aee10..47ad93e 100644
--- a/src/gcm-dbus.c
+++ b/src/gcm-dbus.c
@@ -170,7 +170,7 @@ gcm_dbus_init (GcmDbus *dbus)
dbus->priv->timer = g_timer_new ();
/* get all devices */
- ret = gcm_client_coldplug (dbus->priv->client, &error);
+ ret = gcm_client_add_connected (dbus->priv->client, &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 137b325..ff4ebc1 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -1291,6 +1291,43 @@ gcm_prefs_add_device_type (GcmDevice *device)
g_string_free (string, TRUE);
}
+
+/**
+ * gcm_prefs_remove_device:
+ **/
+static void
+gcm_prefs_remove_device (GcmDevice *gcm_device)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ const gchar *id;
+ gchar *id_tmp;
+ gboolean ret;
+
+ /* remove */
+ id = gcm_device_get_id (gcm_device);
+ egg_debug ("removing: %s", id);
+
+ /* get first element */
+ model = GTK_TREE_MODEL (list_store_devices);
+ ret = gtk_tree_model_get_iter_first (model, &iter);
+ if (!ret)
+ return;
+
+ /* get the other elements */
+ do {
+ gtk_tree_model_get (model, &iter,
+ GPM_DEVICES_COLUMN_ID, &id_tmp,
+ -1);
+ if (g_strcmp0 (id_tmp, id) == 0) {
+ gtk_list_store_remove (GTK_LIST_STORE(model), &iter);
+ g_free (id_tmp);
+ break;
+ }
+ g_free (id_tmp);
+ } while (gtk_tree_model_iter_next (model, &iter));
+}
+
/**
* gcm_prefs_added_idle_cb:
**/
@@ -1302,6 +1339,9 @@ gcm_prefs_added_idle_cb (GcmDevice *device)
GtkWidget *widget;
egg_debug ("added: %s", gcm_device_get_id (device));
+ /* remove the saved device if it's already there */
+ gcm_prefs_remove_device (device);
+
/* get the type of the device */
g_object_get (device,
"type", &type,
@@ -1346,34 +1386,10 @@ gcm_prefs_added_cb (GcmClient *gcm_client_, GcmDevice *gcm_device, gpointer user
static void
gcm_prefs_removed_cb (GcmClient *gcm_client_, GcmDevice *gcm_device, gpointer user_data)
{
- GtkTreeIter iter;
- GtkTreeModel *model;
- const gchar *id;
- gchar *id_tmp;
- gboolean ret;
-
- /* remove */
- id = gcm_device_get_id (gcm_device);
- egg_debug ("removed: %s", id);
+ gcm_prefs_remove_device (gcm_device);
- /* get first element */
- model = GTK_TREE_MODEL (list_store_devices);
- ret = gtk_tree_model_get_iter_first (model, &iter);
- if (!ret)
- return;
-
- /* get the other elements */
- do {
- gtk_tree_model_get (model, &iter,
- GPM_DEVICES_COLUMN_ID, &id_tmp,
- -1);
- if (g_strcmp0 (id_tmp, id) == 0) {
- gtk_list_store_remove (GTK_LIST_STORE(model), &iter);
- g_free (id_tmp);
- break;
- }
- g_free (id_tmp);
- } while (gtk_tree_model_iter_next (model, &iter));
+ /* ensure this device is re-added if it's been saved */
+ gcm_client_add_saved (gcm_client, NULL);
}
/**
@@ -1392,8 +1408,16 @@ gcm_prefs_startup_idle_cb (gpointer user_data)
widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_profile"));
gcm_prefs_add_profiles (widget);
- /* coldplug devices */
- ret = gcm_client_coldplug (gcm_client, &error);
+ /* coldplug plugged in devices */
+ ret = gcm_client_add_connected (gcm_client, &error);
+ if (!ret) {
+ egg_warning ("failed to coldplug: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* coldplug saved devices */
+ ret = gcm_client_add_saved (gcm_client, &error);
if (!ret) {
egg_warning ("failed to coldplug: %s", error->message);
g_error_free (error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]