[banshee] Fix DAP support on distros shipping DeviceKit



commit 3aac4c2f77b30de378065222b4261bcb9fcf12bd
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Tue Dec 8 18:44:12 2009 -0800

    Fix DAP support on distros shipping DeviceKit
    
    Check DK for whether the DAP's drive is mounted and where.  For iPods,
    requires latest podsleuth (what will be 0.6.6).

 NEWS                                               |    2 +-
 .../Banshee.Hal/Banshee.HalBackend/DkDisk.cs       |  128 ++++++++++++++++++++
 .../Banshee.Hal/Banshee.HalBackend/Volume.cs       |   20 +++-
 src/Backends/Banshee.Hal/Makefile.am               |    1 +
 .../Banshee.Dap.Ipod/PodSleuthDevice.cs            |    4 +-
 5 files changed, 148 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4a3393a..21b3f68 100644
--- a/NEWS
+++ b/NEWS
@@ -121,7 +121,7 @@ DEPENDENCIES
       * boo >= 0.8.1
 
     * Run-time requirements for default feature stack:
-      * PodSleuth (0.6.4)
+      * PodSleuth (0.6.6 recommended)
       * Brasero   (0.8.1)
       * Avahi
       * gst-plugins-bad (providing the bpmdetect GStreamer plugin)
diff --git a/src/Backends/Banshee.Hal/Banshee.HalBackend/DkDisk.cs b/src/Backends/Banshee.Hal/Banshee.HalBackend/DkDisk.cs
new file mode 100644
index 0000000..485ff39
--- /dev/null
+++ b/src/Backends/Banshee.Hal/Banshee.HalBackend/DkDisk.cs
@@ -0,0 +1,128 @@
+//
+// DkDisk.cs
+//
+// Author:
+//   Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2009 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+using NDesk.DBus;
+
+namespace Banshee.HalBackend
+{
+    public class DkDisk
+    {
+        public static DkDisk FindByDevice (string device_path)
+        {
+            if (device_path == null)
+                return null;
+
+            if (disks == null)
+                return null;
+
+
+            string disk_path = null;
+            try {
+                disk_path = disks.FindDeviceByDeviceFile (device_path);
+            } catch {}
+
+            if (disk_path == null)
+                return null;
+
+            try {
+                return new DkDisk (disk_path);
+            } catch {}
+
+            return null;
+        }
+
+        private IDkDisk disk;
+        private org.freedesktop.DBus.Properties props;
+
+        private DkDisk (string obj_path)
+        {
+            disk = Bus.System.GetObject<IDkDisk>("org.freedesktop.DeviceKit.Disks",
+                new ObjectPath(obj_path));
+
+            props = Bus.System.GetObject<org.freedesktop.DBus.Properties>("org.freedesktop.DeviceKit.Disks",
+                new ObjectPath(obj_path));
+        }
+
+        public bool IsMounted {
+            get {
+                return (bool) props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceIsMounted");
+            }
+        }
+
+        public bool IsReadOnly {
+            get {
+                return (bool) props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceIsReadOnly");
+            }
+        }
+
+        public string MountPoint {
+            get {
+                var ary = (string[])props.Get ("org.freedesktop.DeviceKit.Disks.Device", "DeviceMountPaths");
+                return ary != null && ary.Length > 0 ? ary[0] : null;
+            }
+        }
+
+        public void Eject ()
+        {
+            disk.DriveEject (new string [0]);
+        }
+
+        public void Unmount ()
+        {
+            disk.FilesystemUnmount (new string [0]);
+        }
+
+        private static IDkDisks disks;
+
+        static DkDisk ()
+        {
+            try {
+                disks = Bus.System.GetObject<IDkDisks>("org.freedesktop.DeviceKit.Disks",
+                    new ObjectPath("/org/freedesktop/DeviceKit/Disks"));
+            } catch {}
+        }
+
+        [Interface("org.freedesktop.DeviceKit.Disks")]
+        internal interface IDkDisks
+        {
+            string FindDeviceByDeviceFile (string deviceFile);
+        }
+
+    }
+
+    [Interface("org.freedesktop.DeviceKit.Disks.Device")]
+    public interface IDkDisk
+    {
+        bool DeviceIsMounted { get; }
+        string [] DeviceMountPaths { get; }
+        void DriveEject (string [] options);
+        void FilesystemUnmount (string [] options);
+    }
+}
diff --git a/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs b/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs
index 51620ec..a196925 100644
--- a/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs
+++ b/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs
@@ -61,12 +61,14 @@ namespace Banshee.HalBackend
             return null;
         }
 
