From 16cd689de210fb78757a22bcce6ab4240d8964c6 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 23 Feb 2007 19:17:31 +0000 Subject: [PATCH] small efficiency change and some improvements for the invisible file checkboxes --- macosx/InfoWindowController.m | 36 +++++++++++++++++++++++++++++------ macosx/Torrent.h | 2 +- macosx/Torrent.m | 35 +++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index fcad288cc..985c3348f 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -107,13 +107,19 @@ //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 { - [fTorrents release]; + [[NSNotificationCenter defaultCenter] removeObserver: self]; + + if (fTorrents) + [fTorrents release]; if (fPeers) [fPeers release]; if (fFiles) @@ -399,8 +405,8 @@ if ([fTorrents count] != 1) return; - [[fTorrents objectAtIndex: 0] updateFileProgress]; - [fFileOutline reloadData]; + if ([[fTorrents objectAtIndex: 0] updateFileProgress]) + [fFileOutline reloadData]; } - (void) updateInfoSettings @@ -710,7 +716,7 @@ } - (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell - forTableColumn: (NSTableColumn *) tableColumn item:(id) item + forTableColumn: (NSTableColumn *) tableColumn item: (id) item { if ([[tableColumn identifier] isEqualToString: @"Name"]) { @@ -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"]; diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 2a5c4f959..ae851f37c 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -172,7 +172,7 @@ - (uint64_t) uploadedTotal; - (float) swarmSpeed; -- (void) updateFileProgress; +- (BOOL) updateFileProgress; - (NSNumber *) orderValue; - (void) setOrderValue: (int) orderValue; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 035a482d1..6c09dbef7 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1043,15 +1043,38 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 return fStat->swarmspeed; } -- (void) updateFileProgress +- (BOOL) updateFileProgress { - float * progress = tr_torrentCompletion( fHandle ); + 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"];