banshee r4825 - in trunk/banshee: . src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Hardware src/Dap/Banshee.Dap.MassStorage src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4825 - in trunk/banshee: . src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Hardware src/Dap/Banshee.Dap.MassStorage src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage
- Date: Mon, 10 Nov 2008 19:44:50 +0000 (UTC)
Author: abock
Date: Mon Nov 10 19:44:49 2008
New Revision: 4825
URL: http://svn.gnome.org/viewvc/banshee?rev=4825&view=rev
Log:
* banshee/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs:
Custom Mono.Addins extension node that allows targeting device class
definitions as extensions
* banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml:
Defined a MassStorageDevice extension point and custom node; added
the T-Mobile G1 devices as extensions using new node support
* banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/DeviceMapper.cs:
Use Mono.Addins and the new extension node to load custom devices, so
other devices can be supported in the future without requiring
modifications to Banshee
* banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs:
* banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs:
* banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs:
Updated API to ensure everything works well with Mono.Addins'
TypeExtensionNode instantiation
Added:
trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj
trunk/banshee/src/Core/Banshee.Services/Makefile.am
trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs
trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/DeviceMapper.cs
trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
Added: trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/VendorProductDeviceNode.cs Mon Nov 10 19:44:49 2008
@@ -0,0 +1,105 @@
+//
+// VendorProductDeviceNode.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 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 System.Globalization;
+
+using Mono.Addins;
+
+namespace Banshee.Hardware
+{
+ [NodeAttribute ("vendor-name", true)]
+ [NodeAttribute ("product-name", true)]
+ [NodeAttribute ("vendor-id", true)]
+ [NodeAttribute ("product-id", true)]
+ public class VendorProductDeviceNode : TypeExtensionNode
+ {
+ private short [] vendor_ids;
+ private short [] product_ids;
+
+ private string vendor_name;
+ public string VendorName {
+ get { return vendor_name; }
+ }
+
+ private string product_name;
+ public string ProductName {
+ get { return product_name; }
+ }
+
+ public bool Matches (short vendorId, short productId)
+ {
+ return Match (vendor_ids, vendorId) && Match (product_ids, productId);
+ }
+
+ protected override void Read (NodeElement elem)
+ {
+ base.Read (elem);
+
+ vendor_name = elem.GetAttribute ("vendor-name");
+ product_name = elem.GetAttribute ("product-name");
+ vendor_ids = ParseIds (elem.GetAttribute ("vendor-id"));
+ product_ids = ParseIds (elem.GetAttribute ("product-id"));
+ }
+
+ private static bool Match (short [] ids, short match)
+ {
+ for (int i = 0; i < ids.Length; i++) {
+ if (ids[i] == match) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static short [] ParseIds (string value)
+ {
+ string [] split = value.Split (',');
+ short [] ids = new short[split.Length];
+ for (int i = 0; i < split.Length; i++) {
+ ids[i] = ParseId (split[i]);
+ }
+ return ids;
+ }
+
+ private static short ParseId (string value)
+ {
+ short result = 0;
+
+ if (value.StartsWith ("0x")) {
+ Int16.TryParse (value.Substring (2), NumberStyles.HexNumber,
+ CultureInfo.InvariantCulture, out result);
+ } else {
+ Int16.TryParse (value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite,
+ CultureInfo.InvariantCulture, out result);
+ }
+
+ return result;
+ }
+ }
+}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj Mon Nov 10 19:44:49 2008
@@ -242,6 +242,7 @@
<Compile Include="Banshee.Collection\RescanPipeline.cs" />
<Compile Include="Banshee.Hardware\VendorProductInfo.cs" />
<Compile Include="Banshee.Hardware\IUsbDevice.cs" />
+ <Compile Include="Banshee.Hardware\VendorProductDeviceNode.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Banshee.Services.addin.xml" />
Modified: trunk/banshee/src/Core/Banshee.Services/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Makefile.am (original)
+++ trunk/banshee/src/Core/Banshee.Services/Makefile.am Mon Nov 10 19:44:49 2008
@@ -63,6 +63,7 @@
Banshee.Hardware/IHardwareManager.cs \
Banshee.Hardware/IUsbDevice.cs \
Banshee.Hardware/IVolume.cs \
+ Banshee.Hardware/VendorProductDeviceNode.cs \
Banshee.Hardware/VendorProductInfo.cs \
Banshee.Library/HomeDirectoryImportSource.cs \
Banshee.Library/IImportSource.cs \
Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml Mon Nov 10 19:44:49 2008
@@ -18,5 +18,16 @@
<Extension path="/Banshee/Dap/DeviceClass">
<DeviceClass class="Banshee.Dap.MassStorage.MassStorageSource"/>
</Extension>
+
+ <ExtensionPoint path="/Banshee/Dap/MassStorage/Device">
+ <ExtensionNode name="MassStorageDevice" type="Banshee.Hardware.VendorProductDeviceNode"/>
+ </ExtensionPoint>
+
+ <!-- Any devices we wish to special case and support out of the box -->
+ <Extension path="/Banshee/Dap/MassStorage/Device">
+ <MassStorageDevice class="Banshee.Dap.MassStorage.AndroidDevice"
+ vendor-name="HTC" product-name="T-Mobile G1"
+ vendor-id="0x0bb4" product-id="0x0c01,0x0c02"/>
+ </Extension>
</Addin>
Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.csproj Mon Nov 10 19:44:49 2008
@@ -75,4 +75,7 @@
</Properties>
</MonoDevelop>
</ProjectExtensions>
+ <ItemGroup>
+ <Reference Include="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
+ </ItemGroup>
</Project>
\ No newline at end of file
Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs Mon Nov 10 19:44:49 2008
@@ -59,11 +59,6 @@
private AmazonMp3GroupSource amazon_source;
private string amazon_base_dir;
- public AndroidDevice (VendorProductInfo productInfo, MassStorageSource source)
- : base (productInfo, source)
- {
- }
-
public override void SourceInitialize ()
{
amazon_base_dir = System.IO.Path.Combine (Source.Volume.MountPoint, audio_folders[1]);
Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs Mon Nov 10 19:44:49 2008
@@ -34,16 +34,14 @@
{
public class CustomMassStorageDevice : MassStorageDevice
{
- private VendorProductInfo product_info;
-
- public CustomMassStorageDevice (VendorProductInfo productInfo, MassStorageSource source)
- : base (source)
- {
- product_info = productInfo;
+ private VendorProductInfo vendor_product_info;
+ public VendorProductInfo VendorProductInfo {
+ get { return vendor_product_info; }
+ set { vendor_product_info = value; }
}
public override string Name {
- get { return product_info.ProductName; }
+ get { return vendor_product_info.ProductName; }
}
}
}
Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/DeviceMapper.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/DeviceMapper.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/DeviceMapper.cs Mon Nov 10 19:44:49 2008
@@ -27,46 +27,32 @@
//
using System;
+using Mono.Addins;
+
using Banshee.Hardware;
namespace Banshee.Dap.MassStorage
{
internal static class DeviceMapper
{
- private static DeviceMap [] devices = new DeviceMap [] {
- new DeviceMap (typeof (AndroidDevice), "HTC", "T-Mobile G1", 0x0bb4, 0x0c01),
- new DeviceMap (typeof (AndroidDevice), "HTC", "T-Mobile G1", 0x0bb4, 0x0c02)
- };
-
public static MassStorageDevice Map (MassStorageSource source)
{
- foreach (DeviceMap map in devices) {
- if (map.VendorProductInfo.VendorId == source.UsbDevice.VendorId &&
- map.VendorProductInfo.ProductId == source.UsbDevice.ProductId) {
- return (CustomMassStorageDevice)Activator.CreateInstance (map.DeviceType,
- new object [] { map.VendorProductInfo, source });
+ foreach (VendorProductDeviceNode node in AddinManager.GetExtensionNodes (
+ "/Banshee/Dap/MassStorage/Device")) {
+ short vendor_id = (short)source.UsbDevice.VendorId;
+ short product_id = (short)source.UsbDevice.ProductId;
+
+ if (node.Matches (vendor_id, product_id)) {
+ MassStorageDevice device = (MassStorageDevice)node.CreateInstance ();
+ device.VendorProductInfo = new VendorProductInfo (
+ node.VendorName, node.ProductName,
+ vendor_id, product_id);
+ device.Source = source;
+ return device;
}
}
return new MassStorageDevice (source);
}
-
- private struct DeviceMap
- {
- public DeviceMap (Type type, VendorProductInfo vpi)
- {
- DeviceType = type;
- VendorProductInfo = vpi;
- }
-
- public DeviceMap (Type type, string vendor, string product, short vendorId, short productId)
- {
- DeviceType = type;
- VendorProductInfo = new VendorProductInfo (vendor, product, vendorId, productId);
- }
-
- public VendorProductInfo VendorProductInfo;
- public Type DeviceType;
- }
}
}
Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs Mon Nov 10 19:44:49 2008
@@ -42,13 +42,18 @@
public class MassStorageDevice : IDeviceMediaCapabilities
{
private MassStorageSource source;
- protected MassStorageSource Source {
+ public MassStorageSource Source {
get { return source; }
+ set { source = value; }
+ }
+
+ public MassStorageDevice ()
+ {
}
public MassStorageDevice (MassStorageSource source)
{
- this.source = source;
+ Source = source;
}
public virtual void SourceInitialize ()
@@ -70,7 +75,7 @@
}
try {
- foreach (KeyValuePair<string, string []> item in new KeyValueParser (reader = new StreamReader (path))) {
+ foreach (var item in new KeyValueParser (reader = new StreamReader (path))) {
try {
switch (item.Key) {
case "name": name = item.Value[0]; break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]