mirror of
https://github.com/transmission/transmission
synced 2025-01-31 19:34:05 +00:00
move ratio from mac code to libT code
This commit is contained in:
parent
48ccd81283
commit
d6104b6f71
6 changed files with 27 additions and 15 deletions
|
@ -560,7 +560,16 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
|
|||
|
||||
s->downloaded = tor->downloadedCur + tor->downloadedPrev;
|
||||
s->uploaded = tor->uploadedCur + tor->uploadedPrev;
|
||||
|
||||
|
||||
if( s->downloaded == 0 )
|
||||
{
|
||||
s->ratio = s->uploaded == 0 ? TR_RATIO_NA : TR_RATIO_INF;
|
||||
}
|
||||
else
|
||||
{
|
||||
s->ratio = (float)s->uploaded / (float)s->downloaded;
|
||||
}
|
||||
|
||||
tr_lockUnlock( &tor->lock );
|
||||
|
||||
return s;
|
||||
|
|
|
@ -391,6 +391,10 @@ struct tr_stat_s
|
|||
uint64_t downloaded;
|
||||
uint64_t uploaded;
|
||||
float swarmspeed;
|
||||
|
||||
#define TR_RATIO_NA -1
|
||||
#define TR_RATIO_INF -2
|
||||
float ratio;
|
||||
};
|
||||
|
||||
struct tr_peer_stat_s
|
||||
|
|
|
@ -330,7 +330,7 @@
|
|||
stringByAppendingFormat: @" (%.2f%%)", 100.0 * [torrent progress]]];
|
||||
|
||||
[fStateField setStringValue: [torrent stateString]];
|
||||
[fRatioField setStringValue: [NSString stringForRatioWithDownload: downloadedTotal upload: uploadedTotal]];
|
||||
[fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
|
||||
[fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""];
|
||||
|
||||
NSString * errorMessage = [torrent errorMessage];
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
+ (NSString *) stringForFileSize: (uint64_t) size;
|
||||
+ (NSString *) stringForSpeed: (float) speed;
|
||||
+ (NSString *) stringForSpeedAbbrev: (float) speed;
|
||||
+ (NSString *) stringForRatioWithDownload: (uint64_t) down upload: (uint64_t) up;
|
||||
+ (NSString *) stringForRatio: (float) ratio;
|
||||
|
||||
- (NSAttributedString *) attributedStringFittingInWidth: (float) width
|
||||
attributes: (NSDictionary *) attributes;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#import "StringAdditions.h"
|
||||
#import <transmission.h>
|
||||
|
||||
@implementation NSString (StringAdditions)
|
||||
|
||||
|
@ -93,13 +94,13 @@
|
|||
return [NSString stringWithFormat: @"%.2f G", speed / 1048576.0];
|
||||
}
|
||||
|
||||
+ (NSString *) stringForRatioWithDownload: (uint64_t) down upload: (uint64_t) up
|
||||
+ (NSString *) stringForRatio: (float) ratio
|
||||
{
|
||||
if (down == 0)
|
||||
return up == 0 ? NSLocalizedString(@"N/A", "No Ratio") : [NSString stringWithUTF8String: "\xE2\x88\x9E"];
|
||||
|
||||
float ratio = (float) up / (float) down;
|
||||
if (ratio < 10.0)
|
||||
if (ratio == TR_RATIO_NA)
|
||||
return NSLocalizedString(@"N/A", "No Ratio");
|
||||
else if (ratio == TR_RATIO_INF)
|
||||
return [NSString stringWithUTF8String: "\xE2\x88\x9E"];
|
||||
else if (ratio < 10.0)
|
||||
return [NSString stringWithFormat: @"%.2f", ratio];
|
||||
else if (ratio < 100.0)
|
||||
return [NSString stringWithFormat: @"%.1f", ratio];
|
||||
|
|
|
@ -284,7 +284,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
|||
else
|
||||
[fProgressString appendFormat: NSLocalizedString(@"%@, uploaded %@ (Ratio: %@)", "Torrent -> progress string"),
|
||||
[NSString stringForFileSize: [self size]], [NSString stringForFileSize: [self uploadedTotal]],
|
||||
[NSString stringForRatioWithDownload: [self downloadedTotal] upload: [self uploadedTotal]]];
|
||||
[NSString stringForRatio: [self ratio]]];
|
||||
|
||||
switch (fStat->status)
|
||||
{
|
||||
|
@ -398,8 +398,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
|||
}
|
||||
else
|
||||
{
|
||||
NSString * ratioString = [NSString stringForRatioWithDownload: [self downloadedTotal]
|
||||
upload: [self uploadedTotal]];
|
||||
NSString * ratioString = [NSString stringForRatio: [self ratio]];
|
||||
|
||||
[fShortStatusString setString: [NSString stringWithFormat: NSLocalizedString(@"Ratio: %@, ",
|
||||
"Torrent -> status string"), ratioString]];
|
||||
|
@ -504,8 +503,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
|||
|
||||
- (float) ratio
|
||||
{
|
||||
float downloaded = [self downloadedTotal];
|
||||
return downloaded > 0 ? (float)[self uploadedTotal] / downloaded : -1;
|
||||
return fStat->ratio;
|
||||
}
|
||||
|
||||
- (BOOL) customRatioSetting
|
||||
|
@ -1129,7 +1127,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
|||
{
|
||||
//if finished downloading sort by ratio instead of progress
|
||||
float progress = [self progress];
|
||||
return [NSNumber numberWithFloat: progress < 1.0 ? progress : 2.0 + [self ratio]];
|
||||
return [NSNumber numberWithFloat: progress < 1.0 ? progress : 100.0 + [self ratio]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue