Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* MainWindow.cs, Main.cs, CreateTorrentDialog.cs, TorrentController.cs,

  PeerTreeView.cs, RssManager/RssManagerDialog.cs,
  RssManager/TorrentRssWatcher.cs,
  RssManager/RssManagerController.cs, TorrentTreeView.cs: Ensure all
  events are synced on the main loop
* libs/MonoTorrent.dll: Update to head of the 0.50 branch

svn path=/trunk/monsoon/; revision=114328
  • Loading branch information...
commit 59d205375ae591f3cdde5954031d876f638048e0 1 parent 9bc6bba
Alan McGovern alanmcgovern authored
9 Monsoon/ChangeLog
View
@@ -1,3 +1,12 @@
+2008-09-28 Alan McGovern <alan.mcgovern@gmail.com>
+
+ * MainWindow.cs, Main.cs, CreateTorrentDialog.cs, TorrentController.cs,
+ PeerTreeView.cs, RssManager/RssManagerDialog.cs,
+ RssManager/TorrentRssWatcher.cs,
+ RssManager/RssManagerController.cs, TorrentTreeView.cs: Ensure all
+ events are synced on the main loop
+ * libs/MonoTorrent.dll: Update to head of the 0.50 branch
+
2008-09-22 Alan McGovern <alan.mcgovern@gmail.com>
* Settings/GconfTorrentSettingsController.cs,
16 Monsoon/CreateTorrentDialog.cs
View
@@ -201,10 +201,14 @@ private void createTorrent()
creator.Comment = Comment;
creator.CreatedBy = Defines.ApplicationName;
- creator.Path = SavePath;
-
- creator.Hashed += OnHashed;
-
+ creator.Path = SavePath;
+
+ creator.Hashed += delegate(object o, TorrentCreatorEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnHashed(o, e);
+ return false;
+ });
+ };
TorrentCreatorAsyncResult creatorResult = creator.BeginCreate(null, BeginCreateCb);
ResponseType cancelResult = (ResponseType) progressDialog.Run();
@@ -221,9 +225,7 @@ private void createTorrent()
private void OnHashed(object sender, TorrentCreatorEventArgs args)
{
- Gtk.Application.Invoke (delegate {
- progressDialog.Progress = args.OverallCompletion;
- });
+ progressDialog.Progress = args.OverallCompletion;
}
private void BeginCreateCb(IAsyncResult result)
1  Monsoon/Main.cs
View
@@ -82,6 +82,7 @@ public MainClass(string [] args)
if (DBusInstance.AlreadyRunning)
{
+ Console.WriteLine("Already running");
DBusInstance.CommandParser.ParseCommands (args);
return;
}
66 Monsoon/MainWindow.cs
View
@@ -76,7 +76,7 @@ public partial class MainWindow: Gtk.Window
private PeerTreeView peerTreeView;
private ListStore peerListStore;
- private Dictionary<PeerId, TreeIter> peers;
+ private Dictionary<PeerId, TreePath> peers;
private TreeModelFilter peerFilter;
private FileTreeView fileTreeView;
@@ -97,7 +97,7 @@ public partial class MainWindow: Gtk.Window
private RssManagerController rssManagerController;
- internal Dictionary<PeerId, TreeIter> Peers
+ internal Dictionary<PeerId, TreePath> Peers
{
get { return peers; }
}
@@ -187,8 +187,19 @@ public MainWindow (EngineSettings engineSettings, ListenPortController portContr
{
this.engineSettings = engineSettings;
this.portController = portController;
- portController.PortMapped += delegate { natStatus.PortForwarded = true; };
- portController.RouterFound += delegate { natStatus.RouterFound = true; };
+ portController.PortMapped += delegate {
+ GLib.Idle.Add(delegate {
+ natStatus.PortForwarded = true;
+ return false;
+ });
+ };
+
+ portController.RouterFound += delegate {
+ GLib.Idle.Add(delegate {
+ natStatus.RouterFound = true;
+ return false;
+ });
+ };
interfaceSettings = new GConfInterfaceSettingsController ();
defaultTorrentSettings = new GconfTorrentSettingsController ();
@@ -203,7 +214,9 @@ public MainWindow (EngineSettings engineSettings, ListenPortController portContr
Ticker.Tick ();
Ticker.Tick ();
+
Build ();
+
Ticker.Tock ("Build");
Ticker.Tick();
BuildStatusBar();
@@ -251,8 +264,13 @@ public MainWindow (EngineSettings engineSettings, ListenPortController portContr
RestoreLabels ();
Ticker.Tock ("Restored labels");
- folderWatcher = new TorrentFolderWatcher (new DirectoryInfo (Preferences.ImportLocation));
- folderWatcher.TorrentFound += torrentController.OnTorrentFound;
+ folderWatcher = new TorrentFolderWatcher (new DirectoryInfo (Preferences.ImportLocation));
+ folderWatcher.TorrentFound += delegate(object o, TorrentWatcherEventArgs e) {
+ GLib.Idle.Add(delegate {
+ torrentController.OnTorrentFound(o, e);
+ return false;
+ });
+ };
if (Preferences.ImportEnabled) {
logger.Info ("Starting import folder watcher");
@@ -654,8 +672,8 @@ private bool FilterTorrentTree (TreeModel model, TreeIter iter)
*/
private void BuildPeerTreeView ()
- {
- peers = new Dictionary<MonoTorrent.Client.PeerId,Gtk.TreeIter> ();
+ {
+ peers = new Dictionary<MonoTorrent.Client.PeerId, Gtk.TreePath>();
peerTreeView = new PeerTreeView ();
peerListStore = new ListStore (typeof(PeerId));
@@ -771,15 +789,18 @@ private void OnLabelSelectionChanged (object sender, System.EventArgs e)
//torrentTreeView.Selection.UnselectAll();
//torrentFilter.Refilter();
- }
-
- private void updatePeersPage()
- {
- lock(peers)
- foreach(TreeIter iter in peers.Values){
- peerListStore.EmitRowChanged(peerListStore.GetPath(iter), iter);
- }
- }
+ }
+
+ private void updatePeersPage()
+ {
+ lock (peers)
+ {
+ peerListStore.Foreach(delegate(TreeModel model, TreePath path, TreeIter iter) {
+ peerListStore.EmitRowChanged(path, iter);
+ return true;
+ });
+ }
+ }
private void updateStatusBar()
{
@@ -1182,7 +1203,7 @@ private void updateGeneralPage ()
}
}
- swarmSpeedLabel.Text = ByteConverter.ConvertSpeed (torrentController.GetTorrentSwarm(manager) * manager.Torrent.PieceLength);
+ swarmSpeedLabel.Text = ByteConverter.ConvertSpeed (torrentController.GetTorrentSwarm(manager));
savePathValueLabel.Text = manager.SavePath;
sizeValueLabel.Text = ByteConverter.ConvertSize (manager.Torrent.Size);
createdOnValueLabel.Text = manager.Torrent.CreationDate.ToLongDateString ();
@@ -1543,8 +1564,13 @@ public void LoadTorrent (string path, bool ask)
try
{
- TorrentManager manager = torrentController.addTorrent (torrent, savePath);
- manager.PeerConnected += PeerConnected;
+ TorrentManager manager = torrentController.addTorrent (torrent, savePath);
+ manager.PeerConnected += delegate(object o, PeerConnectionEventArgs e) {
+ GLib.Idle.Add(delegate {
+ PeerConnected(o, e);
+ return false;
+ });
+ };
}
catch (Exception ex)
{
2  Monsoon/PeerTreeView.cs
View
@@ -110,7 +110,7 @@ private void RenderAddress (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gt
PeerId peer = (PeerId) model.GetValue (iter, 0);
if(peer.IsConnected)
- (cell as Gtk.CellRendererText).Text = peer.Uri.Host;
+ (cell as Gtk.CellRendererText).Text = peer.Uri.Host + ":" + peer.Uri.Port;
}
28 Monsoon/RssManager/RssManagerController.cs
View
@@ -83,8 +83,13 @@ public bool AddWatcher(string url)
return false;
TorrentRssWatcher watcher = new TorrentRssWatcher(url);
- feeds.Add(url);
- watcher.TorrentFound += OnTorrentMatched;
+ feeds.Add(url);
+ watcher.TorrentFound += delegate(object o, TorrentRssWatcherEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnTorrentMatched(o, e);
+ return false;
+ });
+ };
watchers.Add(url, watcher);
watcher.StartWatching();
return true;
@@ -104,13 +109,18 @@ public bool RemoveWatcher(string url)
public void RestoreWatchers()
- {
- foreach(string feed in feeds){
- TorrentRssWatcher watcher = new TorrentRssWatcher(feed);
- watcher.TorrentFound += OnTorrentMatched;
- watchers.Add(feed, watcher);
- }
-
+ {
+ foreach (string feed in feeds)
+ {
+ TorrentRssWatcher watcher = new TorrentRssWatcher(feed);
+ watcher.TorrentFound += delegate(object o, TorrentRssWatcherEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnTorrentMatched(o, e);
+ return false;
+ });
+ };
+ watchers.Add(feed, watcher);
+ }
}
public void StartWatchers()
10 Monsoon/RssManager/RssManagerDialog.cs
View
@@ -98,12 +98,10 @@ private void FetchFeeds(object sender, DoWorkEventArgs args)
private void FetchFeedsCompleted(object sender, RunWorkerCompletedEventArgs args)
{
- Gtk.Application.Invoke (delegate {
- itemListStore.Clear();
- foreach(RssItem item in controller.Items){
- itemListStore.AppendValues(item);
- }
- });
+ itemListStore.Clear();
+ foreach(RssItem item in controller.Items){
+ itemListStore.AppendValues(item);
+ }
}
9 Monsoon/RssManager/TorrentRssWatcher.cs
View
@@ -82,8 +82,13 @@ public void StartWatching()
return;
- timer = new Timer();
- timer.Elapsed += OnTimedEvent;
+ timer = new Timer();
+ timer.Elapsed += delegate {
+ GLib.Idle.Add(delegate {
+ OnTimedEvent(null, null);
+ return false;
+ });
+ };
// Set the Interval to 30 seconds.
timer.Interval=30000;
244 Monsoon/TorrentController.cs
View
@@ -89,10 +89,14 @@ public TorrentController(MainWindow mainWindow)
Ticker.Tick ();
engine = new ClientEngine(mainWindow.EngineSettings);
- Ticker.Tock ("Client engine");
-
- engine.ConnectionManager.PeerMessageTransferred += OnPeerMessageTransferred;
-
+ Ticker.Tock ("Client engine");
+
+ engine.ConnectionManager.PeerMessageTransferred += delegate (object o, PeerMessageEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnPeerMessageTransferred(o, e);
+ return false;
+ });
+ };
hashProgress = new Dictionary<MonoTorrent.Client.TorrentManager,int>();
torrentSwarm = new Dictionary<MonoTorrent.Client.TorrentManager, SpeedMonitor>();
torrentsDownloading = new List<TorrentManager>();
@@ -138,25 +142,23 @@ private List<FastResume> LoadFastResume()
}
return list;
+ }
+
+ private void OnPeerMessageTransferred(object sender, PeerMessageEventArgs args)
+ {
+ if (args.Direction != Direction.Incoming)
+ return;
+
+ if (!(args.Message is MonoTorrent.Client.Messages.Standard.HaveMessage))
+ return;
+
+ if (!torrentSwarm.ContainsKey(args.TorrentManager))
+ torrentSwarm.Add(args.TorrentManager, new SpeedMonitor());
+
+ torrentSwarm[args.TorrentManager].AddDelta(args.TorrentManager.Torrent.PieceLength);
}
- private void OnPeerMessageTransferred(object sender, PeerMessageEventArgs args)
- {
- if(args.Direction != Direction.Incoming)
- return;
-
- if(!(args.Message is MonoTorrent.Client.Messages.Standard.HaveMessage))
- return;
-
- Gtk.Application.Invoke(delegate {
- if(!torrentSwarm.ContainsKey(args.TorrentManager))
- torrentSwarm.Add(args.TorrentManager, new SpeedMonitor());
-
- torrentSwarm[args.TorrentManager].AddDelta(args.TorrentManager.Torrent.PieceLength);
- });
- }
-
- public int GetTorrentSwarm(TorrentManager manager)
+ public long GetTorrentSwarm(TorrentManager manager)
{
SpeedMonitor monitor;
if(!torrentSwarm.TryGetValue(manager, out monitor))
@@ -228,17 +230,43 @@ public TorrentManager addTorrent(Torrent torrent, bool startTorrent, bool remove
mainWindow.SeedingLabel.AddTorrent(manager);
}
- logger.Info ("Added torrent " + manager.Torrent.Name);
-
- manager.TorrentStateChanged += OnTorrentStateChanged;
- manager.PieceManager.BlockRequested += OnBlockRequested;
- manager.PieceHashed += OnPieceHashed;
- manager.PeerConnected += OnPeerConnected;
- manager.PeerDisconnected += OnPeerDisconnected;
-
+ logger.Info ("Added torrent " + manager.Torrent.Name);
+
+ manager.TorrentStateChanged += delegate(object o, TorrentStateChangedEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnTorrentStateChanged(o, e);
+ return false;
+ });
+ };
+ manager.PieceManager.BlockRequested += delegate(object o, BlockEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnBlockRequested(o, e);
+ return false;
+ });
+ };
+ manager.PieceHashed += delegate(object o, PieceHashedEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnPieceHashed(o, e);
+ return false;
+ });
+ };
+ manager.PeerConnected += delegate(object o, PeerConnectionEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnPeerConnected(o, e);
+ return false;
+ });
+ };
+
+ manager.PeerDisconnected += delegate(object o, PeerConnectionEventArgs e) {
+ GLib.Idle.Add(delegate {
+ OnPeerDisconnected(o, e);
+ return false;
+ });
+ };
+
// add to "All" label
mainWindow.AllLabel.AddTorrent(manager);
-
+
mainWindow.StoreTorrentSettings();
return manager;
@@ -270,34 +298,35 @@ private void MoveToStorage (ref Torrent torrent)
t.Files[i].Priority = torrent.Files[i].Priority;
torrent = t;
- }
-
- private void OnPeerConnected (object sender, PeerConnectionEventArgs a)
- {
- if(!a.PeerID.IsConnected)
- return;
-
- Gtk.Application.Invoke (delegate {
- mainWindow.Peers.Add (a.PeerID, mainWindow.PeerListStore.AppendValues (a.PeerID));
- });
- }
-
- private void OnPeerDisconnected (object sender, PeerConnectionEventArgs a)
- {
- TreeIter iter;
-
- if(a.PeerID == null)
- return;
-
- Gtk.Application.Invoke (delegate {
- lock(mainWindow.Peers){
- if(!mainWindow.Peers.ContainsKey(a.PeerID))
- return;
- iter = mainWindow.Peers [a.PeerID];
- mainWindow.PeerListStore.Remove (ref iter);
- mainWindow.Peers.Remove (a.PeerID);
- }
- });
+ }
+
+ private void OnPeerConnected(object sender, PeerConnectionEventArgs a)
+ {
+ if (!a.PeerID.IsConnected)
+ return;
+
+ if (!mainWindow.Peers.ContainsKey(a.PeerID)) {
+ TreeIter iter = mainWindow.PeerListStore.AppendValues(a.PeerID);
+ mainWindow.Peers.Add(a.PeerID, mainWindow.PeerListStore.GetPath(iter));
+ }
+ }
+
+ private void OnPeerDisconnected(object sender, PeerConnectionEventArgs a)
+ {
+ lock (mainWindow.Peers)
+ {
+ foreach (PeerId p in new List<PeerId>(mainWindow.Peers.Keys))
+ {
+ if (p.IsConnected)
+ continue;
+
+ TreeIter iter;
+ if (mainWindow.PeerListStore.GetIter(out iter, mainWindow.Peers[p]))
+ mainWindow.PeerListStore.Remove(ref iter);
+
+ mainWindow.Peers.Remove(p);
+ }
+ }
}
private void OnBlockRequested (object sender, BlockEventArgs args)
@@ -346,59 +375,62 @@ private void OnTorrentStateChanged(object sender, TorrentStateChangedEventArgs a
{
TorrentManager manager = (TorrentManager)sender;
completedManager = manager;
- Gtk.Application.Invoke (delegate {
- if (args.OldState == TorrentState.Downloading) {
- logger.Debug("Removing " + manager.Torrent.Name + " from download label");
- mainWindow.DownloadingLabel.RemoveTorrent(manager);
- } else if (args.OldState == TorrentState.Seeding) {
- logger.Debug("Removing " + manager.Torrent.Name + " from upload label");
- mainWindow.SeedingLabel.RemoveTorrent(manager);
- } else if (args.OldState == TorrentState.Hashing) {
- if (hashProgress.ContainsKey(manager))
- hashProgress[manager] = 0;
- }
-
- if (args.NewState == TorrentState.Downloading) {
- logger.Debug("Adding " + manager.Torrent.Name + " to download label");
- mainWindow.DownloadingLabel.AddTorrent(manager);
- } else if (args.NewState == TorrentState.Seeding) {
- logger.Debug("Adding " + manager.Torrent.Name + " to upload label");
- mainWindow.SeedingLabel.AddTorrent(manager);
- } else if (args.NewState == TorrentState.Stopped) {
- lock(mainWindow.Peers)
+ if (args.OldState == TorrentState.Downloading) {
+ logger.Debug("Removing " + manager.Torrent.Name + " from download label");
+ mainWindow.DownloadingLabel.RemoveTorrent(manager);
+ } else if (args.OldState == TorrentState.Seeding) {
+ logger.Debug("Removing " + manager.Torrent.Name + " from upload label");
+ mainWindow.SeedingLabel.RemoveTorrent(manager);
+ } else if (args.OldState == TorrentState.Hashing) {
+ if (hashProgress.ContainsKey(manager))
+ hashProgress[manager] = 0;
+ }
+
+ if (args.NewState == TorrentState.Downloading) {
+ logger.Debug("Adding " + manager.Torrent.Name + " to download label");
+ mainWindow.DownloadingLabel.AddTorrent(manager);
+ } else if (args.NewState == TorrentState.Seeding) {
+ logger.Debug("Adding " + manager.Torrent.Name + " to upload label");
+ mainWindow.SeedingLabel.AddTorrent(manager);
+ } else if (args.NewState == TorrentState.Stopped) {
+ lock(mainWindow.Peers)
+ {
+ List<PeerId> peers = new List<PeerId>(mainWindow.Peers.Keys);
+ foreach (PeerId peer in peers)
{
- List<PeerId> peers = new List<PeerId>(mainWindow.Peers.Keys);
- foreach (PeerId peer in peers)
- {
- if (peer.TorrentManager == args.TorrentManager)
- {
- TreeIter iter = mainWindow.Peers[peer];
- mainWindow.PeerListStore.Remove (ref iter);
- mainWindow.Peers.Remove(peer);
- }
+ if (peer.TorrentManager == args.TorrentManager)
+ {
+ TreeIter iter;
+ if (!mainWindow.Peers.ContainsKey(peer))
+ continue;
+
+ TreePath path = mainWindow.Peers[peer];
+ if (mainWindow.PeerListStore.GetIter(out iter, path))
+ mainWindow.PeerListStore.Remove(ref iter);
+ mainWindow.Peers.Remove(peer);
}
}
- lock (mainWindow.Pieces)
- {
- mainWindow.Pieces.Clear ();
- }
}
-
- if (!prefSettings.EnableNotifications)
- return;
- if (args.NewState != TorrentState.Seeding)
- return;
- if (args.OldState != TorrentState.Downloading)
- return;
+ lock (mainWindow.Pieces)
+ {
+ mainWindow.Pieces.Clear ();
+ }
+ }
+
+ if (!prefSettings.EnableNotifications)
+ return;
+ if (args.NewState != TorrentState.Seeding)
+ return;
+ if (args.OldState != TorrentState.Downloading)
+ return;
- Notifications.Notification notify = new Notifications.Notification (_("Download Complete"), manager.Torrent.Name, Stock.GoDown);
- if (prefSettings.EnableTray)
- notify.AttachToWidget (mainWindow.TrayIcon);
- notify.Urgency = Notifications.Urgency.Low;
- notify.Timeout = 5000;
- notify.Show ();
- notify.AddAction("reveal-item", "Show", OnRevealActivated);
- });
+ Notifications.Notification notify = new Notifications.Notification (_("Download Complete"), manager.Torrent.Name, Stock.GoDown);
+ if (prefSettings.EnableTray)
+ notify.AttachToWidget (mainWindow.TrayIcon);
+ notify.Urgency = Notifications.Urgency.Low;
+ notify.Timeout = 5000;
+ notify.Show ();
+ notify.AddAction("reveal-item", "Show", OnRevealActivated);
}
private void OnRevealActivated (object o, Notifications.ActionArgs args)
14 Monsoon/TorrentTreeView.cs
View
@@ -126,10 +126,16 @@ private void OnTorrentDragDataReceived (object o, DragDataReceivedArgs args)
{
string [] uriList = (Encoding.UTF8.GetString(args.SelectionData.Data).TrimEnd()).Split('\n');
- foreach(string s in uriList){
- Uri uri = new Uri(s.TrimEnd());
- if(uri.IsFile && s.EndsWith(".torrent", StringComparison.OrdinalIgnoreCase))
- torrentController.MainWindow.LoadTorrent (uri.LocalPath);
+ foreach(string s in uriList){
+ try
+ {
+ Uri uri = new Uri(s.TrimEnd());
+ if (uri.IsFile && uri.LocalPath.EndsWith(".torrent", StringComparison.OrdinalIgnoreCase))
+ torrentController.MainWindow.LoadTorrent(uri.LocalPath);
+ }
+ catch
+ {
+ }
}
}
BIN  Monsoon/libs/MonoTorrent.dll
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.