[banshee] Dap.MassStorage: Nokia N95 playlist sync support out of the box (bgo#661507)



commit 55272ed4af65d986cadf623fd7cb983cad57ffe4
Author: Nicholas Little <arealityfarbetween googlemail com>
Date:   Sun Jan 13 02:04:51 2013 +0000

    Dap.MassStorage: Nokia N95 playlist sync support out of the box (bgo#661507)
    
    Adds the necessary infrastructure and device-specific details (such
    as SymbianDevice class and product IDs) to sync playlists with the
    correct format to/from the device.
    
    Signed-off-by: Andres G. Aragoneses <knocte gmail com>

 .../Banshee.Playlist/PlaylistFileUtil.cs           |    3 +-
 .../Banshee.Playlists.Formats/IPlaylistFormat.cs   |    1 +
 .../PlaylistFormatBase.cs                          |   16 +++-
 .../Tests/PlaylistFormatTests.cs                   |   23 ++++-
 .../Banshee.Dap.MassStorage.addin.xml              |    4 +
 .../Banshee.Dap.MassStorage.csproj                 |    1 +
 .../Banshee.Dap.MassStorage/MassStorageDevice.cs   |    4 +
 .../Banshee.Dap.MassStorage/MassStorageSource.cs   |   16 +++-
 .../Banshee.Dap.MassStorage/SymbianDevice.cs       |  107 ++++++++++++++++++++
 src/Dap/Banshee.Dap.MassStorage/Makefile.am        |    1 +
 .../ThemeIcons/128x128/devices/phone-nokia-n95.png |  Bin 0 -> 17226 bytes
 .../ThemeIcons/16x16/devices/phone-nokia-n95.png   |  Bin 0 -> 1208 bytes
 .../ThemeIcons/22x22/devices/phone-nokia-n95.png   |  Bin 0 -> 1248 bytes
 .../ThemeIcons/24x24/devices/phone-nokia-n95.png   |  Bin 0 -> 1413 bytes
 .../ThemeIcons/256x256/devices/phone-nokia-n95.png |  Bin 0 -> 60041 bytes
 .../ThemeIcons/32x32/devices/phone-nokia-n95.png   |  Bin 0 -> 2035 bytes
 .../ThemeIcons/48x48/devices/phone-nokia-n95.png   |  Bin 0 -> 3642 bytes
 src/Hyena                                          |    2 +-
 tests/data/playlist-data/dos_path_nokia.m3u        |    6 +
 19 files changed, 177 insertions(+), 7 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs b/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
index b86eb31..82ae09a 100644
--- a/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
@@ -122,7 +122,7 @@ namespace Banshee.Playlist
             return false;
         }
 
-        public static IPlaylistFormat Load (string playlistUri, Uri baseUri)
+        public static IPlaylistFormat Load (string playlistUri, Uri baseUri, Uri rootPath)
         {
             PlaylistFormatDescription [] formats = PlaylistFileUtil.ExportFormats;
 
@@ -152,6 +152,7 @@ namespace Banshee.Playlist
                 try {
                     IPlaylistFormat playlist = (IPlaylistFormat)Activator.CreateInstance (format.Type);
                     playlist.BaseUri = baseUri;
+                    playlist.RootPath = rootPath;
                     playlist.Load (Banshee.IO.File.OpenRead (new SafeUri (playlistUri)), true);
                     return playlist;
                 } catch (InvalidPlaylistException) {
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs
index c16197f..85d3c01 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs
@@ -47,5 +47,6 @@ namespace Banshee.Playlists.Formats
         Uri BaseUri { get; set; }
         string Title { get; set; }
         char FolderSeparator { get; set; }
+        Uri RootPath { get; set; }
     }
 }
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs
index 02259e0..667b199 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs
@@ -80,7 +80,15 @@ namespace Banshee.Playlists.Formats
         {
             uri = Paths.NormalizeToUnix (uri);
 
-            return BaseUri == null ? new Uri(uri) : new Uri(BaseUri, uri);
+            if (BaseUri == null) {
+                return new Uri (uri);
+            }
+
+            if (RootPath != null) {
+                uri = Paths.SwitchRoot (uri, RootPath.LocalPath, BaseUri.LocalPath);
+            }
+
+            return new Uri (BaseUri, uri);
         }
 
         protected virtual string ExportUri(SafeUri uri)
@@ -93,6 +101,10 @@ namespace Banshee.Playlists.Formats
                 return uri.AbsoluteUri;
             }
 
