cowbell r34 - in trunk: . base gui resources



Author: btaylor
Date: Sun May  4 21:58:33 2008
New Revision: 34
URL: http://svn.gnome.org/viewvc/cowbell?rev=34&view=rev

Log:
2008-05-04  Brad Taylor  <brad getcoded net>
	
	* gui/MainWindow.cs:
	* gui/MetadataProxyProgressDialog.cs:
	* resources/MetadataProxyProgressDialog.glade:
	* base/IMetadataProxyService.cs:
	* base/IMetadataProxy.cs:
	* base/MusicBrainzMetadataProxy.cs: Clean up API and add a
	  MetadataProxy for MusicBrainz.

	* base/AmazonMetadataProxy.cs:
	* base/AmazonSearchService.wsdl:
	* base/MetadataProxyService.cs: Remove non-functional Amazon support.

	* musicbrainz-sharp/MusicBrainz: Bundle musicbrainz-sharp for
	  MusicBrainzMetadataProxy.



Removed:
   trunk/base/AmazonMetadataProxy.cs
   trunk/base/AmazonSearchService.wsdl
Modified:
   trunk/ChangeLog
   trunk/base/IMetadataProxy.cs
   trunk/base/IMetadataProxyService.cs
   trunk/base/Makefile.am
   trunk/base/MetadataProxyService.cs
   trunk/base/MusicBrainzMetadataProxy.cs
   trunk/gui/MainWindow.cs
   trunk/gui/MetadataProxyProgressDialog.cs
   trunk/gui/Runtime.cs
   trunk/resources/MetadataProxyProgressDialog.glade

Modified: trunk/base/IMetadataProxy.cs
==============================================================================
--- trunk/base/IMetadataProxy.cs	(original)
+++ trunk/base/IMetadataProxy.cs	Sun May  4 21:58:33 2008
@@ -23,14 +23,24 @@
 
 namespace Cowbell.Base
 {
-	public delegate void ProgressHandler (bool completed, ProgressStatus s);
+	public delegate void MetadataImportCompletedHandler (object o, MetadataImportCompletedArgs args);
 
 	public interface IMetadataProxy
 	{
-		void Import (ProgressHandler progress_cb);
+		void Import (MetadataImportCompletedHandler completed_handler);
 	}
 
-	public enum ProgressStatus
+	public class MetadataImportCompletedArgs : EventArgs
+	{
+		public MetadataImportStatus Status;
+
+		public MetadataImportCompletedArgs (MetadataImportStatus s)
+		{
+			this.Status = s;
+		}
+	}
+
+	public enum MetadataImportStatus
 	{
 		NetworkError,
 		ArtistNotFound,

Modified: trunk/base/IMetadataProxyService.cs
==============================================================================
--- trunk/base/IMetadataProxyService.cs	(original)
+++ trunk/base/IMetadataProxyService.cs	Sun May  4 21:58:33 2008
@@ -23,14 +23,8 @@
 
 namespace Cowbell.Base
 {
-	public delegate void ImportHeartbeatHandler (string message);
-	public delegate void ImportCompletedHandler (bool success, string message);
-
 	public interface IMetadataProxyService : IService
 	{
-		event ImportHeartbeatHandler ImportHeartbeat;
-		event ImportCompletedHandler ImportCompleted;
-	
-		void FetchMetadata ();
+		void FetchMetadata (MetadataImportCompletedHandler import_completed);
 	}
 }

Modified: trunk/base/Makefile.am
==============================================================================
--- trunk/base/Makefile.am	(original)
+++ trunk/base/Makefile.am	Sun May  4 21:58:33 2008
@@ -1,7 +1,6 @@
 DLL = Cowbell.Base.dll
 
 REFERENCES = \
--r:System.Web.Services \
 -r:../musicbrainz-sharp/MusicBrainz.dll \
 $(TAGLIBSHARP_LIBS)
 
@@ -31,20 +30,9 @@
 XmlPreferencesService.cs \
 IPreferencesService.cs 
 
-wsdl_files = \
-AmazonSearchService.wsdl
-
-wsdl_generated = \
-AmazonSearchService.cs
-
 build_sources = $(addprefix $(srcdir)/, $(FILES))
-wsdl_sources = $(addprefix $(srcdir)/, $(wsdl_files))
-wsdl_generated_sources = $(addprefix $(srcdir)/, $(wsdl_generated))
-
-all: $(wsdl_generated) $(DLL)
 
-$(wsdl_generated): $(wsdl_sources)
-	$(WSDL) -nologo -namespace:Cowbell.Base -out:$(wsdl_generated) $(wsdl_sources)
+all: $(DLL)
 
 $(DLL): $(build_sources) $(RESOURCES)
 	$(CSC) /warnaserror /t:library /codepage:utf8 /debug /out:$@ $(REFERENCES) $(build_sources)
@@ -52,9 +40,7 @@
 cowbelldir = $(prefix)/lib/cowbell
 cowbell_DATA = $(DLL)
 
-CLEANFILES = $(DLL) $(DLL).mdb $(wsdl_generated)
+CLEANFILES = $(DLL) $(DLL).mdb
 
 EXTRA_DIST = \
-$(FILES) \
-$(wsdl_sources) \
-$(wsdl_generated)
+$(FILES)

Modified: trunk/base/MetadataProxyService.cs
==============================================================================
--- trunk/base/MetadataProxyService.cs	(original)
+++ trunk/base/MetadataProxyService.cs	Sun May  4 21:58:33 2008
@@ -28,11 +28,7 @@
 {
 	public class MetadataProxyService : IMetadataProxyService
 	{
-		/* public events */
-		public event ImportHeartbeatHandler ImportHeartbeat;
-		public event ImportCompletedHandler ImportCompleted;
-
-		/* public methods */
+#region public methods
 		public void Load ()
 		{
 			Assembly asm = Assembly.GetCallingAssembly ();
@@ -44,13 +40,6 @@
 						int priority = ((MetadataProxyPriorityAttribute)a).Priority;
 
 						IMetadataProxy p = (IMetadataProxy)Activator.CreateInstance (t);
-						
-/*
-						p.Heartbeat += new StringHandler (OnProxyPulse);
-						p.ConnectionFailed += new StringHandler (OnConnectionFailed);
-						p.ConnectionRejected += new StringHandler (OnConnectionRejected);
-						p.Completed += new VoidHandler (OnProxyCompleted);
-*/
 						proxies.Add (new DictionaryEntry (priority, p));
 					}
 				}
@@ -61,51 +50,43 @@
 			});
 		}
 
