banshee r3347 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Base src/Core/Banshee.Services/Banshee.Collection src/Core/Banshee.Services/Banshee.Library src/Core/Banshee.Services/Banshee.ServiceStack src/Core/Banshee.ThickClient/Banshee.Gui src/Core/Banshee.ThickClient/Banshee.Gui.Widgets
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3347 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Base src/Core/Banshee.Services/Banshee.Collection src/Core/Banshee.Services/Banshee.Library src/Core/Banshee.Services/Banshee.ServiceStack src/Core/Banshee.ThickClient/Banshee.Gui src/Core/Banshee.ThickClient/Banshee.Gui.Widgets
- Date: Thu, 28 Feb 2008 04:41:45 +0000 (GMT)
Author: abock
Date: Thu Feb 28 04:41:45 2008
New Revision: 3347
URL: http://svn.gnome.org/viewvc/banshee?rev=3347&view=rev
Log:
2008-02-27 Aaron Bockover <abock gnome org>
* src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs: Do not set the
main thread automatically and instead require an explicit call to a new
InitializeMainThread method just for sanity to avoid possible race
* src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs: Call
ThreadAssist.InitializeMainThread
* src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs:
Enable the database URI pre-check when importing, minor clean up,
wrap the commits in database transactions, and do an explicit save
on the LibraryAlbumInfo (not sure if this is correct)
* src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTileHost.cs:
Fixed a big threading bug - the actual user job/manager API is designed
to be consumed from many threads, and the UI host for the jobs has to
manage threading; this fixes some odd UI behavior after library imports
* src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTile.cs: Use
generic/type-safe service manager methods
* src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs: Some
clean up, remove an anonymous method to make more readable
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJob.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJobManager.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTile.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTileHost.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs Thu Feb 28 04:41:45 2008
@@ -35,13 +35,19 @@
{
private static Thread main_thread;
- static ThreadAssist ()
+ public static void InitializeMainThread ()
{
main_thread = Thread.CurrentThread;
}
public static bool InMainThread {
- get { return main_thread.Equals (Thread.CurrentThread); }
+ get {
+ if (main_thread == null) {
+ throw new ApplicationException ("ThreadAssist.InitializeMainThread must be called first");
+ }
+
+ return main_thread.Equals (Thread.CurrentThread);
+ }
}
public static void ProxyToMain (EventHandler handler)
@@ -49,7 +55,7 @@
if (!InMainThread) {
Banshee.ServiceStack.Application.Invoke (handler);
} else {
- handler (null, new EventArgs ());
+ handler (null, EventArgs.Empty);
}
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs Thu Feb 28 04:41:45 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2006-2007 Novell, Inc.
+// Copyright (C) 2006-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -69,7 +69,7 @@
private void CreateUserJob ()
{
lock (user_job_mutex) {
- if(user_job != null) {
+ if (user_job != null) {
return;
}
@@ -86,8 +86,8 @@
private void DestroyUserJob ()
{
- lock(user_job_mutex) {
- if(user_job == null) {
+ lock (user_job_mutex) {
+ if (user_job == null) {
return;
}
@@ -108,7 +108,7 @@
double new_progress = (double)processed_count / (double)total_count;
double old_progress = user_job.Progress;
- if(new_progress >= 0.0 && new_progress <= 1.0 && Math.Abs (new_progress - old_progress) > 0.001) {
+ if (new_progress >= 0.0 && new_progress <= 1.0 && Math.Abs (new_progress - old_progress) > 0.001) {
string disp_progress = String.Format (ProgressMessage, processed_count, total_count);
user_job.Title = disp_progress;
@@ -119,8 +119,8 @@
private void CheckForCanceled ()
{
- lock(user_job_mutex) {
- if(user_job != null && user_job.IsCancelRequested) {
+ lock (user_job_mutex) {
+ if (user_job != null && user_job.IsCancelRequested) {
throw new ImportCanceledException ();
}
}
@@ -135,7 +135,7 @@
private void Enqueue (string path)
{
- if(path_queue.Contains (path)) {
+ if (path_queue.Contains (path)) {
return;
}
@@ -148,29 +148,9 @@
public void QueueSource (UriList uris)
{
CreateUserJob ();
-
- ThreadPool.QueueUserWorkItem (delegate {
- try {
- foreach (string path in uris.LocalPaths) {
- Interlocked.Increment (ref scan_ref_count);
- ScanForFiles (path);
- Interlocked.Decrement (ref scan_ref_count);
- }
-
- if(scan_ref_count == 0) {
- ProcessQueue ();
- }
- } catch (ImportCanceledException) {
- FinalizeImport ();
- }
- });
+ ThreadPool.QueueUserWorkItem (ThreadedQueueSource, uris);
}
- // public void QueueSource (Gtk.SelectionData selection)
- // {
- // QueueSource (new UriList (System.Text.Encoding.UTF8.GetString (selection.Data)));
- // }
-
public void QueueSource (string source)
{
QueueSource (new UriList (source));
@@ -180,6 +160,25 @@
{
QueueSource (new UriList (paths));
}
+
+ private void ThreadedQueueSource (object o)
+ {
+ UriList uris = (UriList)o;
+
+ try {
+ foreach (string path in uris.LocalPaths) {
+ Interlocked.Increment (ref scan_ref_count);
+ ScanForFiles (path);
+ Interlocked.Decrement (ref scan_ref_count);
+ }
+
+ if(scan_ref_count == 0) {
+ ProcessQueue ();
+ }
+ } catch (ImportCanceledException) {
+ FinalizeImport ();
+ }
+ }
private void ScanForFiles (string source)
{
@@ -201,7 +200,7 @@
if (is_regular_file) {
try {
- if (!Path.GetFileName (source).StartsWith(".")) {
+ if (!Path.GetFileName (source).StartsWith (".")) {
Enqueue (source);
}
} catch (System.ArgumentException) {
@@ -248,7 +247,7 @@
path_queue.Clear ();
processing_queue = false;
- if(scan_ref_count == 0) {
+ if (scan_ref_count == 0) {
DestroyUserJob ();
OnImportFinished ();
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs Thu Feb 28 04:41:45 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -97,9 +97,9 @@
try {
DatabaseTrackInfo track = AddTrackToLibrary (path);
-
if (track != null && track.DbId > 0) {
- IncrementProcessedCount (String.Format ("{0} - {1}", track.DisplayArtistName, track.DisplayTrackTitle));
+ IncrementProcessedCount (String.Format ("{0} - {1}",
+ track.DisplayArtistName, track.DisplayTrackTitle));
}
} catch (Exception e) {
LogError (path, e);
@@ -116,13 +116,13 @@
{
DatabaseTrackInfo track = null;
- /*if (DatabaseTrackInfo.ContainsUri (uri)) {
+ if (DatabaseTrackInfo.ContainsUri (uri)) {
IncrementProcessedCount (null);
return null;
- }*/
+ }
- //ServiceManager.DbConnection.BeginTransaction ();
- //try {
+ ServiceManager.DbConnection.BeginTransaction ();
+ try {
TagLib.File file = StreamTagger.ProcessUri (uri);
track = new DatabaseTrackInfo ();
StreamTagger.TrackInfoMerge (track, file);
@@ -132,21 +132,24 @@
track.Uri = newpath;
}
- track.DateAdded = DateTime.Now;
LibraryArtistInfo artist = new LibraryArtistInfo (track.ArtistName);
- track.ArtistId = artist.DbId;
- track.AlbumId = new LibraryAlbumInfo (artist, track.AlbumTitle).DbId;
+ LibraryAlbumInfo album = new LibraryAlbumInfo (artist, track.AlbumTitle);
- artist.Save ();
+ track.ArtistId = artist.DbId;
+ track.AlbumId = album.DbId;
+ track.DateAdded = DateTime.Now;
track.Source = ServiceManager.SourceManager.Library;
+ album.Save ();
+ artist.Save ();
track.Save ();
- //ServiceManager.DbConnection.CommitTransaction ();
- /*} catch (Exception) {
+
+ ServiceManager.DbConnection.CommitTransaction ();
+ } catch (Exception) {
ServiceManager.DbConnection.RollbackTransaction ();
throw;
- }*/
+ }
return track;
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJob.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJob.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJob.cs Thu Feb 28 04:41:45 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJobManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJobManager.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.ServiceStack/UserJobManager.cs Thu Feb 28 04:41:45 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -89,7 +89,7 @@
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
{
- return GetEnumerator();
+ return GetEnumerator ();
}
string IService.ServiceName {
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTile.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTile.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTile.cs Thu Feb 28 04:41:45 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -122,8 +122,8 @@
}
Window parent = null;
- if (ServiceManager.Contains ("GtkElementsService")) {
- parent = ServiceManager.Get<GtkElementsService> ("GtkElementsService").PrimaryWindow;
+ if (ServiceManager.Contains<GtkElementsService> ()) {
+ parent = ServiceManager.Get<GtkElementsService> ().PrimaryWindow;
}
cancel_dialog = new Banshee.Widgets.HigMessageDialog (parent,
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTileHost.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTileHost.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/UserJobTileHost.cs Thu Feb 28 04:41:45 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -93,32 +93,36 @@
private void OnJobAdded (object o, UserJobEventArgs args)
{
- lock (this) {
- if (args.Job.DelayShow) {
- // Give the Job 1 second to become more than 33% complete
- Banshee.ServiceStack.Application.RunTimeout (1000, delegate {
+ ThreadAssist.ProxyToMain (delegate {
+ lock (this) {
+ if (args.Job.DelayShow) {
+ // Give the Job 1 second to become more than 33% complete
+ Banshee.ServiceStack.Application.RunTimeout (1000, delegate {
+ AddJob (args.Job);
+ return false;
+ });
+ } else {
AddJob (args.Job);
- return false;
- });
- } else {
- AddJob (args.Job);
+ }
}
- }
+ });
}
private void OnJobRemoved (object o, UserJobEventArgs args)
{
- lock (this) {
- if (job_tiles.ContainsKey (args.Job)) {
- UserJobTile tile = job_tiles[args.Job];
- box.Remove (tile);
- job_tiles.Remove (args.Job);
- }
-
- if (job_tiles.Count <= 0) {
- Hide ();
+ ThreadAssist.ProxyToMain (delegate {
+ lock (this) {
+ if (job_tiles.ContainsKey (args.Job)) {
+ UserJobTile tile = job_tiles[args.Job];
+ box.Remove (tile);
+ job_tiles.Remove (args.Job);
+ }
+
+ if (job_tiles.Count <= 0) {
+ Hide ();
+ }
}
- }
+ });
}
}
}
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs Thu Feb 28 04:41:45 2008
@@ -76,6 +76,8 @@
// Initialize GTK
Gtk.Application.Init ();
Gtk.Window.DefaultIconName = default_icon_name;
+
+ ThreadAssist.InitializeMainThread ();
PlatformHacks.GdkSetProgramClass (Application.InternalName);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]