1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00

add a comparison method for the transfer names to sort the exact same way the Finder does

This commit is contained in:
Mitchell Livingston 2008-06-27 05:15:50 +00:00
parent fd06d85aee
commit 313885df00
5 changed files with 23 additions and 9 deletions

View file

@ -1820,14 +1820,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
else if ([sortType isEqualToString: SORT_NAME])
{
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
selector: @selector(localizedCaseInsensitiveCompare:)] autorelease];
selector: @selector(compareFinder:)] autorelease];
descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, orderDescriptor, nil];
}
else if ([sortType isEqualToString: SORT_STATE])
{
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
selector: @selector(localizedCaseInsensitiveCompare:)] autorelease],
selector: @selector(compareFinder:)] autorelease],
* stateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"stateSortKey" ascending: !asc] autorelease],
* progressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progress" ascending: !asc] autorelease],
* ratioDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"ratio" ascending: !asc] autorelease];
@ -1838,7 +1838,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
else if ([sortType isEqualToString: SORT_PROGRESS])
{
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
selector: @selector(localizedCaseInsensitiveCompare:)] autorelease],
selector: @selector(compareFinder:)] autorelease],
* progressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progress" ascending: asc] autorelease],
* ratioProgressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progressStopRatio"
ascending: asc] autorelease],
@ -1850,7 +1850,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
else if ([sortType isEqualToString: SORT_TRACKER])
{
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc
selector: @selector(localizedCaseInsensitiveCompare:)] autorelease],
selector: @selector(compareFinder:)] autorelease],
* trackerDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"trackerAddressAnnounce" ascending: asc
selector: @selector(localizedCaseInsensitiveCompare:)] autorelease];

View file

@ -2141,6 +2141,7 @@ AAB0ZXh0AAAAAENvcHlyaWdodCBBcHBsZSBDb21wdXRlciwgSW5jLiwgMjAwNQAAAAA</bytes>
</object>
<string key="NSFrame">{{1, 1}, {360, 143}}</string>
<reference key="NSSuperview" ref="754568592"/>
<reference key="NSNextKeyView" ref="423972458"/>
<reference key="NSDocView" ref="423972458"/>
<reference key="NSBGColor" ref="987864771"/>
<int key="NScvFlags">2</int>
@ -2169,6 +2170,7 @@ AAB0ZXh0AAAAAENvcHlyaWdodCBBcHBsZSBDb21wdXRlciwgSW5jLiwgMjAwNQAAAAA</bytes>
</object>
<string key="NSFrame">{{10, 202}, {362, 145}}</string>
<reference key="NSSuperview" ref="296911506"/>
<reference key="NSNextKeyView" ref="198254095"/>
<int key="NSsFlags">530</int>
<reference key="NSVScroller" ref="964808471"/>
<reference key="NSHScroller" ref="265048045"/>
@ -2322,7 +2324,7 @@ AAB0ZXh0AAAAAENvcHlyaWdodCBBcHBsZSBDb21wdXRlciwgSW5jLiwgMjAwNQAAAAA</bytes>
<object class="NSSortDescriptor" key="NSSortDescriptorPrototype">
<string key="NSKey">Client</string>
<bool key="NSAscending">YES</bool>
<string key="NSSelector">localizedCaseInsensitiveCompare:</string>
<string key="NSSelector">compareFinder:</string>
</object>
</object>
<object class="NSTableColumn" id="921856358">
@ -8689,7 +8691,7 @@ zijOSc5pzorOqs66ztvO+88czzzPXc99z57Pvs/fz+/QANAg0EHQYdCC0KLQw9Dj0PPRFNE00VXRddGW
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{634, 496}, {360, 342}}</string>
<string>{{440, 490}, {360, 342}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{63, 584}, {360, 342}}</string>

View file

@ -1752,7 +1752,7 @@ zijOSc5pzorOqs66ztvO+88czzzPXc99z57Pvs/fz+/QANAg0EHQYdCC0KLQw9Dj0PPRFNE00VXRddGW
<object class="NSSortDescriptor" key="NSSortDescriptorPrototype">
<string key="NSKey">Name</string>
<bool key="NSAscending">YES</bool>
<string key="NSSelector">localizedCaseInsensitiveCompare:</string>
<string key="NSSelector">compareFinder:</string>
</object>
</object>
<object class="NSTableColumn" id="155009194">

View file

@ -38,6 +38,7 @@
+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds;
+ (NSString *) timeString: (NSUInteger) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max;
- (NSComparisonResult) compareFinder: (NSString *) string; //how the Finder compares strings
- (NSComparisonResult) compareIP: (NSString *) string;
@end

View file

@ -23,6 +23,7 @@
*****************************************************************************/
#import "NSStringAdditions.h"
#import "NSApplicationAdditions.h"
#import <transmission.h>
@implementation NSString (NSStringAdditions)
@ -144,6 +145,14 @@
return [timeArray componentsJoinedByString: @" "];
}
- (NSComparisonResult) compareFinder: (NSString *) string
{
int comparisonOptions = ![NSApp isOnLeopardOrBetter] ? (NSCaseInsensitiveSearch | NSNumericSearch)
: (NSCaseInsensitiveSearch | NSNumericSearch| NSWidthInsensitiveSearch | NSForcedOrderingSearch);
return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
}
- (NSComparisonResult) compareIP: (NSString *) string
{
NSArray * selfSections = [self componentsSeparatedByString: @"."],
@ -154,9 +163,11 @@
NSEnumerator * selfSectionsEnum = [selfSections objectEnumerator], * newSectionsEnum = [newSections objectEnumerator];
NSString * selfString, * newString;
int comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSNumericSearch | NSForcedOrderingSearch) : NSNumericSearch;
NSComparisonResult result;
while ((selfString = [selfSectionsEnum nextObject]) && (newString = [newSectionsEnum nextObject]))
if ((result = [selfString compare: newString options: NSNumericSearch]) != NSOrderedSame)
if ((result = [selfString compare: newString options: comparisonOptions
range: NSMakeRange(0, [selfString length]) locale: [NSLocale currentLocale]]) != NSOrderedSame)
return result;
return NSOrderedSame;