banshee r3826 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Sources src/Dap/Banshee.Dap.Ipod src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod src/Dap/Banshee.Dap/Banshee.Dap



Author: abock
Date: Fri Apr 25 02:15:00 2008
New Revision: 3826
URL: http://svn.gnome.org/viewvc/banshee?rev=3826&view=rev

Log:
2008-04-24  Aaron Bockover  <abock gnome org>

    * src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs: Added
    a PurgeTracks method that will nuke all entries in CoreTracks with
    a matching primary source ID

    * src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs: Read the
    track database from the iPod

    * src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs: Map the
    iPod tracks to Banshee database tracks

    * src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs: Call LoadDeviceContents
    after creating a DapSource

    * src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs: Added LoadDeviceContents
    and a virtual LoadFromDevice method; LoadFromDevice should be implemented
    by DapSources and will run async - currently only used by IpodSource



Added:
   trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
   trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.mdp
   trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs
   trunk/banshee/src/Dap/Banshee.Dap.Ipod/Makefile.am
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	Fri Apr 25 02:15:00 2008
@@ -88,6 +88,10 @@
             DELETE FROM CoreArtists WHERE ArtistID NOT IN (SELECT ArtistID FROM CoreTracks);
             DELETE FROM CoreAlbums WHERE AlbumID NOT IN (SELECT AlbumID FROM CoreTracks)
         ");
+        
+        protected HyenaSqliteCommand purge_tracks_command = new HyenaSqliteCommand (@"
+            DELETE FROM CoreTracks WHERE PrimarySourceId = ?
+        ");
 
         protected int dbid;
         public int DbId {
@@ -273,6 +277,11 @@
         {
             OnTracksDeleted ();
         }
+        
+        protected virtual void PurgeTracks ()
+        {
+            ServiceManager.DbConnection.Execute (purge_tracks_command, DbId);
+        }
 
         protected override void RemoveTrackRange (DatabaseTrackListModel model, RangeCollection.Range range)
         {
@@ -437,7 +446,9 @@
             get {
                 lock (this) {
                     if (add_track_job == null) {
-                        add_track_job = new BatchUserJob (String.Format (Catalog.GetString ("Adding {0} of {1} to {2}"), "{0}", "{1}", Name), Properties.GetStringList ("Icon.Name"));
+                        add_track_job = new BatchUserJob (String.Format (Catalog.GetString (
+                            "Adding {0} of {1} to {2}"), "{0}", "{1}", Name), 
+                            Properties.GetStringList ("Icon.Name"));
                         //add_track_job.DelayShow = true;
                         add_track_job.Register ();
                     }
@@ -451,8 +462,9 @@
             get {
                 lock (this) {
                     if (delete_track_job == null) {
-                        delete_track_job = new BatchUserJob (String.Format (Catalog.GetString ("Deleting {0} of {1} From {2}"), "{0}", "{1}", Name),
-                                Properties.GetStringList ("Icon.Name"));
+                        delete_track_job = new BatchUserJob (String.Format (Catalog.GetString (
+                            "Deleting {0} of {1} From {2}"), "{0}", "{1}", Name),
+                            Properties.GetStringList ("Icon.Name"));
                         //delete_track_job.DelayShow = true;
                         delete_track_job.Register ();
                     }
@@ -461,12 +473,10 @@
             }
         }
 
-
         protected override void PruneArtistsAlbums ()
         {
             ServiceManager.DbConnection.Execute (prune_artists_albums_command);
             base.PruneArtistsAlbums ();
         }
-
     }
 }

Modified: trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.mdp
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.mdp	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.mdp	Fri Apr 25 02:15:00 2008
@@ -12,6 +12,7 @@
     <File name="Banshee.Dap.Ipod/IpodSource.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Dap.Ipod/PodSleuthDeviceProvider.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Dap.Ipod/PodSleuthDevice.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Dap.Ipod/IpodTrackInfo.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="Banshee.Core" />

Modified: trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs	Fri Apr 25 02:15:00 2008
@@ -98,7 +98,8 @@
                     }
                 }
                 database_supported = true;
-            } catch (DatabaseReadException) {
+            } catch (DatabaseReadException e) {
+                Log.Exception ("Could not read iPod database", e);
                 ipod_device.LoadTrackDatabase (true);
                 database_supported = false;
             } catch (Exception e) {
@@ -115,7 +116,7 @@
                 int file_count = 0;
                 
                 DirectoryInfo m_dir = new DirectoryInfo (Path.Combine (ipod_device.ControlPath, "Music"));
-                foreach (DirectoryInfo f_dir in m_dir.GetDirectories()) {
+                foreach (DirectoryInfo f_dir in m_dir.GetDirectories ()) {
                     file_count += f_dir.GetFiles().Length;
                 }
                 
@@ -125,6 +126,40 @@
             }
         }
         
+        // WARNING: This will be called from a thread!
+        protected override void LoadFromDevice ()
+        {
+            LoadFromDevice (false);
+        }
+        
+        private void LoadFromDevice (bool refresh)
+        {
+            // bool previous_database_supported = database_supported;
+            
+            if (refresh) {
+                ipod_device.TrackDatabase.Reload ();
+            }
+             
+            if (database_supported || (ipod_device.HasTrackDatabase && 
+                ipod_device.ModelInfo.DeviceClass == "shuffle")) {
+                foreach (Track ipod_track in ipod_device.TrackDatabase.Tracks) {
+                    IpodTrackInfo track = new IpodTrackInfo (ipod_track);
+                    track.PrimarySource = this;
+                    track.Save (false);
+                }
+            } 
+            
+            /*else {
+                BuildDatabaseUnsupportedWidget ();
+            }*/
+            
+            /*if(previous_database_supported != database_supported) {
+                OnPropertiesChanged();
+            }*/
+            
+            OnTracksAdded ();
+        }
+        
 #endregion
 
 #region Source Cosmetics

