[banshee] [Gio] Devices with ID_BUS=usb should be considered USB devices too.



commit 564499b6ee24725a7cf1a7e1e37d1af355cb13a0
Author: Alan McGovern <alan mcgovern gmail com>
Date:   Wed Sep 29 00:19:09 2010 +0100

    [Gio] Devices with ID_BUS=usb should be considered USB devices too.
    
    Some devices don't expose the usb Bus and Port numbers and so were
    ignored by the existing heuristics. This made ResolveRootUsbDevice
    return null and cause the UMS addin to ignore some devices. This fixes
    part of #629179.

 .../Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs  |   49 +++++++++++++------
 src/Backends/Banshee.Gio/Makefile.am               |    1 -
 2 files changed, 33 insertions(+), 17 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
index b067459..f5d7976 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
@@ -43,22 +43,19 @@ namespace Banshee.Hardware.Gio
 
         internal static UsbDevice ResolveRootDevice (IDevice device)
         {
-            // First check if the supplied device is an IUsbDevice itself
-            var result = Resolve (device);
-            if (result != null) {
-                return result;
-            }
-
-            // Now walk up the device tree to see if we can find one.
+            // Now walk up the device tree to see if we can find a usb device
+            // NOTE: We walk up the tree to find a UDevMetadataSource which
+            // exposes the right usb properties, but we never use it. Maybe we
+            // should be constructing and wrapping a new RawUsbDevice using the
+            // correct metadata. Maybe it doesn't matter. I'm not sure. At the
+            // moment we re-use the same RawDevice except wrap it in a UsbDevice.
             IRawDevice raw = device as IRawDevice;
             if (raw != null) {
-                var parent = raw.Device.UdevMetadata.Parent;
-                while (parent != null) {
-                    if (parent.PropertyExists (UdevUsbBusNumber) && parent.PropertyExists (UdevUsbDeviceNumber)) {
-                        return new UsbDevice (new RawUsbDevice (raw.Device.Manager, raw.Device.GioMetadata, parent));
-                    }
-                    parent = parent.Parent;
-                }
+                var metadata = ResolveUsingUsbBusAndPort (raw.Device.UdevMetadata, true);
+                if (metadata == null)
+                    metadata = ResolveUsingBusType (raw.Device.UdevMetadata, true);
+                if (metadata != null)
+                    return new UsbDevice (raw.Device);
             }
             return null;
         }
@@ -111,13 +108,33 @@ namespace Banshee.Hardware.Gio
         {
             IRawDevice raw = device as IRawDevice;
             if (raw != null) {
-                var metadata = raw.Device.UdevMetadata;
-                if (metadata.PropertyExists (UdevUsbBusNumber) && metadata.PropertyExists (UdevUsbDeviceNumber))
+                if (ResolveUsingUsbBusAndPort (raw.Device.UdevMetadata, false) != null)
+                    return new UsbDevice (raw.Device);
+                else if (ResolveUsingBusType (raw.Device.UdevMetadata, false) != null)
                     return new UsbDevice (raw.Device);
             }
             return null;
         }
 
+        static UdevMetadataSource ResolveUsingUsbBusAndPort (UdevMetadataSource metadata, bool recurse)
+        {
+            do {
+                if (metadata.PropertyExists (UdevUsbBusNumber) && metadata.PropertyExists (UdevUsbDeviceNumber))
+                    return metadata;
+            } while (recurse && (metadata = metadata.Parent) != null);
+            return null;
+        }
+
+        static UdevMetadataSource ResolveUsingBusType (UdevMetadataSource metadata, bool recurse)
+        {
+            var comparer = StringComparer.OrdinalIgnoreCase;
+            do {
+                if (metadata.PropertyExists ("ID_BUS") && comparer.Equals ("usb", metadata.GetPropertyString ("ID_BUS")))
+                    return metadata;
+            } while (recurse && (metadata = metadata.Parent) != null);
+            return null;
+        }
+
         public RawDevice Device {
             get; set;
         }
diff --git a/src/Backends/Banshee.Gio/Makefile.am b/src/Backends/Banshee.Gio/Makefile.am
index d65842b..1291cc8 100644
--- a/src/Backends/Banshee.Gio/Makefile.am
+++ b/src/Backends/Banshee.Gio/Makefile.am
@@ -13,7 +13,6 @@ SOURCES =  \
 	Banshee.Hardware.Gio/Device.cs \
 	Banshee.Hardware.Gio/DeviceMediaCapabilities.cs \
 	Banshee.Hardware.Gio/DiscVolume.cs \
-	Banshee.Hardware.Gio/DiskDevice.cs \
 	Banshee.Hardware.Gio/HardwareManager.cs \
 	Banshee.Hardware.Gio/LowLevel/GioDriveMetadetaSource.cs \
 	Banshee.Hardware.Gio/LowLevel/GioMetadataSource.cs \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]