]> granicus.if.org Git - transmission/commitdiff
add support to filter file list (not yet implemented in the interface)
authorMitchell Livingston <livings124@transmissionbt.com>
Sun, 7 Dec 2008 18:20:14 +0000 (18:20 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sun, 7 Dec 2008 18:20:14 +0000 (18:20 +0000)
macosx/FileOutlineController.h
macosx/FileOutlineController.m
macosx/Torrent.m

index e54f6195e260857271b26c88232bfee11fcc02ac..d35834a12a32b802d0d7d3bf4e77aa6bbc0c8b59 100644 (file)
 @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;
index 5e08ab972ca46f3222362dd799fb4794e0b745ab..c781edfc45a4426c159932f68efe1b4aec87c088 100644 (file)
@@ -72,14 +72,16 @@ typedef enum
     [self setTorrent: nil];
 }
 
-- (FileOutlineView *) outlineView
+- (void) dealloc
 {
-    return fOutline;
+    [fFileList release];
+    [fFilterText release];
+    [super dealloc];
 }
 
-- (void) outlineViewSelectionDidChange: (NSNotification *) notification
+- (FileOutlineView *) outlineView
 {
-    [[QuickLookController quickLook] updateQuickLook];
+    return fOutline;
 }
 
 - (void) setTorrent: (Torrent *) torrent
@@ -87,20 +89,61 @@ typedef enum
     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;
     }
index 1a0c524395557e2daf69d76d5474713c856b5743..c0d18b0611e4240413fee8a80b7c1879094237a6 100644 (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;