summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2011-01-12 12:40:18 +0000
committerRichard Hughes <richard@hughsie.com>2011-01-12 12:41:53 +0000
commit1fe2b537ebe6bc0e53e212420710a251b3178132 (patch)
tree9a92bc09c9cdedc8993ee0a717b7e8da7175b383
parent3e1c0c1cbb375753b0da59d24ec31fbbbd80484e (diff)
downloadcolord-1fe2b537ebe6bc0e53e212420710a251b3178132.tar.gz
Add a 'Kind' attribute to the device objects
-rw-r--r--client/cd-util.c43
-rwxr-xr-xdoc/create.sh1
-rw-r--r--src/cd-device-array.c39
-rw-r--r--src/cd-device-array.h4
-rw-r--r--src/cd-device.c38
-rw-r--r--src/cd-device.h2
-rw-r--r--src/cd-main.c46
-rw-r--r--src/org.freedesktop.ColorManager.Device.xml13
-rw-r--r--src/org.freedesktop.ColorManager.xml31
9 files changed, 199 insertions, 18 deletions
diff --git a/client/cd-util.c b/client/cd-util.c
index 5f7a784..ceaa260 100644
--- a/client/cd-util.c
+++ b/client/cd-util.c
@@ -105,6 +105,7 @@ static void
cd_util_show_device (const gchar *object_path)
{
const gchar *device_id;
+ const gchar *kind;
const gchar *model;
gchar *profile_tmp;
GDBusProxy *proxy;
@@ -115,6 +116,7 @@ cd_util_show_device (const gchar *object_path)
GVariantIter iter;
GVariant *variant_created = NULL;
GVariant *variant_device_id = NULL;
+ GVariant *variant_kind = NULL;
GVariant *variant_model = NULL;
GVariant *variant_profiles = NULL;
@@ -141,6 +143,13 @@ cd_util_show_device (const gchar *object_path)
created = g_variant_get_uint64 (variant_created);
g_print ("Created:\t%" G_GUINT64_FORMAT "\n", created);
+ /* print kind */
+ variant_kind = g_dbus_proxy_get_cached_property (proxy, "Kind");
+ if (variant_kind != NULL) {
+ kind = g_variant_get_string (variant_kind, NULL);
+ g_print ("Kind:\t\t%s\n", kind);
+ }
+
/* print model */
variant_model = g_dbus_proxy_get_cached_property (proxy, "Model");
model = g_variant_get_string (variant_model, NULL);
@@ -269,6 +278,40 @@ main (int argc, char *argv[])
g_free (object_path_tmp);
}
+ } else if (g_strcmp0 (argv[1], "get-devices-by-kind") == 0) {
+
+ if (argc < 2) {
+ g_print ("Not enough arguments\n");
+ goto out;
+ }
+
+ /* execute sync method */
+ response = g_dbus_connection_call_sync (connection,
+ COLORD_DBUS_SERVICE,
+ COLORD_DBUS_PATH,
+ COLORD_DBUS_INTERFACE,
+ "GetDevicesByKind",
+ g_variant_new ("(s)", argv[2]),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (response == NULL) {
+ /* TRANSLATORS: the DBus method failed */
+ g_print ("%s %s\n", _("The request failed:"), error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* print each device */
+ response_child = g_variant_get_child_value (response, 0);
+ len = g_variant_iter_init (&iter, response_child);
+ for (i=0; i < len; i++) {
+ g_variant_get_child (response_child, i,
+ "o", &object_path_tmp);
+ cd_util_show_device (object_path_tmp);
+ g_free (object_path_tmp);
+ }
+
} else if (g_strcmp0 (argv[1], "get-profiles") == 0) {
/* execute sync method */
diff --git a/doc/create.sh b/doc/create.sh
index b4e778d..e8e7e9c 100755
--- a/doc/create.sh
+++ b/doc/create.sh
@@ -3,5 +3,6 @@
../client/colormgr create-profile profile-victorian temp
../client/colormgr device-add-profile /org/freedesktop/ColorManager/t61xrandr /org/freedesktop/ColorManager/t61xrandr_default
../client/colormgr device-set-property /org/freedesktop/ColorManager/t61xrandr Model "Cray 3000"
+../client/colormgr device-set-property /org/freedesktop/ColorManager/t61xrandr Kind "printer"
../client/colormgr profile-set-property /org/freedesktop/ColorManager/t61xrandr_default Filename /home/hughsie/.color/icc/ibm-t61.icc
../client/colormgr profile-set-property /org/freedesktop/ColorManager/t61xrandr_default Qualifier "RGB.Plain.300dpi"
diff --git a/src/cd-device-array.c b/src/cd-device-array.c
index aaf661f..15288a7 100644
--- a/src/cd-device-array.c
+++ b/src/cd-device-array.c
@@ -118,29 +118,38 @@ cd_device_array_get_by_object_path (CdDeviceArray *device_array,
}
/**
- * cd_device_array_class_init:
+ * cd_device_array_get_array:
+ **/
+GPtrArray *
+cd_device_array_get_array (CdDeviceArray *device_array)
+{
+ CdDeviceArrayPrivate *priv = device_array->priv;
+ return g_ptr_array_ref (priv->array);
+}
+
+/**
+ * cd_device_array_get_by_kind:
**/
-GVariant *
-cd_device_array_get_variant (CdDeviceArray *device_array)
+GPtrArray *
+cd_device_array_get_by_kind (CdDeviceArray *device_array,
+ const gchar *kind)
{
CdDeviceArrayPrivate *priv = device_array->priv;
- CdDevice *device;
+ CdDevice *device_tmp;
+ GPtrArray *array_tmp = NULL;
guint i;
- GVariant *variant;
- GVariant **variant_array = NULL;
- /* copy the object paths */
- variant_array = g_new0 (GVariant *, priv->array->len + 1);
+ /* return all that match kind */
+ array_tmp = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
for (i=0; i<priv->array->len; i++) {
- device = g_ptr_array_index (priv->array, i);
- variant_array[i] = g_variant_new_object_path (cd_device_get_object_path (device));
+ device_tmp = g_ptr_array_index (priv->array, i);
+ if (g_strcmp0 (cd_device_get_kind (device_tmp),
+ kind) == 0) {
+ g_ptr_array_add (array_tmp, g_object_ref (device_tmp));
+ }
}
- /* format the value */
- variant = g_variant_new_array (G_VARIANT_TYPE_OBJECT_PATH,
- variant_array,
- priv->array->len);
- return variant;
+ return array_tmp;
}
/**
diff --git a/src/cd-device-array.h b/src/cd-device-array.h
index fab0190..5656006 100644
--- a/src/cd-device-array.h
+++ b/src/cd-device-array.h
@@ -61,7 +61,9 @@ CdDevice *cd_device_array_get_by_id (CdDeviceArray *device_array,
const gchar *id);
CdDevice *cd_device_array_get_by_object_path (CdDeviceArray *device_array,
const gchar *object_path);
-GVariant *cd_device_array_get_variant (CdDeviceArray *device_array);
+GPtrArray *cd_device_array_get_array (CdDeviceArray *device_array);
+GPtrArray *cd_device_array_get_by_kind (CdDeviceArray *device_array,
+ const gchar *kind);
G_END_DECLS
diff --git a/src/cd-device.c b/src/cd-device.c
index d852322..4c1d161 100644
--- a/src/cd-device.c
+++ b/src/cd-device.c
@@ -43,6 +43,7 @@ struct _CdDevicePrivate
CdProfileArray *profile_array;
gchar *id;
gchar *model;
+ gchar *kind;
gchar *object_path;
GDBusConnection *connection;
GPtrArray *profiles;
@@ -87,6 +88,26 @@ cd_device_get_id (CdDevice *device)
}
/**
+ * cd_device_get_model:
+ **/
+const gchar *
+cd_device_get_model (CdDevice *device)
+{
+ g_return_val_if_fail (CD_IS_DEVICE (device), NULL);
+ return device->priv->model;
+}
+
+/**
+ * cd_device_get_kind:
+ **/
+const gchar *
+cd_device_get_kind (CdDevice *device)
+{
+ g_return_val_if_fail (CD_IS_DEVICE (device), NULL);
+ return device->priv->kind;
+}
+
+/**
* cd_device_set_id:
**/
void
@@ -364,6 +385,13 @@ cd_device_dbus_method_call (GDBusConnection *connection_, const gchar *sender,
g_dbus_method_invocation_return_value (invocation, NULL);
goto out;
}
+ if (g_strcmp0 (property_name, "Kind") == 0) {
+ g_free (priv->kind);
+ priv->kind = g_strdup (property_value);
+ cd_device_dbus_emit_changed (device);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ goto out;
+ }
g_dbus_method_invocation_return_error (invocation,
CD_MAIN_ERROR,
CD_MAIN_ERROR_FAILED,
@@ -404,7 +432,14 @@ cd_device_dbus_get_property (GDBusConnection *connection_, const gchar *sender,
if (g_strcmp0 (property_name, "Model") == 0) {
if (priv->model != NULL)
retval = g_variant_new_string (priv->model);
- else
+ else
+ retval = g_variant_new_string ("");
+ goto out;
+ }
+ if (g_strcmp0 (property_name, "Kind") == 0) {
+ if (priv->kind != NULL)
+ retval = g_variant_new_string (priv->kind);
+ else
retval = g_variant_new_string ("");
goto out;
}
@@ -625,6 +660,7 @@ cd_device_finalize (GObject *object)
}
g_free (priv->id);
g_free (priv->model);
+ g_free (priv->kind);
g_free (priv->object_path);
if (priv->profiles != NULL)
g_ptr_array_unref (priv->profiles);
diff --git a/src/cd-device.h b/src/cd-device.h
index 4247979..f9b5bdf 100644
--- a/src/cd-device.h
+++ b/src/cd-device.h
@@ -53,6 +53,8 @@ GType cd_device_get_type (void);
CdDevice *cd_device_new (void);
/* accessors */
+const gchar *cd_device_get_model (CdDevice *device);
+const gchar *cd_device_get_kind (CdDevice *device);
const gchar *cd_device_get_id (CdDevice *device);
void cd_device_set_id (CdDevice *device,
const gchar *id);
diff --git a/src/cd-main.c b/src/cd-main.c
index d12040e..fce326e 100644
--- a/src/cd-main.c
+++ b/src/cd-main.c
@@ -262,6 +262,31 @@ out:
}
/**
+ * cd_main_object_path_array_to_variant:
+ **/
+static GVariant *
+cd_main_object_path_array_to_variant (GPtrArray *array)
+{
+ CdDevice *device;
+ guint i;
+ GVariant *variant;
+ GVariant **variant_array = NULL;
+
+ /* copy the object paths */
+ variant_array = g_new0 (GVariant *, array->len + 1);
+ for (i=0; i<array->len; i++) {
+ device = g_ptr_array_index (array, i);
+ variant_array[i] = g_variant_new_object_path (cd_device_get_object_path (device));
+ }
+
+ /* format the value */
+ variant = g_variant_new_array (G_VARIANT_TYPE_OBJECT_PATH,
+ variant_array,
+ array->len);
+ return variant;
+}
+
+/**
* cd_main_daemon_method_call:
**/
static void
@@ -276,6 +301,7 @@ cd_main_daemon_method_call (GDBusConnection *connection_, const gchar *sender,
gchar *device_id = NULL;
gchar *object_path_tmp = NULL;
GError *error = NULL;
+ GPtrArray *array = NULL;
guint options;
GVariant *tuple = NULL;
GVariant *value = NULL;
@@ -284,7 +310,23 @@ cd_main_daemon_method_call (GDBusConnection *connection_, const gchar *sender,
if (g_strcmp0 (method_name, "GetDevices") == 0) {
/* format the value */
- value = cd_device_array_get_variant (devices_array);
+ array = cd_device_array_get_array (devices_array);
+ value = cd_main_object_path_array_to_variant (array);
+ tuple = g_variant_new_tuple (&value, 1);
+ g_dbus_method_invocation_return_value (invocation, tuple);
+ goto out;
+ }
+
+ /* return 'as' */
+ if (g_strcmp0 (method_name, "GetDevicesByKind") == 0) {
+
+ /* get all the devices that match this type */
+ g_variant_get (parameters, "(s)", &device_id);
+ array = cd_device_array_get_by_kind (devices_array,
+ device_id);
+
+ /* format the value */
+ value = cd_main_object_path_array_to_variant (array);
tuple = g_variant_new_tuple (&value, 1);
g_dbus_method_invocation_return_value (invocation, tuple);
goto out;
@@ -486,6 +528,8 @@ cd_main_daemon_method_call (GDBusConnection *connection_, const gchar *sender,
g_critical ("failed to process method %s", method_name);
out:
g_free (object_path_tmp);
+ if (array != NULL)
+ g_ptr_array_unref (array);
if (device != NULL)
g_object_unref (device);
if (profile != NULL)
diff --git a/src/org.freedesktop.ColorManager.Device.xml b/src/org.freedesktop.ColorManager.Device.xml
index 0350454..ca52c00 100644
--- a/src/org.freedesktop.ColorManager.Device.xml
+++ b/src/org.freedesktop.ColorManager.Device.xml
@@ -34,6 +34,19 @@
</property>
<!--***********************************************************-->
+ <property name='Kind' type='s' access='read'>
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ The device kind, 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:description>
+ </doc:doc>
+ </property>
+
+ <!--***********************************************************-->
<property name='DeviceId' type='s' access='read'>
<doc:doc>
<doc:description>
diff --git a/src/org.freedesktop.ColorManager.xml b/src/org.freedesktop.ColorManager.xml
index 940625f..b6b0300 100644
--- a/src/org.freedesktop.ColorManager.xml
+++ b/src/org.freedesktop.ColorManager.xml
@@ -168,6 +168,37 @@
</method>
<!--***********************************************************-->
+ <method name='GetDevicesByKind'>
+ <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='s' name='kind' direction='in'>
+ <doc:doc>
+ <doc:summary>
+ <doc:para>
+ A device kind, 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>
+ </arg>
+ <arg type='ao' name='devices' direction='out'>
+ <doc:doc>
+ <doc:summary>
+ <doc:para>
+ An array of device IDs, e.g. <doc:tt>['/org/freedesktop/ColorManager/device/xrandr_ibm_france_ltn154p2_l05']</doc:tt>.
+ </doc:para>
+ </doc:summary>
+ </doc:doc>
+ </arg>
+ </method>
+
+ <!--***********************************************************-->
<method name='FindDeviceById'>
<annotation name='org.freedesktop.DBus.GLib.Async' value=''/>
<doc:doc>