[gnome-settings-daemon] color: Detect when a sensor is inserted and launch the control center for calibration



commit 39b7ecc8c59c385f3c2ec8bb55f740cea1c0e408
Author: Richard Hughes <richard hughsie com>
Date:   Sat May 21 00:02:49 2011 +0100

    color: Detect when a sensor is inserted and launch the control center for calibration
    
    Also, optionally, use libcanberra to make the hardware sound if one is configured.

 configure.ac                      |   10 +++++++
 plugins/color/Makefile.am         |    2 +
 plugins/color/gsd-color-manager.c |   52 +++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0beef8c..9439234 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,6 +103,15 @@ dnl ---------------------------------------------------------------------------
 PKG_CHECK_MODULES(COLORD, colord >= 0.1.8)
 
 dnl ---------------------------------------------------------------------------
+dnl - Check for libcanberra
+dnl ---------------------------------------------------------------------------
+PKG_CHECK_MODULES(LIBCANBERRA, libcanberra-gtk3,
+                  [have_libcanberra=true
+                  AC_DEFINE(HAVE_LIBCANBERRA, 1, [Define if libcanberra should be used])],
+                  [have_libcanberra=false])
+AM_CONDITIONAL(HAVE_LIBCANBERRA, test "x$have_libcanberra" = "xtrue")
+
+dnl ---------------------------------------------------------------------------
 dnl - Check for libnotify
 dnl ---------------------------------------------------------------------------
 
@@ -594,6 +603,7 @@ echo "
         PolicyKit support:        ${HAVE_POLKIT}
 
         Libnotify support:        ${have_libnotify}
+        Libcanberra support:      ${have_libcanberra}
         PulseAudio support:       ${have_pulse}
         PackageKit support:       ${have_packagekit}
         Smartcard support:        ${have_smartcard_support}
diff --git a/plugins/color/Makefile.am b/plugins/color/Makefile.am
index 215f634..a2f6aea 100644
--- a/plugins/color/Makefile.am
+++ b/plugins/color/Makefile.am
@@ -18,6 +18,7 @@ libcolor_la_CPPFLAGS = \
 libcolor_la_CFLAGS = \
 	$(PLUGIN_CFLAGS)		\
 	$(COLORD_CFLAGS)		\
+	$(LIBCANBERRA_CFLAGS)		\
 	$(SETTINGS_PLUGIN_CFLAGS)	\
 	$(AM_CFLAGS)
 
@@ -26,6 +27,7 @@ libcolor_la_LDFLAGS = 		\
 
 libcolor_la_LIBADD  = 		\
 	$(COLORD_LIBS)		\
+	$(LIBCANBERRA_LIBS)	\
 	$(SETTINGS_PLUGIN_LIBS)
 
 plugin_in_files = 		\
diff --git a/plugins/color/gsd-color-manager.c b/plugins/color/gsd-color-manager.c
index f3a1f83..5929bc1 100644
--- a/plugins/color/gsd-color-manager.c
+++ b/plugins/color/gsd-color-manager.c
@@ -25,6 +25,10 @@
 #include <colord.h>
 #include <libnotify/notify.h>
 
+#ifdef HAVE_LIBCANBERRA
+  #include <canberra-gtk.h>
+#endif
+
 #include "gnome-settings-profile.h"
 #include "gsd-color-manager.h"
 
@@ -270,6 +274,48 @@ out:
         g_free (basename);
 }
 
+
+static void
+gcm_session_sensor_added_cb (CdClient *client,
+                             CdSensor *sensor,
+                             GsdColorManager *manager)
+{
+        gboolean ret;
+        GError *error = NULL;
+
+#ifdef HAVE_LIBCANBERRA
+        ca_context_play (ca_gtk_context_get (), 0,
+                         CA_PROP_EVENT_ID, "device-added",
+                         /* TRANSLATORS: this is the application name */
+                         CA_PROP_APPLICATION_NAME, _("GNOME Settings Daemon Color Plugin"),
+                        /* TRANSLATORS: this is a sound description */
+                         CA_PROP_EVENT_DESCRIPTION, _("Color calibration device added"), NULL);
+#endif
+
+        /* open up the color prefs window */
+        ret = g_spawn_command_line_async (BINDIR "/gnome-control-center color",
+                                          &error);
+        if (!ret) {
+                g_warning ("failed to spawn: %s", error->message);
+                g_error_free (error);
+        }
+}
+
+static void
+gcm_session_sensor_removed_cb (CdClient *client,
+                               CdSensor *sensor,
+                               GsdColorManager *manager)
+{
+#ifdef HAVE_LIBCANBERRA
+        ca_context_play (ca_gtk_context_get (), 0,
+                         CA_PROP_EVENT_ID, "device-removed",
+                         /* TRANSLATORS: this is the application name */
+                         CA_PROP_APPLICATION_NAME, _("GNOME Settings Daemon Color Plugin"),
+                        /* TRANSLATORS: this is a sound description */
+                         CA_PROP_EVENT_DESCRIPTION, _("Color calibration device removed"), NULL);
+#endif
+}
+
 static void
 gsd_color_manager_set_property (GObject        *object,
                                 guint           prop_id,
@@ -326,6 +372,12 @@ gsd_color_manager_init (GsdColorManager *manager)
         g_signal_connect (priv->client, "device-added",
                           G_CALLBACK (gcm_session_device_added_notify_cb),
                           manager);
+        g_signal_connect (priv->client, "sensor-added",
+                          G_CALLBACK (gcm_session_sensor_added_cb),
+                          manager);
+        g_signal_connect (priv->client, "sensor-removed",
+                          G_CALLBACK (gcm_session_sensor_removed_cb),
+                          manager);
 }
 
 static void



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