[gnome-color-manager] Actually make GetProfilesForDevice() work



commit 3a6f3a1dd839554cd4c7d6b85dccaa81633fdb77
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 6 11:29:19 2009 +0000

    Actually make GetProfilesForDevice() work

 contrib/gnome-color-manager.spec.in |    5 +--
 data/Makefile.am                    |    2 +
 po/POTFILES.in                      |    1 +
 src/gcm-client.c                    |    5 +++
 src/gcm-dbus.c                      |   53 ++++++++++++++++++++++++++++++++++-
 src/gcm-device.c                    |   19 ++++++++++++
 src/gcm-session.c                   |   15 ----------
 7 files changed, 81 insertions(+), 19 deletions(-)
---
diff --git a/contrib/gnome-color-manager.spec.in b/contrib/gnome-color-manager.spec.in
index 0a68e68..c2f6431 100644
--- a/contrib/gnome-color-manager.spec.in
+++ b/contrib/gnome-color-manager.spec.in
@@ -111,9 +111,7 @@ update-mime-database %{_datadir}/mime &> /dev/null || :
 %files -f %{name}.lang
 %defattr(-,root,root,-)
 %doc AUTHORS COPYING NEWS README
-%{_bindir}/gcm-prefs
-%{_bindir}/gcm-import
-%{_bindir}/gcm-apply
+%{_bindir}/gcm-*
 %dir %{_datadir}/gnome-color-manager
 %dir %{_datadir}/gnome-color-manager/profiles
 %{_datadir}/gnome-color-manager/profiles/*.ic?
@@ -127,6 +125,7 @@ update-mime-database %{_datadir}/mime &> /dev/null || :
 %{_datadir}/applications/gcm-prefs.desktop
 %{_datadir}/applications/gcm-import.desktop
 %{_sysconfdir}/xdg/autostart/*.desktop
+%{_datadir}/dbus-1/services/org.gnome.ColorManager.service
 
 %changelog
 * #LONGDATE# Richard Hughes <richard hughsie com> #VERSION#-0.#BUILD##ALPHATAG#
diff --git a/data/Makefile.am b/data/Makefile.am
index 736070e..f40edb4 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -32,6 +32,7 @@ pkgdata_DATA =						\
 
 EXTRA_DIST =						\
 	$(schema_in_files)				\
+	$(service_in_files)				\
 	$(autostart_in_files)				\
 	$(desktop_in_files)				\
 	$(pkgdata_DATA)
@@ -52,6 +53,7 @@ clean-local :
 	rm -f *~
 
 DISTCLEANFILES =					\
+	org.gnome.ColorManager.service			\
 	gnome-color-manager.schemas			\
 	gcm-apply.desktop				\
 	gcm-prefs.desktop				\
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9cafcb3..43eab84 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,4 +9,5 @@ src/gcm-inspect.c
 src/gcm-import.c
 src/gcm-prefs.c
 src/gcm-utils.c
+src/gcm-session.c
 
diff --git a/src/gcm-client.c b/src/gcm-client.c
index b928e4a..b79ace5 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -175,6 +175,7 @@ gcm_client_gudev_add_type (GcmClient *client, GUdevDevice *udev_device, GcmDevic
 	gchar *id;
 	gboolean ret;
 	GError *error = NULL;
+	const gchar *sysfs_path;
 	GcmClientPrivate *priv = client->priv;
 
 	/* add new device */
@@ -186,12 +187,16 @@ gcm_client_gudev_add_type (GcmClient *client, GUdevDevice *udev_device, GcmDevic
 	/* turn space delimiters into spaces */
 	g_strdelimit (title, "_", ' ');
 
+	/* get sysfs path */
+	sysfs_path = g_udev_device_get_sysfs_path (udev_device);
+
 	/* create device */
 	device = gcm_device_new ();
 	g_object_set (device,
 		      "type", type,
 		      "id", id,
 		      "title", title,
+		      "native-device-sysfs", sysfs_path,
 		      NULL);
 
 	/* load the device */
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
index 00aab06..b671dd1 100644
--- a/src/gcm-dbus.c
+++ b/src/gcm-dbus.c
@@ -82,7 +82,48 @@ gcm_dbus_error_get_type (void)
 void
 gcm_dbus_get_profiles_for_device (GcmDbus *dbus, const gchar *sysfs_path, const gchar *options, DBusGMethodInvocation *context)
 {
-	dbus_g_method_return (context, NULL);
+	GPtrArray *array;
+	GcmDevice *device;
+	gchar **profiles;
+	gchar *sysfs_path_tmp;
+	guint i;
+
+	egg_debug ("getting profiles for %s", sysfs_path);
+
+	/* for now, hardcode one profile per device */
+	profiles = g_new0 (gchar *, 2);
+
+	/* get list */
+	array = gcm_client_get_devices (dbus->priv->client);
+	for (i=0; i<array->len; i++) {
+		device = g_ptr_array_index (array, i);
+
+		/* get the native path of this device */
+		g_object_get (device,
+			      "native-device-sysfs", &sysfs_path_tmp,
+			      NULL);
+
+		/* wrong type of device */
+		if (sysfs_path_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) {
+			g_object_get (device,
+				      "profile", &profiles[0],
+				      NULL);
+			g_free (sysfs_path_tmp);
+			break;
+		}
+		g_free (sysfs_path_tmp);
+	}
+
+	/* return profiles */
+	dbus_g_method_return (context, profiles);
+
+	g_strfreev (profiles);
+	g_ptr_array_unref (array);
 }
 
 /**
@@ -104,9 +145,19 @@ gcm_dbus_class_init (GcmDbusClass *klass)
 static void
 gcm_dbus_init (GcmDbus *dbus)
 {
+	gboolean ret;
+	GError *error = NULL;
+
 	dbus->priv = GCM_DBUS_GET_PRIVATE (dbus);
 	dbus->priv->gconf_client = gconf_client_get_default ();
 	dbus->priv->client = gcm_client_new ();
+
+	/* get all devices */
+	ret = gcm_client_coldplug (dbus->priv->client, &error);
+	if (!ret) {
+		egg_warning ("failed to coldplug: %s", error->message);
+		g_error_free (error);
+	}
 }
 
 /**
diff --git a/src/gcm-device.c b/src/gcm-device.c
index 6eadae7..db48ca9 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -62,6 +62,7 @@ struct _GcmDevicePrivate
 	gchar				*vendor;
 	GConfClient			*gconf_client;
 	GnomeRROutput			*native_device_xrandr;
+	gchar				*native_device_sysfs;
 };
 
 enum {
@@ -77,6 +78,7 @@ enum {
 	PROP_DESCRIPTION,
 	PROP_TITLE,
 	PROP_NATIVE_DEVICE_XRANDR,
+	PROP_NATIVE_DEVICE_SYSFS,
 	PROP_LAST
 };
 
@@ -374,6 +376,9 @@ gcm_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
 	case PROP_NATIVE_DEVICE_XRANDR:
 		g_value_set_pointer (value, priv->native_device_xrandr);
 		break;
+	case PROP_NATIVE_DEVICE_SYSFS:
+		g_value_set_string (value, priv->native_device_sysfs);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -417,6 +422,10 @@ gcm_device_set_property (GObject *object, guint prop_id, const GValue *value, GP
 	case PROP_NATIVE_DEVICE_XRANDR:
 		priv->native_device_xrandr = g_value_get_pointer (value);
 		break;
+	case PROP_NATIVE_DEVICE_SYSFS:
+		g_free (priv->native_device_sysfs);
+		priv->native_device_sysfs = g_strdup (g_value_get_string (value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -522,6 +531,14 @@ gcm_device_class_init (GcmDeviceClass *klass)
 				      G_PARAM_READWRITE);
 	g_object_class_install_property (object_class, PROP_NATIVE_DEVICE_XRANDR, pspec);
 
+	/**
+	 * GcmDevice:native-device-sysfs:
+	 */
+	pspec = g_param_spec_string ("native-device-sysfs", NULL, NULL,
+				     NULL,
+				     G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_NATIVE_DEVICE_SYSFS, pspec);
+
 	g_type_class_add_private (klass, sizeof (GcmDevicePrivate));
 }
 
@@ -533,6 +550,7 @@ gcm_device_init (GcmDevice *device)
 {
 	device->priv = GCM_DEVICE_GET_PRIVATE (device);
 	device->priv->native_device_xrandr = NULL;
+	device->priv->native_device_sysfs = NULL;
 	device->priv->profile = NULL;
 	device->priv->gconf_client = gconf_client_get_default ();
 	device->priv->gamma = gconf_client_get_float (device->priv->gconf_client, "/apps/gnome-color-manager/default_gamma", NULL);
@@ -558,6 +576,7 @@ gcm_device_finalize (GObject *object)
 	g_free (priv->vendor);
 	g_free (priv->title);
 	g_free (priv->id);
+	g_free (priv->native_device_sysfs);
 	g_object_unref (priv->gconf_client);
 
 	G_OBJECT_CLASS (gcm_device_parent_class)->finalize (object);
diff --git a/src/gcm-session.c b/src/gcm-session.c
index 2d562e3..46d3f68 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -21,28 +21,13 @@
 
 #include "config.h"
 
-//#include <errno.h>
-//#include <string.h>
-//#include <unistd.h>
-//#include <stdlib.h>
-//#include <glib.h>
 #include <glib/gi18n.h>
 #include <dbus/dbus-glib.h>
 #include <gtk/gtk.h>
-//#include <locale.h>
-//#include <libnotify/notify.h>
-//#include <packagekit-glib/packagekit.h>
 
 #include "egg-debug.h"
-//#include "egg-dbus-monitor.h"
-
-//#include "gcm-check-update.h"
-//#include "gcm-watch.h"
-//#include "gcm-firmware.h"
-//#include "gcm-hardware.h"
 #include "gcm-dbus.h"
 #include "org.gnome.ColorManager.h"
-//#include "gcm-common.h"
 
 #define GCM_DBUS_SERVICE	"org.gnome.ColorManager"
 #define GCM_DBUS_INTERFACE	"org.gnome.ColorManager"



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