Ticket #5460: add-error-filter.diff

File add-error-filter.diff, 13.1 KB (added by alimony, 6 years ago)
  • macosx/Controller.m

     
    24132413
    24142414- (void) applyFilter
    24152415{
    2416     __block int32_t active = 0, downloading = 0, seeding = 0, paused = 0;
     2416    __block int32_t active = 0, downloading = 0, seeding = 0, paused = 0, error = 0;
    24172417    NSString * filterType = [fDefaults stringForKey: @"Filter"];
    2418     BOOL filterActive = NO, filterDownload = NO, filterSeed = NO, filterPause = NO, filterStatus = YES;
     2418    BOOL filterActive = NO, filterDownload = NO, filterSeed = NO, filterPause = NO, filterError = NO, filterStatus = YES;
    24192419    if ([filterType isEqualToString: FILTER_ACTIVE])
    24202420        filterActive = YES;
    24212421    else if ([filterType isEqualToString: FILTER_DOWNLOAD])
     
    24242424        filterSeed = YES;
    24252425    else if ([filterType isEqualToString: FILTER_PAUSE])
    24262426        filterPause = YES;
     2427    else if ([filterType isEqualToString: FILTER_ERROR])
     2428        filterError = YES;
    24272429    else
    24282430        filterStatus = NO;
    24292431   
     
    24572459                    return NO;
    24582460            }
    24592461        }
     2462        else if ([torrent isError]) {
     2463            OSAtomicIncrement32(&error);
     2464            if (filterStatus && !filterError)
     2465                return NO;
     2466        }
    24602467        else
    24612468        {
    24622469            OSAtomicIncrement32(&paused);
     
    25162523   
    25172524    //set button tooltips
    25182525    if (fFilterBar)
    2519         [fFilterBar setCountAll: [fTorrents count] active: active downloading: downloading seeding: seeding paused: paused];
     2526        [fFilterBar setCountAll: [fTorrents count] active: active downloading: downloading seeding: seeding paused: paused error:error];
    25202527   
    25212528    //if either the previous or current lists are blank, set its value to the other
    25222529    const BOOL groupRows = [allTorrents count] > 0 ? [fDefaults boolForKey: @"SortByGroup"] : ([fDisplayedTorrents count] > 0 && [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]]);
  • macosx/FilterBar.xib

     
    11<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    2 <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     2<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
    33    <dependencies>
    44        <deployment identifier="macosx"/>
    5         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
     5        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
    66    </dependencies>
    77    <objects>
    88        <customObject id="-2" userLabel="File's Owner" customClass="FilterBarController">
    99            <connections>
    1010                <outlet property="fActiveFilterButton" destination="3" id="30"/>
    1111                <outlet property="fDownloadFilterButton" destination="8" id="29"/>
     12                <outlet property="fErrorFilterButton" destination="nvH-xy-86S" id="Rsj-yc-FIu"/>
    1213                <outlet property="fGroupsButton" destination="4" id="49"/>
    1314                <outlet property="fNoFilterButton" destination="9" id="27"/>
    1415                <outlet property="fPauseFilterButton" destination="6" id="28"/>
     
    2021        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
    2122        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
    2223        <customView id="2" userLabel="FilterBar" customClass="FilterBarView">
    23             <rect key="frame" x="0.0" y="0.0" width="457" height="23"/>
     24            <rect key="frame" x="0.0" y="0.0" width="501" height="23"/>
    2425            <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
    2526            <subviews>
    2627                <button verticalHuggingPriority="750" id="3" customClass="FilterButton">
     
    110111                    </connections>
    111112                </button>
    112113                <searchField wantsLayer="YES" verticalHuggingPriority="750" id="10">
    113                     <rect key="frame" x="357" y="2" width="95" height="19"/>
     114                    <rect key="frame" x="401" y="2" width="95" height="19"/>
    114115                    <autoresizingMask key="autoresizingMask" flexibleMinX="YES"/>
    115116                    <searchFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" bezelStyle="round" id="11">
    116117                        <font key="font" metaFont="smallSystem"/>
     
    122123                        <outlet property="searchMenuTemplate" destination="22" id="48"/>
    123124                    </connections>
    124125                </searchField>
     126                <button verticalHuggingPriority="750" id="nvH-xy-86S" customClass="FilterButton">
     127                    <rect key="frame" x="329" y="2" width="43" height="17"/>
     128                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
     129                    <buttonCell key="cell" type="recessed" title="Error" bezelStyle="recessed" alignment="center" controlSize="mini" lineBreakMode="truncatingTail" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AtX-O4-Mqp">
     130                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
     131                        <font key="font" metaFont="smallSystemBold"/>
     132                    </buttonCell>
     133                    <connections>
     134                        <action selector="setFilter:" target="-2" id="Rm7-FG-rfe"/>
     135                    </connections>
     136                </button>
    125137            </subviews>
     138            <point key="canvasLocation" x="307.5" y="461.5"/>
    126139        </customView>
    127140        <menu title="Menu" id="22" userLabel="SearchFilterMenu">
    128141            <items>
  • macosx/FilterBarController.h

     
    3131#define FILTER_DOWNLOAD @"Download"
    3232#define FILTER_SEED     @"Seed"
    3333#define FILTER_PAUSE    @"Pause"
     34#define FILTER_ERROR    @"Error"
    3435
    3536#define FILTER_TYPE_NAME    @"Name"
    3637#define FILTER_TYPE_TRACKER @"Tracker"
     
    4041@interface FilterBarController : NSViewController
    4142{
    4243    IBOutlet FilterButton * fNoFilterButton, * fActiveFilterButton, * fDownloadFilterButton,
    43                             * fSeedFilterButton, * fPauseFilterButton;
     44                            * fSeedFilterButton, * fPauseFilterButton, * fErrorFilterButton;
    4445   
    4546    IBOutlet NSSearchField * fSearchField;
    4647   
     
    6061- (void) focusSearchField;
    6162
    6263- (void) setCountAll: (NSUInteger) all active: (NSUInteger) active downloading: (NSUInteger) downloading
    63         seeding: (NSUInteger) seeding paused: (NSUInteger) paused;
     64        seeding: (NSUInteger) seeding paused: (NSUInteger) paused error:(NSUInteger) error;
    6465
    6566
    6667@end
  • macosx/FilterBarController.m

     
    5656    [fDownloadFilterButton setTitle: NSLocalizedString(@"Downloading", "Filter Bar -> filter button")];
    5757    [fSeedFilterButton setTitle: NSLocalizedString(@"Seeding", "Filter Bar -> filter button")];
    5858    [fPauseFilterButton setTitle: NSLocalizedString(@"Paused", "Filter Bar -> filter button")];
     59    [fErrorFilterButton setTitle: NSLocalizedString(@"Error", "Filter Bar -> filter button")];
    5960   
    6061    [[fNoFilterButton cell] setBackgroundStyle: NSBackgroundStyleRaised];
    6162    [[fActiveFilterButton cell] setBackgroundStyle: NSBackgroundStyleRaised];
    6263    [[fDownloadFilterButton cell] setBackgroundStyle: NSBackgroundStyleRaised];
    6364    [[fSeedFilterButton cell] setBackgroundStyle: NSBackgroundStyleRaised];
    6465    [[fPauseFilterButton cell] setBackgroundStyle: NSBackgroundStyleRaised];
     66    [[fErrorFilterButton cell] setBackgroundStyle: NSBackgroundStyleRaised];
    6567   
    6668    [[[[fSearchField cell] searchMenuTemplate] itemWithTag: FILTER_TYPE_TAG_NAME] setTitle:
    6769        NSLocalizedString(@"Name", "Filter Bar -> filter menu")];
     
    8587        currentFilterButton = fSeedFilterButton;
    8688    else if ([filterType isEqualToString: FILTER_DOWNLOAD])
    8789        currentFilterButton = fDownloadFilterButton;
     90    else if ([filterType isEqualToString: FILTER_ERROR])
     91        currentFilterButton = fErrorFilterButton;
    8892    else
    8993    {
    9094        //safety
     
    144148        prevFilterButton = fSeedFilterButton;
    145149    else if ([oldFilterType isEqualToString: FILTER_DOWNLOAD])
    146150        prevFilterButton = fDownloadFilterButton;
     151    else if ([oldFilterType isEqualToString: FILTER_ERROR])
     152        prevFilterButton = fErrorFilterButton;
    147153    else
    148154        prevFilterButton = fNoFilterButton;
    149155   
     
    161167            filterType = FILTER_PAUSE;
    162168        else if (sender == fSeedFilterButton)
    163169            filterType = FILTER_SEED;
     170        else if (sender == fErrorFilterButton)
     171            filterType = FILTER_ERROR;
    164172        else
    165173            filterType = FILTER_NONE;
    166174
     
    178186   
    179187    NSButton * button;
    180188    if ([filterType isEqualToString: FILTER_NONE])
    181         button = right ? fActiveFilterButton : fPauseFilterButton;
     189        button = right ? fActiveFilterButton : fErrorFilterButton;
    182190    else if ([filterType isEqualToString: FILTER_ACTIVE])
    183191        button = right ? fDownloadFilterButton : fNoFilterButton;
    184192    else if ([filterType isEqualToString: FILTER_DOWNLOAD])
     
    186194    else if ([filterType isEqualToString: FILTER_SEED])
    187195        button = right ? fPauseFilterButton : fDownloadFilterButton;
    188196    else if ([filterType isEqualToString: FILTER_PAUSE])
    189         button = right ? fNoFilterButton : fSeedFilterButton;
     197        button = right ? fErrorFilterButton : fSeedFilterButton;
     198    else if ([filterType isEqualToString: FILTER_ERROR])
     199        button = right ? fNoFilterButton : fPauseFilterButton;
    190200    else
    191201        button = fNoFilterButton;
    192202   
     
    264274}
    265275
    266276- (void) setCountAll: (NSUInteger) all active: (NSUInteger) active downloading: (NSUInteger) downloading
    267         seeding: (NSUInteger) seeding paused: (NSUInteger) paused
     277        seeding: (NSUInteger) seeding paused: (NSUInteger) paused error: (NSUInteger) error
    268278{
    269279    [fNoFilterButton setCount: all];
    270280    [fActiveFilterButton setCount: active];
    271281    [fDownloadFilterButton setCount: downloading];
    272282    [fSeedFilterButton setCount: seeding];
    273283    [fPauseFilterButton setCount: paused];
     284    [fErrorFilterButton setCount: error];
    274285}
    275286
    276287- (void) menuNeedsUpdate: (NSMenu *) menu
     
    334345    [fDownloadFilterButton sizeToFit];
    335346    [fSeedFilterButton sizeToFit];
    336347    [fPauseFilterButton sizeToFit];
     348    [fErrorFilterButton sizeToFit];
    337349   
    338350    NSRect allRect = [fNoFilterButton frame];
    339351    NSRect activeRect = [fActiveFilterButton frame];
    340352    NSRect downloadRect = [fDownloadFilterButton frame];
    341353    NSRect seedRect = [fSeedFilterButton frame];
    342354    NSRect pauseRect = [fPauseFilterButton frame];
     355    NSRect errorRect = [fErrorFilterButton frame];
    343356   
    344357    //size search filter to not overlap buttons
    345358    NSRect searchFrame = [fSearchField frame];
    346     searchFrame.origin.x = NSMaxX(pauseRect) + 5.0;
     359    searchFrame.origin.x = NSMaxX(errorRect) + 5.0;
    347360    searchFrame.size.width = NSWidth([[self view] frame]) - searchFrame.origin.x - 5.0;
    348361   
    349362    //make sure it is not too long
     
    360373        //calculate width the buttons can take up
    361374        const CGFloat allowedWidth = (searchFrame.origin.x - 5.0) - allRect.origin.x;
    362375        const CGFloat currentWidth = NSWidth(allRect) + NSWidth(activeRect) + NSWidth(downloadRect) + NSWidth(seedRect)
    363                                         + NSWidth(pauseRect) + 4.0; //add 4 for space between buttons
     376                                        + NSWidth(pauseRect) + NSWidth(errorRect) + 4.0; //add 4 for space between buttons
    364377        const CGFloat ratio = allowedWidth / currentWidth;
    365378       
    366379        //decrease button widths proportionally
     
    369382        downloadRect.size.width = NSWidth(downloadRect) * ratio;
    370383        seedRect.size.width = NSWidth(seedRect) * ratio;
    371384        pauseRect.size.width = NSWidth(pauseRect) * ratio;
     385        errorRect.size.width = NSWidth(errorRect) * ratio;
    372386    }
    373387    else;
    374388   
     
    376390    downloadRect.origin.x = NSMaxX(activeRect) + 1.0;
    377391    seedRect.origin.x = NSMaxX(downloadRect) + 1.0;
    378392    pauseRect.origin.x = NSMaxX(seedRect) + 1.0;
     393    errorRect.origin.x = NSMaxX(pauseRect) + 1.0;
    379394   
    380395    [fNoFilterButton setFrame: allRect];
    381396    [fActiveFilterButton setFrame: activeRect];
    382397    [fDownloadFilterButton setFrame: downloadRect];
    383398    [fSeedFilterButton setFrame: seedRect];
    384399    [fPauseFilterButton setFrame: pauseRect];
     400    [fErrorFilterButton setFrame: errorRect];
    385401   
    386402    [fSearchField setFrame: searchFrame];
    387403}