-		public void FetchMetadata ()
+		/**
+		 * Scans all external MetadataServices for matches to the
+		 * current tracks.  When finished, import_completed is invoked
+		 * in the GUI thread.
+		 *
+		 * @param import_completed A delegate to be invoked when the import is completed.
+		 */
+		public void FetchMetadata (MetadataImportCompletedHandler import_completed)
 		{
+			this.import_completed = import_completed;
+
 			foreach (DictionaryEntry d in proxies)
 			{
 				IMetadataProxy p = (IMetadataProxy)d.Value;
-				p.Import (new ProgressHandler (ImportProgress));
+				p.Import (new MetadataImportCompletedHandler (MetadataImported));
 			}
 		}
+#endregion
 
-		/* private fields */
-		List<DictionaryEntry> proxies = new List<DictionaryEntry> ();
+#region private fields
+		private List<DictionaryEntry> proxies = new List<DictionaryEntry> ();
+		private MetadataImportCompletedHandler import_completed = null;
+#endregion
 
-		/* private methods */
-		private void ImportProgress (bool completed, ProgressStatus s)
-		{
-			Console.WriteLine ("Completed: {0}, Status: {1}", completed, s);
-		}
-/*
-		private void OnProxyPulse (string text)
+#region private methods
+		private void MetadataImported (object o, MetadataImportCompletedArgs args)
 		{
-			if (ImportHeartbeat != null) {
-				ImportHeartbeat (text);
+			if (import_completed == null) {
+				Console.WriteLine ("import_completed is null!");
+				return;
 			}
-		}
 
-		private void OnConnectionFailed (string error)
-		{
-			if (ImportCompleted != null) {
-				ImportCompleted (false, String.Format (Catalog.GetString ("Connection Failed:\n\n{0}"), error));
-			}
-		}
-
-		private void OnConnectionRejected (string error)
-		{
-			if (ImportCompleted != null) {
-				ImportCompleted (false, String.Format (Catalog.GetString ("Connection Rejected:\n\n{0}"), error));
-			}
-		}
-
-		private void OnProxyCompleted ()
-		{
-			if (ImportCompleted != null) {
-				ImportCompleted (true, String.Empty);
-			}
+			IDispatchService dispatch_svc
+				= (IDispatchService)ServiceManager.GetService (
+					typeof (IDispatchService));
+			dispatch_svc.GuiDispatch (import_completed, new object[] { this, args });
 		}
-*/
+#endregion
 	}
 }

