Changeset 1302


Ignore:
Timestamp:
Dec 30, 2006, 7:24:09 PM (16 years ago)
Author:
livings124
Message:

move ratio from mac code to libT code

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/transmission.c

    r1288 r1302  
    561561    s->downloaded = tor->downloadedCur + tor->downloadedPrev;
    562562    s->uploaded   = tor->uploadedCur   + tor->uploadedPrev;
    563 
     563   
     564    if( s->downloaded == 0 )
     565    {
     566        s->ratio = s->uploaded == 0 ? TR_RATIO_NA : TR_RATIO_INF;
     567    }
     568    else
     569    {
     570        s->ratio = (float)s->uploaded / (float)s->downloaded;
     571    }
     572   
    564573    tr_lockUnlock( &tor->lock );
    565574
  • trunk/libtransmission/transmission.h

    r1286 r1302  
    392392    uint64_t            uploaded;
    393393    float               swarmspeed;
     394
     395#define TR_RATIO_NA  -1
     396#define TR_RATIO_INF -2
     397    float               ratio;
    394398};
    395399
  • trunk/macosx/InfoWindowController.m

    r1297 r1302  
    331331       
    332332        [fStateField setStringValue: [torrent stateString]];
    333         [fRatioField setStringValue: [NSString stringForRatioWithDownload: downloadedTotal upload: uploadedTotal]];
     333        [fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
    334334        [fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""];
    335335       
  • trunk/macosx/StringAdditions.h

    r777 r1302  
    3535+ (NSString *) stringForSpeed: (float) speed;
    3636+ (NSString *) stringForSpeedAbbrev: (float) speed;
    37 + (NSString *) stringForRatioWithDownload: (uint64_t) down upload: (uint64_t) up;
     37+ (NSString *) stringForRatio: (float) ratio;
    3838
    3939- (NSAttributedString *) attributedStringFittingInWidth: (float) width
  • trunk/macosx/StringAdditions.m

    r1081 r1302  
    2424
    2525#import "StringAdditions.h"
     26#import <transmission.h>
    2627
    2728@implementation NSString (StringAdditions)
     
    9495}
    9596
    96 + (NSString *) stringForRatioWithDownload: (uint64_t) down upload: (uint64_t) up
     97+ (NSString *) stringForRatio: (float) ratio
    9798{
    98     if (down == 0)
    99         return up == 0 ? NSLocalizedString(@"N/A", "No Ratio") : [NSString stringWithUTF8String: "\xE2\x88\x9E"];
    100 
    101     float ratio = (float) up / (float) down;
    102     if (ratio < 10.0)
     99    if (ratio == TR_RATIO_NA)
     100        return NSLocalizedString(@"N/A", "No Ratio");
     101    else if (ratio == TR_RATIO_INF)
     102        return [NSString stringWithUTF8String: "\xE2\x88\x9E"];
     103    else if (ratio < 10.0)
    103104        return [NSString stringWithFormat: @"%.2f", ratio];
    104105    else if (ratio < 100.0)
  • trunk/macosx/Torrent.m

    r1298 r1302  
    285285        [fProgressString appendFormat: NSLocalizedString(@"%@, uploaded %@ (Ratio: %@)", "Torrent -> progress string"),
    286286                [NSString stringForFileSize: [self size]], [NSString stringForFileSize: [self uploadedTotal]],
    287                 [NSString stringForRatioWithDownload: [self downloadedTotal] upload: [self uploadedTotal]]];
     287                [NSString stringForRatio: [self ratio]]];
    288288
    289289    switch (fStat->status)
     
    399399        else
    400400        {
    401             NSString * ratioString = [NSString stringForRatioWithDownload: [self downloadedTotal]
    402                                                 upload: [self uploadedTotal]];
     401            NSString * ratioString = [NSString stringForRatio: [self ratio]];
    403402       
    404403            [fShortStatusString setString: [NSString stringWithFormat: NSLocalizedString(@"Ratio: %@, ",
     
    505504- (float) ratio
    506505{
    507     float downloaded = [self downloadedTotal];
    508     return downloaded > 0 ? (float)[self uploadedTotal] / downloaded : -1;
     506    return fStat->ratio;
    509507}
    510508
     
    11301128    //if finished downloading sort by ratio instead of progress
    11311129    float progress = [self progress];
    1132     return [NSNumber numberWithFloat: progress < 1.0 ? progress : 2.0 + [self ratio]];
     1130    return [NSNumber numberWithFloat: progress < 1.0 ? progress : 100.0 + [self ratio]];
    11331131}
    11341132
Note: See TracChangeset for help on using the changeset viewer.