Changeset 9726


Ignore:
Timestamp:
Dec 12, 2009, 4:39:43 AM (12 years ago)
Author:
livings124
Message:

improve the tracker removing code

Location:
trunk/macosx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoWindowController.m

    r9684 r9726  
    17481748- (void) removeTrackers
    17491749{
    1750     const NSInteger oldCount = [fTrackers count] - [(TrackerNode *)[fTrackers lastObject] tier];
    1751     NSMutableSet * addresses = [NSMutableSet setWithCapacity: oldCount];
    1752    
    1753     NSIndexSet * indexes = [fTrackerTable selectedRowIndexes];
    1754     for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
     1750    NSMutableIndexSet * removeIndexes = [NSMutableIndexSet indexSet];
     1751   
     1752    NSIndexSet * selectedIndexes = [fTrackerTable selectedRowIndexes];
     1753    for (NSUInteger i=0, trackerIndex = 0; i <= [selectedIndexes lastIndex]; ++i)
    17551754    {
    17561755        id item = [fTrackers objectAtIndex: i];
    1757         if ([item isKindOfClass: [NSNumber class]])
    1758         {
    1759             for (++i; i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; ++i)
    1760                 [addresses addObject: [[fTrackers objectAtIndex: i] fullAnnounceAddress]];
    1761             --i;
     1756        const BOOL isSelected = [selectedIndexes containsIndex: i];
     1757        const BOOL isGroup = [item isKindOfClass: [NSNumber class]];
     1758       
     1759        if (isGroup)
     1760        {
     1761            if (isSelected)
     1762            {
     1763                for (++i; i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; ++i)
     1764                    [removeIndexes addIndex: trackerIndex++];
     1765                --i;
     1766            }
    17621767        }
    17631768        else
    1764             [addresses addObject: [(TrackerNode *)item fullAnnounceAddress]];
     1769        {
     1770            if (isSelected)
     1771                [removeIndexes addIndex: trackerIndex];
     1772            ++trackerIndex;
     1773        }
    17651774    }
    17661775   
     
    17691778        NSAlert * alert = [[NSAlert alloc] init];
    17701779       
    1771         if ([addresses count] > 1)
     1780        if ([removeIndexes count] > 1)
    17721781        {
    17731782            [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
    1774                                                                 "Remove trackers alert -> title"), [addresses count]]];
     1783                                                                "Remove trackers alert -> title"), [removeIndexes count]]];
    17751784            [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
    17761785                                        " This cannot be undone.", "Remove trackers alert -> message")];
     
    17981807   
    17991808    Torrent * torrent = [fTorrents objectAtIndex: 0];
    1800     [torrent removeTrackersWithAnnounceAddresses: addresses];
     1809    [torrent removeTrackersAtIndexes: removeIndexes];
    18011810   
    18021811    //reset table with either new or old value
  • trunk/macosx/Torrent.h

    r9667 r9726  
    132132- (NSArray *) allTrackersFlat; //used by GroupRules
    133133- (BOOL) addTrackerToNewTier: (NSString *) tracker;
    134 - (void) removeTrackersWithAnnounceAddresses: (NSSet *) trackers;
     134- (void) removeTrackersAtIndexes: (NSIndexSet *) removeIndexes;
    135135
    136136- (NSString *) comment;
  • trunk/macosx/Torrent.m

    r9715 r9726  
    654654}
    655655
    656 - (void) removeTrackersWithAnnounceAddresses: (NSSet *) trackers
    657 {
     656- (void) removeTrackersAtIndexes: (NSIndexSet *) removeIndexes
     657{
     658    NSAssert([removeIndexes lastIndex] < fInfo->trackerCount, @"Trying to remove trackers outside the tracker count.");
     659   
     660    NSMutableIndexSet * indexes = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, fInfo->trackerCount)];
     661    [indexes removeIndexes: removeIndexes];
     662   
    658663    //recreate the tracker structure
    659     const int oldTrackerCount = fInfo->trackerCount;
    660     tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, oldTrackerCount-1);
    661    
    662     NSInteger newCount = 0;
    663     for (NSInteger oldIndex = 0; oldIndex < oldTrackerCount; ++oldIndex)
    664     {
    665         if (![trackers member: [NSString stringWithUTF8String: fInfo->trackers[oldIndex].announce]])
    666             trackerStructs[newCount++] = fInfo->trackers[oldIndex];
    667     }
     664    tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, [indexes count]);
     665   
     666    int newCount = 0;
     667    for (NSUInteger oldIndex = [indexes firstIndex]; oldIndex != NSNotFound; oldIndex = [indexes indexGreaterThanIndex: oldIndex])
     668        trackerStructs[newCount++] = fInfo->trackers[oldIndex];
    668669   
    669670    const tr_announce_list_err result = tr_torrentSetAnnounceList(fHandle, trackerStructs, newCount);
  • trunk/macosx/TorrentCell.m

    r9723 r9726  
    318318        if (!minimal)
    319319        {
    320             groupRect.size.height--;
    321             groupRect.origin.y--;
     320            groupRect.size.height -= 1.0f;
     321            groupRect.origin.y -= 1.0f;
    322322        }
    323323        const CGFloat radius = minimal ? 3.0f : 6.0f;
     
    546546       
    547547        //not-available section
    548         if ([torrent isActive] && ![torrent isChecking] && [fDefaults boolForKey: @"DisplayProgressBarAvailable"]
    549             && [torrent availableDesired] < 1.0)
     548        if ([torrent isActive] && ![torrent isChecking] && [torrent availableDesired] < 1.0
     549            && [fDefaults boolForKey: @"DisplayProgressBarAvailable"])
    550550        {
    551551            NSRect unavailableRect;
Note: See TracChangeset for help on using the changeset viewer.