diff --git a/macosx/Controller.m b/macosx/Controller.m index c0a256107..c86aee9ce 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -45,7 +45,7 @@ #import "ExpandedPathToPathTransformer.h" #import "ExpandedPathToIconTransformer.h" #import "SpeedLimitToTurtleIconTransformer.h" -#include "utils.h" //tr_getRatio() +#include "utils.h" #import "UKKQueue.h" #import @@ -2633,29 +2633,13 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy ? @"YingYangGroupTemplate.png" : @"UpArrowGroupTemplate.png"]; else { + TorrentGroup * group = (TorrentGroup *)item; + if ([fDefaults boolForKey: @"DisplayGroupRowRatio"]) - { - uint64_t uploaded = 0, downloaded = 0; - NSEnumerator * enumerator = [[item torrents] objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) - { - uploaded += [torrent uploadedTotal]; - downloaded += [torrent downloadedTotal]; - } - - return [NSString stringForRatio: tr_getRatio(uploaded, downloaded)]; - } + return [NSString stringForRatio: [group ratio]]; else { - BOOL upload = [ident isEqualToString: @"UL"]; - - float rate = 0.0; - NSEnumerator * enumerator = [[item torrents] objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) - rate += upload ? [torrent uploadRate] : [torrent downloadRate]; - + float rate = [ident isEqualToString: @"UL"] ? [group uploadRate] : [group downloadRate]; return [NSString stringForSpeed: rate]; } } diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 1807c755d..0ec6c360d 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -30,6 +30,7 @@ #import "QuickLookController.h" #import "NSApplicationAdditions.h" #import "NSStringAdditions.h" +#include "utils.h" //tr_getRatio() #define TAB_INFO_IDENT @"Info" #define TAB_ACTIVITY_IDENT @"Activity" @@ -279,6 +280,7 @@ typedef enum [fUploadedTotalField setStringValue: @""]; [fFailedHashField setStringValue: @""]; [fDateActivityField setStringValue: @""]; + [fRatioField setStringValue: @""]; //options fields [fUploadLimitPopUp setEnabled: NO]; @@ -335,7 +337,6 @@ typedef enum [fStateField setStringValue: @""]; [fProgressField setStringValue: @""]; - [fRatioField setStringValue: @""]; [fSwarmSpeedField setStringValue: @""]; [fErrorMessageView setString: @""]; @@ -1370,6 +1371,11 @@ typedef enum [fPiecesView updateView]; } + else if (numberSelected > 1) + { + [fRatioField setStringValue: [NSString stringForRatio: tr_getRatio(uploadedTotal, downloadedTotal)]]; + } + else; } #warning reload table when necessary? diff --git a/macosx/TorrentGroup.h b/macosx/TorrentGroup.h index a3e32f97a..b34911062 100644 --- a/macosx/TorrentGroup.h +++ b/macosx/TorrentGroup.h @@ -35,4 +35,8 @@ - (NSInteger) groupIndex; - (NSMutableArray *) torrents; +- (float) ratio; +- (float) uploadRate; +- (float) downloadRate; + @end diff --git a/macosx/TorrentGroup.m b/macosx/TorrentGroup.m index f078cf519..bdd75335d 100644 --- a/macosx/TorrentGroup.m +++ b/macosx/TorrentGroup.m @@ -23,6 +23,8 @@ *****************************************************************************/ #import "TorrentGroup.h" +#import "Torrent.h" +#include "utils.h" //tr_getRatio() @implementation TorrentGroup @@ -52,4 +54,40 @@ return fTorrents; } +- (float) ratio +{ + uint64_t uploaded = 0, downloaded = 0; + NSEnumerator * enumerator = [fTorrents objectEnumerator]; + Torrent * torrent; + while ((torrent = [enumerator nextObject])) + { + uploaded += [torrent uploadedTotal]; + downloaded += [torrent downloadedTotal]; + } + + return tr_getRatio(uploaded, downloaded); +} + +- (float) uploadRate +{ + float rate = 0.0; + NSEnumerator * enumerator = [fTorrents objectEnumerator]; + Torrent * torrent; + while ((torrent = [enumerator nextObject])) + rate += [torrent uploadRate]; + + return rate; +} + +- (float) downloadRate +{ + float rate = 0.0; + NSEnumerator * enumerator = [fTorrents objectEnumerator]; + Torrent * torrent; + while ((torrent = [enumerator nextObject])) + rate += [torrent downloadRate]; + + return rate; +} + @end