[Spice-devel] [PATCH spice-gtk 1/2] usb-device-manager: Cleanup USB manufacturer and product strings
Hans de Goede
hdegoede at redhat.com
Thu Jan 26 07:24:55 PST 2012
The strings returned by devices sometimes can benefit from some clean-up.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
gtk/usb-device-manager.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 2a3b753..c5062b7 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -985,6 +985,19 @@ gchar *spice_usb_device_get_description(SpiceUsbDevice *_device, const gchar *fo
if (!product)
product = g_strdup(_("Device"));
+ /* Some devices have unwanted whitespace in their strings */
+ g_strstrip(manufacturer);
+ g_strstrip(product);
+
+ /* Some devices repeat the manufacturer at the beginning of product */
+ if (g_str_has_prefix(product, manufacturer) &&
+ strlen(product) > strlen(manufacturer)) {
+ gchar *tmp = g_strdup(product + strlen(manufacturer));
+ g_free(product);
+ product = tmp;
+ g_strstrip(product);
+ }
+
if (libusb_get_device_descriptor(device, &desc) == LIBUSB_SUCCESS)
descriptor = g_strdup_printf("[%04x:%04x]", desc.idVendor, desc.idProduct);
else
--
1.7.7.6
More information about the Spice-devel
mailing list