Modified: trunk/base/MusicBrainzMetadataProxy.cs
==============================================================================
--- trunk/base/MusicBrainzMetadataProxy.cs	(original)
+++ trunk/base/MusicBrainzMetadataProxy.cs	Sun May  4 21:58:33 2008
@@ -34,7 +34,7 @@
 	public class MusicBrainzMetadataProxy : IMetadataProxy
 	{
 #region public methods
-		public void Import (ProgressHandler progress_cb)
+		public void Import (MetadataImportCompletedHandler completed)
 		{
 			db_svc = (IDatabaseService)ServiceManager.GetService (
 					typeof (IDatabaseService));
@@ -44,13 +44,15 @@
 			
 			Artist a = FindClosestArtist (db_svc.GlobalData.Artist);
 			if (a == null) {
-				progress_cb (true, ProgressStatus.ArtistNotFound);
+				completed (this, new MetadataImportCompletedArgs (
+					MetadataImportStatus.ArtistNotFound));
 				return;
 			}
 
 			Release r = FindClosestRelease (a, db_svc.GlobalData.Album);
 			if (r == null) {
-				progress_cb (true, ProgressStatus.ReleaseNotFound);
+				completed (this, new MetadataImportCompletedArgs (
+					MetadataImportStatus.ReleaseNotFound));
 				return;
 			}
 			
@@ -58,11 +60,13 @@
 			MatchTracks (a, r, db_svc, out num_matches);
 
 			if (num_matches == db_svc.Count) {
-				progress_cb (true, ProgressStatus.CompleteMatch);
+				completed (this, new MetadataImportCompletedArgs (
+					MetadataImportStatus.CompleteMatch));
 				return;
 			}
 
-			progress_cb (true, ProgressStatus.PartialTrackMatch);
+			completed (this, new MetadataImportCompletedArgs (
+				MetadataImportStatus.PartialTrackMatch));
 		}
 #endregion
 

Modified: trunk/gui/MainWindow.cs
==============================================================================
--- trunk/gui/MainWindow.cs	(original)
+++ trunk/gui/MainWindow.cs	Sun May  4 21:58:33 2008
@@ -343,7 +343,8 @@
 
 		private void OnGuessSongInformationActivate (object o, EventArgs args)
 		{
-			MetadataProxyProgressDialog.FetchMetadata ();
+			MetadataProxyProgressDialog d = new MetadataProxyProgressDialog ();
+			d.FetchMetadata ();
 		}
 
 		private void OnEditPreferencesActivate (object o, EventArgs args)

Modified: trunk/gui/MetadataProxyProgressDialog.cs
==============================================================================
--- trunk/gui/MetadataProxyProgressDialog.cs	(original)
+++ trunk/gui/MetadataProxyProgressDialog.cs	Sun May  4 21:58:33 2008
@@ -20,50 +20,71 @@
  */
 
 using Gtk;
-
 using System;
-
 using Cowbell.Base;
 
 namespace Cowbell.Gui
 {
 	public class MetadataProxyProgressDialog : GladeDialog
 	{
-		/* public methods */
+#region public methods
 		public MetadataProxyProgressDialog () : base ("MetadataProxyProgressDialog.glade")
 		{
-			Runtime.MetadataProxy.ImportHeartbeat += new ImportHeartbeatHandler (OnImportHeartbeat);
-			Runtime.MetadataProxy.ImportCompleted += new ImportCompletedHandler (OnImportCompleted);
+			prx_svc = (IMetadataProxyService)ServiceManager.GetService (
+					typeof (IMetadataProxyService));
+			dispatch_svc = (IDispatchService)ServiceManager.GetService (
+					typeof (IDispatchService));
 		}
 
-		public static void FetchMetadata ()
+		public void FetchMetadata ()
 		{
-			Runtime.MetadataProxy.FetchMetadata ();
+			dispatch_svc.BackgroundDispatch (new FetchMetadataHandler (WorkerFetchMetadata),
+			                                 new object[0]);
+			GLib.Timeout.Add (200, new GLib.TimeoutHandler (OnProgressPulse));
 
-			MetadataProxyProgressDialog pd = new MetadataProxyProgressDialog ();
-			pd.Run ();
-			pd.Hide ();
+			dialog.ShowAll ();
 		}
+#endregion
 
-		/* private fields */
+#region private fields
 		[Glade.Widget] private ProgressBar progressbar;
-		[Glade.Widget] private Label ProgressLabel;
 
-		/* private methods */
-		private void OnImportHeartbeat (string message)
+		private IMetadataProxyService prx_svc;
+		private IDispatchService dispatch_svc;
+
+		private delegate void FetchMetadataHandler ();
+#endregion
+
+#region private methods
+		private void WorkerFetchMetadata ()
+		{
+			prx_svc.FetchMetadata (new MetadataImportCompletedHandler (
+				OnImportCompleted));
+		}
+
+		private bool OnProgressPulse ()
 		{
-			ProgressLabel.Markup = String.Format ("<i>{0}</i>",
-							      GLib.Markup.EscapeText (message));
 			progressbar.Pulse ();
+
+			return true;
 		}
 
-		private void OnImportCompleted (bool success, string message)
+		private void OnImportCompleted (object o, MetadataImportCompletedArgs args)
 		{
-			if (!success) {
-				Runtime.Message.ShowError (message);
+			switch (args.Status) {
+			case MetadataImportStatus.NetworkError:
+				Runtime.Message.ShowError (Catalog.GetString ("Unable to connect to the Internet to guess song information.  Try again later."));
+				break;
+			case MetadataImportStatus.ArtistNotFound:
+				Runtime.Message.ShowError (Catalog.GetString ("The selected Artist was not found.  Please verify the spelling and try again."));
+				break;
+			case MetadataImportStatus.ReleaseNotFound:
+				Runtime.Message.ShowError (Catalog.GetString ("The selected Album was not found.  Please verify the spelling and try again."));
+				break;
 			}
-
-			Hide ();
+				
+			dialog.Hide ();
 		}
+#endregion
 	}
 }

Modified: trunk/gui/Runtime.cs
==============================================================================
--- trunk/gui/Runtime.cs	(original)
+++ trunk/gui/Runtime.cs	Sun May  4 21:58:33 2008
@@ -24,6 +24,10 @@
 
 namespace Cowbell.Gui
 {
+	/**
+	 * NOTE: Obsolete API -- don't use this for any new code.
+	 * Cheezy static single Runtime pattern.
+	 */
 	public static class Runtime
 	{
 		public static IDatabaseService Database {
@@ -56,62 +60,6 @@
 
 		public static bool Dirty;
 
-/*
-		public static void Main (string[] args)
-		{
-			Catalog.Init ();
-
-			parser = new CliParser (Globals.AppName,
-						Catalog.GetString ("An elegant music organizer."),
-						Catalog.GetString ("[OPTIONS]... [FILE]..."));
-
-			parser.AddOption (new string[] {"h", "help"}, Catalog.GetString ("display this help and exit"), false);
-			parser.AddOption (new string[] {"v", "version"}, Catalog.GetString ("display the current version and exit"), false);
-			parser.AddOption (new string[] {"debug"}, Catalog.GetString ("enables debugging output"), false);
-			parser.AddOption (new string[] {"batch"}, Catalog.GetString ("enables batch tagging mode"), false);
-			parser.AddOption (new string[] {"q", "quiet"}, Catalog.GetString ("disables prompts when in batch tagging mode"), false);
-			
-			try {
-				parser.Parse (args);
-			} catch (Exception e) {
-				Console.WriteLine (e.Message);
-				Console.WriteLine (parser.GetHelp ());
-				Environment.Exit (1);
-			}
-
-			if (parser["help"] != null || parser["h"] != null) {
-				Console.WriteLine (parser.GetHelp ());
-				return;
-			}
-
-			if (parser["version"] != null || parser["v"] != null) {
-				Console.WriteLine (Catalog.GetString ("{0}, version {1}"),
-				                   Globals.AppName, Globals.AppVersion);
-				return;
-			}
-
-			if (parser["debug"] != null) {
-				Console.WriteLine ("Debug mode enabled.");
-				Debug.OutputEnabled = true;
-			}
-
-			if (parser["batch"] != null) {
-				bool quiet = true;
-				if (parser["quiet"] != null || parser["q"] != null) {
-					quiet = false;
-				}
-
-				new Runtime ();
-				new Batch (parser.Parameters, quiet);
-				return;
-			}
-			
-			new Runtime ();
-			gui = new Gui.Gui ();
-			gui.Show ();
-		}
-*/
-
 		public static void Init ()
 		{
 			Dirty = false;

Modified: trunk/resources/MetadataProxyProgressDialog.glade
==============================================================================
--- trunk/resources/MetadataProxyProgressDialog.glade	(original)
+++ trunk/resources/MetadataProxyProgressDialog.glade	Sun May  4 21:58:33 2008
@@ -53,42 +53,41 @@
       </child>
 
       <child>
-	<widget class="GtkVBox" id="vbox3">
-	  <property name="border_width">5</property>
+	<widget class="GtkHBox" id="hbox2">
 	  <property name="visible">True</property>
 	  <property name="homogeneous">False</property>
 	  <property name="spacing">12</property>
 
 	  <child>
-	    <widget class="GtkHBox" id="hbox2">
+	    <widget class="GtkImage" id="image1">
+	      <property name="visible">True</property>
+	      <property name="stock">gtk-dialog-info</property>
+	      <property name="icon_size">6</property>
+	      <property name="xalign">0.5</property>
+	      <property name="yalign">0</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkVBox" id="vbox4">
 	      <property name="visible">True</property>
 	      <property name="homogeneous">False</property>
 	      <property name="spacing">12</property>
 
 	      <child>
-		<widget class="GtkImage" id="image1">
-		  <property name="visible">True</property>
-		  <property name="stock">gtk-dialog-info</property>
-		  <property name="icon_size">6</property>
-		  <property name="xalign">0.5</property>
-		  <property name="yalign">0</property>
-		  <property name="xpad">0</property>
-		  <property name="ypad">0</property>
-		</widget>
-		<packing>
-		  <property name="padding">0</property>
-		  <property name="expand">False</property>
-		  <property name="fill">True</property>
-		</packing>
-	      </child>
-
-	      <child>
 		<widget class="GtkLabel" id="label">
 		  <property name="visible">True</property>
 		  <property name="can_focus">True</property>
 		  <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot; size=&quot;x-large&quot;&gt;Guessing Song Information&lt;/span&gt;
 
-Currently contacting Amazon's servers to guess the correct
+Currently connecting to the Internet to guess the correct
 information for your songs.  This may take a few minutes.</property>
 		  <property name="use_underline">False</property>
 		  <property name="use_markup">True</property>
@@ -106,23 +105,10 @@
 		</widget>
 		<packing>
 		  <property name="padding">0</property>
-		  <property name="expand">True</property>
-		  <property name="fill">True</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
 		</packing>
 	      </child>
-	    </widget>
-	    <packing>
-	      <property name="padding">0</property>
-	      <property name="expand">True</property>
-	      <property name="fill">True</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkVBox" id="vbox2">
-	      <property name="visible">True</property>
-	      <property name="homogeneous">False</property>
-	      <property name="spacing">6</property>
 
 	      <child>
 		<widget class="GtkProgressBar" id="progressbar">
@@ -139,31 +125,6 @@
 		  <property name="fill">False</property>
 		</packing>
 	      </child>
-
-	      <child>
-		<widget class="GtkLabel" id="ProgressLabel">
-		  <property name="visible">True</property>
-		  <property name="label" translatable="yes"></property>
-		  <property name="use_underline">False</property>
-		  <property name="use_markup">False</property>
-		  <property name="justify">GTK_JUSTIFY_LEFT</property>
-		  <property name="wrap">False</property>
-		  <property name="selectable">False</property>
-		  <property name="xalign">0</property>
-		  <property name="yalign">0.5</property>
-		  <property name="xpad">0</property>
-		  <property name="ypad">0</property>
-		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		  <property name="width_chars">-1</property>
-		  <property name="single_line_mode">False</property>
-		  <property name="angle">0</property>
-		</widget>
-		<packing>
-		  <property name="padding">0</property>
-		  <property name="expand">False</property>
-		  <property name="fill">False</property>
-		</packing>
-	      </child>
 	    </widget>
 	    <packing>
 	      <property name="padding">0</property>



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