banshee r3117 - in branches/banshee/stable: . ext/libmtp-sharp ext/libmtp-sharp/Base ext/libmtp-sharp/Functions src/Core/Banshee.Base/Dap src/Dap/Banshee.Dap.Mtp



Author: gburt
Date: Thu Jan 31 06:29:34 2008
New Revision: 3117
URL: http://svn.gnome.org/viewvc/banshee?rev=3117&view=rev

Log:
2008-01-31  Gabriel Burt  <gabriel burt gmail com>

	This commits fixes more MTP support bugs, and happily, adds support for
	cover art where supported.

	* src/Core/Banshee.Base/Dap/DapMisc.cs: Add support for passing file
	extension when trying to determine mimetype.

	* src/Dap/Banshee.Dap.Mtp/Makefile.am:
	* src/Dap/Banshee.Dap.Mtp/AlbumSet.cs: New file for keeping track of what
	album/artwork should be deleted/added when synching.

	* src/Dap/Banshee.Dap.Mtp/MtpDap.cs: Detect what formats the DAP actually
	supports instead of assuming mp3/wma.  If the device supports JPEGS, send
	cover art on sync if we have it.  Properly convert between the different
	rating sytems (0-100 vs 0-5) and UseCount/PlayCount, and consolidate
	conversion logic.  Translate some untranslated strings.  Avoid spewing
	horribly long exception message when libmtpsharp catches an error.

	* src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs:  Properly round trip rating
	and play count.
	* ext/libmtp-sharp/Base/Enums.cs: Remove leading LIBMTP_FILETYPE_ on a
	million enum values.

	* ext/libmtp-sharp/MtpDevice.cs: Rename handle to Handle.  Add GetAlbums
	and GetFileTypes methods.

	* ext/libmtp-sharp/Folder.cs:
	Use device.Handle instead of handle.

	* ext/libmtp-sharp/Base/Album.cs: Rename struct to AlbumStruct.

	* ext/libmtp-sharp/Makefile.am:
	* ext/libmtp-sharp/Album.cs: New class for supporting cover art.

	* ext/libmtp-sharp/Base/FileSampleData.cs: Make usable.

	* ext/libmtp-sharp/Functions/AlbumManagement.cs:
	* ext/libmtp-sharp/Functions/FileManagement.cs: Make some libmtp methods
	public.

	* ext/libmtp-sharp/Functions/FunctionCalls.cs: Add GetFileTypes method.

	* ext/libmtp-sharp/Track.cs: Enum updates and Handle update.


Added:
   branches/banshee/stable/ext/libmtp-sharp/Album.cs
   branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/AlbumSet.cs
Modified:
   branches/banshee/stable/ChangeLog
   branches/banshee/stable/ext/libmtp-sharp/Base/Album.cs
   branches/banshee/stable/ext/libmtp-sharp/Base/Enums.cs
   branches/banshee/stable/ext/libmtp-sharp/Base/FileSampleData.cs
   branches/banshee/stable/ext/libmtp-sharp/Folder.cs
   branches/banshee/stable/ext/libmtp-sharp/Functions/AlbumManagement.cs
   branches/banshee/stable/ext/libmtp-sharp/Functions/FileManagement.cs
   branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs
   branches/banshee/stable/ext/libmtp-sharp/Makefile.am
   branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs
   branches/banshee/stable/ext/libmtp-sharp/Track.cs
   branches/banshee/stable/src/Core/Banshee.Base/Dap/DapMisc.cs
   branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/Makefile.am
   branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs
   branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs

