mirror of
https://github.com/transmission/transmission
synced 2025-02-21 13:46:52 +00:00
Streamlined some code and made it more efficient.
This commit is contained in:
parent
3f8dd961e1
commit
74afbbc50c
2 changed files with 62 additions and 103 deletions
|
@ -139,6 +139,7 @@
|
||||||
- (void) globalStartSettingChange: (NSNotification *) notification;
|
- (void) globalStartSettingChange: (NSNotification *) notification;
|
||||||
|
|
||||||
- (void) attemptToStartAuto: (Torrent *) torrent;
|
- (void) attemptToStartAuto: (Torrent *) torrent;
|
||||||
|
- (void) attemptToStartMultipleAuto: (NSArray *) torrents;
|
||||||
|
|
||||||
- (void) reloadInspector: (NSNotification *) notification;
|
- (void) reloadInspector: (NSNotification *) notification;
|
||||||
|
|
||||||
|
|
|
@ -1032,89 +1032,15 @@ static void sleepCallBack(void * controller, io_service_t y,
|
||||||
|
|
||||||
- (void) globalStartSettingChange: (NSNotification *) notification
|
- (void) globalStartSettingChange: (NSNotification *) notification
|
||||||
{
|
{
|
||||||
#warning redo
|
[self attemptToStartMultipleAuto: fTorrents];
|
||||||
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--;
|
|
||||||
if (amountToStart <= 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ([torrent waitingToStart])
|
|
||||||
[waitingTorrents addObject: torrent];
|
|
||||||
else;
|
|
||||||
}
|
|
||||||
|
|
||||||
int waitingCount = [waitingTorrents count];
|
|
||||||
if (amountToStart > 0 && waitingCount > 0)
|
|
||||||
{
|
|
||||||
if (amountToStart > waitingCount)
|
|
||||||
amountToStart = waitingCount;
|
|
||||||
|
|
||||||
//sort torrents by order
|
|
||||||
if (amountToStart < waitingCount)
|
|
||||||
{
|
|
||||||
NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey:
|
|
||||||
@"orderValue" ascending: YES] autorelease];
|
|
||||||
NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
|
|
||||||
|
|
||||||
[waitingTorrents sortUsingDescriptors: descriptors];
|
|
||||||
[descriptors release];
|
|
||||||
}
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < amountToStart; i++)
|
|
||||||
[[waitingTorrents objectAtIndex: i] startTransfer];
|
|
||||||
}
|
|
||||||
|
|
||||||
[waitingTorrents release];
|
|
||||||
}
|
|
||||||
else;
|
|
||||||
|
|
||||||
[self updateUI: nil];
|
[self updateUI: nil];
|
||||||
|
|
||||||
//update info for changed start setting
|
|
||||||
[self reloadInspector: nil];
|
[self reloadInspector: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) torrentStartSettingChange: (NSNotification *) notification
|
- (void) torrentStartSettingChange: (NSNotification *) notification
|
||||||
{
|
{
|
||||||
//sort torrents by order value
|
[self attemptToStartMultipleAuto: [notification object]];
|
||||||
NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey:
|
|
||||||
@"orderValue" ascending: YES] autorelease];
|
|
||||||
NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
|
|
||||||
|
|
||||||
NSArray * torrents = [[notification object] sortedArrayUsingDescriptors: descriptors];
|
|
||||||
[descriptors release];
|
|
||||||
|
|
||||||
//attempt to start all torrents
|
|
||||||
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
||||||
Torrent * torrent;
|
|
||||||
|
|
||||||
while ((torrent = [enumerator nextObject]))
|
|
||||||
[self attemptToStartAuto: torrent];
|
|
||||||
|
|
||||||
[self updateUI: nil];
|
[self updateUI: nil];
|
||||||
[self reloadInspector: nil];
|
[self reloadInspector: nil];
|
||||||
|
@ -1124,36 +1050,68 @@ static void sleepCallBack(void * controller, io_service_t y,
|
||||||
//will try to start, taking into consideration the start preference
|
//will try to start, taking into consideration the start preference
|
||||||
- (void) attemptToStartAuto: (Torrent *) torrent
|
- (void) attemptToStartAuto: (Torrent *) torrent
|
||||||
{
|
{
|
||||||
if ([torrent progress] >= 1.0)
|
[self attemptToStartMultipleAuto: [NSArray arrayWithObject: torrent]];
|
||||||
[torrent startTransfer];
|
}
|
||||||
else
|
|
||||||
|
- (void) attemptToStartMultipleAuto: (NSArray *) torrents
|
||||||
|
{
|
||||||
|
NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
|
||||||
|
if ([startSetting isEqualToString: @"Start"])
|
||||||
{
|
{
|
||||||
if (![torrent waitingToStart])
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
||||||
return;
|
Torrent * torrent;
|
||||||
|
while ((torrent = [enumerator nextObject]))
|
||||||
|
if ([torrent waitingToStart])
|
||||||
|
[torrent startTransfer];
|
||||||
|
|
||||||
NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
|
return;
|
||||||
if ([startSetting isEqualToString: @"Wait"])
|
}
|
||||||
{
|
else if (![startSetting isEqualToString: @"Wait"])
|
||||||
int desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"];
|
return;
|
||||||
|
else;
|
||||||
Torrent * tempTorrent;
|
|
||||||
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
//sort torrents by order value
|
||||||
while ((tempTorrent = [enumerator nextObject]))
|
NSArray * sortedTorrents;
|
||||||
if ([tempTorrent isActive] && ![tempTorrent isSeeding])
|
if ([torrents count] > 1)
|
||||||
{
|
{
|
||||||
desiredActive--;
|
NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey:
|
||||||
if (desiredActive <= 0)
|
@"orderValue" ascending: YES] autorelease];
|
||||||
return;
|
NSArray * descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
|
||||||
}
|
|
||||||
|
sortedTorrents = [torrents sortedArrayUsingDescriptors: descriptors];
|
||||||
[torrent startTransfer];
|
[descriptors release];
|
||||||
}
|
}
|
||||||
else if ([startSetting isEqualToString: @"Start"])
|
else
|
||||||
[torrent startTransfer];
|
sortedTorrents = torrents;
|
||||||
else;
|
|
||||||
|
int desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"];
|
||||||
|
|
||||||
|
Torrent * torrent;
|
||||||
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
||||||
|
while ((torrent = [enumerator nextObject]))
|
||||||
|
if ([torrent isActive] && ![torrent isSeeding])
|
||||||
|
{
|
||||||
|
desiredActive--;
|
||||||
|
if (desiredActive <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
enumerator = [sortedTorrents objectEnumerator];
|
||||||
|
while ((torrent = [enumerator nextObject]))
|
||||||
|
{
|
||||||
|
if ([torrent progress] >= 1.0)
|
||||||
|
[torrent startTransfer];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ([torrent waitingToStart] && desiredActive > 0)
|
||||||
|
{
|
||||||
|
[torrent startTransfer];
|
||||||
|
desiredActive--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[torrent update];
|
||||||
}
|
}
|
||||||
|
|
||||||
[torrent update];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) reloadInspector: (NSNotification *) notification
|
- (void) reloadInspector: (NSNotification *) notification
|
||||||
|
|
Loading…
Reference in a new issue