[banshee] [Dap.MassStorage] Make sure loaded before auto-sync



commit 4c17d342b4d3c536f1322c86489458d5d8a33ff3
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Tue Jan 26 10:44:08 2010 -0800

    [Dap.MassStorage] Make sure loaded before auto-sync

 .../Banshee.Dap.MassStorage/MassStorageSource.cs   |   56 +++++++++++---------
 1 files changed, 30 insertions(+), 26 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
index e6ad7f1..3e687c6 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
@@ -137,52 +137,56 @@ namespace Banshee.Dap.MassStorage
             }*/
         }
 
+        private System.Threading.ManualResetEvent import_reset_event;
         private DatabaseImportManager importer;
         // WARNING: This will be called from a thread!
         protected override void LoadFromDevice ()
         {
+            import_reset_event = new System.Threading.ManualResetEvent (false);
+
             importer = new DatabaseImportManager (this);
             importer.KeepUserJobHidden = true;
-            importer.Threaded = false; // We are already threaded
             importer.Finished += OnImportFinished;
 
             foreach (string audio_folder in BaseDirectories) {
                 importer.Enqueue (audio_folder);
             }
+
+            import_reset_event.WaitOne ();
         }
 
         private void OnImportFinished (object o, EventArgs args)
         {
             importer.Finished -= OnImportFinished;
 
-            if (!CanSyncPlaylists) {
-                return;
-            }
-
-            Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
-                "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
-            int [] psources = new int [] {DbId};
-            foreach (string playlist_path in PlaylistFiles) {
-                IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path, new Uri (BaseDirectory));
-                if (loaded_playlist == null)
-                    continue;
-
-                PlaylistSource playlist = new PlaylistSource (System.IO.Path.GetFileNameWithoutExtension (playlist_path), this);
-                playlist.Save ();
-                //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
-                foreach (Dictionary<string, object> element in loaded_playlist.Elements) {
-                    string track_path = (element["uri"] as Uri).LocalPath;
-                    int track_id = DatabaseTrackInfo.GetTrackIdForUri (new SafeUri (track_path), psources);
-                    if (track_id == 0) {
-                        Log.DebugFormat ("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path);
-                    } else {
-                        ServiceManager.DbConnection.Execute (insert_cmd, playlist.DbId, track_id);
+            if (CanSyncPlaylists) {
+                var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
+                    "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
+                int [] psources = new int [] {DbId};
+                foreach (string playlist_path in PlaylistFiles) {
+                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path, new Uri (BaseDirectory));
+                    if (loaded_playlist == null)
+                        continue;
+
+                    PlaylistSource playlist = new PlaylistSource (System.IO.Path.GetFileNameWithoutExtension (playlist_path), this);
+                    playlist.Save ();
+                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
+                    foreach (Dictionary<string, object> element in loaded_playlist.Elements) {
+                        string track_path = (element["uri"] as Uri).LocalPath;
+                        int track_id = DatabaseTrackInfo.GetTrackIdForUri (new SafeUri (track_path), psources);
+                        if (track_id == 0) {
+                            Log.DebugFormat ("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path);
+                        } else {
+                            ServiceManager.DbConnection.Execute (insert_cmd, playlist.DbId, track_id);
+                        }
                     }
+                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false;
+                    playlist.UpdateCounts ();
+                    AddChildSource (playlist);
                 }
-                //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false;
-                playlist.UpdateCounts ();
-                AddChildSource (playlist);
             }
+
+            import_reset_event.Set ();
         }
 
         public override void CopyTrackTo (DatabaseTrackInfo track, SafeUri uri, BatchUserJob job)



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