[gnome-color-manager] Add a DBus method GetDevices() and relax the checks in GetProfilesForDevice() to also take a device



commit ff1644096c53e80da84c40c968ce9d0aa33f5bd0
Author: Richard Hughes <richard hughsie com>
Date:   Tue Mar 23 18:15:18 2010 +0000

    Add a DBus method GetDevices() and relax the checks in GetProfilesForDevice() to also take a device ID

 src/gcm-dbus.c                 |   79 +++++++++++++++++++++++++++++++++-------
 src/gcm-dbus.h                 |    4 ++-
 src/gcm-inspect.c              |   16 ++++----
 src/org.gnome.ColorManager.xml |   29 +++++++++++++--
 4 files changed, 103 insertions(+), 25 deletions(-)
---
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
index 84ace0f..8176d18 100644
--- a/src/gcm-dbus.c
+++ b/src/gcm-dbus.c
@@ -162,12 +162,14 @@ gcm_dbus_get_idle_time (GcmDbus	*dbus)
  * gcm_dbus_get_profiles_for_device_internal:
  **/
 static GPtrArray *
-gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *sysfs_path)
+gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *device_id_with_prefix)
 {
 	gboolean ret;
 	gchar *filename;
-	gchar *sysfs_path_tmp;
+	const gchar *device_id;
+	gchar *device_id_tmp;
 	guint i;
+	gboolean use_native_device = FALSE;
 	GcmDevice *device;
 	GcmProfile *profile;
 	GFile *file;
@@ -175,6 +177,19 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *sysfs_pat
 	GPtrArray *array;
 	GPtrArray *array_devices;
 
+	/* strip the prefix, if there is any */
+	device_id = g_strstr_len (device_id_with_prefix, -1, ":");
+	if (device_id == NULL) {
+		device_id = device_id_with_prefix;
+	} else {
+		device_id++;
+		use_native_device = TRUE;
+	}
+
+	/* use the sysfs path to be backwards compatible */
+	if (g_str_has_prefix (device_id_with_prefix, "/"))
+		use_native_device = TRUE;
+
 	/* create a temp array */
 	array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
 
@@ -183,18 +198,24 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *sysfs_pat
 	for (i=0; i<array_devices->len; i++) {
 		device = g_ptr_array_index (array_devices, i);
 
-		/* get the native path of this device */
-		g_object_get (device,
-			      "native-device", &sysfs_path_tmp,
-			      NULL);
+		/* get the id for this device */
+		if (use_native_device) {
+			g_object_get (device,
+				      "native-device", &device_id_tmp,
+				      NULL);
+		} else {
+			g_object_get (device,
+				      "id", &device_id_tmp,
+				      NULL);
+		}
 
 		/* wrong type of device */
-		if (sysfs_path_tmp == NULL)
+		if (device_id_tmp == NULL)
 			continue;
 
 		/* compare what we have against what we were given */
-		egg_debug ("comparing %s with %s", sysfs_path_tmp, sysfs_path);
-		if (g_strcmp0 (sysfs_path_tmp, sysfs_path) == 0) {
+		egg_debug ("comparing %s with %s", device_id_tmp, device_id);
+		if (g_strcmp0 (device_id_tmp, device_id) == 0) {
 			g_object_get (device,
 				      "profile-filename", &filename,
 				      NULL);
@@ -215,7 +236,7 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *sysfs_pat
 			g_object_unref (profile);
 			g_free (filename);
 		}
-		g_free (sysfs_path_tmp);
+		g_free (device_id_tmp);
 	}
 
 	/* unref list of devices */
@@ -264,10 +285,42 @@ gcm_dbus_get_profiles_for_type_internal (GcmDbus *dbus, GcmDeviceTypeEnum type)
 }
 
 /**
+ * gcm_dbus_get_devices:
+ **/
+void
+gcm_dbus_get_devices (GcmDbus *dbus, DBusGMethodInvocation *context)
+{
+	GcmDevice *device;
+	guint i;
+	gchar **devices;
+	GPtrArray *array;
+
+	egg_debug ("getting list of devices");
+
+	/* copy the device id */
+	array = gcm_client_get_devices (dbus->priv->client);
+	devices = g_new0 (gchar *, array->len + 1);
+	for (i=0; i<array->len; i++) {
+		device = g_ptr_array_index (array, i);
+		devices[i] = g_strdup (gcm_device_get_id (device));
+	}
+
+	/* return devices */
+	dbus_g_method_return (context, devices);
+
+	/* reset time */
+	g_timer_reset (dbus->priv->timer);
+
+	/* unref list of devices */
+	g_strfreev (devices);
+	g_ptr_array_unref (array);
+}
+
+/**
  * gcm_dbus_get_profiles_for_device:
  **/
 void
-gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *sysfs_path, const gchar *options, DBusGMethodInvocation *context)
+gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *device_id, const gchar *options, DBusGMethodInvocation *context)
 {
 	GPtrArray *array_profiles;
 	GcmProfile *profile;
@@ -277,10 +330,10 @@ gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *sysfs_path, const
 	GPtrArray *array_structs;
 	GValue *value;
 
-	egg_debug ("getting profiles for %s", sysfs_path);
+	egg_debug ("getting profiles for %s", device_id);
 
 	/* get array of profile filenames */
-	array_profiles = gcm_dbus_get_profiles_for_device_internal (dbus, sysfs_path);
+	array_profiles = gcm_dbus_get_profiles_for_device_internal (dbus, device_id);
 
 	/* copy data to dbus struct */
 	array_structs = g_ptr_array_sized_new (array_profiles->len);
diff --git a/src/gcm-dbus.h b/src/gcm-dbus.h
index b003f0d..0a0cd40 100644
--- a/src/gcm-dbus.h
+++ b/src/gcm-dbus.h
@@ -65,7 +65,7 @@ guint		 gcm_dbus_get_idle_time			(GcmDbus	*dbus);
 
 /* org.gnome.ColorManager */
 void		 gcm_dbus_get_profiles_for_device	(GcmDbus	*dbus,
-							 const gchar	*sysfs_path,
+							 const gchar	*device_id,
 							 const gchar	*options,
 							 DBusGMethodInvocation *context);
 void		 gcm_dbus_get_profiles_for_type		(GcmDbus	*dbus,
@@ -75,6 +75,8 @@ void		 gcm_dbus_get_profiles_for_type		(GcmDbus	*dbus,
 void		 gcm_dbus_get_profile_for_window	(GcmDbus	*dbus,
 							 guint		 xid,
 							 DBusGMethodInvocation *context);
+void		 gcm_dbus_get_devices			(GcmDbus	*dbus,
+							 DBusGMethodInvocation *context);
 
 G_END_DECLS
 
diff --git a/src/gcm-inspect.c b/src/gcm-inspect.c
index 6634ecc..36efe39 100644
--- a/src/gcm-inspect.c
+++ b/src/gcm-inspect.c
@@ -168,7 +168,7 @@ out:
  * gcm_inspect_show_profiles_for_device:
  **/
 static gboolean
-gcm_inspect_show_profiles_for_device (const gchar *sysfs_path)
+gcm_inspect_show_profiles_for_device (const gchar *device_id)
 {
 	gboolean ret;
 	DBusGConnection *connection;
@@ -200,7 +200,7 @@ gcm_inspect_show_profiles_for_device (const gchar *sysfs_path)
 
 	/* execute sync method */
 	ret = dbus_g_proxy_call (proxy, "GetProfilesForDevice", &error,
-				 G_TYPE_STRING, sysfs_path,
+				 G_TYPE_STRING, device_id,
 				 G_TYPE_STRING, "",
 				 G_TYPE_INVALID,
 				 custom_g_type_string_string, &profile_data_array,
@@ -220,7 +220,7 @@ gcm_inspect_show_profiles_for_device (const gchar *sysfs_path)
 	}
 
 	/* TRANSLATORS: this is a list of profiles suitable for the device */
-	g_print ("%s %s\n", _("Suitable profiles for:"), sysfs_path);
+	g_print ("%s %s\n", _("Suitable profiles for:"), device_id);
 
 	/* list each entry */
 	for (i=0; i<profile_data_array->len; i++) {
@@ -458,7 +458,7 @@ main (int argc, char **argv)
 	gboolean x11 = FALSE;
 	gboolean dump = FALSE;
 	guint xid = 0;
-	gchar *sysfs_path = NULL;
+	gchar *device_id = NULL;
 	gchar *type = NULL;
 	GcmDeviceTypeEnum type_enum;
 	guint retval = 0;
@@ -468,7 +468,7 @@ main (int argc, char **argv)
 		{ "x11", 'x', 0, G_OPTION_ARG_NONE, &x11,
 			/* TRANSLATORS: command line option */
 			_("Show X11 properties"), NULL },
-		{ "device", '\0', 0, G_OPTION_ARG_STRING, &sysfs_path,
+		{ "device", '\0', 0, G_OPTION_ARG_STRING, &device_id,
 			/* TRANSLATORS: command line option */
 			_("Get the profiles for a specific device"), NULL },
 		{ "xid", '\0', 0, G_OPTION_ARG_INT, &xid,
@@ -501,8 +501,8 @@ main (int argc, char **argv)
 
 	if (x11 || dump)
 		gcm_inspect_show_x11_atoms ();
-	if (sysfs_path != NULL)
-		gcm_inspect_show_profiles_for_device (sysfs_path);
+	if (device_id != NULL)
+		gcm_inspect_show_profiles_for_device (device_id);
 	if (xid != 0)
 		gcm_inspect_show_profile_for_window (xid);
 	if (type != NULL) {
@@ -518,7 +518,7 @@ main (int argc, char **argv)
 	if (dump)
 		gcm_inspect_get_properties ();
 
-	g_free (sysfs_path);
+	g_free (device_id);
 	g_free (type);
 	return retval;
 }
diff --git a/src/org.gnome.ColorManager.xml b/src/org.gnome.ColorManager.xml
index 81e246e..3562de5 100644
--- a/src/org.gnome.ColorManager.xml
+++ b/src/org.gnome.ColorManager.xml
@@ -82,11 +82,12 @@
           </doc:para>
         </doc:description>
       </doc:doc>
-      <arg type="s" name="sysfs_path" direction="in">
+      <arg type="s" name="device_id" direction="in">
         <doc:doc>
           <doc:summary>
             <doc:para>
-              A sysfs path, e.g. <doc:tt>/sys/class/usb/hiddev0</doc:tt>
+              A device ID which can be a sysfs path, e.g. <doc:tt>sysfs:/sys/class/usb/hiddev0</doc:tt>
+              or a raw device ID, e.g. <doc:tt>xrandr_ibm_france_ltn154p2_l05</doc:tt>.
             </doc:para>
           </doc:summary>
         </doc:doc>
@@ -125,7 +126,8 @@
         <doc:doc>
           <doc:summary>
             <doc:para>
-              A device type, e.g. <doc:tt>scanner</doc:tt>, <doc:tt>display</doc:tt>, <doc:tt>printer</doc:tt> or <doc:tt>camera</doc:tt>.
+              A device type, e.g. <doc:tt>scanner</doc:tt>, <doc:tt>display</doc:tt>,
+              <doc:tt>printer</doc:tt> or <doc:tt>camera</doc:tt>.
             </doc:para>
           </doc:summary>
         </doc:doc>
@@ -182,6 +184,27 @@
       </arg>
     </method>
 
+    <!--*****************************************************************************************-->
+    <method name="GetDevices">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <doc:doc>
+        <doc:description>
+          <doc:para>
+            Gets a list of all the devices which have assigned color profiles.
+          </doc:para>
+        </doc:description>
+      </doc:doc>
+      <arg type="as" name="devices" direction="out">
+        <doc:doc>
+          <doc:summary>
+            <doc:para>
+              An array of device IDs, e.g. <doc:tt>['xrandr_ibm_france_ltn154p2_l05']</doc:tt>.
+            </doc:para>
+          </doc:summary>
+        </doc:doc>
+      </arg>
+    </method>
+
     <!-- ************************************************************ -->
     <signal name="Changed">
       <doc:doc>



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