Added: trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs	Fri Apr 25 02:15:00 2008
@@ -0,0 +1,119 @@
+//
+// IpodTrackInfo.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 Banshee.Base;
+using Banshee.Collection;
+using Banshee.Collection.Database;
+
+namespace Banshee.Dap.Ipod
+{   
+    public class IpodTrackInfo : DatabaseTrackInfo
+    {
+        private IPod.Track track;
+        internal IPod.Track IpodTrack {
+            get { return track; }
+        }
+        
+        private int ipod_id;
+        internal int IpodId {
+            get { return ipod_id; }
+        }
+        
+        public IpodTrackInfo (IPod.Track track) : base ()
+        {
+            this.track = track;
+            LoadFromIpodTrack ();
+            CanSaveToDatabase = true;
+        }
+        
+        public IpodTrackInfo (TrackInfo track, IPod.TrackDatabase database)
+        {
+            if (track is IpodTrackInfo) {
+                this.track = ((IpodTrackInfo)track).IpodTrack;
+                LoadFromIpodTrack ();
+            } else {
+                Uri = track.Uri;
+                AlbumTitle = track.AlbumTitle;
+                ArtistName = track.ArtistName;
+                TrackTitle = track.TrackTitle;
+                Genre = track.Genre;
+                Duration = track.Duration;
+                Rating = track.Rating;
+                PlayCount = track.PlayCount;
+                LastPlayed = track.LastPlayed;
+                DateAdded = track.DateAdded;
+                TrackCount = track.TrackCount;
+                TrackNumber = track.TrackNumber;
+                Year = track.Year;
+            }
+            
+            CanSaveToDatabase = true;
+        }
+        
+        private void LoadFromIpodTrack ()
+        {
+            try {
+                Uri = new SafeUri (track.Uri.LocalPath);
+            } catch { 
+                Uri = null;
+            }
+
+            ipod_id = (int)track.Id;
+            Duration = track.Duration;
+            PlayCount = track.PlayCount;
+
+            AlbumTitle = String.IsNullOrEmpty (track.Album) ? null : track.Album;
+            ArtistName = String.IsNullOrEmpty (track.Artist) ? null : track.Artist;
+            TrackTitle = String.IsNullOrEmpty (track.Title) ? null : track.Title;
+            Genre = String.IsNullOrEmpty (track.Genre) ? null : track.Genre;
+            
+            switch (track.Rating) {
+                case IPod.TrackRating.One:   Rating = 1; break;
+                case IPod.TrackRating.Two:   Rating = 2; break;
+                case IPod.TrackRating.Three: Rating = 3; break;
+                case IPod.TrackRating.Four:  Rating = 4; break;
+                case IPod.TrackRating.Five:  Rating = 5; break;
+                case IPod.TrackRating.Zero: 
+                default:                     Rating = 0; break;
+            }
+            
+            LastPlayed = track.LastPlayed;
+            DateAdded = track.DateAdded;
+            TrackCount = track.TotalTracks;
+            TrackNumber = track.TrackNumber;
+            Year = track.Year;
+
+            if (track.IsProtected) {
+                CanPlay = false;
+                // FIXME: indicate the song is DRMed
+            }
+        }
+    }
+}

Modified: trunk/banshee/src/Dap/Banshee.Dap.Ipod/Makefile.am
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Ipod/Makefile.am	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Ipod/Makefile.am	Fri Apr 25 02:15:00 2008
@@ -4,6 +4,7 @@
 
 SOURCES =  \
 	Banshee.Dap.Ipod/IpodSource.cs \
+	Banshee.Dap.Ipod/IpodTrackInfo.cs \
 	Banshee.Dap.Ipod/PodSleuthDevice.cs \
 	Banshee.Dap.Ipod/PodSleuthDeviceProvider.cs
 

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs	Fri Apr 25 02:15:00 2008
@@ -102,7 +102,9 @@
         {
             foreach (TypeExtensionNode node in supported_dap_types) {
                 try {
-                    return (DapSource)Activator.CreateInstance (node.Type, new object [] { device });
+                    DapSource source = (DapSource)Activator.CreateInstance (node.Type, new object [] { device });
+                    source.LoadDeviceContents ();
+                    return source;
                 } catch (System.Reflection.TargetInvocationException e) {
                     if (!(e.InnerException is InvalidDeviceException)) {
                         Log.Exception (e);

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	Fri Apr 25 02:15:00 2008
@@ -44,7 +44,7 @@
 
 namespace Banshee.Dap
 {
-    public abstract class DapSource : RemovableSource
+    public abstract class DapSource : RemovableSource, IDisposable
     {
         private IDevice device;
         internal IDevice Device {
@@ -57,6 +57,11 @@
             type_unique_id = device.Uuid;
         }
 
+        public override void Dispose ()
+        {
+            PurgeTracks ();
+        }
+
 #region Source
 
         protected override void Initialize ()
@@ -99,8 +104,26 @@
         
 #endregion
         
-#region Track Management/Syncing       
+#region Track Management/Syncing   
+
+        internal void LoadDeviceContents ()
+        {
+            ThreadPool.QueueUserWorkItem (ThreadedLoadDeviceContents);
+        }
+        
+        private void ThreadedLoadDeviceContents (object state)
+        {
+            PurgeTracks ();
+            SetStatus (String.Format (Catalog.GetString ("Loading {0}"), Name), false);
+            LoadFromDevice ();
+            OnTracksAdded ();
+            HideStatus ();
+        }
 
+        protected virtual void LoadFromDevice ()
+        {
+        }
+        
         protected abstract void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri);  
 
         protected bool TrackNeedsTranscoding (TrackInfo track)



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