compile with charles_ last set of changes...currently file selection doesn't apply

This commit is contained in:
Mitchell Livingston 2007-07-10 03:30:25 +00:00
parent 0c39aa6565
commit 2dc3f8b8f0
5 changed files with 50 additions and 136 deletions

View File

@ -103,16 +103,17 @@
if (![self isRowSelected: row]) if (![self isRowSelected: row])
{ {
NSDictionary * item = [self itemAtRow: row]; NSDictionary * item = [self itemAtRow: row];
Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent];
if ([[item objectForKey: @"IsFolder"] boolValue] if ([[item objectForKey: @"IsFolder"] boolValue]
|| ![[(InfoWindowController *)[[self window] windowController] selectedTorrent] || ![torrent canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]])
canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]])
[fNormalColor set]; [fNormalColor set];
else else
{ {
int priority = [[item objectForKey: @"Priority"] intValue]; NSIndexSet * indexSet = [item objectForKey: @"Indexes"];
if (priority == PRIORITY_HIGH) if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet])
[fHighPriorityColor set]; [fHighPriorityColor set];
else if (priority == PRIORITY_LOW) else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet])
[fLowPriorityColor set]; [fLowPriorityColor set];
else else
[fNormalColor set]; [fNormalColor set];
@ -132,6 +133,7 @@
[super drawRect: r]; [super drawRect: r];
NSDictionary * item; NSDictionary * item;
NSIndexSet * indexSet;
int i, priority; int i, priority;
Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent]; Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent];
for (i = 0; i < [self numberOfRows]; i++) for (i = 0; i < [self numberOfRows]; i++)
@ -139,13 +141,15 @@
if ([self isRowSelected: i]) if ([self isRowSelected: i])
{ {
item = [self itemAtRow: i]; item = [self itemAtRow: i];
if (![[item objectForKey: @"IsFolder"] boolValue] if ([[item objectForKey: @"IsFolder"] boolValue])
&& [torrent canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]) continue;
indexSet = [item objectForKey: @"Indexes"];
if ([torrent canChangeDownloadCheckForFiles: indexSet])
{ {
priority = [[item objectForKey: @"Priority"] intValue]; if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet])
if (priority == PRIORITY_HIGH)
[fHighPriorityColor set]; [fHighPriorityColor set];
else if (priority == PRIORITY_LOW) else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet])
[fLowPriorityColor set]; [fLowPriorityColor set];
else else
continue; continue;

View File

@ -37,15 +37,15 @@
if (![torrent canChangeDownloadCheckForFiles: indexes]) if (![torrent canChangeDownloadCheckForFiles: indexes])
return; return;
int priority = segment, actualPriority; int priority;
if (priority == 0) if (segment == 0)
actualPriority = PRIORITY_LOW; priority = TR_PRI_LOW;
else if (priority == 2) else if (segment == 2)
actualPriority = PRIORITY_HIGH; priority = TR_PRI_HIGH;
else else
actualPriority = PRIORITY_NORMAL; priority = TR_PRI_NORMAL;
[torrent setFilePriority: actualPriority forIndexes: indexes]; [torrent setFilePriority: priority forIndexes: indexes];
[(FileOutlineView *)[self controlView] reloadData]; [(FileOutlineView *)[self controlView] reloadData];
} }
@ -57,9 +57,9 @@
if (![torrent canChangeDownloadCheckForFiles: indexSet]) if (![torrent canChangeDownloadCheckForFiles: indexSet])
return; return;
BOOL low = [torrent hasFilePriority: PRIORITY_LOW forIndexes: indexSet], BOOL low = [torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet],
normal = [torrent hasFilePriority: PRIORITY_NORMAL forIndexes: indexSet], normal = [torrent hasFilePriority: TR_PRI_NORMAL forIndexes: indexSet],
high = [torrent hasFilePriority: PRIORITY_HIGH forIndexes: indexSet]; high = [torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet];
FileOutlineView * view = (FileOutlineView *)[self controlView]; FileOutlineView * view = (FileOutlineView *)[self controlView];
int row = [view hoverRow]; int row = [view hoverRow];

View File

