1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

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 @interface FileOutlineController : NSObject
{ {
Torrent * fTorrent; Torrent * fTorrent;
NSArray * fFileList;
IBOutlet FileOutlineView * fOutline; IBOutlet FileOutlineView * fOutline;
NSString * fFilterText;
} }
- (FileOutlineView *) outlineView; - (FileOutlineView *) outlineView;
- (void) setTorrent: (Torrent *) torrent; - (void) setTorrent: (Torrent *) torrent;
- (void) setFilterText: (NSString *) text;
- (void) reloadData; - (void) reloadData;
- (void) setCheck: (id) sender; - (void) setCheck: (id) sender;

View file

@ -72,35 +72,78 @@ typedef enum
[self setTorrent: nil]; [self setTorrent: nil];
} }
- (void) dealloc
{
[fFileList release];
[fFilterText release];
[super dealloc];
}
- (FileOutlineView *) outlineView - (FileOutlineView *) outlineView
{ {
return fOutline; return fOutline;
} }
- (void) outlineViewSelectionDidChange: (NSNotification *) notification
{
[[QuickLookController quickLook] updateQuickLook];
}
- (void) setTorrent: (Torrent *) torrent - (void) setTorrent: (Torrent *) torrent
{ {
fTorrent = torrent; fTorrent = torrent;
[fOutline setTorrent: fTorrent]; [fOutline setTorrent: fTorrent];
[fFileList release];
fFileList = [[fTorrent fileList] retain];
[fFilterText release];
fFilterText = nil;
[fOutline deselectAll: nil]; [fOutline deselectAll: nil];
[fOutline reloadData]; [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 - (void) reloadData
{ {
[fTorrent updateFileStat]; [fTorrent updateFileStat];
[fOutline reloadData]; [fOutline reloadData];
} }
- (void) outlineViewSelectionDidChange: (NSNotification *) notification
{
[[QuickLookController quickLook] updateQuickLook];
}
- (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item - (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
{ {
if (!item) if (!item)
return fTorrent ? [[fTorrent fileList] count] : 0; return fFileList ? [fFileList count] : 0;
else else
{ {
FileListNode * node = (FileListNode *)item; FileListNode * node = (FileListNode *)item;
@ -115,7 +158,7 @@ typedef enum
- (id) outlineView: (NSOutlineView *) outlineView child: (NSInteger) index ofItem: (id) item - (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 - (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
@ -295,7 +338,7 @@ typedef enum
NSIndexSet * indexSet = [fOutline selectedRowIndexes]; NSIndexSet * indexSet = [fOutline selectedRowIndexes];
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
if ([[NSFileManager defaultManager] fileExistsAtPath: if ([[NSFileManager defaultManager] fileExistsAtPath:
[downloadFolder stringByAppendingPathComponent: [[[fTorrent fileList] objectAtIndex: i] fullPath]]]) [downloadFolder stringByAppendingPathComponent: [[fFileList objectAtIndex: i] fullPath]]])
return YES; return YES;
return NO; return NO;
} }

View file

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