if (add)
{
- [torrent setOrderValue: [fTorrents count]]; //ensure that queue order is always sequential
-
[torrent update];
[fTorrents addObject: torrent];
[torrent release];
[fTorrents removeObjectsInArray: torrents];
- NSInteger lowestOrderValue = NSIntegerMax;
for (Torrent * torrent in torrents)
{
//let's expand all groups that have removed items - they either don't exist anymore, are already expanded, or are collapsed (rpc)
if (deleteTorrent)
[torrent trashTorrent];
- lowestOrderValue = MIN(lowestOrderValue, [torrent orderValue]);
-
[torrent closeRemoveTorrent];
}
[torrents release];
-
- //reset the order values if necessary
- if (lowestOrderValue < [fTorrents count])
- {
- for (NSInteger i = lowestOrderValue; i < [fTorrents count]; i++)
- [[fTorrents objectAtIndex: i] setOrderValue: i];
- }
[fTableView deselectAll: nil];
- (void) updateTorrentHistory
{
NSMutableArray * history = [NSMutableArray arrayWithCapacity: [fTorrents count]];
-
+
for (Torrent * torrent in fTorrents)
[history addObject: [torrent history]];
-
+
[history writeToFile: [NSHomeDirectory() stringByAppendingPathComponent: SUPPORT_FOLDER] atomically: YES];
}
NSString * sortType = [fDefaults stringForKey: @"Sort"];
const BOOL asc = ![fDefaults boolForKey: @"SortReverse"];
- NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue" ascending: asc] autorelease];
-
- NSArray * descriptors;
- if ([sortType isEqualToString: SORT_ORDER])
- descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
- else if ([sortType isEqualToString: SORT_NAME])
+ NSArray * descriptors = nil;
+ if ([sortType isEqualToString: SORT_NAME])
{
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
selector: @selector(compareFinder:)] autorelease];
- descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, orderDescriptor, nil];
+ descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
}
else if ([sortType isEqualToString: SORT_STATE])
{
* ratioDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"ratio" ascending: !asc] autorelease];
descriptors = [[NSArray alloc] initWithObjects: stateDescriptor, progressDescriptor, ratioDescriptor,
- nameDescriptor, orderDescriptor, nil];
+ nameDescriptor, nil];
}
else if ([sortType isEqualToString: SORT_PROGRESS])
{
* ratioDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"ratio" ascending: asc] autorelease];
descriptors = [[NSArray alloc] initWithObjects: progressDescriptor, ratioProgressDescriptor, ratioDescriptor,
- nameDescriptor, orderDescriptor, nil];
+ nameDescriptor, nil];
}
else if ([sortType isEqualToString: SORT_TRACKER])
{
* trackerDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"trackerAddressAnnounce" ascending: asc
selector: @selector(localizedCaseInsensitiveCompare:)] autorelease];
- descriptors = [[NSArray alloc] initWithObjects: trackerDescriptor, nameDescriptor, orderDescriptor, nil];
+ descriptors = [[NSArray alloc] initWithObjects: trackerDescriptor, nameDescriptor, nil];
}
else if ([sortType isEqualToString: SORT_ACTIVITY])
{
NSSortDescriptor * activityDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"dateActivityOrAdd" ascending: !asc]
autorelease];
- descriptors = [[NSArray alloc] initWithObjects: rateDescriptor, activityDescriptor, orderDescriptor, nil];
+ descriptors = [[NSArray alloc] initWithObjects: rateDescriptor, activityDescriptor, nil];
}
- else
+ else if ([sortType isEqualToString: SORT_DATE])
{
NSSortDescriptor * dateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"dateAdded" ascending: asc] autorelease];
- descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, orderDescriptor, nil];
+ descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, nil];
}
+ else; //no need to sort by queue order
//actually sort
- if ([fDefaults boolForKey: @"SortByGroup"])
+ if (descriptors)
{
- for (TorrentGroup * group in fDisplayedTorrents)
- [[group torrents] sortUsingDescriptors: descriptors];
+ if ([fDefaults boolForKey: @"SortByGroup"])
+ {
+ for (TorrentGroup * group in fDisplayedTorrents)
+ [[group torrents] sortUsingDescriptors: descriptors];
+ }
+ else
+ [fDisplayedTorrents sortUsingDescriptors: descriptors];
+
+ [descriptors release];
}
- else
- [fDisplayedTorrents sortUsingDescriptors: descriptors];
-
- [descriptors release];
[fTableView reloadData];
}
NSUInteger insertIndex = topTorrent ? [fTorrents indexOfObject: topTorrent] + 1 : 0;
NSIndexSet * insertIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(insertIndex, [movingTorrents count])];
[fTorrents insertObjects: movingTorrents atIndexes: insertIndexes];
-
- //redo order values
- for (NSInteger i = 0; i < [fTorrents count]; i++)
- [[fTorrents objectAtIndex: i] setOrderValue: i];
}
[self applyFilter: nil];
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
waitToStart: (NSNumber *) waitToStart
- orderValue: (NSNumber *) orderValue groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers;
+ groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers;
- (BOOL) shouldUseIncompleteFolderForName: (NSString *) name;
- (void) updateDownloadFolder;
downloadFolder: location
useIncompleteFolder: nil incompleteFolder: nil
ratioSetting: nil ratioLimit: nil
- waitToStart: nil orderValue: nil groupValue: nil addedTrackers: nil];
+ waitToStart: nil groupValue: nil addedTrackers: nil];
if (self)
{
downloadFolder: location
useIncompleteFolder: nil incompleteFolder: nil
ratioSetting: nil ratioLimit: nil
- waitToStart: nil orderValue: nil groupValue: nil addedTrackers: nil];
+ waitToStart: nil groupValue: nil addedTrackers: nil];
return self;
}
ratioSetting: [history objectForKey: @"RatioSetting"]
ratioLimit: [history objectForKey: @"RatioLimit"]
waitToStart: [history objectForKey: @"WaitToStart"]
- orderValue: [history objectForKey: @"OrderValue"]
groupValue: [history objectForKey: @"GroupValue"]
addedTrackers: [history objectForKey: @"AddedTrackers"]];
[NSNumber numberWithInt: fRatioSetting], @"RatioSetting",
[NSNumber numberWithFloat: fRatioLimit], @"RatioLimit",
[NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
- [NSNumber numberWithInt: fOrderValue], @"OrderValue",
[NSNumber numberWithInt: fGroupValue], @"GroupValue",
[NSNumber numberWithBool: fAddedTrackers], @"AddedTrackers", nil];
return fStat->swarmSpeed;
}
-- (NSInteger) orderValue
-{
- return fOrderValue;
-}
-
-- (void) setOrderValue: (NSInteger) orderValue
-{
- fOrderValue = orderValue;
-}
-
- (NSInteger) groupValue
{
return fGroupValue;
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
waitToStart: (NSNumber *) waitToStart
- orderValue: (NSNumber *) orderValue groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers
+ groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers
{
if (!(self = [super init]))
return nil;
[self createFileList];
- fOrderValue = orderValue ? [orderValue intValue] : tr_sessionCountTorrents(lib) - 1;
fGroupValue = groupValue ? [groupValue intValue] : [[GroupsController groups] groupIndexForTorrent: self];
fAddedTrackers = addedTrackers ? [addedTrackers boolValue] : NO;