[gnome-color-manager] Return the title and filename of each profile on the DBus interface to save the client scanning each
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Return the title and filename of each profile on the DBus interface to save the client scanning each
- Date: Fri, 4 Dec 2009 13:21:50 +0000 (UTC)
commit e1d2fb94954891f621f4ead22dbd1f4c1cebb3f7
Author: Richard Hughes <richard hughsie com>
Date: Fri Dec 4 11:47:16 2009 +0000
Return the title and filename of each profile on the DBus interface to save the client scanning each one
src/gcm-dbus.c | 104 ++++++++++++++++++++++++++++++++-------
src/gcm-inspect.c | 44 ++++++++++++++---
src/org.gnome.ColorManager.xml | 4 +-
3 files changed, 124 insertions(+), 28 deletions(-)
---
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
index dc7f1d3..48dd0a3 100644
--- a/src/gcm-dbus.c
+++ b/src/gcm-dbus.c
@@ -30,6 +30,7 @@
#include "gcm-utils.h"
#include "gcm-dbus.h"
#include "gcm-client.h"
+#include "gcm-profile.h"
static void gcm_dbus_finalize (GObject *object);
@@ -144,27 +145,57 @@ gcm_dbus_get_idle_time (GcmDbus *dbus)
return idle;
}
+#define GCM_DBUS_STRUCT_STRING_STRING (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID))
+
/**
- * gcm_dbus_get_profiles_for_device:
+ * gcm_dbus_get_title_for_profile:
**/
-void
-gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *sysfs_path, const gchar *options, DBusGMethodInvocation *context)
+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;
+ gchar *sysfs_path_tmp;
+ gchar *profile;
GPtrArray *array;
GcmDevice *device;
- gchar **profiles;
- gchar *sysfs_path_tmp;
- guint i;
+ GPtrArray *array_devices;
- egg_debug ("getting profiles for %s", sysfs_path);
-
- /* for now, hardcode one profile per device */
- profiles = g_new0 (gchar *, 2);
+ /* create a temp array */
+ array = g_ptr_array_new_with_free_func (g_free);
/* get list */
- array = gcm_client_get_devices (dbus->priv->client);
- for (i=0; i<array->len; i++) {
- device = g_ptr_array_index (array, i);
+ array_devices = gcm_client_get_devices (dbus->priv->client);
+ 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,
@@ -179,22 +210,57 @@ gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *sysfs_path, const
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", &profiles[0],
+ "profile-filename", &profile,
NULL);
- g_free (sysfs_path_tmp);
- break;
+ g_ptr_array_add (array, profile);
}
g_free (sysfs_path_tmp);
}
+ /* 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;
+ gchar *title;
+ guint i;
+ GPtrArray *array_structs;
+ GValue *value;
+
+ egg_debug ("getting profiles for %s", sysfs_path);
+
+ /* get array of profile filenames */
+ array_profiles = gcm_dbus_get_profiles_for_device_internal (dbus, sysfs_path);
+
+ /* 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);
+ 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);
+ g_ptr_array_add (array_structs, g_value_get_boxed (value));
+ g_free (value);
+ g_free (title);
+ }
+
/* return profiles */
- dbus_g_method_return (context, profiles);
+ dbus_g_method_return (context, array_structs);
/* reset time */
g_timer_reset (dbus->priv->timer);
- g_strfreev (profiles);
- g_ptr_array_unref (array);
+ g_ptr_array_unref (array_profiles);
}
/**
diff --git a/src/gcm-inspect.c b/src/gcm-inspect.c
index 3870038..1344d10 100644
--- a/src/gcm-inspect.c
+++ b/src/gcm-inspect.c
@@ -161,8 +161,13 @@ gcm_inspect_show_profiles_for_device (const gchar *sysfs_path)
DBusGConnection *connection;
DBusGProxy *proxy;
GError *error = NULL;
- gchar **profiles = 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);
@@ -173,12 +178,19 @@ gcm_inspect_show_profiles_for_device (const gchar *sysfs_path)
"/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, "GetProfilesForDevice", &error,
G_TYPE_STRING, sysfs_path,
G_TYPE_STRING, "",
G_TYPE_INVALID,
- G_TYPE_STRV, &profiles,
+ custom_g_type_string_string, &profile_data_array,
G_TYPE_INVALID);
if (!ret) {
egg_warning ("failed: %s", error->message);
@@ -186,8 +198,8 @@ gcm_inspect_show_profiles_for_device (const gchar *sysfs_path)
goto out;
}
- /* no entries */
- if (profiles[0] == NULL) {
+ /* no data */
+ if (profile_data_array->len == 0) {
/* TRANSLATORS: no rofile has been asigned to this device */
g_print ("%s\n", _("There are no ICC profiles for this device"));
goto out;
@@ -195,11 +207,29 @@ 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);
- for (i=0; profiles[i] != NULL; i++)
- g_print ("%i.\t%s\n", i+1, profiles[i]);
+
+ /* 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\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);
- g_strfreev (profiles);
return ret;
}
diff --git a/src/org.gnome.ColorManager.xml b/src/org.gnome.ColorManager.xml
index 29e2d20..56181a2 100644
--- a/src/org.gnome.ColorManager.xml
+++ b/src/org.gnome.ColorManager.xml
@@ -70,11 +70,11 @@
</doc:summary>
</doc:doc>
</arg>
- <arg type="as" name="profiles" direction="out">
+ <arg type="a(ss)" name="profiles" direction="out">
<doc:doc>
<doc:summary>
<doc:para>
- A list of filenames of suitable profiles to use with this device.
+ An array of profile display names and filenames of suitable profiles to use with this device.
</doc:para>
</doc:summary>
</doc:doc>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]