+            if (RootPath != null) {
+                return Paths.SwitchRoot (uri.LocalPath, BaseUri.LocalPath, RootPath.LocalPath);
+            }
+
             var result = Paths.MakePathRelative (uri.LocalPath, new DirectoryInfo (BaseUri.LocalPath).FullName);
 
             return result ?? uri.AbsoluteUri;
@@ -133,5 +145,7 @@ namespace Banshee.Playlists.Formats
         }
 
         public virtual char FolderSeparator { get; set; }
+
+        public Uri RootPath { get; set; } //if not null, elements should have Absolute Uris
     }
 }
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/Tests/PlaylistFormatTests.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/Tests/PlaylistFormatTests.cs
index f7c28ae..a34f485 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/Tests/PlaylistFormatTests.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/Tests/PlaylistFormatTests.cs
@@ -132,6 +132,19 @@ namespace Banshee.Playlists.Formats.Tests
             LoadTest (new M3uPlaylistFormat (), "extended.m3u", false);
         }
 
+        [Test] // https://bugzilla.gnome.org/show_bug.cgi?id=661507
+        public void ReadM3uWithDosPathAsRootPath ()
+        {
+            playlists_dir = Path.Combine (TestsDir, "data/playlist-data");
+            IPlaylistFormat playlist = LoadPlaylist (new M3uPlaylistFormat (),
+                                                     "dos_path_nokia.m3u",
+                                                     new Uri ("E:\\"));
+            Assert.AreEqual (playlist.Elements [0].Uri.AbsoluteUri.ToString (),
+                             "file:///iamyourbase/Music/Atari%20Doll/Atari%20Doll/01.%20Queen%20for%20a%20Day.mp3");
+            Assert.AreEqual (playlist.Elements [1].Uri.AbsoluteUri.ToString (),
+                             "file:///iamyourbase/Music/Barenaked%20Ladies/All%20Their%20Greatest%20Hits%201991/04.%20One%20Week.mp3");
+        }
+
         [Test]
         public void ReadPlsSimple ()
         {
@@ -162,13 +175,21 @@ namespace Banshee.Playlists.Formats.Tests
 
 #region Utilities
 
-        private IPlaylistFormat LoadPlaylist (IPlaylistFormat playlist, string filename)
+        private IPlaylistFormat LoadPlaylist (IPlaylistFormat playlist, string filename, Uri rootPath)
         {
             playlist.BaseUri = BaseUri;
+            if (rootPath != null) {
+                playlist.RootPath = rootPath;
+            }
             playlist.Load (File.OpenRead (Path.Combine (playlists_dir, filename)), true);
             return playlist;
         }
 
+        private IPlaylistFormat LoadPlaylist (IPlaylistFormat playlist, string filename)
+        {
+            return LoadPlaylist (playlist, filename, null);
+        }
+
         private void LoadTest (IPlaylistFormat playlist, string filename, bool mmsh)
         {
             LoadPlaylist (playlist, filename);
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
index 251e665..9735d33 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
@@ -28,6 +28,10 @@
     <MassStorageDevice class="Banshee.Dap.MassStorage.MaemoDevice"
         vendor-name="Nokia" product-name="Nokia N900 Phone"
         vendor-id="0x0421" product-id="0x01c7"/>
+    <MassStorageDevice class="Banshee.Dap.MassStorage.SymbianDevice"
+        vendor-name="Nokia" product-name="N95"
+        vendor-id="0x0421" product-id="0x04ed"/>
+
     <!-- 0ff9 is the HTC Desire -->
     <MassStorageDevice class="Banshee.Dap.MassStorage.AndroidDevice" 
         vendor-name="HTC" product-name="HTC Android Phone"
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
index d3126e1..fd65910 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
@@ -74,6 +74,7 @@
     <Compile Include="Banshee.Dap.MassStorage\MaemoDevice.cs" />
     <Compile Include="Banshee.Dap.MassStorage\NookDevice.cs" />
     <Compile Include="Banshee.Dap.MassStorage\RockBoxDevice.cs" />
+    <Compile Include="Banshee.Dap.MassStorage\SymbianDevice.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Dap.MassStorage.addin.xml">
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
index 9569899..a1970ab 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
@@ -209,6 +209,10 @@ namespace Banshee.Dap.MassStorage
             get { return FolderDepth; }
         }
 
+        internal virtual Uri RootPath {
+            get { return null; }
+        }
+
         protected virtual string DefaultFolderSeparator {
             get { return null; }
         }
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
index 660e176..338275f 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
@@ -168,8 +168,12 @@ namespace Banshee.Dap.MassStorage
                 foreach (string playlist_path in PlaylistFiles) {
                     // playlist_path has a file:// prefix, and GetDirectoryName messes it up,
                     // so we need to convert it to a regular path
-                    string base_folder = System.IO.Path.GetDirectoryName (SafeUri.UriToFilename (playlist_path));
-                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path, new Uri (base_folder));
+                    string base_folder = ms_device.RootPath != null ? BaseDirectory :
+                        System.IO.Path.GetDirectoryName (SafeUri.UriToFilename (playlist_path));
+
+                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path,
+                                                                             new Uri (base_folder),
+                                                                             ms_device.RootPath);
                     if (loaded_playlist == null)
                         continue;
 
