Changeset 7794


Ignore:
Timestamp:
Jan 24, 2009, 7:07:25 PM (12 years ago)
Author:
livings124
Message:

determine queue order solely on order in the fTorrent array - this gets around potential problems when relaunching with less torrents

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r7757 r7794  
    842842    if (add)
    843843    {
    844         [torrent setOrderValue: [fTorrents count]]; //ensure that queue order is always sequential
    845        
    846844        [torrent update];
    847845        [fTorrents addObject: torrent];
     
    12171215    [fTorrents removeObjectsInArray: torrents];
    12181216   
    1219     NSInteger lowestOrderValue = NSIntegerMax;
    12201217    for (Torrent * torrent in torrents)
    12211218    {
     
    12281225            [torrent trashTorrent];
    12291226       
    1230         lowestOrderValue = MIN(lowestOrderValue, [torrent orderValue]);
    1231        
    12321227        [torrent closeRemoveTorrent];
    12331228    }
    12341229   
    12351230    [torrents release];
    1236 
    1237     //reset the order values if necessary
    1238     if (lowestOrderValue < [fTorrents count])
    1239     {
    1240         for (NSInteger i = lowestOrderValue; i < [fTorrents count]; i++)
    1241             [[fTorrents objectAtIndex: i] setOrderValue: i];
    1242     }
    12431231   
    12441232    [fTableView deselectAll: nil];
     
    17231711{
    17241712    NSMutableArray * history = [NSMutableArray arrayWithCapacity: [fTorrents count]];
    1725 
     1713   
    17261714    for (Torrent * torrent in fTorrents)
    17271715        [history addObject: [torrent history]];
    1728 
     1716   
    17291717    [history writeToFile: [NSHomeDirectory() stringByAppendingPathComponent: SUPPORT_FOLDER] atomically: YES];
    17301718}
     
    17971785    const BOOL asc = ![fDefaults boolForKey: @"SortReverse"];
    17981786   
    1799     NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue" ascending: asc] autorelease];
    1800    
    1801     NSArray * descriptors;
    1802     if ([sortType isEqualToString: SORT_ORDER])
    1803         descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
    1804     else if ([sortType isEqualToString: SORT_NAME])
     1787    NSArray * descriptors = nil;
     1788    if ([sortType isEqualToString: SORT_NAME])
    18051789    {
    18061790        NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
    18071791                                                selector: @selector(compareFinder:)] autorelease];
    18081792       
    1809         descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, orderDescriptor, nil];
     1793        descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
    18101794    }
    18111795    else if ([sortType isEqualToString: SORT_STATE])
     
    18181802       
    18191803        descriptors = [[NSArray alloc] initWithObjects: stateDescriptor, progressDescriptor, ratioDescriptor,
    1820                                                             nameDescriptor, orderDescriptor, nil];
     1804                                                            nameDescriptor, nil];
    18211805    }
    18221806    else if ([sortType isEqualToString: SORT_PROGRESS])
     
    18301814       
    18311815        descriptors = [[NSArray alloc] initWithObjects: progressDescriptor, ratioProgressDescriptor, ratioDescriptor,
    1832                                                             nameDescriptor, orderDescriptor, nil];
     1816                                                            nameDescriptor, nil];
    18331817    }
    18341818    else if ([sortType isEqualToString: SORT_TRACKER])
     
    18391823                                                selector: @selector(localizedCaseInsensitiveCompare:)] autorelease];
    18401824       
    1841         descriptors = [[NSArray alloc] initWithObjects: trackerDescriptor, nameDescriptor, orderDescriptor, nil];
     1825        descriptors = [[NSArray alloc] initWithObjects: trackerDescriptor, nameDescriptor, nil];
    18421826    }
    18431827    else if ([sortType isEqualToString: SORT_ACTIVITY])
     
    18471831                                                    autorelease];
    18481832       
    1849         descriptors = [[NSArray alloc] initWithObjects: rateDescriptor, activityDescriptor, orderDescriptor, nil];
    1850     }
    1851     else
     1833        descriptors = [[NSArray alloc] initWithObjects: rateDescriptor, activityDescriptor, nil];
     1834    }
     1835    else if ([sortType isEqualToString: SORT_DATE])
    18521836    {
    18531837        NSSortDescriptor * dateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"dateAdded" ascending: asc] autorelease];
    18541838   
    1855         descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, orderDescriptor, nil];
    1856     }
     1839        descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, nil];
     1840    }
     1841    else; //no need to sort by queue order
    18571842   
    18581843    //actually sort
    1859     if ([fDefaults boolForKey: @"SortByGroup"])
    1860     {
    1861         for (TorrentGroup * group in fDisplayedTorrents)
    1862             [[group torrents] sortUsingDescriptors: descriptors];
    1863     }
    1864     else
    1865         [fDisplayedTorrents sortUsingDescriptors: descriptors];
    1866    
    1867     [descriptors release];
     1844    if (descriptors)
     1845    {
     1846        if ([fDefaults boolForKey: @"SortByGroup"])
     1847        {
     1848            for (TorrentGroup * group in fDisplayedTorrents)
     1849                [[group torrents] sortUsingDescriptors: descriptors];
     1850        }
     1851        else
     1852            [fDisplayedTorrents sortUsingDescriptors: descriptors];
     1853       
     1854        [descriptors release];
     1855    }
    18681856   
    18691857    [fTableView reloadData];
     
    27192707            NSIndexSet * insertIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(insertIndex, [movingTorrents count])];
    27202708            [fTorrents insertObjects: movingTorrents atIndexes: insertIndexes];
    2721            
    2722             //redo order values
    2723             for (NSInteger i = 0; i < [fTorrents count]; i++)
    2724                 [[fTorrents objectAtIndex: i] setOrderValue: i];
    27252709        }
    27262710       
  • trunk/macosx/Torrent.h

    r7659 r7794  
    7070    BOOL fFinishedSeeding, fWaitToStart, fStalled;
    7171   
    72     NSInteger fOrderValue, fGroupValue;
     72    NSInteger fGroupValue;
    7373   
    7474    BOOL fAddedTrackers;
     
    231231- (CGFloat) swarmSpeed;
    232232
    233 - (NSInteger) orderValue;
    234 - (void) setOrderValue: (NSInteger) orderValue;
    235 
    236233- (NSInteger) groupValue;
    237234- (void) setGroupValue: (NSInteger) groupValue;
  • trunk/macosx/Torrent.m

    r7659 r7794  
    3737        ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
    3838        waitToStart: (NSNumber *) waitToStart
    39         orderValue: (NSNumber *) orderValue groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers;
     39        groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers;
    4040
    4141- (BOOL) shouldUseIncompleteFolderForName: (NSString *) name;
     
    8383            useIncompleteFolder: nil incompleteFolder: nil
    8484            ratioSetting: nil ratioLimit: nil
    85             waitToStart: nil orderValue: nil groupValue: nil addedTrackers: nil];
     85            waitToStart: nil groupValue: nil addedTrackers: nil];
    8686   
    8787    if (self)
     
    108108            useIncompleteFolder: nil incompleteFolder: nil
    109109            ratioSetting: nil ratioLimit: nil
    110             waitToStart: nil orderValue: nil groupValue: nil addedTrackers: nil];
     110            waitToStart: nil groupValue: nil addedTrackers: nil];
    111111   
    112112    return self;
     
    124124                ratioLimit: [history objectForKey: @"RatioLimit"]
    125125                waitToStart: [history objectForKey: @"WaitToStart"]
    126                 orderValue: [history objectForKey: @"OrderValue"]
    127126                groupValue: [history objectForKey: @"GroupValue"]
    128127                addedTrackers: [history objectForKey: @"AddedTrackers"]];
     
    161160                    [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit",
    162161                    [NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
    163                     [NSNumber numberWithInt: fOrderValue], @"OrderValue",
    164162                    [NSNumber numberWithInt: fGroupValue], @"GroupValue",
    165163                    [NSNumber numberWithBool: fAddedTrackers], @"AddedTrackers", nil];
     
    13661364}
    13671365
    1368 - (NSInteger) orderValue
    1369 {
    1370     return fOrderValue;
    1371 }
    1372 
    1373 - (void) setOrderValue: (NSInteger) orderValue
    1374 {
    1375     fOrderValue = orderValue;
    1376 }
    1377 
    13781366- (NSInteger) groupValue
    13791367{
     
    16171605        ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
    16181606        waitToStart: (NSNumber *) waitToStart
    1619         orderValue: (NSNumber *) orderValue groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers
     1607        groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers
    16201608{
    16211609    if (!(self = [super init]))
     
    17081696    [self createFileList];
    17091697       
    1710     fOrderValue = orderValue ? [orderValue intValue] : tr_sessionCountTorrents(lib) - 1;
    17111698    fGroupValue = groupValue ? [groupValue intValue] : [[GroupsController groups] groupIndexForTorrent: self];
    17121699   
Note: See TracChangeset for help on using the changeset viewer.