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; - (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate;
- (NSArray *) peerSortDescriptors; - (NSArray *) peerSortDescriptors;
- (void) setFileCheckState: (int) state forItem: (NSMutableDictionary *) item;
- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild;
- (int) stateSettingToPopUpIndex: (int) index; - (int) stateSettingToPopUpIndex: (int) index;
- (int) popUpIndexToStateSetting: (int) index; - (int) popUpIndexToStateSetting: (int) index;
@ -107,17 +104,12 @@
//set file table //set file table
[fFileOutline setDoubleAction: @selector(revealFile:)]; [fFileOutline setDoubleAction: @selector(revealFile:)];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(fileFinished:) name: @"FileFinished" object: nil];
//set blank inspector //set blank inspector
[self updateInfoForTorrents: [NSArray array]]; [self updateInfoForTorrents: [NSArray array]];
} }
- (void) dealloc - (void) dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver: self];
if (fTorrents) if (fTorrents)
[fTorrents release]; [fTorrents release];
if (fPeers) if (fPeers)
@ -729,7 +721,7 @@
} }
else if ([[tableColumn identifier] isEqualToString: @"Check"]) else if ([[tableColumn identifier] isEqualToString: @"Check"])
{ {
/*if (!item) if (!item)
{ {
[(NSButtonCell *)cell setImagePosition: NSNoImage]; [(NSButtonCell *)cell setImagePosition: NSNoImage];
[cell setEnabled: NO]; [cell setEnabled: NO];
@ -738,8 +730,8 @@
[(NSButtonCell *)cell setImagePosition: NSImageOnly]; [(NSButtonCell *)cell setImagePosition: NSImageOnly];
[cell setEnabled: [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Remaining"] intValue] > 0 [cell setEnabled: [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Remaining"] intValue] > 0
: [[item objectForKey: @"Progress"] floatValue] < 1.0];*/ : [[item objectForKey: @"Progress"] floatValue] < 1.0];
[(NSButtonCell *)cell setImagePosition: NSNoImage]; //[(NSButtonCell *)cell setImagePosition: NSNoImage];
} }
else; else;
} }
@ -747,73 +739,15 @@
- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object - (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object
forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
{ {
Torrent * torrent = [fTorrents objectAtIndex: 0];
int state = [object intValue] != NSOffState ? NSOnState : NSOffState; int state = [object intValue] != NSOffState ? NSOnState : NSOffState;
[self setFileCheckState: state forItem: item]; [torrent setFileCheckState: state forFileItem: item];
NSMutableDictionary * topItem = [self resetFileCheckStateForItemParent: item]; NSMutableDictionary * topItem = [torrent resetFileCheckStateForItemParent: item];
[fFileOutline reloadItem: topItem reloadChildren: YES]; [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 - (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation
{ {

View File

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

View File

@ -30,6 +30,8 @@
#define MAX_PIECES 324 #define MAX_PIECES 324
#define BLANK_PIECE -99 #define BLANK_PIECE -99
#define INVALID -99
@interface Torrent (Private) @interface Torrent (Private)
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib - (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; 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) updateFileProgress
{ {
BOOL change = NO; 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] [dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]-1]
forKey: @"Remaining"]; 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; 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; NSMutableDictionary * item;
} if (!(item = [originalChild objectForKey: @"Parent"]))
return originalChild;
- (NSArray *) fileList
{ int state = INVALID;
return fFileList;
} NSMutableDictionary * child;
NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
- (int) fileCount while ((child = [enumerator nextObject]))
{ {
return fInfo->fileCount; 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 - (NSDate *) date