1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 16:52:39 +00:00

simplify some of the repetitive queue code a bit

This commit is contained in:
Mitchell Livingston 2007-06-20 00:54:05 +00:00
parent 34b2b2e698
commit c17c6eba58
3 changed files with 33 additions and 28 deletions

View file

@ -167,9 +167,11 @@
- (void) updateUI;
- (void) updateTorrentsInQueue;
- (int) numToStartFromQueue: (BOOL) downloadQueue;
- (void) torrentFinishedDownloading: (NSNotification *) notification;
- (void) torrentRestartedDownloading: (NSNotification *) notification;
- (void) updateTorrentHistory;
- (void) sortTorrents;

View file

@ -1376,27 +1376,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
BOOL download = [fDefaults boolForKey: @"Queue"],
seed = [fDefaults boolForKey: @"QueueSeed"];
//determine the number of downloads needed to start
int desiredDownloadActive = download ? [fDefaults integerForKey: @"QueueDownloadNumber"] : 0,
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;
}
}
int desiredDownloadActive = [self numToStartFromQueue: YES],
desiredSeedActive = [self numToStartFromQueue: NO];
//sort torrents by order value
NSArray * sortedTorrents;
@ -1412,7 +1393,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
else
sortedTorrents = fTorrents;
enumerator = [sortedTorrents objectEnumerator];
Torrent * torrent;
NSEnumerator * enumerator = [sortedTorrents objectEnumerator];
while ((torrent = [enumerator nextObject]))
{
if (![torrent isActive] && [torrent waitingToStart])
@ -1445,6 +1427,29 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
[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
{
Torrent * torrent = [notification object];
@ -1467,8 +1472,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
if (![fWindow isKeyWindow])
[fBadger incrementCompleted];
#warning make better
if ([fDefaults boolForKey: @"QueueSeed"])
if ([fDefaults boolForKey: @"QueueSeed"] && [self numToStartFromQueue: NO] <= 0)
{
[torrent stopTransfer];
[torrent setWaitToStart: YES];
@ -1483,8 +1487,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
[fInfoController updateInfoStats];
#warning make better
if ([fDefaults boolForKey: @"Queue"])
if ([fDefaults boolForKey: @"Queue"] && [self numToStartFromQueue: YES] <= 0)
{
[torrent stopTransfer];
[torrent setWaitToStart: YES];

View file

@ -1369,9 +1369,9 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
tr_torrentSetFilePriority(fHandle, index, actualPriority);
}
#warning when going seeding to download, update queue
[self update];
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self]; //for paused torrents
if ([self isPaused])
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self]; //for paused torrents
}
- (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet