[banshee/gio-hardware] [GioHardware] Fix iPod source removal



commit d5f0f806af06ac50f3929e18a3f9da936b1d95bc
Author: Alex Launi <alex launi gmail com>
Date:   Thu Aug 5 11:17:37 2010 +0200

    [GioHardware] Fix iPod source removal
    
    iPods were not being removed as a source, even though they were being ejected
    at the GIO level.

 src/Backends/Banshee.Gio/Banshee.Gio.csproj        |    4 +
 .../Banshee.Hardware.Gio/HardwareManager.cs        |    1 -
 .../Banshee.Hardware.Gio/LowLevel/Manager.cs       |   73 +++++++++-----------
 .../LowLevel/RawBlockDevice.cs                     |    3 +
 .../Banshee.Hardware.Gio/LowLevel/RawDevice.cs     |    1 +
 .../Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs  |    1 +
 .../Banshee.Hardware.Gio/LowLevel/RawVolume.cs     |   10 ++-
 .../Banshee.Dap.AppleDevice/AppleDeviceSource.cs   |   17 +++--
 src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs      |    4 +-
 src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs |    1 -
 10 files changed, 64 insertions(+), 51 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.Gio.csproj b/src/Backends/Banshee.Gio/Banshee.Gio.csproj
index 916997d..d59a1d1 100644
--- a/src/Backends/Banshee.Gio/Banshee.Gio.csproj
+++ b/src/Backends/Banshee.Gio/Banshee.Gio.csproj
@@ -106,6 +106,10 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\..\..\..\..\..\..\usr\local\lib\mono\gkeyfile-sharp-1.0\gkeyfile-sharp.dll</HintPath>
     </Reference>
+    <Reference Include="gudev-sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3565e728cafab25e">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\bin\gudev-sharp.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Banshee.IO.Gio\DemuxVfs.cs" />
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs
index 51ebd8f..3b50596 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs
@@ -57,7 +57,6 @@ namespace Banshee.Hardware.Gio
         void HandleManagerDeviceRemoved (object o, MountArgs args)
         {
             if (DeviceRemoved != null) {
-                Hyena.Log.Debug ("HardwareManager firing DeviceRemoved event");
                 DeviceRemoved (this, new DeviceRemovedArgs (args.Device.Uuid));
             }
         }
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
index 2736010..19e8472 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
@@ -43,52 +43,20 @@ namespace Banshee.Hardware.Gio
 
         private Client client;
         private VolumeMonitor monitor;
+        private Dictionary<string, string> device_uuids;
 
         public event EventHandler<MountArgs> DeviceAdded;
         public event EventHandler<MountArgs> DeviceRemoved;
 
         public Manager ()
         {
+            device_uuids = new Dictionary<string, string> ();
             client = new Client (subsystems);
             monitor = VolumeMonitor.Default;
             monitor.MountAdded += HandleMonitorMountAdded;
             monitor.MountRemoved += HandleMonitorMountRemoved;
+            monitor.VolumeRemoved += HandleMonitorVolumeRemoved;
         }
-//
-//        void HandleClientUevent (object o, UeventArgs args)
-//        {
-//            if (args.Action == "add")
-//                TryAddUdevDevice (args.Device);
-//            else if (args.Action == "remove")
-//                TryRemoveUdevDevice (args.Device);
-//            else
-//                Console.WriteLine ("Unknown action: {0}", args.Action);
-//        }
-//
-//        void TryAddUdevDevice (GUdev.Device device)
-//        {
-//            // We only want to match MTP devices for the moment. GIO should be able
-//            // to discover everything else.
-//            if (device.GetPropertyAsInt ("ID_GPHOTO2") == 1 &&
-//                device.GetPropertyAsInt ("ID_MEDIA_PLAYER") == 1) {
-//                var h = DeviceAdded;
-//                if (h != null) {
-//                    var v = new UsbDevice (new UDevDevice (this,
-//                                              null,
-//                                              new UdevMetadataSource (device)));
-//                    h (this, new MountArgs (v));
-//                }
-//            }
-//        }
-//
-//        void TryRemoveUdevDevice (GUdev.Device device)
-//        {
-//            if (device.GetPropertyAsInt ("ID_GPHOTO2") == 1 &&
-//                device.GetPropertyAsInt ("ID_MEDIA_PLAYER") == 1) {
-//
-//            }
-//        }
-//
 
 #region IDisposable
         public void Dispose ()
@@ -113,6 +81,7 @@ namespace Banshee.Hardware.Gio
                                           new GioVolumeMetadataSource (mount.Volume),
                                           new UdevMetadataSource (device));
                 h (this, new MountArgs (HardwareManager.Resolve (new Device (v))));
+                device_uuids [mount.Volume.Name] = v.Uuid;
             }
         }
 
@@ -120,16 +89,40 @@ namespace Banshee.Hardware.Gio
         {
             // Manually get the mount as gio-sharp translates it to the wrong managed object
             var mount = GLib.MountAdapter.GetObject ((GLib.Object) args.Args [0]);
-            if (mount.Volume == null || mount.Root.Path == null)
+            if (mount.Volume == null || mount.Root == null || mount.Root.Path == null) {
+                return;
+            }
+
+            VolumeRemoved (mount.Volume);
+        }
+
+        void HandleMonitorVolumeRemoved (object o, VolumeRemovedArgs args)
+        {
+            var volume = GLib.VolumeAdapter.GetObject ((GLib.Object) args.Args [0]);
+            if (volume == null) {
                 return;
+            }
+
+            VolumeRemoved (volume);
+        }
 
