move torrent check code to the Torrent class

This commit is contained in:
Mitchell Livingston 2007-03-02 01:34:06 +00:00
parent 930fa86d0e
commit 81cda31d78
3 changed files with 76 additions and 89 deletions

View File

@ -60,9 +60,6 @@
- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate;
- (NSArray *) peerSortDescriptors;
- (void) setFileCheckState: (int) state forItem: (NSMutableDictionary *) item;
- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild;
- (int) stateSettingToPopUpIndex: (int) index;
- (int) popUpIndexToStateSetting: (int) index;
@ -107,17 +104,12 @@
//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)
@ -729,7 +721,7 @@
}
else if ([[tableColumn identifier] isEqualToString: @"Check"])
{
/*if (!item)
if (!item)
{
[(NSButtonCell *)cell setImagePosition: NSNoImage];
[cell setEnabled: NO];
@ -738,8 +730,8 @@
[(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];
: [[item objectForKey: @"Progress"] floatValue] < 1.0];
//[(NSButtonCell *)cell setImagePosition: NSNoImage];
}
else;
}
@ -747,73 +739,15 @@
- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object
forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
{
Torrent * torrent = [fTorrents objectAtIndex: 0];
int state = [object intValue] != NSOffState ? NSOnState : NSOffState;
[self setFileCheckState: state forItem: item];
NSMutableDictionary * topItem = [self resetFileCheckStateForItemParent: item];
[torrent setFileCheckState: state forFileItem: item];
NSMutableDictionary * topItem = [torrent resetFileCheckStateForItemParent: item];
[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"];
if (![[item objectForKey: @"IsFolder"] boolValue])
return;
NSMutableDictionary * child;
NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
while ((child = [enumerator nextObject]))
if (state != [[child objectForKey: @"Check"] intValue])
[self setFileCheckState: state forItem: child];
}
- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild
{
NSMutableDictionary * item;
if (!(item = [originalChild objectForKey: @"Parent"]))
return originalChild;
int state = INVALID;
NSMutableDictionary * child;
NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
while ((child = [enumerator nextObject]))
{
if (state == INVALID)
{
state = [[child objectForKey: @"Check"] intValue];
if (state == NSMixedState)
break;
}
else if (state != [[child objectForKey: @"Check"] intValue])
{
state = NSMixedState;
break;
}
else;
}
if (state != [[item objectForKey: @"Check"] intValue])
{
[item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
return [self resetFileCheckStateForItemParent: item];
}
else
return originalChild;
}
- (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation
{

View File

@ -172,13 +172,14 @@
- (uint64_t) uploadedTotal;
- (float) swarmSpeed;
- (BOOL) updateFileProgress;
- (NSNumber *) orderValue;
- (void) setOrderValue: (int) orderValue;
- (NSArray *) fileList;
- (int) fileCount;
- (BOOL) updateFileProgress;
- (void) setFileCheckState: (int) state forFileItem: (NSMutableDictionary *) item;
- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild;
- (NSDate *) date;
- (NSNumber *) stateSortKey;

View File

@ -30,6 +30,8 @@
#define MAX_PIECES 324
#define BLANK_PIECE -99
#define INVALID -99
@interface Torrent (Private)
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
@ -1043,6 +1045,26 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return fStat->swarmspeed;
}
- (NSNumber *) orderValue
{
return [NSNumber numberWithInt: fOrderValue];
}
- (void) setOrderValue: (int) orderValue
{
fOrderValue = orderValue;
}
- (NSArray *) fileList
{
return fFileList;
}
- (int) fileCount
{
return fInfo->fileCount;
}
- (BOOL) updateFileProgress
{
BOOL change = NO;
@ -1067,7 +1089,8 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
[dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]-1]
forKey: @"Remaining"];
[[NSNotificationCenter defaultCenter] postNotificationName: @"FileFinished" object: item];
[item setObject: [NSNumber numberWithInt: NSOnState] forKey: @"Check"];
[self resetFileCheckStateForItemParent: item];
}
}
}
@ -1077,24 +1100,53 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return change;
}
- (NSNumber *) orderValue
- (void) setFileCheckState: (int) state forFileItem: (NSMutableDictionary *) item
{
return [NSNumber numberWithInt: fOrderValue];
[item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
if (![[item objectForKey: @"IsFolder"] boolValue])
return;
NSMutableDictionary * child;
NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
while ((child = [enumerator nextObject]))
if (state != [[child objectForKey: @"Check"] intValue])
[self setFileCheckState: state forFileItem: child];
}
- (void) setOrderValue: (int) orderValue
- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild
{
fOrderValue = orderValue;
}
- (NSArray *) fileList
{
return fFileList;
}
- (int) fileCount
{
return fInfo->fileCount;
NSMutableDictionary * item;
if (!(item = [originalChild objectForKey: @"Parent"]))
return originalChild;
int state = INVALID;
NSMutableDictionary * child;
NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
while ((child = [enumerator nextObject]))
{
if (state == INVALID)
{
state = [[child objectForKey: @"Check"] intValue];
if (state == NSMixedState)
break;
}
else if (state != [[child objectForKey: @"Check"] intValue])
{
state = NSMixedState;
break;
}
else;
}
if (state != [[item objectForKey: @"Check"] intValue])
{
[item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
return [self resetFileCheckStateForItemParent: item];
}
else
return originalChild;
}
- (NSDate *) date