[gnome-color-manager] Only make the calibrate button sensitive when supported hardware devices are attached
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Only make the calibrate button sensitive when supported hardware devices are attached
- Date: Tue, 3 Nov 2009 11:09:17 +0000 (UTC)
commit 6debd1bf1a33a05d4212414f9ac47dc7f22242d9
Author: Richard Hughes <richard hughsie com>
Date: Tue Nov 3 11:08:24 2009 +0000
Only make the calibrate button sensitive when supported hardware devices are attached
This requires a fixed ArgyllCMS, but the patch is pending review
configure.ac | 16 ++++++++
contrib/gnome-color-manager.spec.in | 1 +
src/Makefile.am | 3 +
src/gcm-prefs.c | 71 +++++++++++++++++++++++++++++++++++
4 files changed, 91 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 012a5c9..524e4a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,6 +128,10 @@ PKG_CHECK_MODULES(VTE, vte >= $VTE_REQUIRED)
AC_SUBST(VTE_CFLAGS)
AC_SUBST(VTE_LIBS)
+PKG_CHECK_MODULES(GUDEV, gudev-1.0)
+AC_SUBST(GUDEV_CFLAGS)
+AC_SUBST(GUDEV_LIBS)
+
AC_PATH_PROG(GCONFTOOL, gconftool-2)
AM_GCONF_SOURCE_2
@@ -160,6 +164,17 @@ fi
AM_CONDITIONAL(HAVE_DOCBOOK2MAN, [test "$DOCBOOK2MAN" != "no"])
dnl ---------------------------------------------------------------------------
+dnl - Autodetect the hardware device
+dnl - This requires 55-Argyll.rules to set COLOR_MEASUREMENT_DEVICE
+dnl ---------------------------------------------------------------------------
+AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-hardware-detection],[enable hardware auto-detection (requires fixed argyllcms)]),
+ enable_hardware_detection=$enableval,enable_hardware_detection=no)
+AM_CONDITIONAL(GCM_HARDWARE_DETECTION, test x$enable_hardware_detection = xyes)
+if test x$enable_hardware_detection = xyes; then
+ AC_DEFINE(GCM_HARDWARE_DETECTION,1,[Build hardware autodetection])
+fi
+
+dnl ---------------------------------------------------------------------------
dnl - Makefiles, etc.
dnl ---------------------------------------------------------------------------
AC_OUTPUT([
@@ -189,6 +204,7 @@ echo "
compiler: ${CC}
cflags: ${CFLAGS}
cppflags: ${CPPFLAGS}
+ hardware auto-detection: ${enable_hardware_detection}
gconf-schema dir: $GCONF_SCHEMA_FILE_DIR
"
diff --git a/contrib/gnome-color-manager.spec.in b/contrib/gnome-color-manager.spec.in
index c035738..c601891 100644
--- a/contrib/gnome-color-manager.spec.in
+++ b/contrib/gnome-color-manager.spec.in
@@ -38,6 +38,7 @@ BuildRequires: vte-devel
BuildRequires: gnome-doc-utils
BuildRequires: unique-devel >= %{unique_version}
BuildRequires: intltool
+BuildRequires: libgudev1-devel
%description
gnome-color-manager provides a way to control ICC colour profiles.
diff --git a/src/Makefile.am b/src/Makefile.am
index b4b2aff..ab8f15c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,8 @@ INCLUDES = \
$(UNIQUE_CFLAGS) \
$(GCONF_CFLAGS) \
$(VTE_CFLAGS) \
+ -DG_UDEV_API_IS_SUBJECT_TO_CHANGE \
+ $(GUDEV_CFLAGS) \
-DBINDIR=\"$(bindir)\" \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-DVERSION="\"$(VERSION)\"" \
@@ -71,6 +73,7 @@ gcm_prefs_LDADD = \
$(UNIQUE_LIBS) \
$(GCONF_LIBS) \
$(VTE_LIBS) \
+ $(GUDEV_LIBS) \
$(GTK_LIBS)
gcm_prefs_CFLAGS = \
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 4f3f9bf..061b7d8 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -24,6 +24,7 @@
#include <math.h>
#include <unique/unique.h>
#include <glib/gstdio.h>
+#include <gudev/gudev.h>
#include "egg-debug.h"
@@ -37,6 +38,7 @@ static guint current_device = 0;
static GcmClut *current_clut = NULL;
static GnomeRRScreen *rr_screen = NULL;
static GPtrArray *profiles_array = NULL;
+static GUdevClient *client = NULL;
enum {
GPM_DEVICES_COLUMN_ID,
@@ -656,6 +658,64 @@ gcm_prefs_randr_event_cb (GnomeRRScreen *screen, gpointer data)
}
/**
+ * gcm_prefs_has_hardware_device_attached:
+ **/
+static gboolean
+gcm_prefs_has_hardware_device_attached (void)
+{
+ GList *devices;
+ GList *l;
+ GUdevDevice *device;
+ gboolean ret = FALSE;
+
+ /* get all USB devices */
+ devices = g_udev_client_query_by_subsystem (client, "usb");
+ for (l = devices; l != NULL; l = l->next) {
+ device = l->data;
+ ret = g_udev_device_get_property_as_boolean (device, "COLOR_MEASUREMENT_DEVICE");
+ if (ret) {
+ egg_debug ("found color management device: %s", g_udev_device_get_sysfs_path (device));
+ break;
+ }
+ }
+
+ g_list_foreach (devices, (GFunc) g_object_unref, NULL);
+ g_list_free (devices);
+ return ret;
+}
+
+/**
+ * gcm_prefs_check_calibration_hardware:
+ **/
+static void
+gcm_prefs_check_calibration_hardware (void)
+{
+ gboolean ret;
+ GtkWidget *widget;
+
+ /* find whether we have hardware installed */
+ ret = gcm_prefs_has_hardware_device_attached ();
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_calibrate"));
+
+#ifdef GCM_HARDWARE_DETECTION
+ /* disable the button if no supported hardware is found */
+ gtk_widget_set_sensitive (widget, ret);
+#else
+ egg_debug ("not setting calibrate button %s as not compiled with hardware detection", ret ? "sensitive" : "insensitive");
+#endif
+}
+
+/**
+ * gcm_prefs_uevent_cb:
+ **/
+static void
+gcm_prefs_uevent_cb (GUdevClient *client_, const gchar *action, GUdevDevice *device, gpointer user_data)
+{
+ egg_debug ("uevent %s", action);
+ gcm_prefs_check_calibration_hardware ();
+}
+
+/**
* main:
**/
int
@@ -673,6 +733,7 @@ main (int argc, char **argv)
GtkTreeSelection *selection;
GnomeRROutput **outputs;
guint i;
+ const gchar *subsystems[] = {"usb", NULL};
const GOptionEntry options[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
@@ -714,6 +775,14 @@ main (int argc, char **argv)
goto out;
}
+ /* use GUdev to find properties */
+ client = g_udev_client_new (subsystems);
+ g_signal_connect (client, "uevent",
+ G_CALLBACK (gcm_prefs_uevent_cb), NULL);
+
+ /* coldplug calibrate button sensitivity */
+ gcm_prefs_check_calibration_hardware ();
+
/* create list stores */
list_store_devices = gtk_list_store_new (GPM_DEVICES_COLUMN_LAST, G_TYPE_UINT,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
@@ -813,6 +882,8 @@ out:
g_main_loop_unref (loop);
if (rr_screen != NULL)
gnome_rr_screen_destroy (rr_screen);
+ if (client != NULL)
+ g_object_unref (client);
if (builder != NULL)
g_object_unref (builder);
if (profiles_array != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]