+
+        void VolumeRemoved (GLib.Volume volume)
+        {
             var h = DeviceRemoved;
             if (h != null) {
-                Hyena.Log.Debug ("LowLevel manager Firing device removed event");
-                var v = new RawVolume (mount.Volume,
+
+                var device = GudevDeviceFromGioVolume (volume);
+                var v = new RawVolume (volume,
                                           this,
-                                          new GioVolumeMetadataSource (mount.Volume),
-                                          new UdevMetadataSource (null));
+                                          new GioVolumeMetadataSource (volume),
+                                          new UdevMetadataSource (device));
+
+                if (device_uuids.ContainsKey (volume.Name)) {
+                    v.Uuid = device_uuids [volume.Name];
+                    device_uuids.Remove (volume.Name);
+                }
+
                 h (this, new MountArgs (new Device (v)));
             }
         }
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs
index ae976b9..6c3cf07 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs
@@ -115,6 +115,9 @@ namespace Banshee.Hardware.Gio
            get {
                return UdevMetadata.Uuid;
            }
+           set {
+               throw new NotSupportedException (); 
+           }
         }
 
         public override string Vendor {
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs
index e71b1be..9b3d0c8 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs
@@ -100,6 +100,7 @@ namespace Banshee.Hardware.Gio
 
         public abstract string Uuid {
             get;
+            set;
         }
 
         public abstract string Vendor {
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
index bd37ed4..3566ab7 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
@@ -120,6 +120,7 @@ namespace Banshee.Hardware.Gio
          
          public override string Uuid {
             get { return UdevMetadata.Uuid; }
+            set { throw new NotSupportedException (); }
          }
          
          
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs
index 148d265..ddf6c34 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs
@@ -159,8 +159,9 @@ namespace Banshee.Hardware.Gio
                 Volume.Eject (MountUnmountFlags.Force, null, (s, result) =>
                 {
                     try {
-                        if (!Volume.EjectWithOperationFinish (result))
+                        if (!Volume.EjectWithOperationFinish (result)) {
                             Hyena.Log.ErrorFormat ("Failed to eject {0}", Volume.Name);
+                        }
                     } catch (Exception e) {
                         Hyena.Log.Exception (e);
                     }
@@ -226,8 +227,13 @@ namespace Banshee.Hardware.Gio
             get { return "Product Not Implemented"; }
         }
 
+        // This is a hack. I put a set here because when we eject a volume
+        // there's no useful uuid so instead I'm going to store it, and set it
+        // based on device name. Horrible, I know.
+        private string uuid;
         public override string Uuid {
-            get { return UdevMetadata.Uuid; }
+            get { return uuid ?? UdevMetadata.Uuid; }
+            set { uuid = value; }
         }
 
         public RawBlockDevice Parent {
diff --git a/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs b/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
index c4251e2..7adb357 100644
--- a/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
+++ b/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
@@ -86,9 +86,14 @@ namespace Banshee.Dap.AppleDevice
             Initialize ();
 
             // FIXME: Properly parse the device, color and generation and don't use the fallback strings
-            AddDapProperty (Catalog.GetString ("Device"), Device.IpodInfo.ModelString);
+
+            // IpodInfo is null on Macos formated ipods. I don't think we can really do anything with them
+            // but they get loaded as UMS devices if we throw an NRE here.
+            if (Device.IpodInfo != null) {
+                AddDapProperty (Catalog.GetString ("Device"), Device.IpodInfo.ModelString);
+                AddDapProperty (Catalog.GetString ("Generation"), Device.IpodInfo.GenerationString);
+            }
             AddDapProperty (Catalog.GetString ("Color"), "black");
-            AddDapProperty (Catalog.GetString ("Generation"), Device.IpodInfo.GenerationString);
             AddDapProperty (Catalog.GetString ("Capacity"), string.Format ("{0:0.00}GB", BytesCapacity));
             AddDapProperty (Catalog.GetString ("Avaiable"), string.Format ("{0:0.00}GB", BytesAvailable));
             AddDapProperty (Catalog.GetString ("Serial number"), Volume.Serial);
@@ -175,9 +180,11 @@ namespace Banshee.Dap.AppleDevice
             foreach (var ipod_track in MediaDatabase.Tracks) {
                 try {
                     var track = new AppleDeviceTrackInfo (ipod_track);
-                    track.PrimarySource = this;
-                    track.Save (false);
-                    tracks_map.Add (track.TrackId, track);
+                    if (!tracks_map.ContainsKey (track.TrackId)) {
+                        track.PrimarySource = this;
+                        track.Save (false);
+                        tracks_map.Add (track.TrackId, track);
+                    }
                 } catch (Exception e) {
                     Log.Exception (e);
                     Console.WriteLine (e);
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs b/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
index 33fb31a..868f160 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
@@ -206,7 +206,8 @@ namespace Banshee.Dap
 
                         source = service.FindDeviceSource (device);
                         if (source != null) {
-                            Log.DebugFormat ("Found DAP support ({0}) for device {1}", source.GetType ().FullName, source.Name);
+                            Log.DebugFormat ("Found DAP support ({0}) for device {1} and Uuid {2}", source.GetType ().FullName,
+                                             source.Name, device.Uuid);
                             service.sources.Add (device.Uuid, source);
                         }
                     } catch (Exception e) {
@@ -280,7 +281,6 @@ namespace Banshee.Dap
 
         private void OnHardwareDeviceRemoved (object o, DeviceRemovedArgs args)
         {
-            Log.Debug ("DapService unmapping device after removed");
             UnmapDevice (args.DeviceUuid);
         }
 
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs b/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
index 18581f4..940bc8c 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
@@ -119,7 +119,6 @@ namespace Banshee.Dap
                     Log.Exception (e);
                 }
             });
-
             return true;
         }
 



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