cowbell r37 - in trunk: . base gui
- From: btaylor svn gnome org
- To: svn-commits-list gnome org
- Subject: cowbell r37 - in trunk: . base gui
- Date: Mon, 2 Jun 2008 05:03:23 +0000 (UTC)
Author: btaylor
Date: Mon Jun 2 05:03:23 2008
New Revision: 37
URL: http://svn.gnome.org/viewvc/cowbell?rev=37&view=rev
Log:
2008-06-01 Brad Taylor <brad getcoded net>
* gui/AlbumCoverImage.cs:
* base/IMetadataProxyService.cs:
* base/IMetadataProxy.cs:
* base/MetadataProxyService.cs: Rework IMetadataProxy to also provide
album artwork. Make MetadataProxyService perform async logic, remove
that logic from individual IMetadataProxies.
* base/MusicBrainzMetadataProxy.cs: Grab the release's ASIN, and use
Amazon for album artwork. Remove ancient Amazon web service and dev
tag.
Modified:
trunk/ChangeLog
trunk/base/IMetadataProxy.cs
trunk/base/IMetadataProxyService.cs
trunk/base/MetadataProxyService.cs
trunk/base/MusicBrainzMetadataProxy.cs
trunk/gui/AlbumCoverImage.cs
Modified: trunk/base/IMetadataProxy.cs
==============================================================================
--- trunk/base/IMetadataProxy.cs (original)
+++ trunk/base/IMetadataProxy.cs Mon Jun 2 05:03:23 2008
@@ -23,30 +23,10 @@
namespace Cowbell.Base
{
- public delegate void MetadataImportCompletedHandler (object o, MetadataImportCompletedArgs args);
-
public interface IMetadataProxy
{
- void Import (MetadataImportCompletedHandler completed_handler);
+ MetadataImportStatus Import ();
byte[] FetchAlbumArtwork ();
}
- public class MetadataImportCompletedArgs : EventArgs
- {
- public MetadataImportStatus Status;
-
- public MetadataImportCompletedArgs (MetadataImportStatus s)
- {
- this.Status = s;
- }
- }
-
- public enum MetadataImportStatus
- {
- NetworkError,
- ArtistNotFound,
- ReleaseNotFound,
- PartialTrackMatch,
- CompleteMatch
- }
}
Modified: trunk/base/IMetadataProxyService.cs
==============================================================================
--- trunk/base/IMetadataProxyService.cs (original)
+++ trunk/base/IMetadataProxyService.cs Mon Jun 2 05:03:23 2008
@@ -23,9 +23,41 @@
namespace Cowbell.Base
{
+ public delegate void MetadataImportCompletedHandler (object o, MetadataImportCompletedArgs args);
+ public delegate void ArtworkDownloadCompletedHandler (object o, ArtworkDownloadCompletedArgs args);
+
public interface IMetadataProxyService : IService
{
void FetchMetadata (MetadataImportCompletedHandler import_completed);
- byte[] FetchAlbumArtwork ();
+ void FetchAlbumArtwork (ArtworkDownloadCompletedHandler download_completed);
+ }
+
+ public class ArtworkDownloadCompletedArgs : EventArgs
+ {
+ public byte[] Data;
+
+ public ArtworkDownloadCompletedArgs (byte[] data)
+ {
+ this.Data = data;
+ }
+ }
+
+ public class MetadataImportCompletedArgs : EventArgs
+ {
+ public MetadataImportStatus Status;
+
+ public MetadataImportCompletedArgs (MetadataImportStatus s)
+ {
+ this.Status = s;
+ }
+ }
+
+ public enum MetadataImportStatus
+ {
+ NetworkError,
+ ArtistNotFound,
+ ReleaseNotFound,
+ PartialTrackMatch,
+ CompleteMatch
}
}
Modified: trunk/base/MetadataProxyService.cs
==============================================================================
--- trunk/base/MetadataProxyService.cs (original)
+++ trunk/base/MetadataProxyService.cs Mon Jun 2 05:03:23 2008
@@ -31,6 +31,10 @@
#region public methods
public void Load ()
{
+ dispatch_svc
+ = (IDispatchService)ServiceManager.GetService (
+ typeof (IDispatchService));
+
Assembly asm = Assembly.GetCallingAssembly ();
foreach (Type t in asm.GetTypes ())
{
@@ -50,16 +54,16 @@
});
}
- // TODO:
- public byte[] FetchAlbumArtwork ()
+ public void FetchAlbumArtwork (ArtworkDownloadCompletedHandler download_completed)
{
- foreach (DictionaryEntry d in proxies)
- {
- IMetadataProxy p = (IMetadataProxy)d.Value;
- return p.FetchAlbumArtwork ();
+ if (download_completed == null) {
+ throw new ArgumentNullException ("download_completed");
}
-
- return null;
+
+ this.download_completed = download_completed;
+
+ dispatch_svc.BackgroundDispatch (new FetchArtworkHandler (WorkerFetchAlbumArtwork),
+ new object[0]);
}
/**
@@ -71,34 +75,67 @@
*/
public void FetchMetadata (MetadataImportCompletedHandler import_completed)
{
+ if (import_completed == null) {
+ throw new ArgumentNullException ("import_completed");
+ }
+
this.import_completed = import_completed;
- foreach (DictionaryEntry d in proxies)
- {
- IMetadataProxy p = (IMetadataProxy)d.Value;
- p.Import (new MetadataImportCompletedHandler (MetadataImported));
- }
+ dispatch_svc.BackgroundDispatch (new FetchMetadataHandler (WorkerFetchMetadata),
+ new object[0]);
}
#endregion
#region private fields
private List<DictionaryEntry> proxies = new List<DictionaryEntry> ();
+ private ArtworkDownloadCompletedHandler download_completed = null;
private MetadataImportCompletedHandler import_completed = null;
+
+ private IDispatchService dispatch_svc;
#endregion
#region private methods
- private void MetadataImported (object o, MetadataImportCompletedArgs args)
+ private void WorkerFetchAlbumArtwork ()
{
- if (import_completed == null) {
- Console.WriteLine ("import_completed is null!");
- return;
+ byte[] data = null;
+ for (int i = 0; i < proxies.Count; i++) {
+ IMetadataProxy p = (IMetadataProxy)proxies[i].Value;
+
+ data = p.FetchAlbumArtwork ();
+ if (data != null && data.Length > 0) {
+ break;
+ }
}
- IDispatchService dispatch_svc
- = (IDispatchService)ServiceManager.GetService (
- typeof (IDispatchService));
- dispatch_svc.GuiDispatch (import_completed, new object[] { this, args });
+ dispatch_svc.GuiDispatch (download_completed, new object[] {
+ this, new ArtworkDownloadCompletedArgs (data) });
}
+
+ private void WorkerFetchMetadata ()
+ {
+ MetadataImportStatus max_status = MetadataImportStatus.NetworkError;
+ for (int i = 0; i < proxies.Count; i++) {
+ IMetadataProxy p = (IMetadataProxy)proxies[i].Value;
+
+ MetadataImportStatus status = p.Import ();
+ if ((int)status > (int)max_status) {
+ max_status = status;
+ }
+
+ if (status == MetadataImportStatus.CompleteMatch) {
+ max_status = status;
+ break;
+ }
+ }
+
+ dispatch_svc.GuiDispatch (import_completed, new object[] {
+ this, new MetadataImportCompletedArgs (max_status) });
+ }
+#endregion
+
+#region private delegates
+ private delegate void FetchMetadataHandler ();
+ private delegate void FetchArtworkHandler ();
#endregion
}
}
Modified: trunk/base/MusicBrainzMetadataProxy.cs
==============================================================================
--- trunk/base/MusicBrainzMetadataProxy.cs (original)
+++ trunk/base/MusicBrainzMetadataProxy.cs Mon Jun 2 05:03:23 2008
@@ -43,33 +43,26 @@
typeof (IDispatchService));
}
- public void Import (MetadataImportCompletedHandler completed)
+ public MetadataImportStatus Import ()
{
Artist artist;
Release release;
FindClosestAlbumAndRelease (out artist, out release);
if (artist == null) {
- completed (this, new MetadataImportCompletedArgs (
- MetadataImportStatus.ArtistNotFound));
- return;
+ return MetadataImportStatus.ArtistNotFound;
} else if (release == null) {
- completed (this, new MetadataImportCompletedArgs (
- MetadataImportStatus.ReleaseNotFound));
- return;
+ return MetadataImportStatus.ReleaseNotFound;
}
int num_matches;
MatchTracks (artist, release, db_svc, out num_matches);
if (num_matches == db_svc.Count) {
- completed (this, new MetadataImportCompletedArgs (
- MetadataImportStatus.CompleteMatch));
- return;
+ return MetadataImportStatus.CompleteMatch;
}
- completed (this, new MetadataImportCompletedArgs (
- MetadataImportStatus.PartialTrackMatch));
+ return MetadataImportStatus.PartialTrackMatch;
}
public byte[] FetchAlbumArtwork ()
Modified: trunk/gui/AlbumCoverImage.cs
==============================================================================
--- trunk/gui/AlbumCoverImage.cs (original)
+++ trunk/gui/AlbumCoverImage.cs Mon Jun 2 05:03:23 2008
@@ -108,29 +108,31 @@
public void Download ()
{
- IDispatchService dispatch_svc
- = (IDispatchService)ServiceManager.GetService (
- typeof (IDispatchService));
-
stamp = GetStamp (db_svc.GlobalData);
- if (!UserPixbuf) {
- if (covers.ContainsKey (stamp)) {
- original = covers[stamp] as Pixbuf;
- if (original == null) {
- ShowDefaultCover ();
- return;
- }
- Refresh ();
- } else {
- // We're already loading
- if (original == loadingcover) {
- return;
- }
+ if (UserPixbuf) {
+ return;
+ }
- ShowLoadingCover ();
- dispatch_svc.BackgroundDispatch (new VoidHandler (ProxyDownload));
+ if (covers.ContainsKey (stamp)) {
+ original = covers[stamp] as Pixbuf;
+ if (original == null) {
+ ShowDefaultCover ();
+ return;
}
+ Refresh ();
+ return;
}
+
+ // We're already loading
+ if (original == loadingcover) {
+ return;
+ }
+
+ ShowLoadingCover ();
+
+ prx_svc.FetchAlbumArtwork (
+ new ArtworkDownloadCompletedHandler (
+ OnArtworkDownloadComplete));
}
public void ShowDefaultCover ()
@@ -192,10 +194,9 @@
Refresh ();
}
- private void ProxyDownload ()
+ private void OnArtworkDownloadComplete (object o, ArtworkDownloadCompletedArgs args)
{
- byte[] bytes = prx_svc.FetchAlbumArtwork ();
-
+ byte[] bytes = args.Data;
try {
if (bytes != null && bytes.Length > 0) {
pixbuf = new Gdk.Pixbuf (bytes);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]