[gnome-color-manager] Use the hardware calibration device in the profile name. Fixes #605259
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Use the hardware calibration device in the profile name. Fixes #605259
- Date: Wed, 23 Dec 2009 15:37:40 +0000 (UTC)
commit 6a2336cf2bc1e23601d83ab7f18d8ac09b9ca3ba
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 23 15:36:57 2009 +0000
Use the hardware calibration device in the profile name. Fixes #605259
src/Makefile.am | 2 +
src/gcm-calibrate-argyll.c | 7 +-
src/gcm-color-device.c | 329 ++++++++++++++++++++++++++++++++++++++++++++
src/gcm-color-device.h | 64 +++++++++
src/gcm-prefs.c | 68 +++------
5 files changed, 422 insertions(+), 48 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b7ea6a7..4a2a8cd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,8 @@ libgcmshared_a_SOURCES = \
gcm-xserver.h \
gcm-client.c \
gcm-client.h \
+ gcm-color-device.c \
+ gcm-color-device.h \
gcm-device.c \
gcm-device.h \
gcm-cie-widget.c \
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index d233e6e..726a164 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -520,6 +520,7 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
gchar *basename = NULL;
gchar *description = NULL;
gchar *manufacturer = NULL;
+ gchar *device = NULL;
gchar *model = NULL;
GPtrArray *array = NULL;
GtkWidget *widget;
@@ -530,6 +531,7 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
"description", &description,
"manufacturer", &manufacturer,
"model", &model,
+ "device", &device,
NULL);
/* get correct name of the command */
@@ -543,8 +545,8 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
date = g_date_new ();
g_date_set_time_t (date, time (NULL));
- /* this is the formattted custom profile description. It can't be translated as we need 7-bit ASCII */
- description_new = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", "Custom", description, date->year, date->month, date->day);
+ /* get description */
+ description_new = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", device, description, date->year, date->month, date->day);
/* TRANSLATORS: this is the copyright string, where it might be "Copyright (c) 2009 Edward Scissorhands" */
copyright = g_strdup_printf ("%s %04i %s", _("Copyright (c)"), date->year, g_get_real_name ());
@@ -604,6 +606,7 @@ out:
g_free (model);
g_free (description);
g_free (description_new);
+ g_free (device);
g_free (copyright);
g_strfreev (argv);
return ret;
diff --git a/src/gcm-color-device.c b/src/gcm-color-device.c
new file mode 100644
index 0000000..a45ca2a
--- /dev/null
+++ b/src/gcm-color-device.c
@@ -0,0 +1,329 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:gcm-color-device
+ * @short_description: Colorimeter device abstraction
+ *
+ * This object allows the programmer to detect a color sensor device.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gudev/gudev.h>
+
+#include "gcm-color-device.h"
+
+#include "egg-debug.h"
+
+static void gcm_color_device_finalize (GObject *object);
+
+#define GCM_COLOR_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_COLOR_DEVICE, GcmColorDevicePrivate))
+
+/**
+ * GcmColorDevicePrivate:
+ *
+ * Private #GcmColorDevice data
+ **/
+struct _GcmColorDevicePrivate
+{
+ gboolean present;
+ gchar *vendor;
+ gchar *model;
+ GUdevClient *client;
+};
+
+enum {
+ PROP_0,
+ PROP_PRESENT,
+ PROP_VENDOR,
+ PROP_MODEL,
+ PROP_LAST
+};
+
+enum {
+ SIGNAL_CHANGED,
+ SIGNAL_LAST
+};
+
+static guint signals[SIGNAL_LAST] = { 0 };
+
+G_DEFINE_TYPE (GcmColorDevice, gcm_color_device, G_TYPE_OBJECT)
+
+/**
+ * gcm_color_device_get_property:
+ **/
+static void
+gcm_color_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GcmColorDevice *color_device = GCM_COLOR_DEVICE (object);
+ GcmColorDevicePrivate *priv = color_device->priv;
+
+ switch (prop_id) {
+ case PROP_PRESENT:
+ g_value_set_boolean (value, priv->present);
+ break;
+ case PROP_VENDOR:
+ g_value_set_string (value, priv->vendor);
+ break;
+ case PROP_MODEL:
+ g_value_set_string (value, priv->model);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+/**
+ * gcm_color_device_set_property:
+ **/
+static void
+gcm_color_device_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GcmColorDevice *color_device = GCM_COLOR_DEVICE (object);
+ GcmColorDevicePrivate *priv = color_device->priv;
+
+ switch (prop_id) {
+ case PROP_PRESENT:
+ priv->present = g_value_get_boolean (value);
+ break;
+ case PROP_VENDOR:
+ g_free (priv->vendor);
+ priv->vendor = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_MODEL:
+ g_free (priv->model);
+ priv->model = g_strdup (g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+/**
+ * gcm_color_device_class_init:
+ **/
+static void
+gcm_color_device_class_init (GcmColorDeviceClass *klass)
+{
+ GParamSpec *pspec;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gcm_color_device_finalize;
+ object_class->get_property = gcm_color_device_get_property;
+ object_class->set_property = gcm_color_device_set_property;
+
+ /**
+ * GcmColorDevice:present:
+ */
+ pspec = g_param_spec_boolean ("present", NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_PRESENT, pspec);
+
+ /**
+ * GcmColorDevice:vendor:
+ */
+ pspec = g_param_spec_string ("vendor", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_VENDOR, pspec);
+
+ /**
+ * GcmColorDevice:model:
+ */
+ pspec = g_param_spec_string ("model", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_MODEL, pspec);
+
+ /**
+ * GcmColorDevice::added:
+ **/
+ signals[SIGNAL_CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GcmColorDeviceClass, changed),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_type_class_add_private (klass, sizeof (GcmColorDevicePrivate));
+}
+
+
+/**
+ * gcm_color_device_device_add:
+ **/
+static gboolean
+gcm_color_device_device_add (GcmColorDevice *color_device, GUdevDevice *device)
+{
+ gboolean ret;
+ GcmColorDevicePrivate *priv = color_device->priv;
+
+ /* interesting device? */
+ ret = g_udev_device_get_property_as_boolean (device, "COLOR_MEASUREMENT_DEVICE");
+ if (!ret)
+ goto out;
+
+ /* get data */
+ egg_debug ("adding color management device: %s", g_udev_device_get_sysfs_path (device));
+ priv->present = TRUE;
+
+ /* vendor */
+ g_free (priv->vendor);
+ priv->vendor = g_strdup (g_udev_device_get_property (device, "ID_VENDOR_FROM_DATABASE"));
+
+ /* model */
+ g_free (priv->model);
+ priv->model = g_strdup (g_udev_device_get_property (device, "ID_MODEL_FROM_DATABASE"));
+
+ /* signal the addition */
+ egg_debug ("emit: changed");
+ g_signal_emit (color_device, signals[SIGNAL_CHANGED], 0);
+out:
+ return ret;
+}
+
+/**
+ * gcm_color_device_device_remove:
+ **/
+static gboolean
+gcm_color_device_device_remove (GcmColorDevice *color_device, GUdevDevice *device)
+{
+ gboolean ret;
+ GcmColorDevicePrivate *priv = color_device->priv;
+
+ /* interesting device? */
+ ret = g_udev_device_get_property_as_boolean (device, "COLOR_MEASUREMENT_DEVICE");
+ if (!ret)
+ goto out;
+
+ /* get data */
+ egg_debug ("removing color management device: %s", g_udev_device_get_sysfs_path (device));
+ priv->present = FALSE;
+
+ /* vendor */
+ g_free (priv->vendor);
+ priv->vendor = NULL;
+
+ /* model */
+ g_free (priv->model);
+ priv->model = NULL;
+
+ /* signal the removal */
+ egg_debug ("emit: changed");
+ g_signal_emit (color_device, signals[SIGNAL_CHANGED], 0);
+out:
+ return ret;
+}
+
+/**
+ * gcm_color_device_coldplug:
+ **/
+static gboolean
+gcm_color_device_coldplug (GcmColorDevice *color_device)
+{
+ GList *devices;
+ GList *l;
+ gboolean ret = FALSE;
+ GcmColorDevicePrivate *priv = color_device->priv;
+
+ /* get all USB devices */
+ devices = g_udev_client_query_by_subsystem (priv->client, "usb");
+ for (l = devices; l != NULL; l = l->next) {
+ ret = gcm_color_device_device_add (color_device, l->data);
+ if (ret) {
+ egg_debug ("found color management device");
+ break;
+ }
+ }
+
+ g_list_foreach (devices, (GFunc) g_object_unref, NULL);
+ g_list_free (devices);
+ return ret;
+}
+
+/**
+ * gcm_prefs_uevent_cb:
+ **/
+static void
+gcm_prefs_uevent_cb (GUdevClient *client, const gchar *action, GUdevDevice *device, GcmColorDevice *color_device)
+{
+ egg_debug ("uevent %s", action);
+ if (g_strcmp0 (action, "add") == 0) {
+ gcm_color_device_device_add (color_device, device);
+ } else if (g_strcmp0 (action, "remove") == 0) {
+ gcm_color_device_device_remove (color_device, device);
+ }
+}
+
+/**
+ * gcm_color_device_init:
+ **/
+static void
+gcm_color_device_init (GcmColorDevice *color_device)
+{
+ const gchar *subsystems[] = {"usb", NULL};
+
+ color_device->priv = GCM_COLOR_DEVICE_GET_PRIVATE (color_device);
+ color_device->priv->vendor = NULL;
+ color_device->priv->model = NULL;
+
+ /* use GUdev to find the calibration device */
+ color_device->priv->client = g_udev_client_new (subsystems);
+ g_signal_connect (color_device->priv->client, "uevent",
+ G_CALLBACK (gcm_prefs_uevent_cb), color_device);
+
+ /* coldplug */
+ gcm_color_device_coldplug (color_device);
+}
+
+/**
+ * gcm_color_device_finalize:
+ **/
+static void
+gcm_color_device_finalize (GObject *object)
+{
+ GcmColorDevice *color_device = GCM_COLOR_DEVICE (object);
+ GcmColorDevicePrivate *priv = color_device->priv;
+
+ g_object_unref (priv->client);
+ g_free (priv->vendor);
+ g_free (priv->model);
+
+ G_OBJECT_CLASS (gcm_color_device_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_color_device_new:
+ *
+ * Return value: a new GcmColorDevice object.
+ **/
+GcmColorDevice *
+gcm_color_device_new (void)
+{
+ GcmColorDevice *color_device;
+ color_device = g_object_new (GCM_TYPE_COLOR_DEVICE, NULL);
+ return GCM_COLOR_DEVICE (color_device);
+}
+
diff --git a/src/gcm-color-device.h b/src/gcm-color-device.h
new file mode 100644
index 0000000..18beb7f
--- /dev/null
+++ b/src/gcm-color-device.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GCM_COLOR_DEVICE_H
+#define __GCM_COLOR_DEVICE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_COLOR_DEVICE (gcm_color_device_get_type ())
+#define GCM_COLOR_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_COLOR_DEVICE, GcmColorDevice))
+#define GCM_COLOR_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_COLOR_DEVICE, GcmColorDeviceClass))
+#define GCM_IS_COLOR_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_COLOR_DEVICE))
+#define GCM_IS_COLOR_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_COLOR_DEVICE))
+#define GCM_COLOR_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_COLOR_DEVICE, GcmColorDeviceClass))
+
+typedef struct _GcmColorDevicePrivate GcmColorDevicePrivate;
+typedef struct _GcmColorDevice GcmColorDevice;
+typedef struct _GcmColorDeviceClass GcmColorDeviceClass;
+
+struct _GcmColorDevice
+{
+ GObject parent;
+ GcmColorDevicePrivate *priv;
+};
+
+struct _GcmColorDeviceClass
+{
+ GObjectClass parent_class;
+ void (* changed) (void);
+ /* padding for future expansion */
+ void (*_gcm_reserved1) (void);
+ void (*_gcm_reserved2) (void);
+ void (*_gcm_reserved3) (void);
+ void (*_gcm_reserved4) (void);
+ void (*_gcm_reserved5) (void);
+};
+
+GType gcm_color_device_get_type (void);
+GcmColorDevice *gcm_color_device_new (void);
+
+G_END_DECLS
+
+#endif /* __GCM_COLOR_DEVICE_H */
+
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 57d41d6..eb8fbf3 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -33,13 +33,14 @@
#include "egg-debug.h"
-#include "gcm-utils.h"
-#include "gcm-profile.h"
#include "gcm-calibrate-argyll.h"
-#include "gcm-client.h"
-#include "gcm-xyz.h"
#include "gcm-cie-widget.h"
+#include "gcm-client.h"
+#include "gcm-color-device.h"
+#include "gcm-profile.h"
#include "gcm-trc-widget.h"
+#include "gcm-utils.h"
+#include "gcm-xyz.h"
/* DISTROS: you will have to patch if you have changed the name of these packages */
#define GCM_PREFS_PACKAGE_NAME_SHARED_COLOR_TARGETS "shared-color-targets"
@@ -52,8 +53,8 @@ static GcmDevice *current_device = NULL;
static GnomeRRScreen *rr_screen = NULL;
static GPtrArray *profiles_array = NULL;
static GPtrArray *profiles_array_in_combo = NULL;
-static GUdevClient *client = NULL;
static GcmClient *gcm_client = NULL;
+static GcmColorDevice *color_device = NULL;
static gboolean setting_up_device = FALSE;
static GtkWidget *info_bar = NULL;
static GtkWidget *cie_widget = NULL;
@@ -225,9 +226,12 @@ gcm_prefs_calibrate_display (GcmCalibrate *calibrate)
manufacturer = g_strdup (_("Unknown manufacturer"));
}
- // TODO: get calibration device model
+ /* get calibration device model */
+ g_object_get (color_device,
+ "model", &device,
+ NULL);
- /* get device */
+ /* get device, harder */
if (device == NULL) {
/* TRANSLATORS: this is the formattted custom profile description. "Custom" refers to the fact that it's user generated */
device = g_strdup (_("Custom"));
@@ -1041,33 +1045,6 @@ gcm_prefs_add_profiles_columns (GtkTreeView *treeview)
}
/**
- * 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_set_calibrate_button_sensitivity:
**/
static void
@@ -1096,7 +1073,9 @@ gcm_prefs_set_calibrate_button_sensitivity (void)
if (type == GCM_DEVICE_TYPE_DISPLAY) {
/* find whether we have hardware installed */
- ret = gcm_prefs_has_hardware_device_attached ();
+ g_object_get (color_device,
+ "present", &ret,
+ NULL);
#ifndef GCM_HARDWARE_DETECTION
egg_debug ("overriding device presence %i with TRUE", ret);
ret = TRUE;
@@ -1849,12 +1828,11 @@ out:
}
/**
- * gcm_prefs_uevent_cb:
+ * gcm_prefs_color_device_changed_cb:
**/
static void
-gcm_prefs_uevent_cb (GUdevClient *client_, const gchar *action, GUdevDevice *device, gpointer user_data)
+gcm_prefs_color_device_changed_cb (GcmColorDevice *_color_device, gpointer user_data)
{
- egg_debug ("uevent %s", action);
gcm_prefs_set_calibrate_button_sensitivity ();
}
@@ -2267,7 +2245,6 @@ main (int argc, char **argv)
gboolean use_global;
gboolean use_atom;
GtkTreeSelection *selection;
- const gchar *subsystems[] = {"usb", NULL};
GtkWidget *info_bar_label;
GtkSizeGroup *size_group = NULL;
GtkSizeGroup *size_group2 = NULL;
@@ -2317,11 +2294,6 @@ main (int argc, char **argv)
goto out;
}
- /* use GUdev to find the calibration device */
- client = g_udev_client_new (subsystems);
- g_signal_connect (client, "uevent",
- G_CALLBACK (gcm_prefs_uevent_cb), NULL);
-
/* create list stores */
list_store_devices = gtk_list_store_new (GPM_DEVICES_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
@@ -2524,6 +2496,10 @@ main (int argc, char **argv)
g_signal_connect (gcm_client, "added", G_CALLBACK (gcm_prefs_added_cb), NULL);
g_signal_connect (gcm_client, "removed", G_CALLBACK (gcm_prefs_removed_cb), NULL);
+ /* use the color device */
+ color_device = gcm_color_device_new ();
+ g_signal_connect (color_device, "changed", G_CALLBACK (gcm_prefs_color_device_changed_cb), NULL);
+
/* set the parent window if it is specified */
if (xid != 0) {
egg_debug ("Setting xid %i", xid);
@@ -2629,10 +2605,10 @@ out:
g_object_unref (size_group2);
if (current_device != NULL)
g_object_unref (current_device);
+ if (color_device != NULL)
+ g_object_unref (color_device);
if (rr_screen != NULL)
gnome_rr_screen_destroy (rr_screen);
- if (client != NULL)
- g_object_unref (client);
if (gconf_client != NULL)
g_object_unref (gconf_client);
if (builder != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]