Ignore:
Timestamp:
Jan 18, 2012, 1:40:34 AM (10 years ago)
Author:
livings124
Message:

miscellaneous fiddling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13167 r13169  
    19131913- (void) sortTorrentsCallUpdates: (BOOL) callUpdates includeQueueOrder: (BOOL) includeQueueOrder
    19141914{
    1915     //don't do anything else if we don't have to
    1916     const BOOL sortByGroup = [fDefaults boolForKey: @"SortByGroup"];
    1917     const NSUInteger count = [fDisplayedTorrents count];
    1918     if (count == 0 || (!sortByGroup && count == 1))
    1919         return;
    1920    
    1921     NSString * sortType = [fDefaults stringForKey: @"Sort"];
    1922    
    1923     if (!includeQueueOrder && [sortType isEqualToString: SORT_ORDER])
    1924         return;
    1925    
    19261915    const BOOL asc = ![fDefaults boolForKey: @"SortReverse"];
    19271916   
     
    19291918    NSSortDescriptor * nameDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"name" ascending: asc selector: @selector(localizedStandardCompare:)];
    19301919   
     1920    NSString * sortType = [fDefaults stringForKey: @"Sort"];
    19311921    if ([sortType isEqualToString: SORT_STATE])
    19321922    {
     
    19351925                        * ratioDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"ratio" ascending: !asc];
    19361926       
    1937         descriptors = [[NSArray alloc] initWithObjects: stateDescriptor, progressDescriptor, ratioDescriptor, nameDescriptor, nil];
     1927        descriptors = [NSArray arrayWithObjects: stateDescriptor, progressDescriptor, ratioDescriptor, nameDescriptor, nil];
    19381928    }
    19391929    else if ([sortType isEqualToString: SORT_PROGRESS])
     
    19431933                        * ratioDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"ratio" ascending: asc];
    19441934       
    1945         descriptors = [[NSArray alloc] initWithObjects: progressDescriptor, ratioProgressDescriptor, ratioDescriptor, nameDescriptor, nil];
     1935        descriptors = [NSArray arrayWithObjects: progressDescriptor, ratioProgressDescriptor, ratioDescriptor, nameDescriptor, nil];
    19461936    }
    19471937    else if ([sortType isEqualToString: SORT_TRACKER])
     
    19491939        NSSortDescriptor * trackerDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"trackerSortKey" ascending: asc selector: @selector(localizedCaseInsensitiveCompare:)];
    19501940       
    1951         descriptors = [[NSArray alloc] initWithObjects: trackerDescriptor, nameDescriptor, nil];
     1941        descriptors = [NSArray arrayWithObjects: trackerDescriptor, nameDescriptor, nil];
    19521942    }
    19531943    else if ([sortType isEqualToString: SORT_ACTIVITY])
     
    19561946        NSSortDescriptor * activityDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"dateActivityOrAdd" ascending: !asc];
    19571947       
    1958         descriptors = [[NSArray alloc] initWithObjects: rateDescriptor, activityDescriptor, nameDescriptor, nil];
     1948        descriptors = [NSArray arrayWithObjects: rateDescriptor, activityDescriptor, nameDescriptor, nil];
    19591949    }
    19601950    else if ([sortType isEqualToString: SORT_DATE])
     
    19621952        NSSortDescriptor * dateDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"dateAdded" ascending: asc];
    19631953       
    1964         descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, nameDescriptor, nil];
     1954        descriptors = [NSArray arrayWithObjects: dateDescriptor, nameDescriptor, nil];
    19651955    }
    19661956    else if ([sortType isEqualToString: SORT_SIZE])
     
    19681958        NSSortDescriptor * sizeDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"size" ascending: asc];
    19691959       
    1970         descriptors = [[NSArray alloc] initWithObjects: sizeDescriptor, nameDescriptor, nil];
     1960        descriptors = [NSArray arrayWithObjects: sizeDescriptor, nameDescriptor, nil];
    19711961    }
    19721962    else if ([sortType isEqualToString: SORT_NAME])
    19731963    {
    1974         descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
     1964        descriptors = [NSArray arrayWithObject: nameDescriptor];
    19751965    }
    19761966    else
    19771967    {
    19781968        NSAssert1([sortType isEqualToString: SORT_ORDER], @"Unknown sort type received: %@", sortType);
    1979         NSAssert(includeQueueOrder, @"Sorting by queue order when we shouldn't");
     1969       
     1970        if (!includeQueueOrder)
     1971            return;
    19801972       
    19811973        NSSortDescriptor * orderDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"queuePosition" ascending: asc];
    19821974       
    1983         descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
     1975        descriptors = [NSArray arrayWithObject: orderDescriptor];
    19841976    }
    19851977   
     
    19871979   
    19881980    //actually sort
    1989     if (sortByGroup)
     1981    if ([fDefaults boolForKey: @"SortByGroup"])
    19901982    {
    19911983        for (TorrentGroup * group in fDisplayedTorrents)
     
    20021994            [fTableView reloadData];
    20031995    }
    2004    
    2005     [descriptors release];
    20061996}
    20071997
     
    21542144        [fFilterBar setCountAll: [fTorrents count] active: active downloading: downloading seeding: seeding paused: paused];
    21552145   
     2146    //if either the previous or current lists are blank, set its value to the other
     2147    const BOOL groupRows = [allTorrents count] > 0 ? [fDefaults boolForKey: @"SortByGroup"] : ([fDisplayedTorrents count] > 0 && [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]]);
     2148    const BOOL wasGroupRows = [fDisplayedTorrents count] > 0 ? [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]] : groupRows;
     2149   
    21562150    #warning could probably be merged with later code somehow
    21572151    //clear display cache for not-shown torrents
     
    21592153    {
    21602154        //for each torrent, removes the previous piece info if it's not in allTorrents, and keeps track of which torrents we already found in allTorrents
    2161         void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL *) = ^(id obj, NSUInteger idx, BOOL * stop) {
     2155        void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL *) = ^(Torrent * torrent, NSUInteger idx, BOOL * stop) {
    21622156            //we used to keep track of which torrents we already found in allTorrents, but it wasn't safe fo concurrent enumeration
    2163             if (![allTorrents containsObject: obj])
    2164                 [(Torrent *)obj setPreviousFinishedPieces: nil];
     2157            if (![allTorrents containsObject: torrent])
     2158                [torrent setPreviousFinishedPieces: nil];
    21652159        };
    21662160       
    2167         if ([[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]])
     2161        if (wasGroupRows)
    21682162            [fDisplayedTorrents enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(id obj, NSUInteger idx, BOOL * stop) {
    21692163                [[(TorrentGroup *)obj torrents] enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: removePreviousFinishedPieces];
     
    21852179    }
    21862180   
    2187     //place torrents into groups
    2188     //if either the previous or current lists are blank, set its value to the other
    2189     const BOOL groupRows = [allTorrents count] > 0 ? [fDefaults boolForKey: @"SortByGroup"] : ([fDisplayedTorrents count] > 0 && [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]]);
    2190     const BOOL wasGroupRows = [fDisplayedTorrents count] > 0 ? [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]] : groupRows;
     2181    //add/remove torrents (and rearrange for groups), one by one
    21912182    if (!groupRows && !wasGroupRows)
    21922183    {
     
    42134204        return nil;
    42144205   
    4215     NSInteger seeding = 0, downloading = 0;
     4206    NSUInteger seeding = 0, downloading = 0;
    42164207    for (Torrent * torrent in fTorrents)
    42174208    {
Note: See TracChangeset for help on using the changeset viewer.