[gnome-color-manager] Move the device matching from a hardcoded list to a set of udev rules
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Move the device matching from a hardcoded list to a set of udev rules
- Date: Tue, 29 Dec 2009 12:55:13 +0000 (UTC)
commit d18c49a780a908033cbe673f2a6bc2d3381206b1
Author: Richard Hughes <richard hughsie com>
Date: Tue Dec 29 12:19:25 2009 +0000
Move the device matching from a hardcoded list to a set of udev rules
Makefile.am | 1 +
configure.ac | 9 +++++++++
contrib/gnome-color-manager.spec.in | 2 ++
rules/95-gnome-color-manager.rules | 21 +++++++++++++++++++++
rules/Makefile.am | 10 ++++++++++
src/gcm-client.c | 30 +++++-------------------------
6 files changed, 48 insertions(+), 25 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index de11a8d..efe8d4d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,6 +3,7 @@ SUBDIRS = \
help \
man \
data \
+ rules \
src
snapshot:
diff --git a/configure.ac b/configure.ac
index 6d3e6ea..92b4d05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,14 @@ if test x$enable_strict != xno; then
fi
fi
+# udev rules go in /lib, not /usr/lib
+if test "$prefix" = "/usr" -o "$prefix" = "/usr/local" ; then
+ slashlibdir=/lib
+else
+ slashlibdir=$prefix/lib
+fi
+AC_SUBST(slashlibdir)
+
dnl ---------------------------------------------------------------------------
dnl - Extra verbose warning switches
dnl ---------------------------------------------------------------------------
@@ -215,6 +223,7 @@ Makefile
src/Makefile
help/Makefile
man/Makefile
+rules/Makefile
data/Makefile
data/tests/Makefile
data/icons/Makefile
diff --git a/contrib/gnome-color-manager.spec.in b/contrib/gnome-color-manager.spec.in
index 8a9e027..b358eff 100644
--- a/contrib/gnome-color-manager.spec.in
+++ b/contrib/gnome-color-manager.spec.in
@@ -21,6 +21,7 @@ Requires: unique >= %{unique_version}
Requires: shared-mime-info
Requires: dbus-glib >= %{dbus_glib_version}
Requires: dbus-x11
+Requires: udev
Requires: vte
Requires: lcms
Requires: PackageKit
@@ -110,6 +111,7 @@ update-mime-database %{_datadir}/mime &> /dev/null || :
%files -f %{name}.lang
%defattr(-,root,root,-)
%doc AUTHORS COPYING NEWS README
+/lib/udev/rules.d/*.rules
%{_bindir}/gcm-*
%dir %{_datadir}/gnome-color-manager
%{_datadir}/gnome-color-manager/gcm-*.ui
diff --git a/rules/95-gnome-color-manager.rules b/rules/95-gnome-color-manager.rules
new file mode 100644
index 0000000..f844c4c
--- /dev/null
+++ b/rules/95-gnome-color-manager.rules
@@ -0,0 +1,21 @@
+# 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.
+
+# HP Printers
+SUBSYSTEM=="usb", ENV{ID_HPLIP}!="", ENV{GCM_DEVICE}="1", ENV{GCM_TYPE}="printer"
+
+# USB SANE scanners
+SUBSYSTEM=="usb", ENV{libsane_matched}!="", ENV{GCM_DEVICE}="1", ENV{GCM_TYPE}="scanner"
+
+# Cameras with gphoto drivers
+SUBSYSTEM=="usb", ENV{ID_GPHOTO2}!="", ENV{GCM_DEVICE}="1", ENV{GCM_TYPE}="camera"
+
+# video cameras
+SUBSYSTEM=="video4linux", ENV{ID_V4L_PRODUCT}!="", ENV{GCM_DEVICE}="1", ENV{GCM_TYPE}="camera"
+
diff --git a/rules/Makefile.am b/rules/Makefile.am
new file mode 100644
index 0000000..ec6282c
--- /dev/null
+++ b/rules/Makefile.am
@@ -0,0 +1,10 @@
+udevrulesdir = $(slashlibdir)/udev/rules.d
+udevrules_DATA = \
+ 95-gnome-color-manager.rules
+
+EXTRA_DIST = \
+ $(udevrules_DATA)
+
+clean-local :
+ rm -f *~
+
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 98959c8..0202d73 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -287,32 +287,12 @@ gcm_client_gudev_add (GcmClient *client, GUdevDevice *udev_device)
{
const gchar *value;
- /* only matches HP printers, need to expand to all of CUPS printers */
- value = g_udev_device_get_property (udev_device, "ID_HPLIP");
+ /* matches our udev rules, which we can change without recompiling */
+ value = g_udev_device_get_property (udev_device, "GCM_DEVICE");
if (value != NULL) {
- egg_debug ("found printer device: %s", g_udev_device_get_sysfs_path (udev_device));
- gcm_client_gudev_add_type (client, udev_device, GCM_DEVICE_TYPE_PRINTER);
- }
-
- /* sane is slightly odd in a lowercase property, and "yes" as a value rather than "1" */
- value = g_udev_device_get_property (udev_device, "libsane_matched");
- if (value != NULL) {
- egg_debug ("found scanner device: %s", g_udev_device_get_sysfs_path (udev_device));
- gcm_client_gudev_add_type (client, udev_device, GCM_DEVICE_TYPE_SCANNER);
- }
-
- /* only matches cameras with gphoto drivers */
- value = g_udev_device_get_property (udev_device, "ID_GPHOTO2");
- if (value != NULL) {
- egg_debug ("found gphoto camera device: %s", g_udev_device_get_sysfs_path (udev_device));
- gcm_client_gudev_add_type (client, udev_device, GCM_DEVICE_TYPE_CAMERA);
- }
-
- /* only matches cameras with v4l devices */
- value = g_udev_device_get_property (udev_device, "ID_V4L_PRODUCT");
- if (value != NULL) {
- egg_debug ("found v4l camera device: %s", g_udev_device_get_sysfs_path (udev_device));
- gcm_client_gudev_add_type (client, udev_device, GCM_DEVICE_TYPE_CAMERA);
+ value = g_udev_device_get_property (udev_device, "GCM_TYPE");
+ egg_debug ("found %s device: %s", value, g_udev_device_get_sysfs_path (udev_device));
+ gcm_client_gudev_add_type (client, udev_device, gcm_device_type_from_text (value));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]