Added: branches/banshee/stable/ext/libmtp-sharp/Album.cs
==============================================================================
--- (empty file)
+++ branches/banshee/stable/ext/libmtp-sharp/Album.cs	Thu Jan 31 06:29:34 2008
@@ -0,0 +1,188 @@
+/***************************************************************************
+ *  Album.cs
+ *
+ *  Copyright (C) 2008 Novell
+ *  Authors:
+ *  Gabriel Burt (gburt novell com)
+ ****************************************************************************/
+
+/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
+ *
+ *  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.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace Mtp
+{
+	public class Album
+	{
+		private AlbumStruct album;
+		private MtpDevice device;
+        private bool saved;
+        private List<int> track_ids;
+
+        public uint AlbumId {
+            get { return saved ? album.album_id : 0; }
+        }
+
+        public List<int> TrackIds {
+            get { return track_ids; }
+        }
+
+        public bool Saved {
+            get { return saved; }
+        }
+
+        public string Name {
+            get { return album.name; }
+            set {
+                album.name = value;
+            }
+        }
+
+        public string Artist {
+            get { return album.artist; }
+            set {
+                album.artist = value;
+            }
+        }
+
+        public string Genre {
+            get { return album.genre; }
+            set {
+                album.genre = value;
+            }
+        }
+
+        public uint TrackCount {
+            get { return album.no_tracks; }
+            set {
+                album.no_tracks = value;
+            }
+        }
+
+        public Album (MtpDevice device, string name, string artist, string genre)
+        {
+            this.device = device;
+            this.album = new AlbumStruct ();
+            Name = name;
+            Artist = artist;
+            Genre = genre;
+            TrackCount = 0;
+            track_ids = new List<int> ();
+        }
+
+        internal Album (MtpDevice device, AlbumStruct album)
+        {
+            this.device = device;
+            this.album = album;
+            this.saved = true;
+
+            if (album.tracks != IntPtr.Zero) {
+                int [] vals = new int [TrackCount];
+                Marshal.Copy ((IntPtr)album.tracks, (int[])vals, 0, (int)TrackCount);
+                track_ids = new List<int> (vals);
+            } else {
+                track_ids = new List<int> ();
+            }
+        }
+        
+        public void Save ()
+        {
+            Save (null, 0, 0);
+        }
+
+        public void Save (byte [] cover_art, uint width, uint height)
+        {
+            TrackCount = (uint) track_ids.Count;
+
+            if (album.tracks != IntPtr.Zero) {
+                Marshal.FreeHGlobal (album.tracks);
+            }
+
+            if (TrackCount == 0) {
+                album.tracks = IntPtr.Zero;
+            } else {
+                album.tracks = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (int)) * (int)TrackCount);
+                Marshal.Copy (track_ids.ToArray (), 0, album.tracks, (int)TrackCount);
+            }
+
+            if (saved) {
+                saved = AlbumManagement.LIBMTP_Update_Album (device.Handle, album) == 0;
+            } else {
+                saved = AlbumManagement.LIBMTP_Create_New_Album (device.Handle, ref album, 0) == 0;
+            }
+
+            if (album.tracks != IntPtr.Zero) {
+                Marshal.FreeHGlobal (album.tracks);
+            }
+
+            if (!saved)
+                return;
+
+            if (cover_art == null) {
+                return;
+            }
+            
+            FileSampleData cover = new FileSampleData ();
+            cover.data = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (byte)) * cover_art.Length);
+            Marshal.Copy (cover_art, 0, cover.data, cover_art.Length);
+            cover.size = (ulong)cover_art.Length;
+            cover.width = width;
+            cover.height = height;
+            cover.filetype = FileType.JPEG;
+
+            if (FileManagement.LIBMTP_Send_Representative_Sample (device.Handle, AlbumId, ref cover) != 0) {
+                //Console.WriteLine ("failed to send representative sample file");
+            }
+            Marshal.FreeHGlobal (cover.data);
+        }
+
+        public void AddTrack (Track track)
+        {
+            track_ids.Add ((int)track.FileId);
+            TrackCount++;
+        }
+
+        public void RemoveTrack (Track track)
+        {
+            track_ids.Remove ((int)track.FileId);
+            TrackCount--;
+        }
+
+        public void ClearTracks ()
+        {
+            track_ids.Clear ();
+            TrackCount = 0;
+        }
+
+        public void Remove ()
+        {
+			LibMtp.LIBMTP_Delete_Object(device.Handle, AlbumId);
+        }
+
+        public override string ToString ()
+        {
+            return String.Format ("Album < Id: {4}, '{0}' by '{1}', genre '{2}', tracks {3} >", Name, Artist, Genre, TrackCount, AlbumId);
+        }
+	}
+}

