From: Mitchell Livingston Date: Sun, 11 Oct 2009 13:42:10 +0000 (+0000) Subject: #2488 when sorting by tracker, first use the tracker that comes first alphabetically X-Git-Tag: 1.80b5~588 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2af26e1d7c2823e99e69dbb469a51492a103bd46;p=transmission #2488 when sorting by tracker, first use the tracker that comes first alphabetically --- diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 939040024..47fa19fb9 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -1270,7 +1270,7 @@ typedef struct /* whether or not we've ever scraped to this tracker */ tr_bool hasScraped; - /* ex: legaltorrents.com */ + /* ex: http://www.legaltorrents.com:7070 */ char host[1024]; /* the full announce URL */ diff --git a/macosx/Controller.m b/macosx/Controller.m index 2940c20df..b0b8c7189 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1941,10 +1941,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy descriptors = [[NSArray alloc] initWithObjects: progressDescriptor, ratioProgressDescriptor, ratioDescriptor, nameDescriptor, nil]; } - #warning broken else if ([sortType isEqualToString: SORT_TRACKER]) { - NSSortDescriptor * trackerDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"trackerAddressAnnounce" ascending: asc + NSSortDescriptor * trackerDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"trackerSortKey" ascending: asc selector: @selector(localizedCaseInsensitiveCompare:)] autorelease]; descriptors = [[NSArray alloc] initWithObjects: trackerDescriptor, nameDescriptor, nil]; @@ -3472,8 +3471,10 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy break; case SORT_ACTIVITY_TAG: sortType = SORT_ACTIVITY; + break; default: NSAssert1(NO, @"Unknown sort tag received: %d", [menuItem tag]); + return; } [menuItem setState: [sortType isEqualToString: [fDefaults stringForKey: @"Sort"]] ? NSOnState : NSOffState]; @@ -4110,7 +4111,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy if (!torrent) { - [pool release]; + [pool drain]; NSLog(@"No torrent found matching the given torrent struct from the RPC callback!"); return; diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 64a527554..741b61618 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -226,6 +226,7 @@ - (BOOL) isStalled; - (NSInteger) stateSortKey; +- (NSString *) trackerSortKey; - (tr_torrent *) torrentStruct; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 3d74c6841..a137e7363 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1478,6 +1478,24 @@ int trashDataFile(const char * filename) return 2; } +- (NSString *) trackerSortKey +{ + int count; + tr_tracker_stat * stats = tr_torrentTrackers(fHandle, &count); + + NSString * best = nil; + + for (int i=0; i < count; ++i) + { + NSString * tracker = [NSString stringWithUTF8String: stats[i].host]; + if (!best || [tracker localizedCaseInsensitiveCompare: best] == NSOrderedAscending) + best = tracker; + } + + tr_torrentTrackersFree(stats, count); + return best; +} + - (tr_torrent *) torrentStruct { return fHandle;