Changeset 7892


Ignore:
Timestamp:
Feb 14, 2009, 9:15:57 PM (12 years ago)
Author:
livings124
Message:

have the mac ui use libT's ratio settings (attempt 1); when seed ratio is reached in libT, set the seed ratio setting to "seed forever"

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r7888 r7892  
    998998                if( ratio >= seedRatio ) {
    999999                    tr_torrentStop( tor );
     1000                   
     1001                    /* set to no ratio limit to allow easy restarting */
     1002                    tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED );
     1003                   
    10001004                    fireRatioLimitHit( tor );
    10011005                }
  • trunk/libtransmission/torrent.c

    r7891 r7892  
    218218tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio )
    219219{
    220     double r = 0;
    221220    tr_bool isLimited;
    222221
     
    225224        case TR_RATIOLIMIT_SINGLE:
    226225            isLimited = TRUE;
    227             r = tr_torrentGetRatioLimit( tor );
     226            if( ratio )
     227                *ratio = tr_torrentGetRatioLimit( tor );
    228228            break;
    229229
    230230        case TR_RATIOLIMIT_GLOBAL:
    231231            if(( isLimited = tr_sessionIsRatioLimited( tor->session )))
    232                 r = tr_sessionGetRatioLimit( tor->session );
     232                if( ratio )
     233                    *ratio = tr_sessionGetRatioLimit( tor->session );
    233234            break;
    234235
     
    238239    }
    239240
    240     *ratio = r;
    241241    return isLimited;
    242242}
  • trunk/libtransmission/torrent.h

    r7888 r7892  
    7171                                              tr_direction       direction );
    7272
    73 tr_bool     tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio );
    74 
    7573
    7674
  • trunk/libtransmission/transmission.h

    r7891 r7892  
    573573double     tr_sessionGetRatioLimit        ( const tr_session  * session);
    574574
     575tr_bool    tr_torrentGetSeedRatio         ( const tr_torrent * tor, double * ratio );
     576
    575577double     tr_sessionGetRawSpeed          ( const tr_session  * session,
    576578                                           tr_direction         direction );
  • trunk/macosx/Controller.m

    r7802 r7892  
    202202       
    203203        tr_benc settings;
    204         tr_bencInitDict(&settings, 20);
     204        tr_bencInitDict(&settings, 22);
    205205        tr_sessionGetDefaultSettings(&settings);
    206206       
     
    232232        tr_bencDictAddStr(&settings, TR_PREFS_KEY_PROXY_USERNAME,  [[fDefaults stringForKey: @"ProxyUsername"] UTF8String]);
    233233        tr_bencDictAddInt(&settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED,  [fDefaults boolForKey: @"RPCAuthorize"]);
     234        tr_bencDictAddDouble(&settings, TR_PREFS_KEY_RATIO, [fDefaults floatForKey: @"RatioLimit"]);
     235        tr_bencDictAddInt(&settings, TR_PREFS_KEY_RATIO_ENABLED, [fDefaults boolForKey: @"RatioCheck"]);
    234236        tr_bencDictAddInt(&settings, TR_PREFS_KEY_RPC_ENABLED,  [fDefaults boolForKey: @"RPC"]);
    235237        tr_bencDictAddInt(&settings, TR_PREFS_KEY_RPC_PORT,  [fDefaults integerForKey: @"RPCPort"]);
     
    23972399{
    23982400    [fDefaults setBool: sender == fCheckRatioItem forKey: @"RatioCheck"];
     2401   
     2402    [fPrefsController applyRatioSetting: nil];
    23992403}
    24002404
  • trunk/macosx/InfoWindowController.m

    r7659 r7892  
    606606   
    607607    //set ratio view
    608     if (checkRatio == NSOnState)
     608    if (checkRatio == TR_RATIOLIMIT_SINGLE)
    609609        index = OPTION_POPUP_LIMIT;
    610     else if (checkRatio == NSOffState)
     610    else if (checkRatio == TR_RATIOLIMIT_UNLIMITED)
    611611        index = OPTION_POPUP_NO_LIMIT;
    612     else if (checkRatio == NSMixedState)
     612    else if (checkRatio == TR_RATIOLIMIT_GLOBAL)
    613613        index = OPTION_POPUP_GLOBAL;
    614614    else
     
    617617    [fRatioPopUp setEnabled: YES];
    618618   
    619     [fRatioLimitField setHidden: checkRatio != NSOnState];
     619    [fRatioLimitField setHidden: checkRatio != TR_RATIOLIMIT_SINGLE];
    620620    if (ratioLimit != INVALID)
    621621        [fRatioLimitField setFloatValue: ratioLimit];
     
    12301230{
    12311231    NSInteger setting;
     1232    bool single = NO;
    12321233    switch ([sender indexOfSelectedItem])
    12331234    {
    12341235        case OPTION_POPUP_LIMIT:
    1235             setting = NSOnState;
     1236            setting = TR_RATIOLIMIT_SINGLE;
     1237            single = YES;
    12361238            break;
    12371239        case OPTION_POPUP_NO_LIMIT:
    1238             setting = NSOffState;
     1240            setting = TR_RATIOLIMIT_UNLIMITED;
    12391241            break;
    12401242        case OPTION_POPUP_GLOBAL:
    1241             setting = NSMixedState;
     1243            setting = TR_RATIOLIMIT_GLOBAL;
    12421244            break;
    12431245        default:
     
    12481250        [torrent setRatioSetting: setting];
    12491251   
    1250     BOOL single = setting == NSOnState;
    12511252    [fRatioLimitField setHidden: !single];
    12521253    if (single)
    12531254    {
    12541255        [fRatioLimitField selectText: self];
    1255         [[self window] makeKeyAndOrderFront:self];
     1256        [[self window] makeKeyAndOrderFront: self];
    12561257    }
    12571258   
  • trunk/macosx/PrefsController.m

    r7727 r7892  
    192192   
    193193    //set stop ratio
    194     [self updateRatioStopField];
     194    [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
    195195   
    196196    //set limits
     
    569569- (void) applyRatioSetting: (id) sender
    570570{
    571     [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
     571    //[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
     572    tr_sessionSetRatioLimited(fHandle, [fDefaults boolForKey: @"RatioCheck"]);
     573    tr_sessionSetRatioLimit(fHandle, [fDefaults floatForKey: @"RatioLimit"]);
    572574}
    573575
    574576- (void) updateRatioStopField
    575577{
    576     if (!fHasLoaded)
    577         return;
    578    
    579     [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
     578    if (fHasLoaded)
     579        [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
    580580   
    581581    [self applyRatioSetting: nil];
     
    585585{
    586586    [fDefaults setFloat: [sender floatValue] forKey: @"RatioLimit"];
     587   
    587588    [self applyRatioSetting: nil];
    588589}
  • trunk/macosx/Torrent.h

    r7794 r7892  
    2828@class FileListNode;
    2929
    30 #define INVALID -99
    31 
    3230typedef enum
    3331{
     
    6664    NSDate * fPreviousFinishedIndexesDate;
    6765   
    68     CGFloat fRatioLimit;
    69     NSInteger fRatioSetting;
    7066    BOOL fFinishedSeeding, fWaitToStart, fStalled;
    7167   
     
    108104
    109105- (CGFloat) ratio;
    110 - (NSInteger) ratioSetting;
    111 - (void) setRatioSetting: (NSInteger) setting;
     106- (tr_ratiolimit) ratioSetting;
     107- (void) setRatioSetting: (tr_ratiolimit) setting;
    112108- (CGFloat) ratioLimit;
    113109- (void) setRatioLimit: (CGFloat) limit;
    114 - (CGFloat) actualStopRatio; //returns INVALID if will not stop
     110- (BOOL) seedRatioSet;
    115111- (CGFloat) progressStopRatio;
    116112
     
    181177
    182178- (NSInteger) eta;
    183 - (NSInteger) etaRatio;
    184179
    185180- (CGFloat) notAvailableDesired;
  • trunk/macosx/Torrent.m

    r7794 r7892  
    3535        downloadFolder: (NSString *) downloadFolder
    3636        useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
    37         ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
    3837        waitToStart: (NSNumber *) waitToStart
    3938        groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers;
     
    4847- (void) completenessChange: (NSNumber *) status;
    4948
     49- (void) ratioLimitHit;
     50
    5051- (void) quickPause;
    5152- (void) endQuickPause;
    5253
    53 - (NSString *) etaString: (NSInteger) eta;
     54- (NSString *) etaString;
    5455
    5556- (void) updateAllTrackers: (NSMutableArray *) trackers;
     
    6465{
    6566    [(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:)
    66                 withObject: [[NSNumber alloc] initWithInt: status] waitUntilDone: NO];
     67        withObject: [[NSNumber alloc] initWithInt: status] waitUntilDone: NO];
     68}
     69
     70void ratioLimitHitCallback(tr_torrent * torrent, void * torrentData)
     71{
     72    [(Torrent *)torrentData performSelectorOnMainThread: @selector(ratioLimitHit) withObject: nil waitUntilDone: NO];
    6773}
    6874
     
    8288            downloadFolder: location
    8389            useIncompleteFolder: nil incompleteFolder: nil
    84             ratioSetting: nil ratioLimit: nil
    8590            waitToStart: nil groupValue: nil addedTrackers: nil];
    8691   
     
    107112            downloadFolder: location
    108113            useIncompleteFolder: nil incompleteFolder: nil
    109             ratioSetting: nil ratioLimit: nil
    110114            waitToStart: nil groupValue: nil addedTrackers: nil];
    111115   
     
    121125                useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"]
    122126                incompleteFolder: [history objectForKey: @"IncompleteFolder"]
    123                 ratioSetting: [history objectForKey: @"RatioSetting"]
    124                 ratioLimit: [history objectForKey: @"RatioLimit"]
    125127                waitToStart: [history objectForKey: @"WaitToStart"]
    126128                groupValue: [history objectForKey: @"GroupValue"]
     
    145147        if ((date = [history objectForKey: @"DateCompleted"]))
    146148            tr_torrentSetDoneDate(fHandle, [date timeIntervalSince1970]);
     149       
     150        //upgrading from versions < 1.60: get old stop ratio settings
     151        NSNumber * ratioSetting;
     152        if ((ratioSetting = [history objectForKey: @"RatioSetting"]))
     153        {
     154            switch ([ratioSetting intValue])
     155            {
     156                case NSOnState: [self setRatioSetting: TR_RATIOLIMIT_SINGLE]; break;
     157                case NSOffState: [self setRatioSetting: TR_RATIOLIMIT_UNLIMITED]; break;
     158                case NSMixedState: [self setRatioSetting: TR_RATIOLIMIT_GLOBAL]; break;
     159            }
     160        }
     161        NSNumber * ratioLimit;
     162        if ((ratioLimit = [history objectForKey: @"RatioLimit"]))
     163            [self setRatioLimit: [ratioLimit floatValue]];
    147164    }
    148165    return self;
     
    157174                    [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
    158175                    [NSNumber numberWithBool: [self isActive]], @"Active",
    159                     [NSNumber numberWithInt: fRatioSetting], @"RatioSetting",
    160                     [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit",
    161176                    [NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
    162177                    [NSNumber numberWithInt: fGroupValue], @"GroupValue",
     
    280295    fStat = tr_torrentStat(fHandle);
    281296   
    282     //check to stop for ratio
    283     CGFloat stopRatio;
    284     if ([self isSeeding] && (stopRatio = [self actualStopRatio]) != INVALID && [self ratio] >= stopRatio)
    285     {
    286         [self setRatioSetting: NSOffState];
    287         [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentStoppedForRatio" object: self];
    288        
    289         [self stopTransfer];
    290         fStat = tr_torrentStat(fHandle);
    291        
    292         fFinishedSeeding = YES;
    293     }
    294    
    295297    //check if stalled (stored because based on time and needs to check if it was previously stalled)
    296298    fStalled = [self isActive] && [fDefaults boolForKey: @"CheckStalled"]
     
    360362}
    361363
    362 - (NSInteger) ratioSetting
    363 {
    364     return fRatioSetting;
    365 }
    366 
    367 - (void) setRatioSetting: (NSInteger) setting
    368 {
    369     fRatioSetting = setting;
     364- (tr_ratiolimit) ratioSetting
     365{
     366    return tr_torrentGetRatioMode(fHandle);
     367}
     368
     369- (void) setRatioSetting: (tr_ratiolimit) setting
     370{
     371    tr_torrentSetRatioMode(fHandle, setting);
    370372}
    371373
    372374- (CGFloat) ratioLimit
    373375{
    374     return fRatioLimit;
     376    return tr_torrentGetRatioLimit(fHandle);
    375377}
    376378
    377379- (void) setRatioLimit: (CGFloat) limit
    378380{
    379     if (limit >= 0)
    380         fRatioLimit = limit;
    381 }
    382 
    383 - (CGFloat) actualStopRatio
    384 {
    385     if (fRatioSetting == NSOnState)
    386         return fRatioLimit;
    387     else if (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"])
    388         return [fDefaults floatForKey: @"RatioLimit"];
    389     else
    390         return INVALID;
    391 }
    392 
     381    NSAssert(limit >= 0, @"Ratio cannot be negative");
     382    tr_torrentSetRatioLimit(fHandle, limit);
     383}
     384
     385- (BOOL) seedRatioSet
     386{
     387    return tr_torrentGetSeedRatio(fHandle, NULL);
     388}
     389
     390#warning move to libtransmission
    393391- (CGFloat) progressStopRatio
    394392{
    395     CGFloat stopRatio, ratio;
    396     if ((stopRatio = [self actualStopRatio]) == INVALID || (ratio = [self ratio]) >= stopRatio)
     393    double stopRatio, ratio;
     394    if (!tr_torrentGetSeedRatio(fHandle, &stopRatio) || (ratio = [self ratio]) >= stopRatio)
    397395        return 1.0;
    398396    else if (stopRatio > 0.0)
     
    904902}
    905903
    906 - (NSInteger) etaRatio
    907 {
    908     if (![self isSeeding])
    909         return TR_ETA_UNKNOWN;
    910    
    911     CGFloat uploadRate = [self uploadRate];
    912     if (uploadRate < 0.1)
    913         return TR_ETA_UNKNOWN;
    914    
    915     CGFloat stopRatio = [self actualStopRatio], ratio = [self ratio];
    916     if (stopRatio == INVALID || ratio >= stopRatio)
    917         return TR_ETA_UNKNOWN;
    918    
    919     CGFloat haveDownloaded = (CGFloat)([self downloadedTotal] > 0 ? [self downloadedTotal] : [self haveVerified]);
    920     CGFloat needUploaded = haveDownloaded * (stopRatio - ratio);
    921     return needUploaded / uploadRate / 1024.0;
    922 }
    923 
    924904- (CGFloat) notAvailableDesired
    925905{
     
    10871067   
    10881068    //add time when downloading
    1089     if (fStat->activity == TR_STATUS_DOWNLOAD || ([self isSeeding]
    1090         && (fRatioSetting == NSOnState || (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"]))))
    1091     {
    1092         NSInteger eta = fStat->activity == TR_STATUS_DOWNLOAD ? [self eta] : [self etaRatio];
    1093         string = [string stringByAppendingFormat: @" - %@", [self etaString: eta]];
    1094     }
     1069    if (fStat->activity == TR_STATUS_DOWNLOAD || ([self isSeeding] && [self seedRatioSet]))
     1070        string = [string stringByAppendingFormat: @" - %@", [self etaString]];
    10951071   
    10961072    return string;
     
    12301206- (NSString *) remainingTimeString
    12311207{
    1232     if (![self isActive] || ([self isSeeding]
    1233         && !(fRatioSetting == NSOnState || (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"]))))
     1208    if (fStat->activity == TR_STATUS_DOWNLOAD || ([self isSeeding] && [self seedRatioSet]))
     1209        return [self etaString];
     1210    else
    12341211        return [self shortStatusString];
    1235    
    1236     return [self etaString: [self isSeeding] ? [self etaRatio] : [self eta]];
    12371212}
    12381213
     
    16031578        downloadFolder: (NSString *) downloadFolder
    16041579        useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
    1605         ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
    16061580        waitToStart: (NSNumber *) waitToStart
    16071581        groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers
     
    16831657   
    16841658    tr_torrentSetCompletenessCallback(fHandle, completenessChangeCallback, self);
     1659    tr_torrentSetRatioLimitHitCallback(fHandle, ratioLimitHitCallback, self);
    16851660   
    16861661    fNameString = [[NSString alloc] initWithUTF8String: fInfo->name];
    16871662    fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString];
    16881663       
    1689     fRatioSetting = ratioSetting ? [ratioSetting intValue] : NSMixedState;
    1690     fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"];
    16911664    fFinishedSeeding = NO;
    16921665   
     
    18791852   
    18801853    [self update];
    1881 }
     1854}
     1855
     1856- (void) ratioLimitHit
     1857{
     1858    fStat = tr_torrentStat(fHandle);
     1859   
     1860    [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentStoppedForRatio" object: self];
     1861   
     1862    fFinishedSeeding = YES;
     1863}
    18821864
    18831865- (void) quickPause
     
    19121894}
    19131895
    1914 - (NSString *) etaString: (NSInteger) eta
    1915 {
     1896- (NSString *) etaString
     1897{
     1898    const NSInteger eta = [self eta];
    19161899    switch (eta)
    19171900    {
Note: See TracChangeset for help on using the changeset viewer.