[banshee] Add support for WebOS devices (BGO #585112)



commit 7bb0c13c7be43a5327744020e5d639d2f6319caa
Author: Jeff Wheeler <jeff jeffwheeler name>
Date:   Mon Jul 13 10:40:13 2009 -0700

    Add support for WebOS devices (BGO #585112)
    
    Signed-off-by: Gabriel Burt <gabriel burt gmail com>

 .../Banshee.Hardware/VendorProductDeviceNode.cs    |   10 +-
 .../Banshee.Dap.MassStorage.addin.xml              |    7 +-
 .../Banshee.Dap.MassStorage.csproj                 |    2 +
 .../AmazonMp3GroupSource.cs                        |   74 ++++++++
 .../Banshee.Dap.MassStorage/AndroidDevice.cs       |   41 +----
 .../Banshee.Dap.MassStorage/WebOSDevice.cs         |  189 ++++++++++++++++++++
 src/Dap/Banshee.Dap.MassStorage/Makefile.am        |    4 +-
 7 files changed, 282 insertions(+), 45 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs b/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs
index d9d214e..15afb8d 100644
--- a/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs
+++ b/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs
@@ -89,17 +89,19 @@ namespace Banshee.Hardware
         
         private static short ParseId (string value)
         {
-            short result = 0;
+            // Parse as an integer, then typecast, to avoid overflow issues
+            // with regards to the sign bit.
+            int result = 0;
             
             if (value.StartsWith ("0x")) {
-                Int16.TryParse (value.Substring (2), NumberStyles.HexNumber, 
+                Int32.TryParse (value.Substring (2), NumberStyles.HexNumber,
                     CultureInfo.InvariantCulture, out result);
             } else {
-                Int16.TryParse (value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, 
+                Int32.TryParse (value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite,
                     CultureInfo.InvariantCulture, out result);
             }
             
-            return result;
+            return (short)result;
         }
     }
 }
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 8f1ac87..f74494b 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
@@ -3,11 +3,11 @@
     id="Banshee.Dap.MassStorage"
     version="1.0"
     compatVersion="1.0"
-    copyright="© 2008 Novell Inc. Licensed under the MIT X11 license."
+    copyright="Copyright 2008 Novell Inc., Copyright 2009 Jeff Wheeler. Licensed under the MIT X11 license."
     name="Mass Storage Media Player Support"
     category="Hardware"
     description="Provides support for media players that use USB Mass Storage without keeping an internal database."
-    author="Gabriel Burt, Aaron Bockover"
+    author="Gabriel Burt, Aaron Bockover, Jeff Wheeler"
     url="http://banshee-project.org/";
     defaultEnabled="true">
 
@@ -28,6 +28,9 @@
     <MassStorageDevice class="Banshee.Dap.MassStorage.AndroidDevice" 
         vendor-name="HTC" product-name="Android G1 Phone"
         vendor-id="0x0bb4" product-id="0x0c01,0x0c02"/>
+    <MassStorageDevice class="Banshee.Dap.MassStorage.WebOSDevice"
+        vendor-name="Palm" product-name="Pre"
+        vendor-id="0x0830" product-id="0x8004"/>
   </Extension>
 
 </Addin>
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
index 3e8a458..cb8b8d3 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
@@ -61,6 +61,8 @@
     <Compile Include="Banshee.Dap.MassStorage\AndroidDevice.cs" />
     <Compile Include="Banshee.Dap.MassStorage\DeviceMapper.cs" />
     <Compile Include="Banshee.Dap.MassStorage\CustomMassStorageDevice.cs" />
+    <Compile Include="Banshee.Dap.MassStorage\AmazonMp3GroupSource.cs" />
+    <Compile Include="Banshee.Dap.MassStorage\WebOSDevice.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Dap.MassStorage.addin.xml" />
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs
new file mode 100644
index 0000000..1041187
--- /dev/null
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs
@@ -0,0 +1,74 @@
+//
+// AmazonMp3GroupSource.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//   Jeff Wheeler <jeff jeffwheeler name>
+//
+// Copyright (C) 2008 Novell, Inc.
+// Copyright (C) 2009 Jeff Wheeler
+//
+// 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 Mono.Unix;
+
+using Banshee.Library;
+
+namespace Banshee.Dap.MassStorage
+{
+    public class AmazonMp3GroupSource : MediaGroupSource, IPurchasedMusicSource
+    {
+        private String amazon_base_dir;
+
+        public AmazonMp3GroupSource (DapSource parent, String amazon_dir, String amazon_base_dir)
+            : base (parent, Catalog.GetString ("Purchased Music"))
+        {
+            this.amazon_base_dir = amazon_base_dir;
+
+            Properties.SetString ("Icon.Name", "amazon-mp3-source");
+            ConditionSql = String.Format ("(CoreTracks.Uri LIKE \"%{0}%\")", amazon_dir);
+        }
+
+        public override void Activate ()
+        {
+            base.Activate ();
+            active = true;
+        }
+
+        public override void Deactivate ()
+        {
+            base.Deactivate ();
+            active = false;
+        }
+
+        public void Import ()
+        {
+            LibraryImportManager importer = new LibraryImportManager (true);
+            importer.Enqueue (amazon_base_dir);
+        }
+
+        private bool active;
+        public bool Active {
+            get { return active; }
+        }
+    }
+}
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
index 47c3d79..c466d4b 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
@@ -3,8 +3,10 @@
 //
 // Author:
 //   Aaron Bockover <abockover novell com>
+//   Jeff Wheeler <jeff jeffwheeler name>
 //
 // Copyright (C) 2008 Novell, Inc.
+// Copyright (C) 2009 Jeff Wheeler
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -73,7 +75,7 @@ namespace Banshee.Dap.MassStorage
         {
             amazon_base_dir = System.IO.Path.Combine (Source.Volume.MountPoint, audio_folders[1]);
             
-            amazon_source = new AmazonMp3GroupSource (this, Source);
+            amazon_source = new AmazonMp3GroupSource (Source, "amazonmp3", amazon_base_dir);
             amazon_source.AutoHide = true;
         }
         
@@ -158,43 +160,6 @@ namespace Banshee.Dap.MassStorage
             
             return true;
         }
-        
-        private class AmazonMp3GroupSource : MediaGroupSource, IPurchasedMusicSource
-        {
-            private AndroidDevice android;
-            
-            public AmazonMp3GroupSource (AndroidDevice android, DapSource parent) 
-                : base (parent, Catalog.GetString ("Purchased Music"))
-            {
-                this.android = android;
-                
-                Properties.SetString ("Icon.Name", "amazon-mp3-source");
-                ConditionSql = "(CoreTracks.Uri LIKE \"amazonmp3/%\")";
-            }
-            
-            public override void Activate ()
-            {
-                base.Activate ();
-                active = true;
-            }
-
-            public override void Deactivate ()
-            {
-                base.Deactivate ();
-                active = false;
-            }
-            
-            public void Import ()
-            {
-                LibraryImportManager importer = new LibraryImportManager (true);
-                importer.Enqueue (android.amazon_base_dir);
-            }
-            
-            private bool active;
-            public bool Active {
-                get { return active; }
-            }
-        }
 
 #endregion
 
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
new file mode 100644
index 0000000..8220aaf
--- /dev/null
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
@@ -0,0 +1,189 @@
+//
+// WebOSDevice.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//   Jeff Wheeler <jeff jeffwheeler name>
+//
+// Copyright (C) 2008 Novell, Inc.
+// Copyright (C) 2009 Jeff Wheeler
+//
+// 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 Mono.Unix;
+
+using Banshee.Base;
+using Banshee.Hardware;
+using Banshee.Library;
+using Banshee.Collection;
+using Banshee.Collection.Database;
+
+namespace Banshee.Dap.MassStorage
+{
+    public class WebOSDevice : CustomMassStorageDevice
+    {
+        private static string [] playback_mime_types = new string [] {
+            // Video
+            "video/mp4-generic",
+            "video/quicktime",
+            "video/mp4",
+            "video/mpeg4",
+            "video/3gp",
+            "video/3gpp2",
+            "application/sdp",
+
+            // Audio
+            "audio/3gpp",
+            "audio/3ga",
+            "audio/3gpp2",
+            "audio/amr",
+            "audio/x-amr",
+            "audio/mpa",
+            "audio/mp3",
+            "audio/x-mp3",
+            "audio/x-mpg",
+            "audio/mpeg",
+            "audio/mpeg3",
+            "audio/mpg3",
+            "audio/mpg",
+            "audio/mp4",
+            "audio/m4a",
+            "audio/aac",
+            "audio/x-aac",
+            "audio/mp4a-latm",
+            "audio/wav"
+        };
+
+        // The Pre theoretically supports these formats, but it does not
+        // recognize them within the media player.
+        private static string [] playlist_formats = new string [] {
+            // "audio/x-scpls",
+            // "audio/mpegurl",
+            // "audio/x-mpegurl"
+        };
+
+        private static string [] audio_folders = new string [] {
+            "Music/",
+            "Videos/",
+            "ringtones/",
+            "AmazonMP3/"
+        };
+
+        private static string [] icon_names = new string [] {
+            DapSource.FallbackIcon
+        };
+
+        private AmazonMp3GroupSource amazon_source;
+        private string amazon_base_dir;
+
+        private RingtonesGroupSource ringtones_source;
+
+        public override void SourceInitialize ()
+        {
+            amazon_base_dir = System.IO.Path.Combine (Source.Volume.MountPoint, audio_folders[3]);
+
+            amazon_source = new AmazonMp3GroupSource (Source, "AmazonMP3", amazon_base_dir);
+            amazon_source.AutoHide = true;
+
+            ringtones_source = new RingtonesGroupSource (Source);
+            ringtones_source.AutoHide = true;
+        }
+
+        public override bool LoadDeviceConfiguration ()
+        {
+            return true;
+        }
+
+        public override string Name {
+            get { return VendorProductInfo.ProductName; }
+        }
+
+        public override string [] AudioFolders {
+            get { return audio_folders; }
+        }
+
+        public override string [] PlaybackMimeTypes {
+            get { return playback_mime_types; }
+        }
+
+        public override int FolderDepth {
+            get { return 2; }
+        }
+
+        public override string CoverArtFileType {
+            get { return "jpeg"; }
+        }
+
+        public override int CoverArtSize {
+            get { return 320; }
+        }
+
+        public override string [] PlaylistFormats {
+            get { return playlist_formats; }
+        }
+
+        public override string [] GetIconNames ()
+        {
+            return icon_names;
+        }
+
+#region Amazon MP3 Store Purchased Tracks Management
+
+        public override bool DeleteTrackHook (DatabaseTrackInfo track)
+        {
+            // Do not allow removing purchased tracks if not in the
+            // Amazon Purchased Music source; this should prevent
+            // accidental deletion of purchased music that may not
+            // have been copied from the device yet.
+            //
+            // TODO: Provide some feedback when a purchased track is
+            // skipped from deletion
+            //
+            // FIXME: unfortunately this does not work due to
+            // the cache models being potentially different
+            // even though they will always reference the same tracks
+            // amazon_source.TrackModel.IndexOf (track) >= 0
+            if (!amazon_source.Active && amazon_source.Count > 0 && track.Uri.LocalPath.StartsWith (amazon_base_dir)) {
+                return false;
+            }
+
+            return true;
+        }
+
+#endregion
+
+#region Ringtones Support
+
+    private class RingtonesGroupSource : MediaGroupSource
+    {
+        // TODO: Support dropping files onto this playlist to copy into the ringtones directory
+        public RingtonesGroupSource (DapSource parent)
+            : base (parent, Catalog.GetString ("Ringtones"))
+        {
+            ConditionSql = "(CoreTracks.Uri LIKE \"%ringtones/%\")";
+        }
+    }
+
+#endregion
+
+    }
+}
diff --git a/src/Dap/Banshee.Dap.MassStorage/Makefile.am b/src/Dap/Banshee.Dap.MassStorage/Makefile.am
index fb502ed..ebe8018 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Makefile.am
+++ b/src/Dap/Banshee.Dap.MassStorage/Makefile.am
@@ -4,12 +4,14 @@ LINK = $(REF_DAP_MASS_STORAGE)
 INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
 
 SOURCES =  \
+	Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs \
 	Banshee.Dap.MassStorage/AndroidDevice.cs \
 	Banshee.Dap.MassStorage/CustomMassStorageDevice.cs \
 	Banshee.Dap.MassStorage/DeviceMapper.cs \
 	Banshee.Dap.MassStorage/KeyValueParser.cs \
 	Banshee.Dap.MassStorage/MassStorageDevice.cs \
-	Banshee.Dap.MassStorage/MassStorageSource.cs
+	Banshee.Dap.MassStorage/MassStorageSource.cs \
+	Banshee.Dap.MassStorage/WebOSDevice.cs
 
 RESOURCES = Banshee.Dap.MassStorage.addin.xml
 



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