small efficiency change and some improvements for the invisible file checkboxes

This commit is contained in:
Mitchell Livingston 2007-02-23 19:17:31 +00:00
parent 74d2eefac4
commit 16cd689de2
3 changed files with 63 additions and 10 deletions

View File

@ -107,12 +107,18 @@
//set file table
[fFileOutline setDoubleAction: @selector(revealFile:)];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(fileFinished:) name: @"FileFinished" object: nil];
//set blank inspector
[self updateInfoForTorrents: [NSArray array]];
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
if (fTorrents)
[fTorrents release];
if (fPeers)
[fPeers release];
@ -399,7 +405,7 @@
if ([fTorrents count] != 1)
return;
[[fTorrents objectAtIndex: 0] updateFileProgress];
if ([[fTorrents objectAtIndex: 0] updateFileProgress])
[fFileOutline reloadData];
}
@ -723,8 +729,16 @@
}
else if ([[tableColumn identifier] isEqualToString: @"Check"])
{
/*[(NSButtonCell *)cell setImagePosition: item ? NSImageOnly : NSNoImage];
[cell setEnabled: NO];*/
/*if (!item)
{
[(NSButtonCell *)cell setImagePosition: NSNoImage];
[cell setEnabled: NO];
return;
}
[(NSButtonCell *)cell setImagePosition: NSImageOnly];
[cell setEnabled: [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Remaining"] intValue] > 0
: [[item objectForKey: @"Progress"] floatValue] < 1.0];*/
[(NSButtonCell *)cell setImagePosition: NSNoImage];
}
else;
@ -741,6 +755,16 @@
[fFileOutline reloadItem: topItem reloadChildren: YES];
}
- (void) fileFinished: (NSNotification *) notification
{
NSMutableDictionary * item = [notification object];
[item setObject: [NSNumber numberWithInt: NSOnState] forKey: @"Check"];
NSMutableDictionary * topItem = [self resetFileCheckStateForItemParent: item];
[fFileOutline reloadItem: topItem reloadChildren: YES];
}
- (void) setFileCheckState: (int) state forItem: (NSMutableDictionary *) item
{
[item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];

View File

@ -172,7 +172,7 @@
- (uint64_t) uploadedTotal;
- (float) swarmSpeed;
- (void) updateFileProgress;
- (BOOL) updateFileProgress;
- (NSNumber *) orderValue;
- (void) setOrderValue: (int) orderValue;

View File

@ -1043,15 +1043,38 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return fStat->swarmspeed;
}
- (void) updateFileProgress
- (BOOL) updateFileProgress
{
BOOL change = NO;
float * progress = tr_torrentCompletion(fHandle);
NSNumber * progressNum;
NSMutableDictionary * item, * dict;
int i, fileCount = [self fileCount];
for (i = 0; i < fileCount; i++)
[[fFileFlatList objectAtIndex: i] setObject: [NSNumber numberWithFloat: progress[i]] forKey: @"Progress"];
{
if (!(progressNum = [[fFileFlatList objectAtIndex: i] objectForKey: @"Progress"])
|| [progressNum floatValue] != progress[i])
{
item = [fFileFlatList objectAtIndex: i];
[item setObject: [NSNumber numberWithFloat: progress[i]] forKey: @"Progress"];
change = YES;
if (progress[i] == 1.0)
{
dict = item;
while ((dict = [dict objectForKey: @"Parent"]))
[dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]-1]
forKey: @"Remaining"];
[[NSNotificationCenter defaultCenter] postNotificationName: @"FileFinished" object: item];
}
}
}
free(progress);
return change;
}
- (NSNumber *) orderValue
@ -1256,7 +1279,10 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
[siblings addObject: dict];
if (isFolder)
{
[dict setObject: [NSMutableArray array] forKey: @"Children"];
[dict setObject: [NSNumber numberWithInt: 1] forKey: @"Remaining"];
}
else
{
[flatList addObject: dict];
@ -1269,6 +1295,9 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
}
else
{
if (isFolder)
[dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]+1] forKey: @"Remaining"];
int dictState = [[dict objectForKey: @"Check"] intValue];
if (dictState != NSMixedState && dictState != state)
[dict setObject: [NSNumber numberWithInt: NSMixedState] forKey: @"Check"];