mirror of
https://github.com/transmission/transmission
synced 2024-12-25 17:17:31 +00:00
simplify some of the repetitive queue code a bit
This commit is contained in:
parent
34b2b2e698
commit
c17c6eba58
3 changed files with 33 additions and 28 deletions
|
@ -167,9 +167,11 @@
|
||||||
- (void) updateUI;
|
- (void) updateUI;
|
||||||
|
|
||||||
- (void) updateTorrentsInQueue;
|
- (void) updateTorrentsInQueue;
|
||||||
|
- (int) numToStartFromQueue: (BOOL) downloadQueue;
|
||||||
|
|
||||||
- (void) torrentFinishedDownloading: (NSNotification *) notification;
|
- (void) torrentFinishedDownloading: (NSNotification *) notification;
|
||||||
- (void) torrentRestartedDownloading: (NSNotification *) notification;
|
- (void) torrentRestartedDownloading: (NSNotification *) notification;
|
||||||
|
|
||||||
- (void) updateTorrentHistory;
|
- (void) updateTorrentHistory;
|
||||||
|
|
||||||
- (void) sortTorrents;
|
- (void) sortTorrents;
|
||||||
|
|
|
@ -1376,27 +1376,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
BOOL download = [fDefaults boolForKey: @"Queue"],
|
BOOL download = [fDefaults boolForKey: @"Queue"],
|
||||||
seed = [fDefaults boolForKey: @"QueueSeed"];
|
seed = [fDefaults boolForKey: @"QueueSeed"];
|
||||||
|
|
||||||
//determine the number of downloads needed to start
|
int desiredDownloadActive = [self numToStartFromQueue: YES],
|
||||||
int desiredDownloadActive = download ? [fDefaults integerForKey: @"QueueDownloadNumber"] : 0,
|
desiredSeedActive = [self numToStartFromQueue: NO];
|
||||||
desiredSeedActive = seed ? [fDefaults integerForKey: @"QueueSeedNumber"] : 0;
|
|
||||||
|
|
||||||
Torrent * torrent;
|
|
||||||
NSEnumerator * enumerator;
|
|
||||||
if (download || seed)
|
|
||||||
{
|
|
||||||
enumerator = [fTorrents objectEnumerator];
|
|
||||||
while ((torrent = [enumerator nextObject]))
|
|
||||||
if ([torrent isActive] && ![torrent isStalled] && ![torrent isError])
|
|
||||||
{
|
|
||||||
if ([torrent allDownloaded])
|
|
||||||
desiredSeedActive--;
|
|
||||||
else
|
|
||||||
desiredDownloadActive--;
|
|
||||||
|
|
||||||
if (desiredDownloadActive <= 0 && desiredSeedActive <= 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort torrents by order value
|
//sort torrents by order value
|
||||||
NSArray * sortedTorrents;
|
NSArray * sortedTorrents;
|
||||||
|
@ -1412,7 +1393,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
else
|
else
|
||||||
sortedTorrents = fTorrents;
|
sortedTorrents = fTorrents;
|
||||||
|
|
||||||
enumerator = [sortedTorrents objectEnumerator];
|
Torrent * torrent;
|
||||||
|
NSEnumerator * enumerator = [sortedTorrents objectEnumerator];
|
||||||
while ((torrent = [enumerator nextObject]))
|
while ((torrent = [enumerator nextObject]))
|
||||||
{
|
{
|
||||||
if (![torrent isActive] && [torrent waitingToStart])
|
if (![torrent isActive] && [torrent waitingToStart])
|
||||||
|
@ -1445,6 +1427,29 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
[self updateTorrentHistory];
|
[self updateTorrentHistory];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (int) numToStartFromQueue: (BOOL) downloadQueue
|
||||||
|
{
|
||||||
|
if (![fDefaults boolForKey: downloadQueue ? @"Queue" : @"QueueSeed"])
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int desired = [fDefaults integerForKey: downloadQueue ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
|
||||||
|
|
||||||
|
Torrent * torrent;
|
||||||
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
||||||
|
while ((torrent = [enumerator nextObject]))
|
||||||
|
if ([torrent isActive] && ![torrent isStalled] && ![torrent isError])
|
||||||
|
{
|
||||||
|
if ([torrent allDownloaded] != downloadQueue)
|
||||||
|
{
|
||||||
|
desired--;
|
||||||
|
if (desired <= 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return desired;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) torrentFinishedDownloading: (NSNotification *) notification
|
- (void) torrentFinishedDownloading: (NSNotification *) notification
|
||||||
{
|
{
|
||||||
Torrent * torrent = [notification object];
|
Torrent * torrent = [notification object];
|
||||||
|
@ -1467,8 +1472,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
if (![fWindow isKeyWindow])
|
if (![fWindow isKeyWindow])
|
||||||
[fBadger incrementCompleted];
|
[fBadger incrementCompleted];
|
||||||
|
|
||||||
#warning make better
|
if ([fDefaults boolForKey: @"QueueSeed"] && [self numToStartFromQueue: NO] <= 0)
|
||||||
if ([fDefaults boolForKey: @"QueueSeed"])
|
|
||||||
{
|
{
|
||||||
[torrent stopTransfer];
|
[torrent stopTransfer];
|
||||||
[torrent setWaitToStart: YES];
|
[torrent setWaitToStart: YES];
|
||||||
|
@ -1483,8 +1487,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
|
|
||||||
[fInfoController updateInfoStats];
|
[fInfoController updateInfoStats];
|
||||||
|
|
||||||
#warning make better
|
if ([fDefaults boolForKey: @"Queue"] && [self numToStartFromQueue: YES] <= 0)
|
||||||
if ([fDefaults boolForKey: @"Queue"])
|
|
||||||
{
|
{
|
||||||
[torrent stopTransfer];
|
[torrent stopTransfer];
|
||||||
[torrent setWaitToStart: YES];
|
[torrent setWaitToStart: YES];
|
||||||
|
|
|
@ -1369,8 +1369,8 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
tr_torrentSetFilePriority(fHandle, index, actualPriority);
|
tr_torrentSetFilePriority(fHandle, index, actualPriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning when going seeding to download, update queue
|
|
||||||
[self update];
|
[self update];
|
||||||
|
if ([self isPaused])
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self]; //for paused torrents
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self]; //for paused torrents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue