1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

If changing preference:

• from wait to start automatically, start all waiting transfers.
•  to higher number of active torrents, start waiting torrents until amount active is met.
This commit is contained in:
Mitchell Livingston 2006-06-23 17:40:56 +00:00
parent b0204b34bd
commit f2aa216dc7
2 changed files with 63 additions and 1 deletions

View file

@ -215,6 +215,9 @@ static void sleepCallBack(void * controller, io_service_t y,
[nc addObserver: self selector: @selector(checkWaitingForFinished:)
name: @"TorrentFinishedDownloading" object: nil];
[nc addObserver: self selector: @selector(startSettingChange:)
name: @"StartSettingChange" object: nil];
//timer to update the interface
fCompleted = 0;
[self updateUI: nil];
@ -985,6 +988,65 @@ static void sleepCallBack(void * controller, io_service_t y,
}
}
- (void) startSettingChange: (NSNotification *) notification
{
NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
if ([startSetting isEqualToString: @"Start"])
{
NSEnumerator * enumerator = [fTorrents objectEnumerator];
Torrent * torrent;
while ((torrent = [enumerator nextObject]))
if ([torrent waitingToStart])
[torrent startTransfer];
}
else if ([startSetting isEqualToString: @"Wait"])
{
NSMutableArray * waitingTorrents = [[NSMutableArray alloc] initWithCapacity: [fTorrents count]];
int amountToStart = [fDefaults integerForKey: @"WaitToStartNumber"];
NSEnumerator * enumerator = [fTorrents objectEnumerator];
Torrent * torrent;
while ((torrent = [enumerator nextObject]))
{
if ([torrent isActive])
{
if (![torrent isSeeding])
amountToStart--;
}
else if ([torrent waitingToStart])
[waitingTorrents addObject: torrent];
else;
}
int waitingCount = [waitingTorrents count];
if (amountToStart > waitingCount)
amountToStart = waitingCount;
//sort torrents by date to start earliest added
if (amountToStart > 0 && amountToStart < waitingCount)
{
NSSortDescriptor * dateDescriptor = [[[NSSortDescriptor alloc] initWithKey:
@"date" ascending: YES] autorelease];
NSArray * descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, nil];
[waitingTorrents sortUsingDescriptors: descriptors];
[descriptors release];
}
int i;
for (i = 0; i < amountToStart; i++)
[[waitingTorrents objectAtIndex: i] startTransfer];
[waitingTorrents release];
}
else;
[self updateUI: nil];
#warning reload inspector
}
- (int) numberOfRowsInTableView: (NSTableView *) t
{
return [fTorrents count];

View file

@ -452,7 +452,7 @@
else
[fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"];
#warning notification recheck
[[NSNotificationCenter defaultCenter] postNotificationName: @"StartSettingChange" object: self];
}
- (void) setMoveTorrent: (id) sender