Changeset 562


Ignore:
Timestamp:
Jul 13, 2006, 12:11:41 AM (16 years ago)
Author:
livings124
Message:

initial support for filtering (the interface is temporary btw)

Location:
trunk/macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r556 r562  
    3939    tr_handle_t                 * fLib;
    4040    int                         fCompleted;
    41     NSMutableArray              * fTorrents;
     41   
     42    NSMutableArray              * fTorrents, * fFilteredTorrents;
    4243   
    4344    PrefsController             * fPrefsController;
     
    5859    IBOutlet NSTextField        * fTotalDLField, * fTotalULField, * fTotalTorrentsField;
    5960   
    60     NSString                    * fSortType;
     61    NSString                    * fSortType, * fFilterType;
    6162    IBOutlet NSMenuItem         * fNameSortItem, * fStateSortItem, * fProgressSortItem,
    62                                 * fDateSortItem, * fOrderSortItem;
     63                                * fDateSortItem, * fOrderSortItem,
     64                                * fNoFilterItem, * fPauseFilterItem,
     65                                * fSeedFilterItem, * fDownloadFilterItem;
    6366                               
    6467    IBOutlet NSMenuItem         * fNextInfoTabItem, * fPrevInfoTabItem;
     
    125128- (void) sortTorrents;
    126129- (void) setSort: (id) sender;
     130- (void) applyFilter;
     131- (void) setFilter: (id) sender;
    127132
    128133- (void) toggleSpeedLimit: (id) sender;
  • trunk/macosx/Controller.m

    r558 r562  
    6666    {
    6767        fLib = tr_init();
     68       
    6869        fTorrents = [[NSMutableArray alloc] initWithCapacity: 10];
     70        fFilteredTorrents = [[NSMutableArray alloc] initWithCapacity: 10];
     71       
    6972        fDefaults = [NSUserDefaults standardUserDefaults];
    7073        fInfoController = [[InfoWindowController alloc] initWithWindowNibName: @"InfoWindow"];
     
    8689
    8790    [fTorrents release];
     91    [fFilteredTorrents release];
     92   
    8893    [fToolbar release];
    8994    [fInfoController release];
     
    149154    [fSpeedLimitButton setToolTip: @"Speed Limit overrides the total bandwidth limits with its own limits."];
    150155
    151     [fTableView setTorrents: fTorrents];
     156    [fTableView setTorrents: fFilteredTorrents];
    152157    [[fTableView tableColumnWithIdentifier: @"Torrent"] setDataCell: [[TorrentCell alloc] init]];
    153158
     
    193198    [currentSortItem setState: NSOnState];
    194199   
     200    //set filter
     201    fFilterType = [[fDefaults stringForKey: @"Filter"] retain];
     202
     203    NSMenuItem * currentFilterItem;
     204    if ([fFilterType isEqualToString: @"Pause"])
     205        currentFilterItem = fPauseFilterItem;
     206    else if ([fFilterType isEqualToString: @"Seed"])
     207        currentFilterItem = fSeedFilterItem;
     208    else if ([fFilterType isEqualToString: @"Download"])
     209        currentFilterItem = fDownloadFilterItem;
     210    else
     211        currentFilterItem = fNoFilterItem;
     212   
     213    [currentFilterItem setState: NSOnState];
     214   
    195215    //set upload limit action button
    196216    [fUploadLimitItem setTitle: [NSString stringWithFormat: @"Limit (%d KB/s)",
     
    270290    [[NSRunLoop currentRunLoop] addTimer: fAutoImportTimer forMode: NSDefaultRunLoopMode];
    271291   
    272     [self sortTorrents];
     292    [self applyFilter];
    273293   
    274294    [fWindow makeKeyAndOrderFront: nil];
     
    370390        [torrent update];
    371391        [self attemptToStartAuto: torrent];
     392       
    372393        [fTorrents addObject: torrent];
    373394       
     
    418439            [torrent update];
    419440            [self attemptToStartAuto: torrent];
     441           
    420442            [fTorrents addObject: torrent];
    421443        }
     
    427449
    428450    [self updateUI: nil];
    429     [self sortTorrents];
     451    [self applyFilter];
    430452    [self updateTorrentHistory];
    431453}
     
    433455- (NSArray *) torrentsAtIndexes: (NSIndexSet *) indexSet
    434456{
    435     if ([fTorrents respondsToSelector: @selector(objectsAtIndexes:)])
    436         return [fTorrents objectsAtIndexes: indexSet];
     457    if ([fFilteredTorrents respondsToSelector: @selector(objectsAtIndexes:)])
     458        return [fFilteredTorrents objectsAtIndexes: indexSet];
    437459    else
    438460    {
     
    440462        unsigned int i;
    441463        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    442             [torrents addObject: [fTorrents objectAtIndex: i]];
     464            [torrents addObject: [fFilteredTorrents objectAtIndex: i]];
    443465
    444466        return torrents;
     
    500522   
    501523    [self updateUI: nil];
     524    [self applyFilter];
    502525    [fInfoController updateInfoStatsAndSettings];
    503526    [self updateTorrentHistory];
     
    525548   
    526549    [self updateUI: nil];
     550    [self applyFilter];
    527551    [fInfoController updateInfoStatsAndSettings];
    528552    [self updateTorrentHistory];
     
    560584            {
    561585                title = [NSString stringWithFormat: @"Comfirm Removal of \"%@\"",
    562                             [[fTorrents objectAtIndex: [fTableView selectedRow]] name]];
     586                            [[fFilteredTorrents objectAtIndex: [fTableView selectedRow]] name]];
    563587                message = @"This transfer is active."
    564588                            " Once removed, continuing the transfer will require the torrent file."
     
    629653
    630654        [torrent removeForever];
     655       
     656        [fFilteredTorrents removeObject: torrent];
    631657        [fTorrents removeObject: torrent];
    632658    }
     
    651677    [fTableView deselectAll: nil];
    652678    [self updateUI: nil];
     679    [self applyFilter];
    653680    [self updateTorrentHistory];
    654681}
     
    741768   
    742769    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    743         [[fTorrents objectAtIndex: i] revealData];
     770        [[fFilteredTorrents objectAtIndex: i] revealData];
    744771}
    745772
     
    782809        if ([torrent justFinished])
    783810        {
     811            if (![fFilterType isEqualToString: @"None"])
     812                [self applyFilter];
    784813            [self checkToStartWaiting: torrent];
    785814       
    786815            //notifications
    787816            [self notifyGrowl: @"Download Complete" message: [[torrent name] stringByAppendingString:
    788                                                     @" finished downloading"] identifier: @"Download Complete"];
     817                                            @" finished downloading"] identifier: @"Download Complete"];
    789818            if (![fWindow isKeyWindow])
    790819                fCompleted++;
     
    816845- (void) updateTorrentHistory
    817846{
    818     NSMutableArray * history = [NSMutableArray
    819         arrayWithCapacity: [fTorrents count]];
     847    NSMutableArray * history = [NSMutableArray arrayWithCapacity: [fTorrents count]];
    820848
    821849    NSEnumerator * enumerator = [fTorrents objectEnumerator];
    822850    Torrent * torrent;
    823     while( ( torrent = [enumerator nextObject] ) )
     851    while ((torrent = [enumerator nextObject]))
    824852        [history addObject: [torrent history]];
    825853
     
    833861    NSArray * selectedTorrents = nil;
    834862    int numSelected = [fTableView numberOfSelectedRows];
    835     if (numSelected > 0 && numSelected < [fTorrents count])
     863    if (numSelected > 0 && numSelected < [fFilteredTorrents count])
    836864        selectedTorrents = [self torrentsAtIndexes: [fTableView selectedRowIndexes]];
    837865
     
    871899        descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
    872900
    873     [fTorrents sortUsingDescriptors: descriptors];
     901    [fFilteredTorrents sortUsingDescriptors: descriptors];
    874902   
    875903    [descriptors release];
     
    884912        NSMutableIndexSet * indexSet = [[NSMutableIndexSet alloc] init];
    885913        while ((torrent = [enumerator nextObject]))
    886             [indexSet addIndex: [fTorrents indexOfObject: torrent]];
     914            [indexSet addIndex: [fFilteredTorrents indexOfObject: torrent]];
    887915       
    888916        [fTableView selectRowIndexes: indexSet byExtendingSelection: NO];
     
    926954
    927955    [self sortTorrents];
     956}
     957
     958- (void) applyFilter
     959{
     960    NSMutableArray * tempTorrents = [[NSMutableArray alloc] initWithCapacity: [fTorrents count]];
     961
     962    if ([fFilterType isEqualToString: @"Pause"])
     963    {
     964        NSEnumerator * enumerator = [fTorrents objectEnumerator];
     965        Torrent * torrent;
     966        while ((torrent = [enumerator nextObject]))
     967            if (![torrent isActive])
     968                [tempTorrents addObject: torrent];
     969    }
     970    else if ([fFilterType isEqualToString: @"Seed"])
     971    {
     972        NSEnumerator * enumerator = [fTorrents objectEnumerator];
     973        Torrent * torrent;
     974        while ((torrent = [enumerator nextObject]))
     975            if ([torrent isActive] && [torrent progress] >= 1.0)
     976                [tempTorrents addObject: torrent];
     977    }
     978    else if ([fFilterType isEqualToString: @"Download"])
     979    {
     980        NSEnumerator * enumerator = [fTorrents objectEnumerator];
     981        Torrent * torrent;
     982        while ((torrent = [enumerator nextObject]))
     983            if ([torrent isActive] && [torrent progress] < 1.0)
     984                [tempTorrents addObject: torrent];
     985    }
     986    else
     987        [tempTorrents setArray: fTorrents];
     988   
     989    [fFilteredTorrents setArray: tempTorrents];
     990    [tempTorrents release];
     991   
     992    [self sortTorrents];
     993}
     994
     995//resets filter and sorts torrents
     996- (void) setFilter: (id) sender
     997{
     998    NSMenuItem * prevFilterItem;
     999    if ([fFilterType isEqualToString: @"Pause"])
     1000        prevFilterItem = fPauseFilterItem;
     1001    else if ([fFilterType isEqualToString: @"Seed"])
     1002        prevFilterItem = fSeedFilterItem;
     1003    else if ([fFilterType isEqualToString: @"Download"])
     1004        prevFilterItem = fDownloadFilterItem;
     1005    else
     1006        prevFilterItem = fNoFilterItem;
     1007   
     1008    if (sender != prevFilterItem)
     1009    {
     1010        [prevFilterItem setState: NSOffState];
     1011        [sender setState: NSOnState];
     1012
     1013        [fFilterType release];
     1014        if (sender == fNoFilterItem)
     1015            fFilterType = [[NSString alloc] initWithString: @"None"];
     1016        else if (sender == fPauseFilterItem)
     1017            fFilterType = [[NSString alloc] initWithString: @"Pause"];
     1018        else if (sender == fSeedFilterItem)
     1019            fFilterType = [[NSString alloc] initWithString: @"Seed"];
     1020        else
     1021            fFilterType = [[NSString alloc] initWithString: @"Download"];
     1022           
     1023        [fDefaults setObject: fFilterType forKey: @"Filter"];
     1024    }
     1025
     1026    [self applyFilter];
    9281027}
    9291028
     
    10451144        [torrentToStart startTransfer];
    10461145       
     1146        [self applyFilter];
    10471147        [self updateUI: nil];
    10481148        [fInfoController updateInfoStatsAndSettings];
     
    10551155    [self attemptToStartMultipleAuto: [notification object]];
    10561156
     1157    [self applyFilter];
    10571158    [self updateUI: nil];
    10581159    [fInfoController updateInfoStatsAndSettings];
     
    10641165    [self attemptToStartMultipleAuto: fTorrents];
    10651166   
     1167    [self applyFilter];
    10661168    [self updateUI: nil];
    10671169    [fInfoController updateInfoStatsAndSettings];
     
    10711173- (void) torrentStoppedForRatio: (NSNotification *) notification
    10721174{
     1175    [self applyFilter];
    10731176    [fInfoController updateInfoStatsAndSettings];
    10741177   
     
    11971300- (int) numberOfRowsInTableView: (NSTableView *) t
    11981301{
    1199     return [fTorrents count];
     1302    return [fFilteredTorrents count];
    12001303}
    12011304
     
    12031306    forTableColumn: (NSTableColumn *) tableColumn row: (int) row
    12041307{
    1205     [cell setTorrent: [fTorrents objectAtIndex: row]];
     1308    [cell setTorrent: [fFilteredTorrents objectAtIndex: row]];
    12061309}
    12071310
     
    12671370        NSArray * selectedTorrents = nil;
    12681371        int numSelected = [fTableView numberOfSelectedRows];
    1269         if (numSelected > 0 && numSelected < [fTorrents count])
     1372        if (numSelected > 0 && numSelected < [fFilteredTorrents count])
    12701373            selectedTorrents = [self torrentsAtIndexes: [fTableView selectedRowIndexes]];
    12711374   
     
    12751378        //move torrent in array
    12761379        NSArray * movingTorrents = [[self torrentsAtIndexes: indexes] retain];
    1277         [fTorrents removeObjectsInArray: movingTorrents];
     1380        [fFilteredTorrents removeObjectsInArray: movingTorrents];
    12781381       
    12791382        //determine the insertion index now that transfers to move have been removed
     
    12841387        //insert objects at new location
    12851388        for (i = 0; i < [movingTorrents count]; i++)
    1286             [fTorrents insertObject: [movingTorrents objectAtIndex: i] atIndex: newRow - decrease + i];
     1389            [fFilteredTorrents insertObject: [movingTorrents objectAtIndex: i] atIndex: newRow - decrease + i];
    12871390       
    12881391        [movingTorrents release];
     
    12961399        else;
    12971400       
     1401        #warning change
    12981402        for (i = low; i <= high; i++)
    12991403            [[fTorrents objectAtIndex: i] setOrderValue: i];
     
    13081412            NSMutableIndexSet * indexSet = [[NSMutableIndexSet alloc] init];
    13091413            while ((torrent = [enumerator nextObject]))
    1310                 [indexSet addIndex: [fTorrents indexOfObject: torrent]];
     1414                [indexSet addIndex: [fFilteredTorrents indexOfObject: torrent]];
    13111415           
    13121416            [fTableView selectRowIndexes: indexSet byExtendingSelection: NO];
     
    15201624       
    15211625        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    1522             if ([[fTorrents objectAtIndex: i] isActive])
     1626            if ([[fFilteredTorrents objectAtIndex: i] isActive])
    15231627                return YES;
    15241628        return NO;
     
    15321636       
    15331637        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    1534             if ([[fTorrents objectAtIndex: i] isPaused])
     1638            if ([[fFilteredTorrents objectAtIndex: i] isPaused])
    15351639                return YES;
    15361640        return NO;
     
    16101714        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    16111715        {
    1612             torrent = [fTorrents objectAtIndex: i];
     1716            torrent = [fFilteredTorrents objectAtIndex: i];
    16131717            if (!warning && [torrent isActive])
    16141718            {
     
    16531757        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    16541758        {
    1655             torrent = [fTorrents objectAtIndex: i];
     1759            torrent = [fFilteredTorrents objectAtIndex: i];
    16561760            if ([torrent isActive])
    16571761                return YES;
     
    16721776        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    16731777        {
    1674             torrent = [fTorrents objectAtIndex: i];
     1778            torrent = [fFilteredTorrents objectAtIndex: i];
    16751779            if ([torrent isPaused])
    16761780                return YES;
     
    17491853    NSRect windowRect = [fWindow frame];
    17501854    float newHeight = windowRect.size.height - [fScrollView frame].size.height
    1751         + [fTorrents count] * ([fTableView rowHeight] + [fTableView intercellSpacing].height) + 30.0;
     1855        + [fFilteredTorrents count] * ([fTableView rowHeight] + [fTableView intercellSpacing].height) + 30.0;
    17521856
    17531857    float minHeight = [fWindow minSize].height;
  • trunk/macosx/Defaults.plist

    r539 r562  
    3333        <key>DownloadLimit</key>
    3434        <integer>100</integer>
     35        <key>Filter</key>
     36        <string>None</string>
    3537        <key>History</key>
    3638        <array/>
  • trunk/macosx/English.lproj/MainMenu.nib/classes.nib

    r555 r562  
    1515                resumeSelectedTorrents = id;
    1616                revealFile = id;
     17                setFilter = id;
    1718                setInfoTab = id;
    1819                setLimitGlobalEnabled = id;
     
    3738                fAdvancedBarItem = NSMenuItem;
    3839                fDateSortItem = NSMenuItem;
     40                fDownloadFilterItem = NSMenuItem;
    3941                fDownloadLimitItem = NSMenuItem;
    4042                fDownloadMenu = NSMenu;
     
    4244                fNameSortItem = NSMenuItem;
    4345                fNextInfoTabItem = NSMenuItem;
     46                fNoFilterItem = NSMenuItem;
    4447                fOrderSortItem = NSMenuItem;
     48                fPauseFilterItem = NSMenuItem;
    4549                fPrevInfoTabItem = NSMenuItem;
    4650                fProgressSortItem = NSMenuItem;
     
    4852                fRatioSetItem = NSMenuItem;
    4953                fScrollView = NSScrollView;
     54                fSeedFilterItem = NSMenuItem;
    5055                fSmallViewItem = NSMenuItem;
    5156                fSpeedLimitButton = NSButton;
Note: See TracChangeset for help on using the changeset viewer.