mirror of
https://github.com/transmission/transmission
synced 2025-03-06 19:48:15 +00:00
hopefully function for getting priorities is a bit faster
This commit is contained in:
parent
5975ae7a59
commit
3440ad7ef3
4 changed files with 91 additions and 43 deletions
|
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue