for priorities experiment with a set instead of an array

This commit is contained in:
Mitchell Livingston 2007-07-13 04:52:40 +00:00
parent 3440ad7ef3
commit e6ba612b78
5 changed files with 20 additions and 24 deletions

View File

@ -109,12 +109,12 @@
[fNormalColor set];
else
{
NSArray * priorities = [torrent filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
NSSet * priorities = [torrent filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
if ([priorities count] == 0)
[fNormalColor set];
else
{
int priority = [[priorities objectAtIndex: 0] intValue];
int priority = [[priorities anyObject] intValue];
if (priority == TR_PRI_LOW)
[fLowPriorityColor set];
else if (priority == TR_PRI_HIGH)
@ -148,10 +148,10 @@
item = [self itemAtRow: i];
if (![[item objectForKey: @"IsFolder"] boolValue])
{
NSArray * priorities = [torrent filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
NSSet * priorities = [torrent filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
if ([priorities count] == 1)
{
int priority = [[priorities objectAtIndex: 0] intValue];
int priority = [[priorities anyObject] intValue];
if (priority == TR_PRI_LOW)
[fLowPriorityColor set];
else if (priority == TR_PRI_HIGH)

View File

@ -52,14 +52,14 @@
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
{
Torrent * torrent = [(InfoWindowController *)[[[self controlView] window] windowController] selectedTorrent];
NSIndexSet * indexSet = [fItem objectForKey: @"Indexes"];
NSSet * priorities = [torrent filePrioritiesForIndexes: [fItem objectForKey: @"Indexes"]];
if (![torrent canChangeDownloadCheckForFiles: indexSet])
if ([priorities count] == 0)
return;
BOOL low = [torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet],
normal = [torrent hasFilePriority: TR_PRI_NORMAL forIndexes: indexSet],
high = [torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet];
BOOL low = [priorities containsObject: [NSNumber numberWithInt: TR_PRI_LOW]],
normal = [priorities containsObject: [NSNumber numberWithInt: TR_PRI_NORMAL]],
high = [priorities containsObject: [NSNumber numberWithInt: TR_PRI_HIGH]];
FileOutlineView * view = (FileOutlineView *)[self controlView];
int row = [view hoverRow];

View File

@ -932,7 +932,7 @@
}
else if ([ident isEqualToString: @"Priority"])
{
NSArray * priorities = [[fTorrents objectAtIndex: 0] filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
NSSet * priorities = [[fTorrents objectAtIndex: 0] filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
int count = [priorities count];
if (count == 0)
@ -941,7 +941,7 @@
return NSLocalizedString(@"Multiple Priorities", "Inspector -> files tab -> tooltip");
else
{
int priority = [[priorities objectAtIndex: 0] intValue];
int priority = [[priorities anyObject] intValue];
if (priority == TR_PRI_LOW)
return NSLocalizedString(@"Low Priority", "Inspector -> files tab -> tooltip");
else if (priority == TR_PRI_HIGH)

View File

@ -206,7 +206,7 @@
- (void) setFileCheckState: (int) state forIndexes: (NSIndexSet *) indexSet;
- (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet;
- (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet;
- (NSArray *) filePrioritiesForIndexes: (NSIndexSet *) indexSet;
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet;
- (NSDate *) dateAdded;
- (NSDate *) dateCompleted;

View File

@ -1352,10 +1352,10 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return NO;
}
- (NSArray *) filePrioritiesForIndexes: (NSIndexSet *) indexSet
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet
{
BOOL low = NO, normal = NO, high = NO;
NSMutableArray * priorities = [NSMutableArray arrayWithCapacity: 3];
NSMutableSet * priorities = [NSMutableSet setWithCapacity: 3];
int index, priority;
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
@ -1366,28 +1366,24 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
priority = tr_torrentGetFilePriority(fHandle, index);
if (priority == TR_PRI_LOW)
{
if (!low)
low = YES;
else
if (low)
continue;
low = YES;
}
else if (priority == TR_PRI_HIGH)
{
if (!high)
high = YES;
else
if (high)
continue;
high = YES;
}
else
{
if (!normal)
normal = YES;
else
if (normal)
continue;
normal = YES;
}
[priorities addObject: [NSNumber numberWithInt: priority]];
if (low && normal && high)
break;
}