"switch-ify" some code

This commit is contained in:
Mitchell Livingston
2007-10-01 21:52:31 +00:00
parent b84305cdf3
commit 1770fa78d6
3 changed files with 64 additions and 45 deletions

View File

@@ -334,7 +334,7 @@
- (Torrent *) selectedTorrent
{
return fTorrents && [fTorrents count] > 0 ? [fTorrents objectAtIndex: 0] : nil;
return fTorrents && [fTorrents count] == 1 ? [fTorrents objectAtIndex: 0] : nil;
}
- (void) updateInfoStats
@@ -430,10 +430,10 @@
return;
Torrent * torrent = [fTorrents objectAtIndex: 0];
int seeders = [torrent seeders], leechers = [torrent leechers], downloaded = [torrent completedFromTracker];
[fSeedersField setStringValue: seeders < 0 ? @"" : [NSString stringWithFormat: @"%d", seeders]];
[fLeechersField setStringValue: leechers < 0 ? @"" : [NSString stringWithFormat: @"%d", leechers]];
[fCompletedFromTrackerField setStringValue: downloaded < 0 ? @"" : [NSString stringWithFormat: @"%d", downloaded]];
int seeders = [torrent seeders], leechers = [torrent leechers], completed = [torrent completedFromTracker];
[fSeedersField setStringValue: seeders > 0 ? [NSString stringWithFormat: @"%d", seeders] : @""];
[fLeechersField setStringValue: leechers > 0 ? [NSString stringWithFormat: @"%d", leechers] : @""];
[fCompletedFromTrackerField setStringValue: completed > 0 ? [NSString stringWithFormat: @"%d", completed] : @""];
BOOL active = [torrent isActive];
@@ -460,16 +460,21 @@
[components addObject: [NSString stringWithFormat:
NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), count]];
connected = [NSString stringWithFormat: @"%@: %@", connected, [components componentsJoinedByString: @", "]];
connected = [connected stringByAppendingFormat: @": %@", [components componentsJoinedByString: @", "]];
}
[fConnectedPeersField setStringValue: connected];
[fDownloadingFromField setIntValue: [torrent peersSendingToUs]];
[fUploadingToField setIntValue: [torrent peersGettingFromUs]];
}
else
{
[fConnectedPeersField setStringValue: NSLocalizedString(@"info not available", "Inspector -> Peers tab -> peers")];
[fDownloadingFromField setStringValue: @""];
[fUploadingToField setStringValue: @""];
}
[fDownloadingFromField setStringValue: active ? [NSString stringWithFormat: @"%d", [torrent peersSendingToUs]] : @""];
[fUploadingToField setStringValue: active ? [NSString stringWithFormat: @"%d", [torrent peersGettingFromUs]] : @""];
[fKnownField setIntValue: [torrent totalPeersKnown]];
[fPeers release];