[gnome-color-manager] Add a gnome-settings-daemon module to fix some hard to fix bugs



commit dbebdeaeda3e9d48d5fa61bd9a2cd334fb61a4ce
Author: Richard Hughes <richard hughsie com>
Date:   Mon Jul 26 16:49:50 2010 +0100

    Add a gnome-settings-daemon module to fix some hard to fix bugs
    
    This allows us to:
    
    1) set gcm-apply when we switch users, so the correct VCGT is used
    2) open the calibration window when a colorimeter is plugged in

 Makefile.am                         |    1 +
 configure.ac                        |    2 +
 contrib/gnome-color-manager.spec.in |    4 +
 session/.gitignore                  |    5 +
 session/Makefile.am                 |   44 ++++
 session/color.gnome-settings-plugin |    8 +
 session/egg-console-kit.c           |  411 +++++++++++++++++++++++++++++++++++
 session/egg-console-kit.h           |   75 +++++++
 session/gsd-color-manager.c         |  167 ++++++++++++++
 session/gsd-color-manager.h         |   56 +++++
 session/gsd-color-plugin.c          |   99 +++++++++
 session/gsd-color-plugin.h          |   57 +++++
 src/Makefile.am                     |    1 +
 src/gcm-apply.c                     |   12 +
 14 files changed, 942 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0121d84..3dcc91b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,7 @@ SUBDIRS = 						\
 	policy						\
 	rules						\
 	tools						\
+	session						\
 	src
 
 snapshot:
diff --git a/configure.ac b/configure.ac
index aa540d6..b030aba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -141,6 +141,7 @@ PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 2.90.3)
 PKG_CHECK_MODULES(GUDEV, gudev-1.0)
 PKG_CHECK_MODULES(LCMS, lcms2)
 PKG_CHECK_MODULES(X11, x11)
+PKG_CHECK_MODULES(SETTINGS_DAEMON, gnome-settings-daemon)
 PKG_CHECK_MODULES(USB, [libusb-1.0 >= 1.0.0])
 
 dnl Required for the properties window
@@ -314,6 +315,7 @@ policy/Makefile
 po/Makefile.in
 rules/Makefile
 src/Makefile
+session/Makefile
 tools/Makefile
 docs/Makefile
 docs/huey/Makefile