+        private DkDisk dk_disk;
         private BlockDevice parent;
         private string [] method_names;
 
         protected Volume (BlockDevice parent, Hal.Manager manager, Hal.Device device) : base (manager, device)
         {
             this.parent = parent ?? BlockDevice.Resolve<IBlockDevice> (manager, device.Parent);
+            dk_disk = DkDisk.FindByDevice (DeviceNode);
 
             method_names = HalDevice.PropertyExists (method_names_property)
                 ? device.GetPropertyStringList (method_names_property)
@@ -78,7 +80,13 @@ namespace Banshee.HalBackend
         }
 
         public string MountPoint {
-            get { return HalDevice["volume.mount_point"]; }
+            get {
+                if (dk_disk != null && dk_disk.MountPoint != null) {
+                    return dk_disk.MountPoint;
+                } else {
+                    return HalDevice["volume.mount_point"];
+                }
+            }
         }
 
         public string FileSystem {
@@ -99,7 +107,7 @@ namespace Banshee.HalBackend
         }*/
 
         public bool IsMounted {
-            get { return HalDevice.GetPropertyBoolean ("volume.is_mounted"); }
+            get { return (dk_disk != null && dk_disk.IsMounted) || HalDevice.GetPropertyBoolean ("volume.is_mounted"); }
         }
 
         public bool ShouldIgnore {
@@ -107,7 +115,7 @@ namespace Banshee.HalBackend
         }
 
         public bool IsReadOnly {
-            get { return HalDevice.GetPropertyBoolean ("volume.is_mounted_read_only"); }
+            get { return (dk_disk != null && dk_disk.IsReadOnly) || HalDevice.GetPropertyBoolean ("volume.is_mounted_read_only"); }
         }
 
         public ulong Capacity {
@@ -156,7 +164,11 @@ namespace Banshee.HalBackend
         public void Unmount ()
         {
             if (CanUnmount && HalDevice.IsVolume) {
-                HalDevice.Volume.Unmount ();
+                if (dk_disk != null) {
+                    dk_disk.Unmount ();
+                } else {
+                    HalDevice.Volume.Unmount ();
+                }
             }
         }
 
diff --git a/src/Backends/Banshee.Hal/Makefile.am b/src/Backends/Banshee.Hal/Makefile.am
index 0fc3777..9ab35e4 100644
--- a/src/Backends/Banshee.Hal/Makefile.am
+++ b/src/Backends/Banshee.Hal/Makefile.am
@@ -10,6 +10,7 @@ SOURCES =  \
 	Banshee.HalBackend/DeviceMediaCapabilities.cs \
 	Banshee.HalBackend/DiscVolume.cs \
 	Banshee.HalBackend/DiskDevice.cs \
+	Banshee.HalBackend/DkDisk.cs \
 	Banshee.HalBackend/HardwareManager.cs \
 	Banshee.HalBackend/UsbDevice.cs \
 	Banshee.HalBackend/Volume.cs \
diff --git a/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs b/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs
index 26b974c..b2efe43 100644
--- a/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs
+++ b/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs
@@ -60,9 +60,9 @@ namespace Banshee.Dap.Ipod
             {
                 this.volume = volume;
 
-                MountPoint = volume.GetPropertyString ("volume.mount_point");
+                MountPoint = volume.MountPoint;
                 Label = volume.GetPropertyString ("volume.label");
-                IsMountedReadOnly = volume.GetPropertyBoolean ("volume.is_mounted_read_only");
+                IsMountedReadOnly = volume.IsReadOnly;
                 Uuid = volume.GetPropertyString ("volume.uuid");
             }
 



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