[gnome-color-manager] Add another method on the DBus interface, GetProfilesForType()
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add another method on the DBus interface, GetProfilesForType()
- Date: Fri, 4 Dec 2009 13:22:00 +0000 (UTC)
commit a36be6d98eb106d9f84464083005fcc26d2896b8
Author: Richard Hughes <richard hughsie com>
Date: Fri Dec 4 12:30:01 2009 +0000
Add another method on the DBus interface, GetProfilesForType()
src/gcm-dbus.c | 178 +++++++++++++++++++++++++++++++---------
src/gcm-dbus.h | 4 +
src/gcm-inspect.c | 100 ++++++++++++++++++++++-
src/org.gnome.ColorManager.xml | 41 +++++++++-
4 files changed, 282 insertions(+), 41 deletions(-)
---
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
index 48dd0a3..04015de 100644
--- a/src/gcm-dbus.c
+++ b/src/gcm-dbus.c
@@ -148,49 +148,23 @@ gcm_dbus_get_idle_time (GcmDbus *dbus)
#define GCM_DBUS_STRUCT_STRING_STRING (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID))
/**
- * gcm_dbus_get_title_for_profile:
- **/
-static gchar *
-gcm_dbus_get_title_for_profile (GcmDbus *dbus, const gchar *filename)
-{
- GcmProfile *profile;
- GError *error = NULL;
- gboolean ret;
- gchar *title = NULL;
-
- /* open and parse filename */
- profile = gcm_profile_new ();
- ret = gcm_profile_parse (profile, filename, &error);
- if (!ret) {
- egg_warning ("failed to parse %s: %s", filename, error->message);
- g_error_free (error);
- goto out;
- }
-
- /* get the title */
- g_object_get (profile,
- "description", &title,
- NULL);
-out:
- g_object_unref (profile);
- return title;
-}
-
-/**
* gcm_dbus_get_profiles_for_device_internal:
**/
static GPtrArray *
gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *sysfs_path)
{
- guint i;
+ gboolean ret;
+ gchar *filename;
gchar *sysfs_path_tmp;
- gchar *profile;
- GPtrArray *array;
+ guint i;
GcmDevice *device;
+ GcmProfile *profile;
+ GError *error = NULL;
+ GPtrArray *array;
GPtrArray *array_devices;
/* create a temp array */
- array = g_ptr_array_new_with_free_func (g_free);
+ array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
/* get list */
array_devices = gcm_client_get_devices (dbus->priv->client);
@@ -210,9 +184,22 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *sysfs_pat
egg_debug ("comparing %s with %s", sysfs_path_tmp, sysfs_path);
if (g_strcmp0 (sysfs_path_tmp, sysfs_path) == 0) {
g_object_get (device,
- "profile-filename", &profile,
+ "profile-filename", &filename,
NULL);
- g_ptr_array_add (array, profile);
+
+ /* open and parse filename */
+ profile = gcm_profile_new ();
+ ret = gcm_profile_parse (profile, filename, &error);
+ if (!ret) {
+ egg_warning ("failed to parse %s: %s", filename, error->message);
+ g_clear_error (&error);
+ } else {
+ g_ptr_array_add (array, g_object_ref (profile));
+ }
+
+ /* unref */
+ g_object_unref (profile);
+ g_free (filename);
}
g_free (sysfs_path_tmp);
}
@@ -223,14 +210,69 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *sysfs_pat
}
/**
+ * gcm_dbus_get_profiles_for_type_internal:
+ **/
+static GPtrArray *
+gcm_dbus_get_profiles_for_type_internal (GcmDbus *dbus, GcmDeviceType type)
+{
+ const gchar *filename;
+ gboolean ret;
+ guint i;
+ GcmProfile *profile;
+ GcmProfileType profile_type;
+ GcmProfileType type_tmp;
+ GError *error = NULL;
+ GPtrArray *array;
+ GPtrArray *array_devices;
+
+ /* create a temp array */
+ array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+
+ /* get the correct profile type for the device type */
+ profile_type = gcm_utils_device_type_to_profile_type (type);
+
+ /* get list */
+ array_devices = gcm_utils_get_profile_filenames ();
+ for (i=0; i<array_devices->len; i++) {
+ filename = g_ptr_array_index (array_devices, i);
+
+ /* open and parse filename */
+ profile = gcm_profile_new ();
+ ret = gcm_profile_parse (profile, filename, &error);
+ if (!ret) {
+ egg_warning ("failed to parse %s: %s", filename, error->message);
+ g_clear_error (&error);
+ } else {
+ /* get the native path of this device */
+ g_object_get (profile,
+ "type", &type_tmp,
+ NULL);
+
+ /* compare what we have against what we were given */
+ egg_debug ("comparing %i with %i", type_tmp, profile_type);
+ if (type_tmp == profile_type)
+ g_ptr_array_add (array, g_object_ref (profile));
+ }
+
+ /* unref */
+ g_object_unref (profile);
+ }
+
+ /* unref list of devices */
+ g_ptr_array_unref (array_devices);
+ return 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)
{
GPtrArray *array_profiles;
- const gchar *profile;
+ GcmProfile *profile;
gchar *title;
+ gchar *filename;
guint i;
GPtrArray *array_structs;
GValue *value;
@@ -243,15 +285,73 @@ gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *sysfs_path, const
/* copy data to dbus struct */
array_structs = g_ptr_array_sized_new (array_profiles->len);
for (i=0; i<array_profiles->len; i++) {
- profile = (const gchar *) g_ptr_array_index (array_profiles, i);
- title = gcm_dbus_get_title_for_profile (dbus, profile);
+ profile = (GcmProfile *) g_ptr_array_index (array_profiles, i);
+
+ /* get the data */
+ g_object_get (profile,
+ "description", &title,
+ "filename", &filename,
+ NULL);
+
+ value = g_new0 (GValue, 1);
+ g_value_init (value, GCM_DBUS_STRUCT_STRING_STRING);
+ g_value_take_boxed (value, dbus_g_type_specialized_construct (GCM_DBUS_STRUCT_STRING_STRING));
+ dbus_g_type_struct_set (value, 0, title, 1, filename, -1);
+ g_ptr_array_add (array_structs, g_value_get_boxed (value));
+ g_free (value);
+ g_free (title);
+ g_free (filename);
+ }
+
+ /* return profiles */
+ dbus_g_method_return (context, array_structs);
+
+ /* reset time */
+ g_timer_reset (dbus->priv->timer);
+
+ g_ptr_array_unref (array_profiles);
+}
+
+/**
+ * gcm_dbus_get_profiles_for_type:
+ **/
+void
+gcm_dbus_get_profiles_for_type (GcmDbus *dbus, const gchar *type, const gchar *options, DBusGMethodInvocation *context)
+{
+ GPtrArray *array_profiles;
+ GcmProfile *profile;
+ gchar *title;
+ gchar *filename;
+ guint i;
+ GPtrArray *array_structs;
+ GValue *value;
+ GcmDeviceType type_enum;
+
+ egg_debug ("getting profiles for %s", type);
+
+ /* get array of profile filenames */
+ type_enum = gcm_device_type_from_text (type);
+ array_profiles = gcm_dbus_get_profiles_for_type_internal (dbus, type_enum);
+
+ /* copy data to dbus struct */
+ array_structs = g_ptr_array_sized_new (array_profiles->len);
+ for (i=0; i<array_profiles->len; i++) {
+ profile = (GcmProfile *) g_ptr_array_index (array_profiles, i);
+
+ /* get the data */
+ g_object_get (profile,
+ "description", &title,
+ "filename", &filename,
+ NULL);
+
value = g_new0 (GValue, 1);
g_value_init (value, GCM_DBUS_STRUCT_STRING_STRING);
g_value_take_boxed (value, dbus_g_type_specialized_construct (GCM_DBUS_STRUCT_STRING_STRING));
- dbus_g_type_struct_set (value, 0, title, 1, profile, -1);
+ dbus_g_type_struct_set (value, 0, title, 1, filename, -1);
g_ptr_array_add (array_structs, g_value_get_boxed (value));
g_free (value);
g_free (title);
+ g_free (filename);
}
/* return profiles */
diff --git a/src/gcm-dbus.h b/src/gcm-dbus.h
index 041bb8f..2413071 100644
--- a/src/gcm-dbus.h
+++ b/src/gcm-dbus.h
@@ -68,6 +68,10 @@ void gcm_dbus_get_profiles_for_device (GcmDbus *dbus,
const gchar *sysfs_path,
const gchar *options,
DBusGMethodInvocation *context);
+void gcm_dbus_get_profiles_for_type (GcmDbus *dbus,
+ const gchar *type,
+ const gchar *options,
+ DBusGMethodInvocation *context);
G_END_DECLS
diff --git a/src/gcm-inspect.c b/src/gcm-inspect.c
index 1344d10..f95be65 100644
--- a/src/gcm-inspect.c
+++ b/src/gcm-inspect.c
@@ -221,7 +221,89 @@ gcm_inspect_show_profiles_for_device (const gchar *sysfs_path)
g_value_unset (gv);
/* done */
- g_print ("%i.\t%s\t%s\n", i+1, title, profile);
+ g_print ("%i.\t%s\n\t%s\n", i+1, title, profile);
+ g_value_array_free (gva);
+ g_free (title);
+ g_free (profile);
+ }
+out:
+ if (profile_data_array != NULL)
+ g_ptr_array_free (profile_data_array, TRUE);
+ g_object_unref (proxy);
+ return ret;
+}
+
+/**
+ * gcm_inspect_show_profiles_for_type:
+ **/
+static gboolean
+gcm_inspect_show_profiles_for_type (const gchar *type)
+{
+ gboolean ret;
+ DBusGConnection *connection;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gchar *title;
+ gchar *profile;
+ guint i;
+ GType custom_g_type_string_string;
+ GPtrArray *profile_data_array = NULL;
+ GValueArray *gva;
+ GValue *gv;
+
+ /* get a session bus connection */
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+
+ /* connect to the interface */
+ proxy = dbus_g_proxy_new_for_name (connection,
+ "org.gnome.ColorManager",
+ "/org/gnome/ColorManager",
+ "org.gnome.ColorManager");
+
+ /* create a specialized type, because dbus-glib sucks monkey balls */
+ custom_g_type_string_string = dbus_g_type_get_collection ("GPtrArray",
+ dbus_g_type_get_struct("GValueArray",
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_INVALID));
+
+ /* execute sync method */
+ ret = dbus_g_proxy_call (proxy, "GetProfilesForType", &error,
+ G_TYPE_STRING, type,
+ G_TYPE_STRING, "",
+ G_TYPE_INVALID,
+ custom_g_type_string_string, &profile_data_array,
+ G_TYPE_INVALID);
+ if (!ret) {
+ egg_warning ("failed: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* no data */
+ if (profile_data_array->len == 0) {
+ /* TRANSLATORS: no rofile has been asigned to this device type */
+ g_print ("%s\n", _("There are no ICC profiles for this device type"));
+ goto out;
+ }
+
+ /* TRANSLATORS: this is a list of profiles suitable for the device */
+ g_print ("%s %s\n", _("Suitable profiles for:"), type);
+
+ /* list each entry */
+ for (i=0; i<profile_data_array->len; i++) {
+ gva = (GValueArray *) g_ptr_array_index (profile_data_array, i);
+ /* 0 */
+ gv = g_value_array_get_nth (gva, 0);
+ title = g_value_dup_string (gv);
+ g_value_unset (gv);
+ /* 1 */
+ gv = g_value_array_get_nth (gva, 1);
+ profile = g_value_dup_string (gv);
+ g_value_unset (gv);
+
+ /* done */
+ g_print ("%i.\t%s\n\t%s\n", i+1, title, profile);
g_value_array_free (gva);
g_free (title);
g_free (profile);
@@ -301,6 +383,8 @@ main (int argc, char **argv)
gboolean x11 = FALSE;
gboolean dump = FALSE;
gchar *sysfs_path = NULL;
+ gchar *type = NULL;
+ GcmDeviceType type_enum;
guint retval = 0;
GOptionContext *context;
@@ -311,6 +395,9 @@ main (int argc, char **argv)
{ "device", '\0', 0, G_OPTION_ARG_FILENAME, &sysfs_path,
/* TRANSLATORS: command line option */
_("Get the profiles for a specific device"), NULL },
+ { "type", '\0', 0, G_OPTION_ARG_FILENAME, &type,
+ /* TRANSLATORS: command line option */
+ _("Get the profiles for a specific device type"), NULL },
{ "dump", 'd', 0, G_OPTION_ARG_NONE, &dump,
/* TRANSLATORS: command line option */
_("Dump all details about this system"), NULL },
@@ -336,10 +423,21 @@ main (int argc, char **argv)
gcm_inspect_show_x11_atoms ();
if (sysfs_path != NULL)
gcm_inspect_show_profiles_for_device (sysfs_path);
+ if (type != NULL) {
+ type_enum = gcm_device_type_from_text (type);
+ if (type_enum == GCM_DEVICE_TYPE_UNKNOWN) {
+ /* TRANSLATORS: this is when the user does --type=mickeymouse */
+ g_print ("%s\n", _("Device type not recognised"));
+ } else {
+ /* show device profiles */
+ gcm_inspect_show_profiles_for_type (type);
+ }
+ }
if (dump)
gcm_inspect_get_properties ();
g_free (sysfs_path);
+ g_free (type);
return retval;
}
diff --git a/src/org.gnome.ColorManager.xml b/src/org.gnome.ColorManager.xml
index 56181a2..776b8fa 100644
--- a/src/org.gnome.ColorManager.xml
+++ b/src/org.gnome.ColorManager.xml
@@ -48,7 +48,7 @@
<doc:doc>
<doc:description>
<doc:para>
- Finds out if the package is installed.
+ Gets the profiles for a specific device.
</doc:para>
</doc:description>
</doc:doc>
@@ -81,6 +81,45 @@
</arg>
</method>
+ <!--*****************************************************************************************-->
+ <method name="GetProfilesForType">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ Gets the profiles for a device type.
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ <arg type="s" name="type" direction="in">
+ <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>.
+ </doc:para>
+ </doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="s" name="options" direction="in">
+ <doc:doc>
+ <doc:summary>
+ <doc:para>
+ Options to give hints about what profiles to choose. Currently unused.
+ </doc:para>
+ </doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="a(ss)" name="profiles" direction="out">
+ <doc:doc>
+ <doc:summary>
+ <doc:para>
+ An array of profile display names and filenames of suitable profiles to use with this type of device.
+ </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]