Ignore:
Timestamp:
Feb 14, 2009, 9:15:57 PM (13 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"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.