small adjustments to the queue

This commit is contained in:
Mitchell Livingston
2009-10-16 23:02:55 +00:00
parent 8d62b38891
commit 22354eb622
3 changed files with 20 additions and 25 deletions

View File

@@ -186,7 +186,7 @@ typedef enum
- (void) updateSpeedFieldsToolTips; - (void) updateSpeedFieldsToolTips;
- (void) updateTorrentsInQueue; - (void) updateTorrentsInQueue;
- (NSInteger) numToStartFromQueue: (BOOL) downloadQueue; - (NSUInteger) numToStartFromQueue: (BOOL) downloadQueue;
- (void) torrentFinishedDownloading: (NSNotification *) notification; - (void) torrentFinishedDownloading: (NSNotification *) notification;
- (void) torrentRestartedDownloading: (NSNotification *) notification; - (void) torrentRestartedDownloading: (NSNotification *) notification;

View File

@@ -1688,33 +1688,33 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
- (void) updateTorrentsInQueue - (void) updateTorrentsInQueue
{ {
BOOL download = [fDefaults boolForKey: @"Queue"], NSUInteger desiredDownloadActive = [fDefaults boolForKey: @"Queue"] ? [self numToStartFromQueue: YES] : NSUIntegerMax,
seed = [fDefaults boolForKey: @"QueueSeed"]; desiredSeedActive = [fDefaults boolForKey: @"QueueSeed"] ? [self numToStartFromQueue: NO] : NSUIntegerMax;
NSInteger desiredDownloadActive = [self numToStartFromQueue: YES],
desiredSeedActive = [self numToStartFromQueue: NO];
for (Torrent * torrent in fTorrents) for (Torrent * torrent in fTorrents)
{ {
if (desiredDownloadActive == 0 && desiredSeedActive == 0)
break;
if (![torrent isActive] && ![torrent isChecking] && [torrent waitingToStart]) if (![torrent isActive] && ![torrent isChecking] && [torrent waitingToStart])
{ {
if (![torrent allDownloaded]) if (![torrent allDownloaded])
{ {
if (!download || desiredDownloadActive > 0) if (desiredDownloadActive > 0)
{ {
[torrent startTransfer]; [torrent startTransfer];
if ([torrent isActive]) if ([torrent isActive])
desiredDownloadActive--; --desiredDownloadActive;
[torrent update]; [torrent update];
} }
} }
else else
{ {
if (!seed || desiredSeedActive > 0) if (desiredSeedActive > 0)
{ {
[torrent startTransfer]; [torrent startTransfer];
if ([torrent isActive]) if ([torrent isActive])
desiredSeedActive--; --desiredSeedActive;
[torrent update]; [torrent update];
} }
} }
@@ -1726,29 +1726,24 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[self updateTorrentHistory]; [self updateTorrentHistory];
} }
- (NSInteger) numToStartFromQueue: (BOOL) downloadQueue - (NSUInteger) numToStartFromQueue: (BOOL) downloadQueue
{ {
if (![fDefaults boolForKey: downloadQueue ? @"Queue" : @"QueueSeed"]) if (![fDefaults boolForKey: downloadQueue ? @"Queue" : @"QueueSeed"])
return 0; return 0;
NSInteger desired = [fDefaults integerForKey: downloadQueue ? @"QueueDownloadNumber" : @"QueueSeedNumber"]; NSUInteger desired = [fDefaults integerForKey: downloadQueue ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
for (Torrent * torrent in fTorrents) for (Torrent * torrent in fTorrents)
{ {
if (desired == 0)
break;
if ([torrent isChecking]) if ([torrent isChecking])
{ --desired;
desired--;
if (desired <= 0)
return 0;
}
else if ([torrent isActive] && ![torrent isStalled] && ![torrent isError]) else if ([torrent isActive] && ![torrent isStalled] && ![torrent isError])
{ {
if ([torrent allDownloaded] != downloadQueue) if ([torrent allDownloaded] != downloadQueue)
{ --desired;
desired--;
if (desired <= 0)
return 0;
}
} }
else; else;
} }
@@ -1786,7 +1781,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"com.apple.DownloadFileFinished" [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"com.apple.DownloadFileFinished"
object: [[torrent downloadFolder] stringByAppendingPathComponent: [torrent name]]]; object: [[torrent downloadFolder] stringByAppendingPathComponent: [torrent name]]];
if ([fDefaults boolForKey: @"QueueSeed"] && [self numToStartFromQueue: NO] <= 0) if ([self numToStartFromQueue: NO] == 0)
{ {
[torrent stopTransfer]; [torrent stopTransfer];
[torrent setWaitToStart: YES]; [torrent setWaitToStart: YES];
@@ -1801,7 +1796,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
Torrent * torrent = [notification object]; Torrent * torrent = [notification object];
if ([torrent isActive]) if ([torrent isActive])
{ {
if ([fDefaults boolForKey: @"Queue"] && [self numToStartFromQueue: YES] <= 0) if ([self numToStartFromQueue: YES] == 0)
{ {
[torrent stopTransfer]; [torrent stopTransfer];
[torrent setWaitToStart: YES]; [torrent setWaitToStart: YES];
@@ -3568,7 +3563,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
break; break;
default: default:
NSAssert1(NO, @"Unknown sort tag received: %d", [menuItem tag]); NSAssert1(NO, @"Unknown sort tag received: %d", [menuItem tag]);
return; return NO;
} }
[menuItem setState: [sortType isEqualToString: [fDefaults stringForKey: @"Sort"]] ? NSOnState : NSOffState]; [menuItem setState: [sortType isEqualToString: [fDefaults stringForKey: @"Sort"]] ? NSOnState : NSOffState];

Binary file not shown.