Modified: branches/banshee/stable/ext/libmtp-sharp/Base/Album.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Base/Album.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Base/Album.cs	Thu Jan 31 06:29:34 2008
@@ -33,14 +33,22 @@
 namespace Mtp
 {
 	[StructLayout(LayoutKind.Sequential)]
-	internal struct Album
+	internal struct AlbumStruct
 	{
 		public uint album_id;
-		[MarshalAs(UnmanagedType.LPStr)] public string name;
-		[MarshalAs(UnmanagedType.LPStr)] public string artist;
-		[MarshalAs(UnmanagedType.LPStr)] public string genre;
-		public IntPtr tracks;  // int*
+
+		[MarshalAs(UnmanagedType.LPStr)]
+        public string name;
+
+		[MarshalAs(UnmanagedType.LPStr)]
+        public string artist;
+
+		[MarshalAs(UnmanagedType.LPStr)]
+        public string genre;
+
+		public IntPtr tracks;
 		public uint no_tracks;
+
 		public IntPtr next; // LIBMTP_album_t*
 
 /*

Modified: branches/banshee/stable/ext/libmtp-sharp/Base/Enums.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Base/Enums.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Base/Enums.cs	Thu Jan 31 06:29:34 2008
@@ -33,48 +33,48 @@
 {
 	public enum FileType
 	{
-		LIBMTP_FILETYPE_WAV,
-		LIBMTP_FILETYPE_MP3,
-		LIBMTP_FILETYPE_WMA,
-		LIBMTP_FILETYPE_OGG,
-		LIBMTP_FILETYPE_AUDIBLE,
-		LIBMTP_FILETYPE_MP4,
-		LIBMTP_FILETYPE_UNDEF_AUDIO,
-		LIBMTP_FILETYPE_WMV,
-		LIBMTP_FILETYPE_AVI,
-		LIBMTP_FILETYPE_MPEG,
-		LIBMTP_FILETYPE_ASF,
-		LIBMTP_FILETYPE_QT,
-		LIBMTP_FILETYPE_UNDEF_VIDEO,
-		LIBMTP_FILETYPE_JPEG,
-		LIBMTP_FILETYPE_JFIF,
-		LIBMTP_FILETYPE_TIFF,
-		LIBMTP_FILETYPE_BMP,
-		LIBMTP_FILETYPE_GIF,
-		LIBMTP_FILETYPE_PICT,
-		LIBMTP_FILETYPE_PNG,
-		LIBMTP_FILETYPE_VCALENDAR1,
-		LIBMTP_FILETYPE_VCALENDAR2,
-		LIBMTP_FILETYPE_VCARD2,
-		LIBMTP_FILETYPE_VCARD3,
-		LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT,
-		LIBMTP_FILETYPE_WINEXEC,
-		LIBMTP_FILETYPE_TEXT,
-		LIBMTP_FILETYPE_HTML,
-		LIBMTP_FILETYPE_FIRMWARE,
-		LIBMTP_FILETYPE_AAC,
-		LIBMTP_FILETYPE_MEDIACARD,
-		LIBMTP_FILETYPE_FLAC,
-		LIBMTP_FILETYPE_MP2,
-		LIBMTP_FILETYPE_M4A,
-		LIBMTP_FILETYPE_DOC,
-		LIBMTP_FILETYPE_XML,
-		LIBMTP_FILETYPE_XLS,
-		LIBMTP_FILETYPE_PPT,
-		LIBMTP_FILETYPE_MHT,
-		LIBMTP_FILETYPE_JP2,
-		LIBMTP_FILETYPE_JPX,
-		LIBMTP_FILETYPE_UNKNOWN
+		WAV,
+		MP3,
+		WMA,
+		OGG,
+		AUDIBLE,
+		MP4,
+		UNDEF_AUDIO,
+		WMV,
+		AVI,
+		MPEG,
+		ASF,
+		QT,
+		UNDEF_VIDEO,
+		JPEG,
+		JFIF,
+		TIFF,
+		BMP,
+		GIF,
+		PICT,
+		PNG,
+		VCALENDAR1,
+		VCALENDAR2,
+		VCARD2,
+		VCARD3,
+		WINDOWSIMAGEFORMAT,
+		WINEXEC,
+		TEXT,
+		HTML,
+		FIRMWARE,
+		AAC,
+		MEDIACARD,
+		FLAC,
+		MP2,
+		M4A,
+		DOC,
+		XML,
+		XLS,
+		PPT,
+		MHT,
+		JP2,
+		JPX,
+		UNKNOWN
 	}
 	
 	public enum ErrorCode

Modified: branches/banshee/stable/ext/libmtp-sharp/Base/FileSampleData.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Base/FileSampleData.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Base/FileSampleData.cs	Thu Jan 31 06:29:34 2008
@@ -35,12 +35,11 @@
 	[StructLayout(LayoutKind.Sequential)]
 	internal struct FileSampleData
 	{
-		int width;
-		int height;
-		int duration;
-		FileType filetype;
-		long size;
-		[MarshalAs(UnmanagedType.LPStr)] string data;  // Make it byte maybe?
-		//FIXME THIS IS BUGGY!
+		public uint width;
+		public uint height;
+		public uint duration;
+		public FileType filetype;
+		public ulong size;
+		public IntPtr data;
 	}
 }

Modified: branches/banshee/stable/ext/libmtp-sharp/Folder.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Folder.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Folder.cs	Thu Jan 31 06:29:34 2008
@@ -75,7 +75,7 @@
 			    throw new ArgumentNullException("name");
 			    
 			// First create the folder on the device and check for error
-			uint id = FolderManagement.CreateFolder (device.handle, name, FolderId);
+			uint id = FolderManagement.CreateFolder (device.Handle, name, FolderId);
 			
 			FolderStruct f = new FolderStruct();
 			f.folder_id = id;
@@ -87,7 +87,7 @@
 		
 		public List<Folder> GetChildren ()
 		{
-			using (FolderHandle handle = FolderManagement.GetFolderList(device.handle))
+			using (FolderHandle handle = FolderManagement.GetFolderList(device.Handle))
 			{
 				// Find the pointer to the folderstruct representing this folder
 				IntPtr ptr = handle.DangerousGetHandle();
@@ -110,13 +110,13 @@
 		
 		public void Remove()
 		{
-			LibMtp.DeleteObject(device.handle, FolderId);
+			LibMtp.DeleteObject(device.Handle, FolderId);
 		}
 		
 		internal static List<Folder> GetRootFolders (MtpDevice device)
 		{
 			List<Folder> folders = new List<Folder>();
-			using (FolderHandle handle = FolderManagement.GetFolderList (device.handle))
+			using (FolderHandle handle = FolderManagement.GetFolderList (device.Handle))
 			{
 				for (IntPtr ptr = handle.DangerousGetHandle(); ptr != IntPtr.Zero;)
 				{

Modified: branches/banshee/stable/ext/libmtp-sharp/Functions/AlbumManagement.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Functions/AlbumManagement.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Functions/AlbumManagement.cs	Thu Jan 31 06:29:34 2008
@@ -35,16 +35,16 @@
 	internal class AlbumManagement
 	{
 		[DllImport("libmtp.dll")]
-		private static extern IntPtr LIBMTP_new_album_t (); // LIBMTP_album_t*
+		internal static extern IntPtr LIBMTP_new_album_t (); // LIBMTP_album_t*
 		[DllImport("libmtp.dll")]
-		private static extern void LIBMTP_destroy_album_t (ref Album album);
+		internal static extern void LIBMTP_destroy_album_t (ref AlbumStruct album);
 		[DllImport("libmtp.dll")]
-		private static extern IntPtr LIBMTP_Get_Album_List (MtpDeviceHandle handle); // LIBMTP_album_t*
+		internal static extern IntPtr LIBMTP_Get_Album_List (MtpDeviceHandle handle); // LIBMTP_album_t*
 		[DllImport("libmtp.dll")]
-		private static extern IntPtr LIBMTP_Get_Album (MtpDeviceHandle handle, uint albumId); // LIBMTP_album_t*
+		internal static extern IntPtr LIBMTP_Get_Album (MtpDeviceHandle handle, uint albumId); // LIBMTP_album_t*
 		[DllImport("libmtp.dll")]
-		private static extern int LIBMTP_Create_New_Album (MtpDeviceHandle handle, ref Album album, uint parentId);
+		internal static extern int LIBMTP_Create_New_Album (MtpDeviceHandle handle, ref AlbumStruct album, uint parentId);
 		[DllImport("libmtp.dll")]
-		private static extern int LIBMTP_Update_Album (MtpDeviceHandle handle, Album album);
+		internal static extern int LIBMTP_Update_Album (MtpDeviceHandle handle, AlbumStruct album);
 	}
 }

Modified: branches/banshee/stable/ext/libmtp-sharp/Functions/FileManagement.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Functions/FileManagement.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Functions/FileManagement.cs	Thu Jan 31 06:29:34 2008
@@ -50,13 +50,22 @@
 		private static extern IntPtr LIBMTP_Get_Filemetadata (MtpDeviceHandle handle, uint fileid); // LIBMTP_file_t *
 		[DllImport("libmtp.dll")]
 		private static extern int LIBMTP_Get_File_To_File (MtpDeviceHandle handle, uint fileId, string path, ProgressFunction function, IntPtr data);
+
 		[DllImport("libmtp.dll")]
 		private static extern int LIBMTP_Send_File_From_File (MtpDeviceHandle handle, string path, ref File fileData, ProgressFunction function, IntPtr data, uint parentHandle);
 		//int LIBMTP_Get_File_To_File_Descriptor (MtpDeviceHandle handle, uint32_t const, int const, ProgressFunction function, void const *const)
 		//int 	LIBMTP_Send_File_From_File_Descriptor (MtpDeviceHandle handle, int const, LIBMTP_file_t *const, ProgressFunction function, void const *const, uint32_t const)
-		//IntPtr LIBMTP_new_filesampledata_t (); // LIBMTP_filesampledata_t *
-		//void LIBMTP_destroy_filesampledata_t (ref FileSampleData data); // LIBMTP_filesampledata_t *
-		//int LIBMTP_Get_Representative_Sample_Format (MtpDeviceHandle handle, LIBMTP_filetype_t const, LIBMTP_filesampledata_t **)
-		//int LIBMTP_Send_Representative_Sample (MtpDeviceHandle handle, uint32_t const, LIBMTP_filesampledata_t *)
-		}
+
+		//[DllImport("libmtp.dll")]
+		//public static extern IntPtr LIBMTP_new_filesampledata_t (); // LIBMTP_filesampledata_t *
+
+		[DllImport("libmtp.dll")]
+		public static extern void LIBMTP_destroy_filesampledata_t (ref FileSampleData data); // LIBMTP_filesampledata_t *
+
+		[DllImport("libmtp.dll")]
+		public static extern int LIBMTP_Get_Representative_Sample_Format (MtpDeviceHandle handle, FileType type, IntPtr data_array);
+
+		[DllImport("libmtp.dll")]
+		public static extern int LIBMTP_Send_Representative_Sample (MtpDeviceHandle handle, uint id, ref FileSampleData sample);
+    }
 }

Modified: branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs	Thu Jan 31 06:29:34 2008
@@ -103,6 +103,20 @@
 		{
 			LIBMTP_Get_Storage (handle, sortMode);
 		}
+
+        public static Int16 [] GetFileTypes (MtpDeviceHandle handle)
+        {
+            IntPtr types = IntPtr.Zero;
+            ushort count = 0;
+            if (LIBMTP_Get_Supported_Filetypes (handle, ref types, ref count) == 0) {
+                Int16 [] type_ary = new Int16 [count];
+                Marshal.Copy (types, type_ary, 0, (int)count);
+                Marshal.FreeHGlobal (types);
+                return type_ary;
+            }
+
+            return new Int16[0];
+        }
 		
 		public static void Init ()
 		{
@@ -132,7 +146,7 @@
 		private static extern void LIBMTP_Clear_Errorstack (MtpDeviceHandle handle);
 		
 		[DllImport("libmtp.dll")]
-		private static extern int LIBMTP_Delete_Object (MtpDeviceHandle handle, uint object_id); 	
+		public static extern int LIBMTP_Delete_Object (MtpDeviceHandle handle, uint object_id); 	
 			
 		// Gets the first connected device:
 		[DllImport("libmtp.dll")]

Modified: branches/banshee/stable/ext/libmtp-sharp/Makefile.am
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Makefile.am	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Makefile.am	Thu Jan 31 06:29:34 2008
@@ -18,10 +18,11 @@
 	$(srcdir)/Base/Error.cs \
 	$(srcdir)/Base/FileSampleData.cs \
 	$(srcdir)/Base/MtpDeviceStruct.cs \
-	$(srcdir)/MtpDevice.cs \
+	$(srcdir)/Album.cs \
 	$(srcdir)/AssemblyInfo.cs \
-	$(srcdir)/Track.cs \
 	$(srcdir)/Folder.cs \
+	$(srcdir)/MtpDevice.cs \
+	$(srcdir)/Track.cs \
 	$(srcdir)/Functions/AlbumManagement.cs \
 	$(srcdir)/Functions/FunctionCalls.cs \
 	$(srcdir)/Functions/FolderManagement.cs \

Modified: branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs	Thu Jan 31 06:29:34 2008
@@ -35,7 +35,7 @@
 {
 	public class MtpDevice : IDisposable
 	{
-		internal MtpDeviceHandle handle;
+		internal MtpDeviceHandle Handle;
 		private MtpDeviceStruct device;
 		private string name;
 		private Folder albumFolder;
@@ -54,23 +54,23 @@
 		public int BatteryLevel {
 			get {
 				ushort level, maxLevel;
-				LibMtp.GetBatteryLevel (handle, out maxLevel, out level);
+				LibMtp.GetBatteryLevel (Handle, out maxLevel, out level);
 				return (int)((level * 100.0) / maxLevel);
 			}
 		}
 
         public string SerialNumber {
-            get { return LibMtp.GetSerialnumber (handle); }
+            get { return LibMtp.GetSerialnumber (Handle); }
         }
 
         public string Version {
-            get { return LibMtp.GetDeviceversion (handle); }
+            get { return LibMtp.GetDeviceversion (Handle); }
         }
 
 		public string Name {
 			get { return name; }
             set {
-                if (LibMtp.SetFriendlyName (handle, value)) {
+                if (LibMtp.SetFriendlyName (Handle, value)) {
                     name = value;
                 }
             }
@@ -111,8 +111,8 @@
 		internal MtpDevice (MtpDeviceHandle handle, MtpDeviceStruct device)
 		{
 			this.device = device;
-			this.handle = handle;
-			this.name = LibMtp.GetFriendlyName(handle);
+			this.Handle = handle;
+			this.name = LibMtp.GetFriendlyName(Handle);
 			SetDefaultFolders ();
 		}
 		
@@ -153,8 +153,8 @@
 		
 		public void Dispose ()
 		{
-			if (!handle.IsClosed)
-				handle.Close();
+			if (!Handle.IsClosed)
+				Handle.Close();
 		}
 		
 		public List<Folder> GetRootFolders()
@@ -169,7 +169,7 @@
 		
 		public List<Track> GetAllTracks(ProgressFunction callback)
 		{
-			IntPtr ptr = TrackManagement.GetTrackListing(handle, callback, IntPtr.Zero);
+			IntPtr ptr = TrackManagement.GetTrackListing(Handle, callback, IntPtr.Zero);
 
 			List<Track> tracks = new List<Track>();
 			
@@ -183,6 +183,21 @@
 			
 			return tracks;
 		}
+
+        public List<Album> GetAlbums ()
+        {
+            List<Album> albums = new List<Album> ();
+
+			IntPtr ptr = AlbumManagement.LIBMTP_Get_Album_List (Handle);
+			while (ptr != IntPtr.Zero)
+			{
+				AlbumStruct d = (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct));
+				albums.Add (new Album(this, d));
+				ptr = d.next;
+			}
+			
+            return albums;
+        }
 		
 		
 		public List<DeviceStorage> GetStorage ()
@@ -200,7 +215,7 @@
 		
 		public void Remove (Track track)
 		{
-			LibMtp.DeleteObject(handle, track.FileId);
+			LibMtp.DeleteObject(Handle, track.FileId);
 		}
 		
 		public void UploadTrack (string path, Track track, Folder folder)
@@ -226,9 +241,20 @@
 				throw new ArgumentNullException("track");
 			
 			// We send the trackstruct by ref so that when the file_id gets filled in, our copy is updated
-			TrackManagement.SendTrack (handle, path, ref track.trackStruct, callback, IntPtr.Zero, folder.FolderId);
-			// LibMtp.GetStorage (handle, 0);
+			TrackManagement.SendTrack (Handle, path, ref track.trackStruct, callback, IntPtr.Zero, folder.FolderId);
+			// LibMtp.GetStorage (Handle, 0);
 		}
+
+        public FileType [] GetFileTypes ()
+        {
+            Int16 [] ints = LibMtp.GetFileTypes (Handle);
+            FileType [] file_types = new FileType [ints.Length];
+            for (int i = 0; i < ints.Length; i++) {
+                file_types[i] = (FileType) ints[i];
+            }
+
+            return file_types;
+        }
 		
 		public static List<MtpDevice> Detect ()
 		{

Modified: branches/banshee/stable/ext/libmtp-sharp/Track.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Track.cs	(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Track.cs	Thu Jan 31 06:29:34 2008
@@ -154,50 +154,50 @@
 			if (string.IsNullOrEmpty(path))
 				throw new ArgumentException ("Cannot be null or empty", "path");
 			
-			TrackManagement.GetTrack (device.handle, trackStruct.item_id, path, callback, IntPtr.Zero);
+			TrackManagement.GetTrack (device.Handle, trackStruct.item_id, path, callback, IntPtr.Zero);
 		}
 		
 		public void UpdateMetadata()
 		{
-			TrackManagement.UpdateTrackMetadata(device.handle, ref trackStruct);
+			TrackManagement.UpdateTrackMetadata(device.Handle, ref trackStruct);
 		}
 		
 		private static FileType DetectFiletype(Track track)
 		{
 			if(track.Filename.EndsWith(".asf", System.StringComparison.OrdinalIgnoreCase))
-				return FileType.LIBMTP_FILETYPE_ASF;
+				return FileType.ASF;
 			
 			if(track.Filename.EndsWith(".avi", System.StringComparison.OrdinalIgnoreCase))
-				return  FileType.LIBMTP_FILETYPE_AVI;
+				return  FileType.AVI;
 			
 			if(track.Filename.EndsWith(".BMP", System.StringComparison.OrdinalIgnoreCase))
-				return  FileType.LIBMTP_FILETYPE_BMP;
+				return  FileType.BMP;
 			
 			if(track.Filename.EndsWith(".JPEG", System.StringComparison.OrdinalIgnoreCase)
 			   || track.Filename.EndsWith(".JPG", System.StringComparison.OrdinalIgnoreCase))
-				return FileType.LIBMTP_FILETYPE_JPEG;
+				return FileType.JPEG;
 			
 			if(track.Filename.EndsWith(".MP3", System.StringComparison.OrdinalIgnoreCase))
-				return FileType.LIBMTP_FILETYPE_MP3;
+				return FileType.MP3;
 			
 			if(track.Filename.EndsWith(".MPG", System.StringComparison.OrdinalIgnoreCase)
 			   || track.Filename.EndsWith(".MPEG", System.StringComparison.OrdinalIgnoreCase))
-				return FileType.LIBMTP_FILETYPE_MPEG;
+				return FileType.MPEG;
 			
 			if(track.Filename.EndsWith(".OGG", System.StringComparison.OrdinalIgnoreCase)
 			   || track.Filename.EndsWith(".OGM", System.StringComparison.OrdinalIgnoreCase))
-				return  FileType.LIBMTP_FILETYPE_OGG;
+				return  FileType.OGG;
 						
 			if(track.Filename.EndsWith(".PNG", System.StringComparison.OrdinalIgnoreCase))
-				return  FileType.LIBMTP_FILETYPE_PNG;
+				return  FileType.PNG;
 			
 			if(track.Filename.EndsWith(".WAV", System.StringComparison.OrdinalIgnoreCase))
-				return FileType.LIBMTP_FILETYPE_WAV;
+				return FileType.WAV;
 									
 			if(track.Filename.EndsWith(".WMA", System.StringComparison.OrdinalIgnoreCase))
-				return FileType.LIBMTP_FILETYPE_WMA;
+				return FileType.WMA;
 
-			return  FileType.LIBMTP_FILETYPE_UNKNOWN;
+			return  FileType.UNKNOWN;
 		}
 	}
 }

Modified: branches/banshee/stable/src/Core/Banshee.Base/Dap/DapMisc.cs
==============================================================================
--- branches/banshee/stable/src/Core/Banshee.Base/Dap/DapMisc.cs	(original)
+++ branches/banshee/stable/src/Core/Banshee.Base/Dap/DapMisc.cs	Thu Jan 31 06:29:34 2008
@@ -108,14 +108,14 @@
         public static string GetCodec(string mimeType) 
         {
             foreach (string codec in MimeTypeMap.Keys) {
-                if (System.Array.IndexOf(MimeTypeMap[codec], mimeType) != -1) {
+                if (codec == mimeType || System.Array.IndexOf(MimeTypeMap[codec], mimeType) != -1) {
                     return codec;
                 }
-             }
+            }
 
             LogCore.Instance.PushWarning("Unknown DAP mimetype " + mimeType, "", false);
             return null;
-        } 
+        }
 
         public static string [] GetExtensions(string codec)
         {

Added: branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/AlbumSet.cs
==============================================================================
--- (empty file)
+++ branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/AlbumSet.cs	Thu Jan 31 06:29:34 2008
@@ -0,0 +1,111 @@
+/***************************************************************************
+ *  AlbumSet.cs
+ *
+ *  Copyright (C) 2008 Novell, Inc.
+ *  Authors:
+ *  Gabriel Burt (gburt novell com)
+ ****************************************************************************/
+
+/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
+ *
+ *  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.Collections.Generic;
+
+using Mono.Unix;
+using Gdk;
+
+using Banshee.Dap;
+using Banshee.Base;
+
+using Mtp;
+
+namespace Banshee.Dap.Mtp
+{
+    public class AlbumSet
+    {
+        private MtpDevice device;
+        private List<Album> old_list;
+        private List<Album> new_list = new List<Album> ();
+        private Dictionary<string, Album> hash = new Dictionary<string, Album> ();
+        private Dictionary<Album, TrackInfo> tracks = new Dictionary<Album, TrackInfo> ();
+
+        public AlbumSet (MtpDevice device)
+        {
+            this.device = device;
+            old_list = device.GetAlbums ();
+            hash.Clear ();
+        }
+
+        public void Ref (MtpDapTrackInfo track)
+        {
+            string key = track.Album + track.Artist;
+            if (!hash.ContainsKey (key)) {
+                Album album = new Album (device, track.Album, track.Artist, track.Genre);
+                new_list.Add (album);
+                hash[key] = album;
+            }
+
+            hash [key].AddTrack (track.OriginalFile);
+            tracks [hash[key]] = track;
+        }
+
+        /*public void Unref (MtpDapTrackInfo track)
+        {
+            Unref (track.OriginalFile);
+        }
+
+        public void Unref (Track track)
+        {
+            string key = track.Album + track.Artist;
+            if (hash.ContainsKey (key)) {
+                hash [key].RemoveTrack (track);
+            }
+        }*/
+
+        private const int MAX_THUMB_WIDTH = 170;
+        public void Save ()
+        {
+            foreach (Album album in old_list) {
+                album.Remove ();
+            }
+
+            foreach (Album album in new_list) {
+                if (tracks.ContainsKey (album)) {
+                    string cover_art_file = tracks[album].CoverArtFileName;
+                    if (cover_art_file != null) {
+                        Gdk.Pixbuf pic = new Gdk.Pixbuf (cover_art_file);
+
+                        int new_h = pic.Height * MAX_THUMB_WIDTH / pic.Width;
+                        Gdk.Pixbuf scaled = pic.ScaleSimple (MAX_THUMB_WIDTH, new_h, InterpType.Hyper);
+
+                        byte [] bytes = scaled.SaveToBuffer ("jpeg");
+                        album.Save (bytes, (uint)scaled.Width, (uint)scaled.Height);
+                        scaled.Dispose ();
+                        pic.Dispose ();
+                    }
+                }
+            }
+
+            tracks.Clear ();
+        }
+    }
+}

Modified: branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/Makefile.am
==============================================================================
--- branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/Makefile.am	(original)
+++ branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/Makefile.am	Thu Jan 31 06:29:34 2008
@@ -5,6 +5,7 @@
 
 ASSEMBLY_SOURCES = \
 	$(top_srcdir)/src/AssemblyInfo.cs \
+	$(srcdir)/AlbumSet.cs \
 	$(srcdir)/MtpDap.cs \
 	$(srcdir)/MtpDapTrackInfo.cs \
 	$(srcdir)/MtpDapPlaylistSource.cs

Modified: branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs
==============================================================================
--- branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs	(original)
+++ branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs	Thu Jan 31 06:29:34 2008
@@ -40,6 +40,7 @@
 using Mono;
 using Mono.Unix;
 using Gtk;
+using Gdk;
 
 using Banshee.Dap;
 using Banshee.Base;
@@ -59,8 +60,6 @@
 namespace Banshee.Dap.Mtp
 {
 	[DapProperties (DapType = DapType.NonGeneric)]
-	[SupportedCodec (CodecType.Mp3)]
-	[SupportedCodec (CodecType.Wma)]
 	public sealed class MtpDap : DapDevice, IImportable//, IPlaylistCapable
 	{
         private static MtpDap mtp_dap;
@@ -70,6 +69,8 @@
 		private List<MtpDapTrackInfo> metadataChangedQueue;
 		private Queue<MtpDapTrackInfo> removeQueue;
 		private List<MtpDapTrackInfo> all_tracks;
+
+        private bool supports_jpegs = false;
         
         private string hal_name = String.Empty;
 
@@ -107,7 +108,6 @@
             int vendor_id = hal_device.GetPropertyInteger ("usb.vendor_id");
             string serial = hal_device ["usb.serial"];
 			
-			
 			List<MtpDevice> devices = null;
 			try {
 				devices = MtpDevice.Detect ();
@@ -159,11 +159,42 @@
             );
 
 			base.Initialize (hal_device);
+
+            List<string> extensions = new List<string>();
+            List<string> mimetypes = new List<string>();
+
+            FileType [] file_types = device.GetFileTypes ();
+            StringBuilder format_sb = new StringBuilder ();
+            bool first_format = true;
+            foreach (FileType format in file_types) {
+                if (format == FileType.JPEG) {
+                    supports_jpegs = true;
+                    continue;
+                }
+
+                string codec = Banshee.Dap.CodecType.GetCodec (format.ToString ().ToLower ());
+                
+                if(codec != null) {
+                    extensions.AddRange (CodecType.GetExtensions(codec));
+                    mimetypes.AddRange (CodecType.GetMimeTypes(codec));
+                    if (first_format) {
+                        first_format = false;
+                    } else {
+                        format_sb.Append (", ");
+                    }
+                    format_sb.Append (codec);
+                }
+            }
+
+            SupportedExtensions = extensions.ToArray();
+            SupportedPlaybackMimeTypes = mimetypes.ToArray();
 			
-			InstallProperty ("Vendor", hal_device["usb.vendor"]);
-			InstallProperty ("Model", hal_name);
-			InstallProperty ("Version", device.Version);
-			InstallProperty ("Serial Number", serial);
+			InstallProperty (Catalog.GetString ("Vendor"), hal_device["usb.vendor"]);
+			InstallProperty (Catalog.GetString ("Model"), hal_name);
+            InstallProperty (Catalog.GetString ("Audio Format(s)"), format_sb.ToString ());
+            InstallProperty (Catalog.GetString ("Album Art"), supports_jpegs ? Catalog.GetString ("Yes") : Catalog.GetString ("No"));
+			InstallProperty (Catalog.GetString ("Version"), device.Version);
+			InstallProperty (Catalog.GetString ("Serial Number"), serial);
 
             // Don't continue until the UI is initialized
             if(!Globals.UIManager.IsInitialized) {
@@ -208,7 +239,9 @@
 			if (!metadataChangedQueue.Contains (info))
 				metadataChangedQueue.Add (info);
 		}
-		
+
+
+
 		protected override void Reload ()
 		{
 			// Clear the list of tracks that banshee keeps
@@ -296,18 +329,22 @@
 			// FIXME: Set the length properly
 			// Fixme: update the reference i'm holding to the original music file?
 			// Why am i holding it anyway?
-			Track f =  new Track (name, length);
+			Track f = new Track (name, length);
+            TrackInfoToMtpTrack (track, f);
+            return f;
+        }
+
+        public void TrackInfoToMtpTrack (TrackInfo track, Track f)
+        {
 			f.Album = track.Album;
 			f.Artist = track.Artist;
 			f.Duration = (uint)track.Duration.TotalMilliseconds;
 			f.Genre = track.Genre;
-			f.Rating = (ushort)track.Rating;
+			f.Rating = (ushort)(track.Rating * 20);
 			f.Title = track.Title;
 			f.TrackNumber = (ushort)track.TrackNumber;
-			f.UseCount = track.TrackCount;
-#warning FIX THIS
-			//f.Year = track.Year > 0 ? track.Year : 0;
-			return f;
+			f.UseCount = (uint)track.PlayCount;
+            f.Date = track.Year + "0101T0000.0";
 		}
 		
 		private void RemoveTracks ()
@@ -322,7 +359,7 @@
 				if (!track.OnCamera (device)) {
 					continue;
                 }
-				
+
 				device.Remove (track.OriginalFile);
 				all_tracks.Remove (track);
 				
@@ -356,16 +393,16 @@
 				FileInfo info = new FileInfo (tracks[i].Uri.AbsolutePath);
 				Track f = ToMusicFile (tracks[i], info.Name, (ulong)info.Length);
 				
-				string message = string.Format (
-                    "Adding: {0} - {1}", f.Artist, f.Title
-                );
 				device.UploadTrack (tracks[i].Uri.AbsolutePath, f);
 				
 				// Create an MtpDapTrackInfo for the new file and add it to our lists
 				MtpDapTrackInfo newTrackInfo = new MtpDapTrackInfo (device, f);
 				newTrackInfo.Changed += OnMetadataChanged;
 				
-				UpdateSaveProgress (sync_title, message, (double) (i + 1) / tracks.Count);
+				UpdateSaveProgress (sync_title,
+                    String.Format ("Adding: {0} - {1}", f.Artist, f.Title),
+                    (double) (i + 1) / tracks.Count
+                );
 				all_tracks.Add (newTrackInfo);
 				AddTrack (newTrackInfo);
 			}
@@ -377,37 +414,38 @@
 				for (int i = 0; i < metadataChangedQueue.Count; i++) {
 					MtpDapTrackInfo info = metadataChangedQueue[i];
 					Track file = info.OriginalFile;
-					file.Album = info.Album;
-					file.Artist = info.Artist;
-					//file.DateAdded = info.DateAdded;
-					file.Duration = (uint) info.Duration.TotalMilliseconds;
-					file.Genre = info.Genre;
-					//file.LastPlayed = info.LastPlayed;
-					file.Rating = (ushort) info.Rating;
-					file.Title = info.Title;
-					file.TrackNumber = (ushort) info.TrackNumber;
-					file.UseCount = info.PlayCount;
-					file.Date = info.Year + "0101T0000.0";
+                    TrackInfoToMtpTrack (info, file);
 					file.UpdateMetadata ();
 				}
 			} finally {
 				metadataChangedQueue.Clear ();
 			}
 		}
-		
+
         private string sync_title;
 		public override void Synchronize ()
 		{
 			// 1. remove everything in the remove queue if it's on the device
 			// 2. Add everything in the tracklist that isn't on the device
 			// 3. Sync playlists?
-		    sync_title = String.Format ("Synchronizing {0}", Name);
+		    sync_title = String.Format (Catalog.GetString ("Synchronizing {0}"), Name);
 			try {
 				RemoveTracks ();
 				UpdateMetadata ();
 				UploadTracks ();
+
+                if (supports_jpegs) {
+                    AlbumSet album_set = new AlbumSet (device);
+                    UpdateSaveProgress (sync_title, Catalog.GetString ("Syncing album art"), 0);
+                    foreach (MtpDapTrackInfo track in all_tracks) {
+                        album_set.Ref (track);
+                    }
+                    album_set.Save ();
+                }
 			} catch (Exception e) {
-				LogCore.Instance.PushWarning ("There was an error while synchronizing the current track.  Please file a bug report.", e.ToString ());
+				LogCore.Instance.PushWarning (String.Format (
+                    Catalog.GetString ("There was an unknown error while synchronizing {0}."), Name
+                ), String.Empty);
 			} finally {
 				ClearTracks (false);
 
@@ -426,7 +464,7 @@
 
 		public void Import (IEnumerable<TrackInfo> tracks, PlaylistSource playlist) 
 		{
-			LogCore.Instance.PushDebug ("MTP: importing tracks", "");
+			LogCore.Instance.PushDebug ("MTP: importing tracks", String.Empty);
 			if (playlist != null) {
 				LogCore.Instance.PushDebug ("Playlist importing not supported",
 				                           "Banshee does not support importing playlists from MTP devices yet...");
@@ -441,7 +479,6 @@
 			importer.UserEvent.Message = Catalog.GetString ("Scanning...");
 			importer.OperationRequested += OnImportOperationRequested;
 			importer.Finished += delegate {
-				importer.UserEvent.Message = "Import complete...";
 				importer.UserEvent.Dispose ();
 			};
 			
@@ -463,19 +500,21 @@
 		private void OnImportOperationRequested (object o, QueuedOperationArgs args) 
 		{
 			if (!(args.Object is MtpDapTrackInfo)) {
-				LogCore.Instance.PushDebug ("Import failure", String.Format (
-                    "An attempt to import a '{0}' was detected. Can only import MtpDapTrackInfo objects", args.Object.GetType ().Name)
+				LogCore.Instance.PushDebug ("Import failure",
+                    String.Format ("An attempt to import a '{0}' was detected. Can only import MtpDapTrackInfo objects",
+                        args.Object.GetType ().Name
+                    )
                 );
 				return;
 			}
 			
 			QueuedOperationManager importer = (QueuedOperationManager)o;
-			MtpDapTrackInfo track = (MtpDapTrackInfo)args.Object;
 
 			if (importer.UserEvent.IsCancelRequested) {
-				importer.UserEvent.Message = "Cancelled";
 				return;
 			}
+
+			MtpDapTrackInfo track = (MtpDapTrackInfo)args.Object;
 			
 			importer.UserEvent.Progress = importer.ProcessedCount / (double)importer.TotalCount;
 			importer.UserEvent.Message = string.Format ("{0}/{1}: {2} - {3}", importer.ProcessedCount, importer.TotalCount, track.DisplayArtist, track.DisplayTitle);
@@ -607,6 +646,5 @@
 		public override bool IsPlaybackSupported {
 			get { return false; }
 		}
-
 	}
 }

Modified: branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs
==============================================================================
--- branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs	(original)
+++ branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs	Thu Jan 31 06:29:34 2008
@@ -51,22 +51,24 @@
             this.camera = camera;
             this.file = file;
 			
-			album = file.Album;
-            artist = file.Artist;
-            duration = TimeSpan.FromMilliseconds(file.Duration);
-            genre = file.Genre;
-            play_count = file.UseCount < 0 ? (uint)0 : (uint)file.UseCount;
-            rating = file.Rating < 0 ? (uint)0 : (uint)file.Rating;
-            title = file.Title;
-            track_number = file.TrackNumber < 0 ? (uint)0 : file.TrackNumber;
-            year = (file.Date != null && file.Date.Length >= 4) ? int.Parse(file.Date.Substring(0, 4)) : 0;
+			Album = file.Album;
+            Artist = file.Artist;
+            Duration = TimeSpan.FromMilliseconds(file.Duration);
+            Genre = file.Genre;
+            PlayCount = file.UseCount < 0 ? (uint)0 : (uint)file.UseCount;
+            Rating = file.Rating < 0 ? (uint) 0 : (uint) (file.Rating / 20);
+            Title = file.Title;
+            TrackNumber = file.TrackNumber < 0 ? (uint)0 : file.TrackNumber;
+            Year = (file.Date != null && file.Date.Length >= 4) ? int.Parse(file.Date.Substring(0, 4)) : 0;
+            //Filesize = file.Filesize; // Unfortunately this info is currently stat'd when needed
 
-            CanPlay = false;             // This can be implemented if there's enough people requesting it
+            // This can be implemented if there's enough people requesting it
+            CanPlay = false;             
             CanSaveToDatabase = true;
             NeedSync = false;
 
 			// Set a URI even though it's not actually accessible through normal API's.
-			uri = new SafeUri("mtp://invalid");
+			uri = new SafeUri(String.Format ("mtp://{0}", file.Filename));
         }
         
         public override bool Equals (object o)



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