diff --git a/contrib/gnome-color-manager.spec.in b/contrib/gnome-color-manager.spec.in
index efdf3d4..c6cee42 100644
--- a/contrib/gnome-color-manager.spec.in
+++ b/contrib/gnome-color-manager.spec.in
@@ -64,6 +64,8 @@ rm -f $RPM_BUILD_ROOT%{_libdir}/control-center-1/panels/*.a
 rm -f $RPM_BUILD_ROOT%{_libdir}/control-center-1/panels/*.la
 rm -f $RPM_BUILD_ROOT%{_libdir}/*.a
 rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
+rm -f $RPM_BUILD_ROOT%{_libdir}/gnome-settings-daemon-2.0/libcolor.a
+rm -f $RPM_BUILD_ROOT%{_libdir}/gnome-settings-daemon-2.0/libcolor.la
 
 %find_lang %name --with-gnome
 
@@ -119,6 +121,8 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &> /dev/null || :
 %{_libdir}/libcolor-glib.so.1.0.0
 %{_libdir}/pkgconfig/libcolor-glib.pc
 %{_datadir}/gtk-doc/html/libcolor-glib
+%{_libdir}/gnome-settings-daemon-2.0/color.gnome-settings-plugin
+%{_libdir}/gnome-settings-daemon-2.0/libcolor.so
 
 %changelog
 * #LONGDATE# Richard Hughes <richard hughsie com> #VERSION#-0.#BUILD##ALPHATAG#
diff --git a/session/.gitignore b/session/.gitignore
new file mode 100644
index 0000000..0c620eb
--- /dev/null
+++ b/session/.gitignore
@@ -0,0 +1,5 @@
+.deps
+.libs
+*.la
+*.lo
+*.o
diff --git a/session/Makefile.am b/session/Makefile.am
new file mode 100644
index 0000000..cba7279
--- /dev/null
+++ b/session/Makefile.am
@@ -0,0 +1,44 @@
+INCLUDES =							\
+	-DI_KNOW_THE_LIBCOLOR_GLIB_API_IS_SUBJECT_TO_CHANGE	\
+	-DBINDIR=\"$(bindir)\"					\
+	-I$(top_srcdir)/libcolor-glib				\
+	$(GLIB_CFLAGS)						\
+	$(GTK_CFLAGS)						\
+	$(SETTINGS_DAEMON_CFLAGS)				\
+	$(GUDEV_CFLAGS)
+
+plugindir = $(libdir)/gnome-settings-daemon-2.0
+plugin_LTLIBRARIES =						\
+	libcolor.la
+plugin_CFLAGS =							\
+	$(WARNINGFLAGS_C)
+
+libcolor_la_SOURCES =						\
+	egg-console-kit.h					\
+	egg-console-kit.c					\
+	gsd-color-plugin.h					\
+	gsd-color-plugin.c					\
+	gsd-color-manager.h					\
+	gsd-color-manager.c
+
+libcolor_la_CPPFLAGS =						\
+	-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\"
+
+libcolor_la_LDFLAGS = -avoid-version -module
+
+libcolor_la_CFLAGS =						\
+	$(SETTINGS_PLUGIN_CFLAGS)				\
+	$(GTK_CFLAGS)						\
+	$(GNOME_CFLAGS)
+
+COLOR_GLIB_LIBS =						\
+	$(top_builddir)/libcolor-glib/libcolor-glib.la
+
+libcolor_la_LIBADD =						\
+	$(COLOR_GLIB_LIBS)
+
+plugin_DATA = color.gnome-settings-plugin
+
+EXTRA_DIST =							\
+	$(plugin_DATA)
+
diff --git a/session/color.gnome-settings-plugin b/session/color.gnome-settings-plugin
new file mode 100644
index 0000000..fb6ec82
--- /dev/null
+++ b/session/color.gnome-settings-plugin
@@ -0,0 +1,8 @@
+[GNOME Settings Plugin]
+Module=color
+IAge=0
+Name=Color
+Description=Color Manager Plugin
+Authors=Richard Hughes
+Copyright=Copyright © 2010
+Website=
diff --git a/session/egg-console-kit.c b/session/egg-console-kit.c
new file mode 100644
index 0000000..312188e
--- /dev/null
+++ b/session/egg-console-kit.c
@@ -0,0 +1,411 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2006-2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "egg-console-kit.h"
+
+static void     egg_console_kit_finalize	(GObject		*object);
+
+#define EGG_CONSOLE_KIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EGG_TYPE_CONSOLE_KIT, EggConsoleKitPrivate))
+
+#define CONSOLEKIT_NAME			"org.freedesktop.ConsoleKit"
+#define CONSOLEKIT_PATH			"/org/freedesktop/ConsoleKit"
+#define CONSOLEKIT_INTERFACE		"org.freedesktop.ConsoleKit"
+
+#define CONSOLEKIT_MANAGER_PATH	 	"/org/freedesktop/ConsoleKit/Manager"
+#define CONSOLEKIT_MANAGER_INTERFACE    "org.freedesktop.ConsoleKit.Manager"
+#define CONSOLEKIT_SEAT_INTERFACE       "org.freedesktop.ConsoleKit.Seat"
+#define CONSOLEKIT_SESSION_INTERFACE    "org.freedesktop.ConsoleKit.Session"
+
+struct EggConsoleKitPrivate
+{
+	GDBusProxy		*proxy_manager;
+	GDBusProxy		*proxy_session;
+	gchar			*session_id;
+};
+
+enum {
+	EGG_CONSOLE_KIT_ACTIVE_CHANGED,
+	EGG_CONSOLE_KIT_LAST_SIGNAL
+};
+
+static gpointer egg_console_kit_object = NULL;
+static guint signals [EGG_CONSOLE_KIT_LAST_SIGNAL] = { 0 };
+G_DEFINE_TYPE (EggConsoleKit, egg_console_kit, G_TYPE_OBJECT)
+
+/**
+ * egg_console_kit_restart:
+ **/
+gboolean
+egg_console_kit_restart (EggConsoleKit *console, GError **error)
+{
+	GVariant *result = NULL;
+	gboolean ret = FALSE;
+	GError *error_local = NULL;
+
+	g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE);
+	g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE);
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	result = g_dbus_proxy_call_sync (console->priv->proxy_manager, "Restart",
+					 NULL,
+					 G_DBUS_CALL_FLAGS_NONE,
+					 -1, NULL, &error_local);
+	if (result == NULL) {
+		g_set_error (error, 1, 0, "Couldn't restart: %s", error_local->message);
+		g_error_free (error_local);
+		goto out;
+	}
+
+	/* success */
+	ret = TRUE;
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return ret;
+}
+
+/**
+ * egg_console_kit_stop:
+ **/
+gboolean
+egg_console_kit_stop (EggConsoleKit *console, GError **error)
+{
+	GVariant *result = NULL;
+	gboolean ret = FALSE;
+	GError *error_local = NULL;
+
+	g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE);
+	g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE);
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	result = g_dbus_proxy_call_sync (console->priv->proxy_manager, "Stop",
+					 NULL,
+					 G_DBUS_CALL_FLAGS_NONE,
+					 -1, NULL, &error_local);
+	if (result == NULL) {
+		g_set_error (error, 1, 0, "Couldn't stop: %s", error_local->message);
+		g_error_free (error_local);
+		goto out;
+	}
+
+	/* success */
+	ret = TRUE;
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return ret;
+}
+
+/**
+ * egg_console_kit_can_stop:
+ **/
+gboolean
+egg_console_kit_can_stop (EggConsoleKit *console, gboolean *can_stop, GError **error)
+{
+	GVariant *result = NULL;
+	gboolean ret = FALSE;
+	GError *error_local = NULL;
+
+	g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE);
+	g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE);
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	result = g_dbus_proxy_call_sync (console->priv->proxy_manager, "CanStop",
+					 NULL,
+					 G_DBUS_CALL_FLAGS_NONE,
+					 -1, NULL, &error_local);
+	if (result == NULL) {
+		g_set_error (error, 1, 0, "Couldn't do CanStop: %s", error_local->message);
+		g_error_free (error_local);
+		goto out;
+	}
+	g_variant_get (result, "(b)", can_stop);
+
+	/* success */
+	ret = TRUE;
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return ret;
+}
+
+/**
+ * egg_console_kit_can_restart:
+ **/
+gboolean
+egg_console_kit_can_restart (EggConsoleKit *console, gboolean *can_restart, GError **error)
+{
+	GVariant *result = NULL;
+	gboolean ret = FALSE;
+	GError *error_local = NULL;
+
+	g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE);
+	g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE);
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	result = g_dbus_proxy_call_sync (console->priv->proxy_manager, "CanRestart",
+					 NULL,
+					 G_DBUS_CALL_FLAGS_NONE,
+					 -1, NULL, &error_local);
+	if (result == NULL) {
+		g_set_error (error, 1, 0, "Couldn't do CanRestart: %s", error_local->message);
+		g_error_free (error_local);
+		goto out;
+	}
+	g_variant_get (result, "(b)", can_restart);
+
+	/* success */
+	ret = TRUE;
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return ret;
+}
+
+/**
+ * egg_console_kit_is_local:
+ *
+ * Return value: Returns whether the session is local
+ **/
+gboolean
+egg_console_kit_is_local (EggConsoleKit *console, gboolean *is_local, GError **error)
+{
+	GVariant *result = NULL;
+	gboolean ret = FALSE;
+	GError *error_local = NULL;
+
+	g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE);
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	/* maybe console kit does not know about our session */
+	if (console->priv->proxy_session == NULL) {
+		g_warning ("no ConsoleKit session");
+		goto out;
+	}
+
+	/* is our session local */
+	result = g_dbus_proxy_call_sync (console->priv->proxy_session, "IsLocal",
+					 NULL,
+					 G_DBUS_CALL_FLAGS_NONE,
+					 -1, NULL, &error_local);
+	if (result == NULL) {
+		g_set_error (error, 1, 0, "IsLocal failed: %s", error_local->message);
+		g_error_free (error_local);
+		goto out;
+	}
+	g_variant_get (result, "(b)", is_local);
+
+	/* success */
+	ret = TRUE;
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return ret;
+}
+
+/**
+ * egg_console_kit_is_active:
+ *
+ * Return value: Returns whether the session is active on the Seat that it is attached to.
+ **/
+gboolean
+egg_console_kit_is_active (EggConsoleKit *console, gboolean *is_active, GError **error)
+{
+	GVariant *result = NULL;
+	gboolean ret = FALSE;
+	GError *error_local = NULL;
+
+	g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE);
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	/* maybe console kit does not know about our session */
+	if (console->priv->proxy_session == NULL) {
+		g_warning ("no ConsoleKit session");
+		goto out;
+	}
+
+	/* is our session active */
+	result = g_dbus_proxy_call_sync (console->priv->proxy_session,
+					 "IsActive",
+					 NULL,
+					 G_DBUS_CALL_FLAGS_NONE,
+					 -1, NULL, &error_local);
+	if (result == NULL) {
+		g_set_error (error, 1, 0, "IsActive failed: %s", error_local->message);
+		g_error_free (error_local);
+		goto out;
+	}
+	g_variant_get (result, "(b)", is_active);
+
+	/* success */
+	ret = TRUE;
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return ret;
+}
+
+/**
+ * egg_console_kit_proxy_signal_cb:
+ **/
+static void
+egg_console_kit_proxy_signal_cb (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name,
+				 GVariant *parameters, EggConsoleKit *console)
+{
+	gboolean active;
+	if (g_strcmp0 (signal_name, "ActiveChanged") == 0) {
+		g_variant_get (parameters, "(b)", &active);
+		g_debug ("emitting active: %i", active);
+		g_signal_emit (console, signals [EGG_CONSOLE_KIT_ACTIVE_CHANGED], 0, active);
+	}
+}
+
+/**
+ * egg_console_kit_class_init:
+ * @klass: The EggConsoleKitClass
+ **/
+static void
+egg_console_kit_class_init (EggConsoleKitClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = egg_console_kit_finalize;
+	g_type_class_add_private (klass, sizeof (EggConsoleKitPrivate));
+	signals [EGG_CONSOLE_KIT_ACTIVE_CHANGED] =
+		g_signal_new ("active-changed",
+			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (EggConsoleKitClass, active_changed),
+			      NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
+			      G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+}
+
+/**
+ * egg_console_kit_init:
+ **/
+static void
+egg_console_kit_init (EggConsoleKit *console)
+{
+	GVariant *result;
+	GError *error = NULL;
+	guint32 pid;
+
+	console->priv = EGG_CONSOLE_KIT_GET_PRIVATE (console);
+	console->priv->proxy_manager = NULL;
+	console->priv->session_id = NULL;
+
+	/* connect to ConsoleKit */
+	console->priv->proxy_manager =
+		g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+					       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+					       NULL,
+					       CONSOLEKIT_NAME,
+					       CONSOLEKIT_MANAGER_PATH,
+					       CONSOLEKIT_MANAGER_INTERFACE,
+					       NULL, &error);
+	if (console->priv->proxy_manager == NULL) {
+		g_warning ("cannot connect to ConsoleKit: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* get the session we are running in */
+	pid = getpid ();
+	result = g_dbus_proxy_call_sync (console->priv->proxy_manager,
+					 "GetSessionForUnixProcess",
+					 g_variant_new ("(u)", pid),
+					 G_DBUS_CALL_FLAGS_NONE,
+					 -1, NULL, &error);
+	if (result == NULL) {
+		g_warning ("Failed to get session for pid %i: %s", pid, error->message);
+		g_error_free (error);
+		goto out;
+	}
+	g_variant_get (result, "(o)", &console->priv->session_id);
+	g_debug ("ConsoleKit session ID: %s", console->priv->session_id);
+
+	/* connect to session */
+	console->priv->proxy_session =
+		g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+					       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+					       NULL,
+					       CONSOLEKIT_NAME,
+					       console->priv->session_id,
+					       CONSOLEKIT_SESSION_INTERFACE,
+					       NULL, &error);
+	if (console->priv->proxy_session == NULL) {
+		g_warning ("cannot connect to %s: %s", console->priv->session_id, error->message);
+		g_error_free (error);
+		goto out;
+	}
+	g_signal_connect (console->priv->proxy_session, "g-signal",
+			  G_CALLBACK (egg_console_kit_proxy_signal_cb), console);
+out:
+	return;
+}
+
+/**
+ * egg_console_kit_finalize:
+ * @object: The object to finalize
+ **/
+static void
+egg_console_kit_finalize (GObject *object)
+{
+	EggConsoleKit *console;
+
+	g_return_if_fail (EGG_IS_CONSOLE_KIT (object));
+
+	console = EGG_CONSOLE_KIT (object);
+
+	g_return_if_fail (console->priv != NULL);
+	if (console->priv->proxy_manager != NULL)
+		g_object_unref (console->priv->proxy_manager);
+	if (console->priv->proxy_session != NULL)
+		g_object_unref (console->priv->proxy_session);
+	g_free (console->priv->session_id);
+
+	G_OBJECT_CLASS (egg_console_kit_parent_class)->finalize (object);
+}
+
+/**
+ * egg_console_kit_new:
+ *
+ * Return value: a new EggConsoleKit object.
+ **/
+EggConsoleKit *
+egg_console_kit_new (void)
+{
+	if (egg_console_kit_object != NULL) {
+		g_object_ref (egg_console_kit_object);
+	} else {
+		egg_console_kit_object = g_object_new (EGG_TYPE_CONSOLE_KIT, NULL);
+		g_object_add_weak_pointer (egg_console_kit_object, &egg_console_kit_object);
+	}
+
+	return EGG_CONSOLE_KIT (egg_console_kit_object);
+}
+
diff --git a/session/egg-console-kit.h b/session/egg-console-kit.h
new file mode 100644
index 0000000..2d897f1
--- /dev/null
+++ b/session/egg-console-kit.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __EGG_CONSOLE_KIT_H
+#define __EGG_CONSOLE_KIT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EGG_TYPE_CONSOLE_KIT		(egg_console_kit_get_type ())
+#define EGG_CONSOLE_KIT(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_TYPE_CONSOLE_KIT, EggConsoleKit))
+#define EGG_CONSOLE_KIT_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), EGG_TYPE_CONSOLE_KIT, EggConsoleKitClass))
+#define EGG_IS_CONSOLE_KIT(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_TYPE_CONSOLE_KIT))
+#define EGG_IS_CONSOLE_KIT_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), EGG_TYPE_CONSOLE_KIT))
+#define EGG_CONSOLE_KIT_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), EGG_TYPE_CONSOLE_KIT, EggConsoleKitClass))
+#define EGG_CONSOLE_KIT_ERROR		(egg_console_kit_error_quark ())
+#define EGG_CONSOLE_KIT_TYPE_ERROR	(egg_console_kit_error_get_type ())
+
+typedef struct EggConsoleKitPrivate EggConsoleKitPrivate;
+
+typedef struct
+{
+	 GObject		 parent;
+	 EggConsoleKitPrivate	*priv;
+} EggConsoleKit;
+
+typedef struct
+{
+	GObjectClass	parent_class;
+	void		(* active_changed)		(EggConsoleKit	*console,
+							 gboolean	 active);
+} EggConsoleKitClass;
+
+GType		 egg_console_kit_get_type	  	(void);
+EggConsoleKit	*egg_console_kit_new			(void);
+gboolean	 egg_console_kit_is_local		(EggConsoleKit	*console,
+							 gboolean	*is_local,
+							 GError		**error);
+gboolean	 egg_console_kit_is_active		(EggConsoleKit	*console,
+							 gboolean	*is_active,
+							 GError		**error);
+gboolean	 egg_console_kit_stop			(EggConsoleKit	*console,
+							 GError		**error);
+gboolean	 egg_console_kit_restart		(EggConsoleKit	*console,
+							 GError		**error);
+gboolean	 egg_console_kit_can_stop		(EggConsoleKit	*console,
+							 gboolean	*can_stop,
+							 GError		**error);
+gboolean	 egg_console_kit_can_restart		(EggConsoleKit	*console,
+							 gboolean	*can_restart,
+							 GError		**error);
+
+G_END_DECLS
+
+#endif /* __EGG_CONSOLE_KIT_H */
+
diff --git a/session/gsd-color-manager.c b/session/gsd-color-manager.c
new file mode 100644
index 0000000..cc86414
--- /dev/null
+++ b/session/gsd-color-manager.c
@@ -0,0 +1,167 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gnome-settings-daemon/gnome-settings-plugin.h>
+#include <libcolor-glib.h>
+
+#include "egg-console-kit.h"
+#include "gsd-color-manager.h"
+
+#define GSD_COLOR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_COLOR_MANAGER, GsdColorManagerPrivate))
+
+struct GsdColorManagerPrivate
+{
+	guint			 timeout;
+	GcmSensorClient		*sensor_client;
+	EggConsoleKit		*console_kit;
+};
+
+static void gsd_color_manager_class_init	(GsdColorManagerClass *klass);
+static void gsd_color_manager_init		(GsdColorManager *color_manager);
+static void gsd_color_manager_finalize		(GObject *object);
+
+G_DEFINE_TYPE (GsdColorManager, gsd_color_manager, G_TYPE_OBJECT)
+
+static gpointer manager_object = NULL;
+
+gboolean
+gsd_color_manager_start (GsdColorManager *manager,
+			 GError **error)
+{
+	g_debug ("Starting color manager");
+	return TRUE;
+}
+
+void
+gsd_color_manager_stop (GsdColorManager *manager)
+{
+	g_debug ("Stopping color manager");
+}
+
+/**
+ * gsd_color_manager_sensor_client_changed_cb:
+ **/
+static void
+gsd_color_manager_sensor_client_changed_cb (GcmSensorClient *sensor_client, GsdColorManager *manager)
+{
+	gboolean ret;
+	GError *error = NULL;
+
+	/* is sensor connected */
+	ret = gcm_sensor_client_get_present (sensor_client);
+	if (!ret)
+		return;
+
+	/* just spawn executable for now */
+	g_debug ("opening gnome-control-center");
+	ret = g_spawn_command_line_async (BINDIR "/gnome-control-center color", &error);
+	if (!ret) {
+		g_warning ("failed to run sensor plug action: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+/**
+ * gsd_color_manager_active_changed_cb:
+ **/
+static void
+gsd_color_manager_active_changed_cb (GcmSensorClient *sensor_client, gboolean is_active, GsdColorManager *manager)
+{
+	gboolean ret;
+	GError *error = NULL;
+
+	/* we don't care */
+	if (!is_active)
+		return;
+
+	/* just spawn executable for now */
+	g_debug ("running gcm-apply");
+	ret = g_spawn_command_line_async (BINDIR "/gcm-apply", &error);
+	if (!ret) {
+		g_warning ("failed to run active changed action: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+static void
+gsd_color_manager_dispose (GObject *object)
+{
+	GsdColorManager *manager;
+
+	manager = GSD_COLOR_MANAGER (object);
+
+	gsd_color_manager_stop (manager);
+
+	G_OBJECT_CLASS (gsd_color_manager_parent_class)->dispose (object);
+}
+
+static void
+gsd_color_manager_class_init (GsdColorManagerClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->dispose = gsd_color_manager_dispose;
+	object_class->finalize = gsd_color_manager_finalize;
+
+	g_type_class_add_private (klass, sizeof (GsdColorManagerPrivate));
+}
+
+static void
+gsd_color_manager_init (GsdColorManager *manager)
+{
+	manager->priv = GSD_COLOR_MANAGER_GET_PRIVATE (manager);
+	manager->priv->sensor_client = gcm_sensor_client_new ();
+	g_signal_connect (manager->priv->sensor_client, "changed",
+			  G_CALLBACK (gsd_color_manager_sensor_client_changed_cb), manager);
+	manager->priv->console_kit = egg_console_kit_new ();
+	g_signal_connect (manager->priv->console_kit, "active-changed",
+			  G_CALLBACK (gsd_color_manager_active_changed_cb), manager);
+}
+
+static void
+gsd_color_manager_finalize (GObject *object)
+{
+	GsdColorManager *color_manager;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (GSD_IS_COLOR_MANAGER (object));
+
+	color_manager = GSD_COLOR_MANAGER (object);
+
+	g_object_unref (color_manager->priv->sensor_client);
+
+	G_OBJECT_CLASS (gsd_color_manager_parent_class)->finalize (object);
+}
+
+GsdColorManager *
+gsd_color_manager_new (void)
+{
+	if (manager_object) {
+		g_object_ref (manager_object);
+	} else {
+		manager_object = g_object_new (GSD_TYPE_COLOR_MANAGER, NULL);
+		g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object);
+	}
+
+	return GSD_COLOR_MANAGER (manager_object);
+}
diff --git a/session/gsd-color-manager.h b/session/gsd-color-manager.h
new file mode 100644
index 0000000..0c70ef5
--- /dev/null
+++ b/session/gsd-color-manager.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GSD_COLOR_MANAGER_H
+#define __GSD_COLOR_MANAGER_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_COLOR_MANAGER		(gsd_color_manager_get_type ())
+#define GSD_COLOR_MANAGER(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_COLOR_MANAGER, GsdColorManager))
+#define GSD_COLOR_MANAGER_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_COLOR_MANAGER, GsdColorManagerClass))
+#define GSD_IS_COLOR_MANAGER(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_COLOR_MANAGER))
+#define GSD_IS_COLOR_MANAGER_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_COLOR_MANAGER))
+#define GSD_COLOR_MANAGER_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_COLOR_MANAGER, GsdColorManagerClass))
+
+typedef struct GsdColorManagerPrivate GsdColorManagerPrivate;
+
+typedef struct
+{
+	GObject parent;
+	GsdColorManagerPrivate *priv;
+} GsdColorManager;
+
+typedef struct
+{
+	GObjectClass parent_class;
+} GsdColorManagerClass;
+
+GType		 gsd_color_manager_get_type	(void) G_GNUC_CONST;
+GsdColorManager	*gsd_color_manager_new		(void);
+gboolean	 gsd_color_manager_start	(GsdColorManager	*manager,
+						 GError			**error);
+void		 gsd_color_manager_stop		(GsdColorManager	*manager);
+
+G_END_DECLS
+
+#endif /* __GSD_COLOR_MANAGER_H */
diff --git a/session/gsd-color-plugin.c b/session/gsd-color-plugin.c
new file mode 100644
index 0000000..3883953
--- /dev/null
+++ b/session/gsd-color-plugin.c
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <gmodule.h>
+#include <gnome-settings-daemon/gnome-settings-plugin.h>
+
+#include "gsd-color-plugin.h"
+#include "gsd-color-manager.h"
+
+struct GsdColorPluginPrivate {
+	GsdColorManager		*manager;
+};
+
+#define GSD_COLOR_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_COLOR_PLUGIN, GsdColorPluginPrivate))
+
+GNOME_SETTINGS_PLUGIN_REGISTER (GsdColorPlugin, gsd_color_plugin)
+
+static void
+gsd_color_plugin_init (GsdColorPlugin *plugin)
+{
+	plugin->priv = GSD_COLOR_PLUGIN_GET_PRIVATE (plugin);
+
+	g_debug ("GsdColorPlugin initializing");
+
+	plugin->priv->manager = gsd_color_manager_new ();
+}
+
+static void
+gsd_color_plugin_finalize (GObject *object)
+{
+	GsdColorPlugin *plugin;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (GSD_IS_COLOR_PLUGIN (object));
+
+	g_debug ("GsdColorPlugin finalizing");
+
+	plugin = GSD_COLOR_PLUGIN (object);
+
+	g_return_if_fail (plugin->priv != NULL);
+
+	if (plugin->priv->manager != NULL)
+		g_object_unref (plugin->priv->manager);
+
+	G_OBJECT_CLASS (gsd_color_plugin_parent_class)->finalize (object);
+}
+
+static void
+impl_activate (GnomeSettingsPlugin *plugin)
+{
+	GError *error = NULL;
+
+	g_debug ("Activating color plugin");
+
+	if (!gsd_color_manager_start (GSD_COLOR_PLUGIN (plugin)->priv->manager, &error)) {
+		g_warning ("Unable to start color manager: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+static void
+impl_deactivate (GnomeSettingsPlugin *plugin)
+{
+	g_debug ("Deactivating color plugin");
+	gsd_color_manager_stop (GSD_COLOR_PLUGIN (plugin)->priv->manager);
+}
+
+static void
+gsd_color_plugin_class_init (GsdColorPluginClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GnomeSettingsPluginClass *plugin_class = GNOME_SETTINGS_PLUGIN_CLASS (klass);
+
+	object_class->finalize = gsd_color_plugin_finalize;
+
+	plugin_class->activate = impl_activate;
+	plugin_class->deactivate = impl_deactivate;
+
+	g_type_class_add_private (klass, sizeof (GsdColorPluginPrivate));
+}
diff --git a/session/gsd-color-plugin.h b/session/gsd-color-plugin.h
new file mode 100644
index 0000000..d72b4bd
--- /dev/null
+++ b/session/gsd-color-plugin.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GSD_COLOR_PLUGIN_H__
+#define __GSD_COLOR_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+#include <gnome-settings-daemon/gnome-settings-plugin.h>
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_COLOR_PLUGIN		(gsd_color_plugin_get_type ())
+#define GSD_COLOR_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_COLOR_PLUGIN, GsdColorPlugin))
+#define GSD_COLOR_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_COLOR_PLUGIN, GsdColorPluginClass))
+#define GSD_IS_COLOR_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_COLOR_PLUGIN))
+#define GSD_IS_COLOR_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_COLOR_PLUGIN))
+#define GSD_COLOR_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_COLOR_PLUGIN, GsdColorPluginClass))
+
+typedef struct GsdColorPluginPrivate GsdColorPluginPrivate;
+
+typedef struct
+{
+	GnomeSettingsPlugin		 parent;
+	GsdColorPluginPrivate		*priv;
+} GsdColorPlugin;
+
+typedef struct
+{
+	GnomeSettingsPluginClass	 parent_class;
+} GsdColorPluginClass;
+
+GType gsd_color_plugin_get_type (void) G_GNUC_CONST;
+
+/* All the plugins must implement this function */
+G_MODULE_EXPORT GType register_gnome_settings_plugin (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GSD_COLOR_PLUGIN_H__ */
diff --git a/src/Makefile.am b/src/Makefile.am
index a8848e8..844c0b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ INCLUDES =						\
 	$(NOTIFY_CFLAGS)				\
 	$(CANBERRA_CFLAGS)				\
 	$(CONTROL_CENTER_CFLAGS)			\
+	$(SETTINGS_DAEMON_CFLAGS)			\
 	-DG_UDEV_API_IS_SUBJECT_TO_CHANGE		\
 	$(GUDEV_CFLAGS)					\
 	-I$(top_srcdir)/libcolor-glib			\
diff --git a/src/gcm-apply.c b/src/gcm-apply.c
index 9b53705..99aa7f2 100644
--- a/src/gcm-apply.c
+++ b/src/gcm-apply.c
@@ -70,6 +70,18 @@ main (int argc, char **argv)
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
+	/*
+	 * FIXME: THIS IS A HACK.
+	 * When gnome-settings-daemon ports from GConf to GSettings we can do this
+	 * properly and install a schema file. Until then, eugh.
+	 */
+	ret = g_spawn_command_line_async ("gconftool-2 --set --type=bool /apps/gnome_settings_daemon/plugins/color/active true", &error);
+	if (!ret) {
+		egg_warning ("failed to install GConf key: %s", error->message);
+		/* non-fatal */
+		g_clear_error (&error);
+	}
+
 	/* get devices */
 	client = gcm_client_new ();
 	ret = gcm_client_coldplug (client, GCM_CLIENT_COLDPLUG_XRANDR, &error);



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