From 3440ad7ef31f794ef596b61b13b826b2f6639806 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 13 Jul 2007 04:20:11 +0000 Subject: [PATCH] hopefully function for getting priorities is a bit faster --- macosx/FileOutlineView.m | 59 ++++++++++++++++++++--------------- macosx/InfoWindowController.m | 29 +++++++++-------- macosx/Torrent.h | 1 + macosx/Torrent.m | 45 ++++++++++++++++++++++++-- 4 files changed, 91 insertions(+), 43 deletions(-) diff --git a/macosx/FileOutlineView.m b/macosx/FileOutlineView.m index 390b1bde4..a858e5b7d 100644 --- a/macosx/FileOutlineView.m +++ b/macosx/FileOutlineView.m @@ -105,17 +105,23 @@ NSDictionary * item = [self itemAtRow: row]; Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent]; - NSIndexSet * indexSet = [item objectForKey: @"Indexes"]; - if ([[item objectForKey: @"IsFolder"] boolValue] || ![torrent canChangeDownloadCheckForFiles: indexSet]) + if ([[item objectForKey: @"IsFolder"] boolValue]) [fNormalColor set]; else { - if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet]) - [fHighPriorityColor set]; - else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet]) - [fLowPriorityColor set]; - else + NSArray * priorities = [torrent filePrioritiesForIndexes: [item objectForKey: @"Indexes"]]; + if ([priorities count] == 0) [fNormalColor set]; + else + { + int priority = [[priorities objectAtIndex: 0] intValue]; + if (priority == TR_PRI_LOW) + [fLowPriorityColor set]; + else if (priority == TR_PRI_HIGH) + [fHighPriorityColor set]; + else + [fNormalColor set]; + } } NSRect rect = [self rectOfRow: row]; @@ -140,27 +146,28 @@ if ([self isRowSelected: i]) { item = [self itemAtRow: i]; - if ([[item objectForKey: @"IsFolder"] boolValue]) - continue; - - indexSet = [item objectForKey: @"Indexes"]; - if ([torrent canChangeDownloadCheckForFiles: indexSet]) + if (![[item objectForKey: @"IsFolder"] boolValue]) { - if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet]) - [fHighPriorityColor set]; - else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet]) - [fLowPriorityColor set]; - else - continue; + NSArray * priorities = [torrent filePrioritiesForIndexes: [item objectForKey: @"Indexes"]]; + if ([priorities count] == 1) + { + int priority = [[priorities objectAtIndex: 0] intValue]; + if (priority == TR_PRI_LOW) + [fLowPriorityColor set]; + else if (priority == TR_PRI_HIGH) + [fHighPriorityColor set]; + else + continue; - NSRect rect = [self rectOfRow: i]; - float width = 14.0; - rect.origin.y += (rect.size.height - width) * 0.5; - rect.origin.x += 3.0; - rect.size.width = width; - rect.size.height = width; - - [[NSBezierPath bezierPathWithOvalInRect: rect] fill]; + NSRect rect = [self rectOfRow: i]; + float width = 14.0; + rect.origin.y += (rect.size.height - width) * 0.5; + rect.origin.x += 3.0; + rect.size.width = width; + rect.size.height = width; + + [[NSBezierPath bezierPathWithOvalInRect: rect] fill]; + } } } } diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 08ffd4c97..a926bb319 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -932,24 +932,23 @@ } else if ([ident isEqualToString: @"Priority"]) { - Torrent * torrent = [fTorrents objectAtIndex: 0]; - NSIndexSet * indexSet = [item objectForKey: @"Indexes"]; + NSArray * priorities = [[fTorrents objectAtIndex: 0] filePrioritiesForIndexes: [item objectForKey: @"Indexes"]]; - if (![torrent canChangeDownloadCheckForFiles: indexSet]) + int count = [priorities count]; + if (count == 0) return NSLocalizedString(@"Priority Not Available", "Inspector -> files tab -> tooltip"); - - 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]; - - if (low && !normal && !high) - return NSLocalizedString(@"Low Priority", "Inspector -> files tab -> tooltip"); - else if (!low && normal && !high) - return NSLocalizedString(@"Normal Priority", "Inspector -> files tab -> tooltip"); - else if (!low && !normal && high) - return NSLocalizedString(@"High Priority", "Inspector -> files tab -> tooltip"); - else + else if (count > 1) return NSLocalizedString(@"Multiple Priorities", "Inspector -> files tab -> tooltip"); + else + { + int priority = [[priorities objectAtIndex: 0] intValue]; + if (priority == TR_PRI_LOW) + return NSLocalizedString(@"Low Priority", "Inspector -> files tab -> tooltip"); + else if (priority == TR_PRI_HIGH) + return NSLocalizedString(@"High Priority", "Inspector -> files tab -> tooltip"); + else + return NSLocalizedString(@"Normal Priority", "Inspector -> files tab -> tooltip"); + } } else return nil; diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 5da4e9171..9e9e48fcc 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -206,6 +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; - (NSDate *) dateAdded; - (NSDate *) dateCompleted; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 3345c5be8..6d0ea3a21 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1314,12 +1314,12 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 { int count = [indexSet count], i = 0, index; int * files = malloc(count * sizeof(int)); - for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) { files[i] = index; i++; } + tr_torrentSetFileDLs(fHandle, files, count, state != NSOffState); free(files); @@ -1332,7 +1332,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 { int count = [indexSet count], i = 0, index; int * files = malloc(count * sizeof(int)); - for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) { files[i] = index; @@ -1353,6 +1352,48 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 return NO; } +- (NSArray *) filePrioritiesForIndexes: (NSIndexSet *) indexSet +{ + BOOL low = NO, normal = NO, high = NO; + NSMutableArray * priorities = [NSMutableArray arrayWithCapacity: 3]; + + int index, priority; + for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) + { + if (![self canChangeDownloadCheckForFiles: [NSIndexSet indexSetWithIndex: index]]) + continue; + + priority = tr_torrentGetFilePriority(fHandle, index); + if (priority == TR_PRI_LOW) + { + if (!low) + low = YES; + else + continue; + } + else if (priority == TR_PRI_HIGH) + { + if (!high) + high = YES; + else + continue; + } + else + { + if (!normal) + normal = YES; + else + continue; + } + + [priorities addObject: [NSNumber numberWithInt: priority]]; + + if (low && normal && high) + break; + } + return priorities; +} + - (NSDate *) dateAdded { return fDateAdded;