@ -666,11 +666,11 @@
Torrent * torrent = [fTorrents objectAtIndex: 0]; Torrent * torrent = [fTorrents objectAtIndex: 0];
if (menuItem == fFilePriorityHigh) if (menuItem == fFilePriorityHigh)
priority = PRIORITY_HIGH; priority = TR_PRI_HIGH;
else if (menuItem == fFilePriorityLow) else if (menuItem == fFilePriorityLow)
priority = PRIORITY_LOW; priority = TR_PRI_LOW;
else else
priority = PRIORITY_NORMAL; priority = TR_PRI_NORMAL;
NSIndexSet * fileIndexSet; NSIndexSet * fileIndexSet;
for (i = [indexSet firstIndex]; i != NSNotFound && (!current || !other); i = [indexSet indexGreaterThanIndex: i]) for (i = [indexSet firstIndex]; i != NSNotFound && (!current || !other); i = [indexSet indexGreaterThanIndex: i])
@ -952,9 +952,9 @@
if (![torrent canChangeDownloadCheckForFiles: indexSet]) if (![torrent canChangeDownloadCheckForFiles: indexSet])
return NSLocalizedString(@"Priority Not Available", "Inspector -> files tab -> tooltip"); return NSLocalizedString(@"Priority Not Available", "Inspector -> files tab -> tooltip");
BOOL low = [torrent hasFilePriority: PRIORITY_LOW forIndexes: indexSet], BOOL low = [torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet],
normal = [torrent hasFilePriority: PRIORITY_NORMAL forIndexes: indexSet], normal = [torrent hasFilePriority: TR_PRI_NORMAL forIndexes: indexSet],
high = [torrent hasFilePriority: PRIORITY_HIGH forIndexes: indexSet]; high = [torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet];
if (low && !normal && !high) if (low && !normal && !high)
return NSLocalizedString(@"Low Priority", "Inspector -> files tab -> tooltip"); return NSLocalizedString(@"Low Priority", "Inspector -> files tab -> tooltip");
@ -1086,11 +1086,11 @@
{ {
int priority; int priority;
if (sender == fFilePriorityHigh) if (sender == fFilePriorityHigh)
priority = PRIORITY_HIGH; priority = TR_PRI_HIGH;
else if (sender == fFilePriorityLow) else if (sender == fFilePriorityLow)
priority = PRIORITY_LOW; priority = TR_PRI_LOW;
else else
priority = PRIORITY_NORMAL; priority = TR_PRI_NORMAL;
Torrent * torrent = [fTorrents objectAtIndex: 0]; Torrent * torrent = [fTorrents objectAtIndex: 0];
NSIndexSet * indexSet = [fFileOutline selectedRowIndexes]; NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];

View File

@ -25,10 +25,6 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <transmission.h> #import <transmission.h>
#define PRIORITY_LOW -1
#define PRIORITY_NORMAL 0
#define PRIORITY_HIGH 1
#define INVALID -99 #define INVALID -99
@interface Torrent : NSObject @interface Torrent : NSObject

View File

@ -45,17 +45,15 @@ static int static_lastid = 0;
checkUpload: (NSNumber *) checkUpload uploadLimit: (NSNumber *) uploadLimit checkUpload: (NSNumber *) checkUpload uploadLimit: (NSNumber *) uploadLimit
checkDownload: (NSNumber *) checkDownload downloadLimit: (NSNumber *) downloadLimit checkDownload: (NSNumber *) checkDownload downloadLimit: (NSNumber *) downloadLimit
pex: (NSNumber *) pex pex: (NSNumber *) pex
waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue;
filesShouldDownload: (NSArray *) filesShouldDownload filePriorities: (NSArray *) filePriorities;
- (void) historyFilePriorities: (NSMutableArray *) history forItems: (NSArray *) items;
- (BOOL) shouldUseIncompleteFolderForName: (NSString *) name; - (BOOL) shouldUseIncompleteFolderForName: (NSString *) name;
- (void) updateDownloadFolder; - (void) updateDownloadFolder;
- (void) createFileListShouldDownload: (NSArray *) filesShouldDownload priorities: (NSArray *) filePriorities; - (void) createFileList;
- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings - (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
flatList: (NSMutableArray *) flatList fileSize: (uint64_t) size index: (int) index priority: (int) priority; flatList: (NSMutableArray *) flatList fileSize: (uint64_t) size index: (int) index;
- (NSImage *) advancedBar; - (NSImage *) advancedBar;
- (void) trashFile: (NSString *) path; - (void) trashFile: (NSString *) path;
@ -88,8 +86,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
checkUpload: nil uploadLimit: nil checkUpload: nil uploadLimit: nil
checkDownload: nil downloadLimit: nil checkDownload: nil downloadLimit: nil
pex: nil pex: nil
waitToStart: nil orderValue: nil waitToStart: nil orderValue: nil];
filesShouldDownload: nil filePriorities: nil];
if (self) if (self)
{ {
@ -119,9 +116,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
downloadLimit: [history objectForKey: @"DownloadLimit"] downloadLimit: [history objectForKey: @"DownloadLimit"]
pex: [history objectForKey: @"Pex"] pex: [history objectForKey: @"Pex"]
waitToStart: [history objectForKey: @"WaitToStart"] waitToStart: [history objectForKey: @"WaitToStart"]
orderValue: [history objectForKey: @"OrderValue"] orderValue: [history objectForKey: @"OrderValue"]];
filesShouldDownload: [history objectForKey: @"FilesShouldDownload"]
filePriorities: [history objectForKey: @"FilePriorities"]];
if (self) if (self)
{ {
@ -158,22 +153,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
if (fIncompleteFolder) if (fIncompleteFolder)
[history setObject: fIncompleteFolder forKey: @"IncompleteFolder"]; [history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
//set file should download
int fileCount = [self fileCount];
NSMutableArray * filesShouldDownload = [NSMutableArray arrayWithCapacity: fileCount];
tr_priority_t * priorities = tr_torrentGetFilePriorities(fHandle);
int i;
for (i = 0; i < fileCount; i++)
[filesShouldDownload addObject: [NSNumber numberWithBool: priorities[i] != TR_PRI_DND]];
free(priorities);
[history setObject: filesShouldDownload forKey: @"FilesShouldDownload"];
//set file priorities
NSMutableArray * filePriorities = [NSMutableArray arrayWithCapacity: fileCount];
[self historyFilePriorities: filePriorities forItems: fFileList];
[history setObject: filePriorities forKey: @"FilePriorities"];
if (fPublicTorrent) if (fPublicTorrent)
[history setObject: [self publicTorrentLocation] forKey: @"TorrentPath"]; [history setObject: [self publicTorrentLocation] forKey: @"TorrentPath"];
@ -1309,8 +1288,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
int index; int index;
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
{ {
if (tr_torrentGetFilePriority(fHandle, index) != TR_PRI_DND if (tr_torrentGetFileDL(fHandle, index) || ![self canChangeDownloadCheckForFiles: [NSIndexSet indexSetWithIndex: index]])
|| ![self canChangeDownloadCheckForFiles: [NSIndexSet indexSetWithIndex: index]])
onState = YES; onState = YES;
else else
offState = YES; offState = YES;
@ -1337,23 +1315,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
{ {
int index; int index;
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
{ tr_torrentSetFileDL(fHandle, index, state != NSOffState);
tr_priority_t actualPriority;
if (state == NSOnState)
{
int priority = [[[fFlatFileList objectAtIndex: index] objectForKey: @"Priority"] intValue];
if (priority == PRIORITY_HIGH)
actualPriority = TR_PRI_HIGH;
else if (priority == PRIORITY_LOW)
actualPriority = TR_PRI_LOW;
else
actualPriority = TR_PRI_NORMAL;
}
else
actualPriority = TR_PRI_DND;
tr_torrentSetFilePriority(fHandle, index, actualPriority);
}
[self update]; [self update];
if ([self isPaused]) if ([self isPaused])
@ -1362,32 +1324,16 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
- (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet - (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet
{ {
NSNumber * priorityValue = [NSNumber numberWithInt: priority];
int index; int index;
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
{ tr_torrentSetFilePriority(fHandle, index, priority);
[[fFlatFileList objectAtIndex: index] setObject: priorityValue forKey: @"Priority"];
if ([self checkForFiles: [NSIndexSet indexSetWithIndex: index]] == NSOnState)
{
tr_priority_t actualPriority;
if (priority == PRIORITY_HIGH)
actualPriority = TR_PRI_HIGH;
else if (priority == PRIORITY_LOW)
actualPriority = TR_PRI_LOW;
else
actualPriority = TR_PRI_NORMAL;
tr_torrentSetFilePriority(fHandle, index, actualPriority);
}
}
} }
- (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet - (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet
{ {
int index; int index;
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
if (priority == [[[fFlatFileList objectAtIndex: index] objectForKey: @"Priority"] intValue] if (priority == tr_torrentGetFilePriority(fHandle, index)
&& [self canChangeDownloadCheckForFiles: [NSIndexSet indexSetWithIndex: index]]) && [self canChangeDownloadCheckForFiles: [NSIndexSet indexSetWithIndex: index]])
return YES; return YES;
return NO; return NO;
@ -1405,8 +1351,8 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
- (NSDate *) dateActivity - (NSDate *) dateActivity
{ {
uint64_t date = fStat->activityDate / 1000; uint64_t date = fStat->activityDate;
return date != 0 ? [NSDate dateWithTimeIntervalSince1970: date] : fDateActivity; return date != 0 ? [NSDate dateWithTimeIntervalSince1970: date / 1000] : fDateActivity;
} }
- (int) stalledMinutes - (int) stalledMinutes
@ -1483,8 +1429,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
checkUpload: (NSNumber *) checkUpload uploadLimit: (NSNumber *) uploadLimit checkUpload: (NSNumber *) checkUpload uploadLimit: (NSNumber *) uploadLimit
checkDownload: (NSNumber *) checkDownload downloadLimit: (NSNumber *) downloadLimit checkDownload: (NSNumber *) checkDownload downloadLimit: (NSNumber *) downloadLimit
pex: (NSNumber *) pex pex: (NSNumber *) pex
waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue;
filesShouldDownload: (NSArray *) filesShouldDownload filePriorities: (NSArray *) filePriorities;
{ {
if (!(self = [super init])) if (!(self = [super init]))
return nil; return nil;
@ -1581,7 +1526,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30]; fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30];
fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30]; fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30];
[self createFileListShouldDownload: filesShouldDownload priorities: filePriorities]; [self createFileList];
//set up advanced bar //set up advanced bar
fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
@ -1597,14 +1542,12 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return self; return self;
} }
- (void) createFileListShouldDownload: (NSArray *) filesShouldDownload priorities: (NSArray *) filePriorities - (void) createFileList
{ {
int count = [self fileCount], i; int count = [self fileCount], i;
tr_file_t * file; tr_file_t * file;
NSMutableArray * pathComponents; NSMutableArray * pathComponents;
NSString * path; NSString * path;
int priority;
tr_priority_t actualPriority;
NSMutableArray * fileList = [[NSMutableArray alloc] init], NSMutableArray * fileList = [[NSMutableArray alloc] init],
* flatFileList = [[NSMutableArray alloc] initWithCapacity: count]; * flatFileList = [[NSMutableArray alloc] initWithCapacity: count];
@ -1622,24 +1565,9 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
else else
path = @""; path = @"";
priority = filePriorities ? [[filePriorities objectAtIndex: i] intValue] : PRIORITY_NORMAL;
[self insertPath: pathComponents forSiblings: fileList withParent: nil previousPath: path [self insertPath: pathComponents forSiblings: fileList withParent: nil previousPath: path
flatList: flatFileList fileSize: file->length index: i priority: priority]; flatList: flatFileList fileSize: file->length index: i];
[pathComponents autorelease]; [pathComponents autorelease];
if (!filesShouldDownload || [[filesShouldDownload objectAtIndex: i] boolValue])
{
if (priority == PRIORITY_HIGH)
actualPriority = TR_PRI_HIGH;
else if (priority == PRIORITY_LOW)
actualPriority = TR_PRI_LOW;
else
actualPriority = TR_PRI_NORMAL;
}
else
actualPriority = TR_PRI_DND;
tr_torrentSetFilePriority(fHandle, i, actualPriority);
} }
fFileList = [[NSArray alloc] initWithArray: fileList]; fFileList = [[NSArray alloc] initWithArray: fileList];
@ -1650,7 +1578,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings - (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
flatList: (NSMutableArray *) flatList fileSize: (uint64_t) size index: (int) index priority: (int) priority flatList: (NSMutableArray *) flatList fileSize: (uint64_t) size index: (int) index
{ {
NSString * name = [components objectAtIndex: 0]; NSString * name = [components objectAtIndex: 0];
BOOL isFolder = [components count] > 1; BOOL isFolder = [components count] > 1;
@ -1683,7 +1611,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
[dict setObject: [NSIndexSet indexSetWithIndex: index] forKey: @"Indexes"]; [dict setObject: [NSIndexSet indexSetWithIndex: index] forKey: @"Indexes"];
[dict setObject: [NSNumber numberWithUnsignedLongLong: size] forKey: @"Size"]; [dict setObject: [NSNumber numberWithUnsignedLongLong: size] forKey: @"Size"];
[dict setObject: [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]] forKey: @"Icon"]; [dict setObject: [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]] forKey: @"Icon"];
[dict setObject: [NSNumber numberWithInt: priority] forKey: @"Priority"];
[flatList addObject: dict]; [flatList addObject: dict];
} }
@ -1698,20 +1625,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
{ {
[components removeObjectAtIndex: 0]; [components removeObjectAtIndex: 0];
[self insertPath: components forSiblings: [dict objectForKey: @"Children"] [self insertPath: components forSiblings: [dict objectForKey: @"Children"]
withParent: dict previousPath: currentPath flatList: flatList fileSize: size index: index priority: priority]; withParent: dict previousPath: currentPath flatList: flatList fileSize: size index: index];
}
}
- (void) historyFilePriorities: (NSMutableArray *) history forItems: (NSArray *) items
{
NSEnumerator * enumerator = [items objectEnumerator];
NSDictionary * item;
while ((item = [enumerator nextObject]))
{
if (![[item objectForKey: @"IsFolder"] boolValue])
[history addObject: [item objectForKey: @"Priority"]];
else
[self historyFilePriorities: history forItems: [item objectForKey: @"Children"]];
} }
} }