banshee r5161 - in trunk/banshee: . build/m4/banshee src/Extensions/Banshee.Torrent/Banshee.Torrent



Author: gburt
Date: Wed Mar 25 04:37:14 2009
New Revision: 5161
URL: http://svn.gnome.org/viewvc/banshee?rev=5161&view=rev

Log:
2009-03-24  Gabriel Burt  <gabriel burt gmail com>

	* build/m4/banshee/torrent.m4:
	* src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs:
	* src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs: Some
	cleanup and build fixes.

Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/build/m4/banshee/torrent.m4
   trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs
   trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs

Modified: trunk/banshee/build/m4/banshee/torrent.m4
==============================================================================
--- trunk/banshee/build/m4/banshee/torrent.m4	(original)
+++ trunk/banshee/build/m4/banshee/torrent.m4	Wed Mar 25 04:37:14 2009
@@ -6,7 +6,7 @@
         PKG_CHECK_MODULES(MONOTORRENT_DBUS, monotorrent-dbus >= 0.2);
 		asms="`$PKG_CONFIG --variable=Libraries monotorrent` `$PKG_CONFIG --variable=Libraries monotorrent-dbus`"
 		for asm in $asms; do
-			MONOTORRENT_ASSEMBLIES="$MONOTORRENT_ASSEMBLIES $asm $asm.mdb"
+			MONOTORRENT_ASSEMBLIES="$MONOTORRENT_ASSEMBLIES $asm"
 		done
         AC_SUBST(MONOTORRENT_DBUS_LIBS)
 		AC_SUBST(MONOTORRENT_ASSEMBLIES)

Modified: trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentFileDownloadTask.cs	Wed Mar 25 04:37:14 2009
@@ -33,96 +33,93 @@
 
 namespace Banshee.Torrent
 {
-	public class TorrentFileDownloadTask : Migo.DownloadCore.HttpFileDownloadTask
-	{
-		private MonoTorrent.DBus.IDownloader downloader;
-		private MonoTorrent.DBus.ITorrent torrent;
-		
-		public TorrentFileDownloadTask(string remoteUri, string localPath, object userState)
-			: base (remoteUri, localPath.Substring(0, localPath.Length - 8), userState)
-		{
-			Console.WriteLine ("Torrent file download task!");
-		}
-		
-		public override long BytesReceived {
-			get 
-			{
-				if (downloader == null)
+    public class TorrentFileDownloadTask : Migo.DownloadCore.HttpFileDownloadTask
+    {
+        private MonoTorrent.DBus.IDownloader downloader;
+        private MonoTorrent.DBus.ITorrent torrent;
+        
+        public TorrentFileDownloadTask (string remoteUri, string localPath, object userState)
+            : base (remoteUri, localPath.Substring (0, localPath.Length - 8), userState)
+        {
+        }
+        
+        public override long BytesReceived {
+            get {
+                if (downloader == null)
                     return 0;
                 
-				return (long)(downloader.GetProgress () / 100.0 * torrent.GetSize ()); 
-			}
-		}
-		
-		public override void CancelAsync ()
-		{
-			if (downloader == null)
+                return (long)(downloader.GetProgress () / 100.0 * torrent.GetSize ()); 
+            }
+        }
+        
+        public override void CancelAsync ()
+        {
+            if (downloader == null)
                 return;
             
-			downloader.Stop ();
-			SetStatus (TaskStatus.Cancelled);
+            downloader.Stop ();
+            SetStatus (TaskStatus.Cancelled);
             OnTaskCompleted (null, true);
-		}
+        }
 
-		public override void ExecuteAsync ()
-		{
-			Console.WriteLine ("Running!");
-			SetStatus (TaskStatus.Running);
-			TorrentService s = (TorrentService) Banshee.ServiceStack.ServiceManager.Get<TorrentService>("TorrentService");
-			downloader = s.Download (this.RemoteUri.ToString(), Path.GetDirectoryName(this.LocalPath));
-			torrent = TorrentService.Bus.GetObject <ITorrent> (TorrentService.BusName, this.downloader.GetTorrent ());
-			
-			this.downloader.StateChanged += delegate {
-				if (downloader.GetState () == TorrentState.Seeding)
-				{
-					Console.WriteLine("Progress");
-					SetProgress(100);
-					SetStatus (TaskStatus.Succeeded);
-					OnTaskCompleted (null, false);
-				}
-			};
-			
-			// There are no events on the torrent IDownloader to indicate when the stats have updated
-			// I need to manually ping the SetProgress event otherwise migo never notices progress changing
-			System.Threading.ThreadPool.QueueUserWorkItem ((System.Threading.WaitCallback)delegate {
-				while (base.Progress != 100 && 
-				       (Status == TaskStatus.Running || Status == TaskStatus.Paused || Status == TaskStatus.Running))
-				{
-					
-					Console.WriteLine("Progress");
-					Hyena.Log.Debug ("Torrent Tick");
-					System.Threading.Thread.Sleep (2000);
-					SetProgress((int)downloader.GetProgress ());
-				}
-			});
-		}
-
-		public override void Pause ()
-		{
-			if (downloader == null)
+        public override void ExecuteAsync ()
+        {
+            SetStatus (TaskStatus.Running);
+            TorrentService s = Banshee.ServiceStack.ServiceManager.Get<TorrentService> ();
+            downloader = s.Download (RemoteUri.ToString (), Path.GetDirectoryName (LocalPath));
+            torrent = TorrentService.Bus.GetObject <ITorrent> (TorrentService.BusName, downloader.GetTorrent ());
+            
+            downloader.StateChanged += OnDownloaderStateChanged;
+            
+            // There are no events on the torrent IDownloader to indicate when the stats have updated
+            // Manually ping the SetProgress event, otherwise migo never notices progress changing
+            System.Threading.ThreadPool.QueueUserWorkItem (UpdateProgress);
+        }
+
+        public override void Pause ()
+        {
+            if (downloader == null)
                 return;
             
-			SetStatus (TaskStatus.Paused);
-			downloader.Pause ();
-		}
-		
-		public override void Resume ()
-		{
-			if (downloader == null)
+            SetStatus (TaskStatus.Paused);
+            downloader.Pause ();
+        }
+        
+        public override void Resume ()
+        {
+            if (downloader == null)
                 return;
             
-			SetStatus (TaskStatus.Running);
-			downloader.Stop ();
-		}
-
-		public override void Stop ()
-		{
-			if (downloader == null)
+            SetStatus (TaskStatus.Running);
+            downloader.Stop ();
+        }
+
+        public override void Stop ()
+        {
+            if (downloader == null)
                 return;
             
-			SetStatus (TaskStatus.Stopped);
-			OnTaskCompleted (null, false);
-			downloader.Stop ();
-		}
-	}
+            SetStatus (TaskStatus.Stopped);
+            OnTaskCompleted (null, false);
+            downloader.Stop ();
+        }
+
+        private void OnDownloaderStateChanged (NDesk.DBus.ObjectPath path, TorrentState from, TorrentState to)
+        {
+            if (downloader.GetState () == TorrentState.Seeding) {
+                SetProgress (100);
+                SetStatus (TaskStatus.Succeeded);
+                OnTaskCompleted (null, false);
+            }
+        }
+
+        private void UpdateProgress (object o)
+        {
+            while (Progress != 100 && 
+                   (Status == TaskStatus.Running || Status == TaskStatus.Paused || Status == TaskStatus.Running)) {
+                System.Threading.Thread.Sleep (2000);
+                SetProgress ((int)downloader.GetProgress ());
+            }
+        }
+    }
 }

Modified: trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Torrent/Banshee.Torrent/TorrentService.cs	Wed Mar 25 04:37:14 2009
@@ -50,7 +50,7 @@
         private Bus bus;
         private IEngine engine;
         private ITorrentService service;
-        private IEngineSettings settings;
+        /*private IEngineSettings settings;
         
         public int MaxDownloadSpeed {
             get { return settings.GetGlobalMaxDownloadSpeed (); }
@@ -60,7 +60,7 @@
         public int MaxUploadSpeed {
             get { return settings.GetGlobalMaxUploadSpeed (); }
             set { settings.SetGlobalMaxUploadSpeed (value); }
-        }
+        }*/
 
         public string ServiceName {
             get { return "TorrentService"; }
@@ -88,7 +88,9 @@
         public void Dispose ()
         {
             if (service != null) {
-                service.DestroyEngine (EngineName);
+                try {
+                    service.DestroyEngine (EngineName);
+                } catch {}
                 service = null;
             }
         }
@@ -100,7 +102,7 @@
         public void DelayedInitialize ()
         {
             bus = Bus.Session;
-                        
+
             try {
                 // Get the service and call a method on it to ensure that it is
                 // running and able to answer queries.



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