@@ -366,7 +370,13 @@ namespace Banshee.Dap.MassStorage
                     System.IO.Stream stream = null;
                     try {
                         stream = Banshee.IO.File.OpenWrite (playlist_path, true);
-                        playlist_format.BaseUri = new Uri (PlaylistsWritePath);
+
+                        if (ms_device.RootPath == null) {
+                            playlist_format.BaseUri = new Uri (PlaylistsWritePath);
+                        } else {
+                            playlist_format.RootPath = ms_device.RootPath;
+                            playlist_format.BaseUri = new Uri (BaseDirectory);
+                        }
 
                         playlist_format.Save (stream, from);
                     } catch (Exception e) {
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/SymbianDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/SymbianDevice.cs
new file mode 100644
index 0000000..e2d6658
--- /dev/null
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/SymbianDevice.cs
@@ -0,0 +1,107 @@
+// 
+// SymbianDevice.cs
+// 
+// Author:
+//   Nicholas Little <arealityfarbetween googlemail com>
+// 
+// Copyright (C) 2012 Nicholas Little
+// 
+// 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 Banshee.IO;
+using Banshee.Hardware;
+using Banshee.Sources;
+using Hyena;
+
+namespace Banshee.Dap.MassStorage
+{
+    public class SymbianDevice : CustomMassStorageDevice
+    {
+        #region MassStorageDevice Property Overrides
+        private static string [] icons = {
+                "phone-nokia-n95",
+                DapSource.FallbackIcon
+        };
+        public override string [] GetIconNames ()
+        {
+            return icons;
+        }
+
+        private Uri root_path = new Uri ("E:\\");
+        internal override Uri RootPath {
+            get { return root_path; }
+        }
+
+        protected override string DefaultFolderSeparator {
+            get { return Paths.Folder.DosSeparator.ToString (); }
+        }
+
+        private static string [] playlist_formats = { "audio/x-mpegurl" };
+        protected override string[] DefaultPlaylistFormats {
+            get { return playlist_formats; }
+        }
+
+        private static string [] audio_folders = { "Music/" };
+        protected override string [] DefaultAudioFolders {
+            get { return audio_folders; }
+        }
+
+        protected override int DefaultFolderDepth {
+            get { return 2; }
+        }
+
+        protected override string DefaultPlaylistPath {
+            get { return "Playlists/"; }
+        }
+
+        private static string [] video_folders = { "My Videos/" };
+        protected override string [] DefaultVideoFolders {
+            get { return video_folders; }
+        }
+
+        private static string [] playback_mime_types = {
+            "audio/mp3",
+            "video/mp4"
+        };
+        protected override string [] DefaultPlaybackMimeTypes {
+            get { return playback_mime_types; }
+        }
+
+        private string default_name;
+        protected override string DefaultName {
+            get {
+                if (string.IsNullOrEmpty (default_name))
+                    default_name = string.Format ("{0} {1}",
+                                                  VendorProductInfo.VendorName,
+                                                  VendorProductInfo.ProductName);
+                return default_name;
+            }
+        }
+
+        public override bool LoadDeviceConfiguration ()
+        {
+            LoadConfig (null);
+            return true;
+        }
+        #endregion
+    }
+}
+
diff --git a/src/Dap/Banshee.Dap.MassStorage/Makefile.am b/src/Dap/Banshee.Dap.MassStorage/Makefile.am
index 24e6490..4b3d329 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Makefile.am
+++ b/src/Dap/Banshee.Dap.MassStorage/Makefile.am
@@ -14,6 +14,7 @@ SOURCES =  \
 	Banshee.Dap.MassStorage/MassStorageSource.cs \
 	Banshee.Dap.MassStorage/NookDevice.cs \
 	Banshee.Dap.MassStorage/RockBoxDevice.cs \
+	Banshee.Dap.MassStorage/SymbianDevice.cs \
 	Banshee.Dap.MassStorage/WebOSDevice.cs
 
 RESOURCES = Banshee.Dap.MassStorage.addin.xml
diff --git a/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/128x128/devices/phone-nokia-n95.png b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/128x128/devices/phone-nokia-n95.png
new file mode 100644
index 0000000..2f8e885
Binary files /dev/null and b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/128x128/devices/phone-nokia-n95.png differ
diff --git a/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/16x16/devices/phone-nokia-n95.png b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/16x16/devices/phone-nokia-n95.png
new file mode 100644
index 0000000..2263fa2
Binary files /dev/null and b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/16x16/devices/phone-nokia-n95.png differ
diff --git a/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/22x22/devices/phone-nokia-n95.png b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/22x22/devices/phone-nokia-n95.png
new file mode 100644
index 0000000..487fef5
Binary files /dev/null and b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/22x22/devices/phone-nokia-n95.png differ
diff --git a/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/24x24/devices/phone-nokia-n95.png b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/24x24/devices/phone-nokia-n95.png
new file mode 100644
index 0000000..05daf4c
Binary files /dev/null and b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/24x24/devices/phone-nokia-n95.png differ
diff --git a/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/256x256/devices/phone-nokia-n95.png b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/256x256/devices/phone-nokia-n95.png
new file mode 100644
index 0000000..e1dc7a8
Binary files /dev/null and b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/256x256/devices/phone-nokia-n95.png differ
diff --git a/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/32x32/devices/phone-nokia-n95.png b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/32x32/devices/phone-nokia-n95.png
new file mode 100644
index 0000000..92408e2
Binary files /dev/null and b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/32x32/devices/phone-nokia-n95.png differ
diff --git a/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/48x48/devices/phone-nokia-n95.png b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/48x48/devices/phone-nokia-n95.png
new file mode 100644
index 0000000..7e68786
Binary files /dev/null and b/src/Dap/Banshee.Dap.MassStorage/ThemeIcons/48x48/devices/phone-nokia-n95.png differ
diff --git a/src/Hyena b/src/Hyena
index 01dd730..a2f18e5 160000
--- a/src/Hyena
+++ b/src/Hyena
@@ -1 +1 @@
-Subproject commit 01dd7306c8a1949c7617bae3c85bfbff410c3a75
+Subproject commit a2f18e52e618bc7aa3f6ad3aa66072acbe89f9e2
diff --git a/tests/data/playlist-data/dos_path_nokia.m3u b/tests/data/playlist-data/dos_path_nokia.m3u
new file mode 100644
index 0000000..4ddc75b
--- /dev/null
+++ b/tests/data/playlist-data/dos_path_nokia.m3u
@@ -0,0 +1,6 @@
+#EXTM3U
+#EXTINF:110,Atari Doll - Queen for a Day
+E:\Music\Atari Doll\Atari Doll\01. Queen for a Day.mp3
+#EXTINF:169,Barenaked Ladies - One Week
+E:\Music\Barenaked Ladies\All Their Greatest Hits 1991\04. One Week.mp3
+



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