add support to filter file list (not yet implemented in the interface)

This commit is contained in:
Mitchell Livingston 2008-12-07 18:20:14 +00:00
parent bdbe24b6e3
commit 7265b4f98d
3 changed files with 57 additions and 8 deletions

View File

@ -30,14 +30,19 @@
@interface FileOutlineController : NSObject
{
Torrent * fTorrent;
NSArray * fFileList;
IBOutlet FileOutlineView * fOutline;
NSString * fFilterText;
}
- (FileOutlineView *) outlineView;
- (void) setTorrent: (Torrent *) torrent;
- (void) setFilterText: (NSString *) text;
- (void) reloadData;
- (void) setCheck: (id) sender;

View File

@ -72,35 +72,78 @@ typedef enum
[self setTorrent: nil];
}
- (void) dealloc
{
[fFileList release];
[fFilterText release];
[super dealloc];
}
- (FileOutlineView *) outlineView
{
return fOutline;
}
- (void) outlineViewSelectionDidChange: (NSNotification *) notification
{
[[QuickLookController quickLook] updateQuickLook];
}
- (void) setTorrent: (Torrent *) torrent
{
fTorrent = torrent;
[fOutline setTorrent: fTorrent];
[fFileList release];
fFileList = [[fTorrent fileList] retain];
[fFilterText release];
fFilterText = nil;
[fOutline deselectAll: nil];
[fOutline reloadData];
}
- (void) setFilterText: (NSString *) text
{
if ([text isEqualToString: @""])
text = nil;
if (text == fFilterText || [text isEqualToString: fFilterText])
return;
[fFilterText release];
fFilterText = [text retain];
[fFileList release];
if (!fFilterText)
fFileList = [[fTorrent fileList] retain];
else
{
NSMutableArray * list = [NSMutableArray arrayWithCapacity: [fTorrent fileCount]];
NSEnumerator * enumerator = [[fTorrent flatFileList] objectEnumerator];
FileListNode * node;
while ((node = [enumerator nextObject]))
if ([[node name] rangeOfString: fFilterText options: NSCaseInsensitiveSearch].location != NSNotFound)
[list addObject: node];
fFileList = [[NSArray alloc] initWithArray: list];
}
[fOutline reloadData];
}
- (void) reloadData
{
[fTorrent updateFileStat];
[fOutline reloadData];
}
- (void) outlineViewSelectionDidChange: (NSNotification *) notification
{
[[QuickLookController quickLook] updateQuickLook];
}
- (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
{
if (!item)
return fTorrent ? [[fTorrent fileList] count] : 0;
return fFileList ? [fFileList count] : 0;
else
{
FileListNode * node = (FileListNode *)item;
@ -115,7 +158,7 @@ typedef enum
- (id) outlineView: (NSOutlineView *) outlineView child: (NSInteger) index ofItem: (id) item
{
return [(item ? [(FileListNode *)item children] : [fTorrent fileList]) objectAtIndex: index];
return [(item ? [(FileListNode *)item children] : fFileList) objectAtIndex: index];
}
- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
@ -295,7 +338,7 @@ typedef enum
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
if ([[NSFileManager defaultManager] fileExistsAtPath:
[downloadFolder stringByAppendingPathComponent: [[[fTorrent fileList] objectAtIndex: i] fullPath]]])
[downloadFolder stringByAppendingPathComponent: [[fFileList objectAtIndex: i] fullPath]]])
return YES;
return NO;
}

View File

@ -466,6 +466,7 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
FileListNode * node;
while ((node = [nodeEnumerator nextObject]))
{
#warning this could be more thorough
if ([[node fullPath] hasPrefix: file])
{
isExtra = NO;