banshee r3884 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Playlist src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp src/Libraries/Mtp/Mtp
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3884 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Playlist src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp src/Libraries/Mtp/Mtp
- Date: Tue, 6 May 2008 03:47:28 +0100 (BST)
Author: gburt
Date: Tue May 6 02:47:27 2008
New Revision: 3884
URL: http://svn.gnome.org/viewvc/banshee?rev=3884&view=rev
Log:
2008-05-05 Gabriel Burt <gabriel burt gmail com>
* src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/AlbumSet.cs:
* src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpDap.cs: Removed old files.
* src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs: Add and remove
album art as needed when adding/removing files.
* src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs:
* src/Core/Banshee.Services/Banshee.Playlist/AbstractPlaylistSource.cs:
Move DeleteSelectedTracks handler to Abstract class so is inherited by
SmartPlaylistSource too.
* src/Libraries/Mtp/Mtp/Album.cs: Add public GetById method.
* src/Libraries/Mtp/Mtp/MtpDevice.cs: Add FileType to mimetype method.
Removed:
trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/AlbumSet.cs
trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpDap.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/AbstractPlaylistSource.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs
trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
trunk/banshee/src/Libraries/Mtp/Mtp/Album.cs
trunk/banshee/src/Libraries/Mtp/Mtp/MtpDevice.cs
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/AbstractPlaylistSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/AbstractPlaylistSource.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/AbstractPlaylistSource.cs Tue May 6 02:47:27 2008
@@ -164,6 +164,14 @@
Update ();
}
+ // Have our parent handle deleting tracks
+ public override void DeleteSelectedTracks ()
+ {
+ if (Parent is PrimarySource) {
+ (Parent as PrimarySource).DeleteSelectedTracksFromChild (this);
+ }
+ }
+
public override bool ShowBrowser {
get { return (Parent is DatabaseSource) ? (Parent as DatabaseSource).ShowBrowser : base.ShowBrowser; }
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs Tue May 6 02:47:27 2008
@@ -179,14 +179,6 @@
}
}
- // Have our parent handle deleting tracks
- public override void DeleteSelectedTracks ()
- {
- if (Parent is PrimarySource) {
- (Parent as PrimarySource).DeleteSelectedTracksFromChild (this);
- }
- }
-
#endregion
#region IUnmapableSource Implementation
Modified: trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs Tue May 6 02:47:27 2008
@@ -40,6 +40,7 @@
using Banshee.ServiceStack;
using Banshee.Library;
using Banshee.Sources;
+using Banshee.Configuration;
using Banshee.Collection;
using Banshee.Collection.Database;
using Banshee.Hardware;
@@ -55,6 +56,12 @@
//private bool supports_jpegs = false;
private Dictionary<int, Track> track_map;
+ private Dictionary<string, Album> album_cache = new Dictionary<string, Album> ();
+
+ private bool supports_jpegs = false;
+ private bool can_sync = NeverSyncAlbumArtSchema.Get () == false;
+ private int thumb_width = AlbumArtWidthSchema.Get ();
+
public override void DeviceInitialize (IDevice device)
{
base.DeviceInitialize (device);
@@ -119,7 +126,18 @@
Name = mtp_device.Name;
Initialize ();
- //ServiceManager.DbConnection.Execute ("
+ List<string> mimetypes = new List<string> ();
+ foreach (FileType format in mtp_device.GetFileTypes ()) {
+ if (format == FileType.JPEG) {
+ supports_jpegs = true;
+ } else {
+ string mimetype = MtpDevice.GetMimeTypeFor (format);
+ if (mimetype != null) {
+ mimetypes.Add (mimetype);
+ }
+ }
+ }
+ AcceptableMimeTypes = mimetypes.ToArray ();
ThreadPool.QueueUserWorkItem (delegate {
track_map = new Dictionary<int, Track> ();
@@ -230,17 +248,44 @@
Track mtp_track = TrackInfoToMtpTrack (track, fromUri);
bool video = (track.MediaAttributes & TrackMediaAttributes.VideoStream) != 0;
Console.WriteLine ("Sending file {0}, is video? {1}", fromUri.LocalPath, video);
- // TODO send callback for smoother progress bar
lock (mtp_device) {
mtp_device.UploadTrack (fromUri.LocalPath, mtp_track, video ? mtp_device.VideoFolder : mtp_device.MusicFolder, OnUploadProgress);
}
+ // Add/update album art
+ if (!video) {
+ string key = MakeAlbumKey (track.ArtistName, track.AlbumTitle);
+ if (!album_cache.ContainsKey (key)) {
+ Album album = new Album (mtp_device, track.AlbumTitle, track.ArtistName, track.Genre);
+ album.AddTrack (mtp_track);
+
+ if (supports_jpegs && can_sync) {
+ try {
+ Gdk.Pixbuf pic = ServiceManager.Get<Banshee.Collection.Gui.ArtworkManager> ().LookupScale (
+ CoverArtSpec.CreateArtistAlbumId (track.ArtistName, track.AlbumTitle), thumb_width
+ );
+ if (pic != null) {
+ byte [] bytes = pic.SaveToBuffer ("jpeg");
+ album.Save (bytes, (uint)pic.Width, (uint)pic.Height);
+ pic.Dispose ();
+ }
+ album_cache[key] = album;
+ } catch {}
+ }
+ } else {
+ Album album = album_cache[key];
+ album.AddTrack (mtp_track);
+ album.Save ();
+ }
+ }
+
MtpTrackInfo new_track = new MtpTrackInfo (mtp_track);
new_track.PrimarySource = this;
new_track.Save (false);
track_map[new_track.TrackId] = mtp_track;
}
+
private int OnUploadProgress (ulong sent, ulong total, IntPtr data)
{
AddTrackJob.DetailedProgress = (double) sent / (double) total;
@@ -250,8 +295,22 @@
protected override void DeleteTrack (DatabaseTrackInfo track)
{
lock (mtp_device) {
- mtp_device.Remove (track_map [track.TrackId]);
+ Track mtp_track = track_map [track.TrackId];
track_map.Remove (track.TrackId);
+
+ // Remove from device
+ mtp_device.Remove (mtp_track);
+
+ // Remove track from album, and remove album from device if it no longer has tracks
+ string key = MakeAlbumKey (track.ArtistName, track.AlbumTitle);
+ if (album_cache.ContainsKey (key)) {
+ Album album = album_cache[key];
+ album.RemoveTrack (track_map[track.TrackId]);
+ if (album.TrackCount == 0) {
+ album.Remove ();
+ album_cache.Remove (key);
+ }
+ }
}
}
@@ -290,5 +349,24 @@
{
Dispose ();
}
+
+ private static string MakeAlbumKey (string artist, string album)
+ {
+ return String.Format ("{0}_{1}", artist, album);
+ }
+
+ public static readonly SchemaEntry<bool> NeverSyncAlbumArtSchema = new SchemaEntry<bool>(
+ "plugins.mtp", "never_sync_albumart",
+ false,
+ "Album art disabled",
+ "Regardless of device's capabilities, do not sync album art"
+ );
+
+ public static readonly SchemaEntry<int> AlbumArtWidthSchema = new SchemaEntry<int>(
+ "plugins.mtp", "albumart_max_width",
+ 170,
+ "Album art max width",
+ "The maximum width to allow for album art."
+ );
}
}
Modified: trunk/banshee/src/Libraries/Mtp/Mtp/Album.cs
==============================================================================
--- trunk/banshee/src/Libraries/Mtp/Mtp/Album.cs (original)
+++ trunk/banshee/src/Libraries/Mtp/Mtp/Album.cs Tue May 6 02:47:27 2008
@@ -185,6 +185,16 @@
return String.Format ("Album < Id: {4}, '{0}' by '{1}', genre '{2}', tracks {3} >", Name, Artist, Genre, TrackCount, AlbumId);
}
+ public static Album GetById (MtpDevice device, uint id)
+ {
+ IntPtr ptr = Album.LIBMTP_Get_Album (device.Handle, id);
+ if (ptr == IntPtr.Zero) {
+ return null;
+ } else {
+ return new Album (device, (AlbumStruct) Marshal.PtrToStructure(ptr, typeof (AlbumStruct)));
+ }
+ }
+
[DllImport("libmtp.dll")]
internal static extern IntPtr LIBMTP_new_album_t (); // LIBMTP_album_t*
Modified: trunk/banshee/src/Libraries/Mtp/Mtp/MtpDevice.cs
==============================================================================
--- trunk/banshee/src/Libraries/Mtp/Mtp/MtpDevice.cs (original)
+++ trunk/banshee/src/Libraries/Mtp/Mtp/MtpDevice.cs Tue May 6 02:47:27 2008
@@ -445,6 +445,24 @@
int LIBMTP_Get_Device_Certificate (LIBMTP_mtpdevice_t *, char **const)
*/
+ public static string GetMimeTypeFor (FileType type)
+ {
+ switch (type) {
+ case FileType.MP3: return "audio/mpeg";
+ case FileType.OGG: return "audio/ogg";
+ case FileType.WMA: return "audio/x-ms-wma";
+ case FileType.WMV: return "video/x-ms-wmv";
+ case FileType.ASF: return "video/x-ms-asf";
+ case FileType.AAC: return "audio/x-aac";
+ case FileType.MP4: return "video/mp4";
+ case FileType.AVI: return "video/avi";
+ case FileType.WAV: return "audio/x-wav";
+ case FileType.MPEG: return "video/mpeg";
+ case FileType.FLAC: return "audio/flac";
+ case FileType.QT: return "video/quicktime";
+ }
+ return null;
+ }
}
[StructLayout(LayoutKind.Sequential)]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]