From 4591bdacbff38676009b53e7cbe0f08fb5fc6384 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sun, 26 Nov 2017 17:18:56 +0000 Subject: [PATCH] Add quirks to set common USB properties The name, summary and icon are not strictly required for a USB device supporting both DFU interfaces, but having this extra data makes GNOME Software look much nicer. Using the quirks feature means we can merge in support for new devices after fwupd has been released for stable distros. --- src/fu-plugin.c | 29 +++++++++++++++++++++++++++++ src/fu-quirks.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/fu-plugin.c b/src/fu-plugin.c index 4362daec8..7d6e89005 100644 --- a/src/fu-plugin.c +++ b/src/fu-plugin.c @@ -343,9 +343,38 @@ fu_plugin_open (FuPlugin *plugin, const gchar *filename, GError **error) void fu_plugin_device_add (FuPlugin *plugin, FuDevice *device) { + FuPluginPrivate *priv = GET_PRIVATE (plugin); + g_return_if_fail (FU_IS_PLUGIN (plugin)); g_return_if_fail (FU_IS_DEVICE (device)); + /* merge any quirks */ + if (FU_IS_USB_DEVICE (device)) { + GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device)); + const gchar *tmp; + + /* name */ + tmp = fu_quirks_lookup_by_usb_device (priv->quirks, + FU_QUIRKS_USB_NAME, + usb_device); + if (tmp != NULL) + fu_device_set_name (device, tmp); + + /* summary */ + tmp = fu_quirks_lookup_by_usb_device (priv->quirks, + FU_QUIRKS_USB_SUMMARY, + usb_device); + if (tmp != NULL) + fu_device_set_summary (device, tmp); + + /* icon */ + tmp = fu_quirks_lookup_by_usb_device (priv->quirks, + FU_QUIRKS_USB_ICON, + usb_device); + if (tmp != NULL) + fu_device_add_icon (device, tmp); + } + g_debug ("emit added from %s: %s", fu_plugin_get_name (plugin), fu_device_get_id (device)); diff --git a/src/fu-quirks.h b/src/fu-quirks.h index 9c5cbdc24..96497c162 100644 --- a/src/fu-quirks.h +++ b/src/fu-quirks.h @@ -158,6 +158,39 @@ const gchar *fu_quirks_lookup_by_usb_device (FuQuirks *self, */ #define FU_QUIRKS_DFU_FORCE_VERSION "fwupd-dfu-force-version" +/** + * FU_QUIRKS_USB_SUMMARY: + * @key: the USB device ID, e.g. `USB\VID_0763&PID_2806` + * @value: the USB device summary, e.g. `An open source display colorimeter` + * + * Sets a name for a specific hardware device. + * + * Since: 1.0.2 + */ +#define FU_QUIRKS_USB_SUMMARY "fwupd-usb-summary" + +/** + * FU_QUIRKS_USB_ICON: + * @key: the USB device ID, e.g. `USB\VID_0763&PID_2806` + * @value: the USB device icon name, e.g. `media-removable` + * + * Adds an icon name for a specific hardware device. + * + * Since: 1.0.2 + */ +#define FU_QUIRKS_USB_ICON "fwupd-usb-icon" + +/** + * FU_QUIRKS_USB_NAME: + * @key: the USB device ID, e.g. `USB\VID_0763&PID_2806` + * @value: the USB device name, e.g. `ColorHug` + * + * Sets a name for a specific hardware device. + * + * Since: 1.0.2 + */ +#define FU_QUIRKS_USB_NAME "fwupd-usb-name" + G_END_DECLS #endif /* __FU_QUIRKS_H */