- Timestamp:
- Feb 14, 2009, 9:15:57 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r7888 r7892 998 998 if( ratio >= seedRatio ) { 999 999 tr_torrentStop( tor ); 1000 1001 /* set to no ratio limit to allow easy restarting */ 1002 tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED ); 1003 1000 1004 fireRatioLimitHit( tor ); 1001 1005 } -
trunk/libtransmission/torrent.c
r7891 r7892 218 218 tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio ) 219 219 { 220 double r = 0;221 220 tr_bool isLimited; 222 221 … … 225 224 case TR_RATIOLIMIT_SINGLE: 226 225 isLimited = TRUE; 227 r = tr_torrentGetRatioLimit( tor ); 226 if( ratio ) 227 *ratio = tr_torrentGetRatioLimit( tor ); 228 228 break; 229 229 230 230 case TR_RATIOLIMIT_GLOBAL: 231 231 if(( isLimited = tr_sessionIsRatioLimited( tor->session ))) 232 r = tr_sessionGetRatioLimit( tor->session ); 232 if( ratio ) 233 *ratio = tr_sessionGetRatioLimit( tor->session ); 233 234 break; 234 235 … … 238 239 } 239 240 240 *ratio = r;241 241 return isLimited; 242 242 } -
trunk/libtransmission/torrent.h
r7888 r7892 71 71 tr_direction direction ); 72 72 73 tr_bool tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio );74 75 73 76 74 -
trunk/libtransmission/transmission.h
r7891 r7892 573 573 double tr_sessionGetRatioLimit ( const tr_session * session); 574 574 575 tr_bool tr_torrentGetSeedRatio ( const tr_torrent * tor, double * ratio ); 576 575 577 double tr_sessionGetRawSpeed ( const tr_session * session, 576 578 tr_direction direction ); -
trunk/macosx/Controller.m
r7802 r7892 202 202 203 203 tr_benc settings; 204 tr_bencInitDict(&settings, 2 0);204 tr_bencInitDict(&settings, 22); 205 205 tr_sessionGetDefaultSettings(&settings); 206 206 … … 232 232 tr_bencDictAddStr(&settings, TR_PREFS_KEY_PROXY_USERNAME, [[fDefaults stringForKey: @"ProxyUsername"] UTF8String]); 233 233 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"]); 234 236 tr_bencDictAddInt(&settings, TR_PREFS_KEY_RPC_ENABLED, [fDefaults boolForKey: @"RPC"]); 235 237 tr_bencDictAddInt(&settings, TR_PREFS_KEY_RPC_PORT, [fDefaults integerForKey: @"RPCPort"]); … … 2397 2399 { 2398 2400 [fDefaults setBool: sender == fCheckRatioItem forKey: @"RatioCheck"]; 2401 2402 [fPrefsController applyRatioSetting: nil]; 2399 2403 } 2400 2404 -
trunk/macosx/InfoWindowController.m
r7659 r7892 606 606 607 607 //set ratio view 608 if (checkRatio == NSOnState)608 if (checkRatio == TR_RATIOLIMIT_SINGLE) 609 609 index = OPTION_POPUP_LIMIT; 610 else if (checkRatio == NSOffState)610 else if (checkRatio == TR_RATIOLIMIT_UNLIMITED) 611 611 index = OPTION_POPUP_NO_LIMIT; 612 else if (checkRatio == NSMixedState)612 else if (checkRatio == TR_RATIOLIMIT_GLOBAL) 613 613 index = OPTION_POPUP_GLOBAL; 614 614 else … … 617 617 [fRatioPopUp setEnabled: YES]; 618 618 619 [fRatioLimitField setHidden: checkRatio != NSOnState];619 [fRatioLimitField setHidden: checkRatio != TR_RATIOLIMIT_SINGLE]; 620 620 if (ratioLimit != INVALID) 621 621 [fRatioLimitField setFloatValue: ratioLimit]; … … 1230 1230 { 1231 1231 NSInteger setting; 1232 bool single = NO; 1232 1233 switch ([sender indexOfSelectedItem]) 1233 1234 { 1234 1235 case OPTION_POPUP_LIMIT: 1235 setting = NSOnState; 1236 setting = TR_RATIOLIMIT_SINGLE; 1237 single = YES; 1236 1238 break; 1237 1239 case OPTION_POPUP_NO_LIMIT: 1238 setting = NSOffState;1240 setting = TR_RATIOLIMIT_UNLIMITED; 1239 1241 break; 1240 1242 case OPTION_POPUP_GLOBAL: 1241 setting = NSMixedState;1243 setting = TR_RATIOLIMIT_GLOBAL; 1242 1244 break; 1243 1245 default: … … 1248 1250 [torrent setRatioSetting: setting]; 1249 1251 1250 BOOL single = setting == NSOnState;1251 1252 [fRatioLimitField setHidden: !single]; 1252 1253 if (single) 1253 1254 { 1254 1255 [fRatioLimitField selectText: self]; 1255 [[self window] makeKeyAndOrderFront: self];1256 [[self window] makeKeyAndOrderFront: self]; 1256 1257 } 1257 1258 -
trunk/macosx/PrefsController.m
r7727 r7892 192 192 193 193 //set stop ratio 194 [ self updateRatioStopField];194 [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]]; 195 195 196 196 //set limits … … 569 569 - (void) applyRatioSetting: (id) sender 570 570 { 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"]); 572 574 } 573 575 574 576 - (void) updateRatioStopField 575 577 { 576 if (!fHasLoaded) 577 return; 578 579 [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]]; 578 if (fHasLoaded) 579 [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]]; 580 580 581 581 [self applyRatioSetting: nil]; … … 585 585 { 586 586 [fDefaults setFloat: [sender floatValue] forKey: @"RatioLimit"]; 587 587 588 [self applyRatioSetting: nil]; 588 589 } -
trunk/macosx/Torrent.h
r7794 r7892 28 28 @class FileListNode; 29 29 30 #define INVALID -9931 32 30 typedef enum 33 31 { … … 66 64 NSDate * fPreviousFinishedIndexesDate; 67 65 68 CGFloat fRatioLimit;69 NSInteger fRatioSetting;70 66 BOOL fFinishedSeeding, fWaitToStart, fStalled; 71 67 … … 108 104 109 105 - (CGFloat) ratio; 110 - ( NSInteger) ratioSetting;111 - (void) setRatioSetting: ( NSInteger) setting;106 - (tr_ratiolimit) ratioSetting; 107 - (void) setRatioSetting: (tr_ratiolimit) setting; 112 108 - (CGFloat) ratioLimit; 113 109 - (void) setRatioLimit: (CGFloat) limit; 114 - ( CGFloat) actualStopRatio; //returns INVALID if will not stop110 - (BOOL) seedRatioSet; 115 111 - (CGFloat) progressStopRatio; 116 112 … … 181 177 182 178 - (NSInteger) eta; 183 - (NSInteger) etaRatio;184 179 185 180 - (CGFloat) notAvailableDesired; -
trunk/macosx/Torrent.m
r7794 r7892 35 35 downloadFolder: (NSString *) downloadFolder 36 36 useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder 37 ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit38 37 waitToStart: (NSNumber *) waitToStart 39 38 groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers; … … 48 47 - (void) completenessChange: (NSNumber *) status; 49 48 49 - (void) ratioLimitHit; 50 50 51 - (void) quickPause; 51 52 - (void) endQuickPause; 52 53 53 - (NSString *) etaString : (NSInteger) eta;54 - (NSString *) etaString; 54 55 55 56 - (void) updateAllTrackers: (NSMutableArray *) trackers; … … 64 65 { 65 66 [(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:) 66 withObject: [[NSNumber alloc] initWithInt: status] waitUntilDone: NO]; 67 withObject: [[NSNumber alloc] initWithInt: status] waitUntilDone: NO]; 68 } 69 70 void ratioLimitHitCallback(tr_torrent * torrent, void * torrentData) 71 { 72 [(Torrent *)torrentData performSelectorOnMainThread: @selector(ratioLimitHit) withObject: nil waitUntilDone: NO]; 67 73 } 68 74 … … 82 88 downloadFolder: location 83 89 useIncompleteFolder: nil incompleteFolder: nil 84 ratioSetting: nil ratioLimit: nil85 90 waitToStart: nil groupValue: nil addedTrackers: nil]; 86 91 … … 107 112 downloadFolder: location 108 113 useIncompleteFolder: nil incompleteFolder: nil 109 ratioSetting: nil ratioLimit: nil110 114 waitToStart: nil groupValue: nil addedTrackers: nil]; 111 115 … … 121 125 useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"] 122 126 incompleteFolder: [history objectForKey: @"IncompleteFolder"] 123 ratioSetting: [history objectForKey: @"RatioSetting"]124 ratioLimit: [history objectForKey: @"RatioLimit"]125 127 waitToStart: [history objectForKey: @"WaitToStart"] 126 128 groupValue: [history objectForKey: @"GroupValue"] … … 145 147 if ((date = [history objectForKey: @"DateCompleted"])) 146 148 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]]; 147 164 } 148 165 return self; … … 157 174 [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder", 158 175 [NSNumber numberWithBool: [self isActive]], @"Active", 159 [NSNumber numberWithInt: fRatioSetting], @"RatioSetting",160 [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit",161 176 [NSNumber numberWithBool: fWaitToStart], @"WaitToStart", 162 177 [NSNumber numberWithInt: fGroupValue], @"GroupValue", … … 280 295 fStat = tr_torrentStat(fHandle); 281 296 282 //check to stop for ratio283 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 295 297 //check if stalled (stored because based on time and needs to check if it was previously stalled) 296 298 fStalled = [self isActive] && [fDefaults boolForKey: @"CheckStalled"] … … 360 362 } 361 363 362 - ( NSInteger) ratioSetting363 { 364 return fRatioSetting;365 } 366 367 - (void) setRatioSetting: ( NSInteger) setting368 { 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); 370 372 } 371 373 372 374 - (CGFloat) ratioLimit 373 375 { 374 return fRatioLimit;376 return tr_torrentGetRatioLimit(fHandle); 375 377 } 376 378 377 379 - (void) setRatioLimit: (CGFloat) limit 378 380 { 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 393 391 - (CGFloat) progressStopRatio 394 392 { 395 CGFloatstopRatio, 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) 397 395 return 1.0; 398 396 else if (stopRatio > 0.0) … … 904 902 } 905 903 906 - (NSInteger) etaRatio907 {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 924 904 - (CGFloat) notAvailableDesired 925 905 { … … 1087 1067 1088 1068 //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]]; 1095 1071 1096 1072 return string; … … 1230 1206 - (NSString *) remainingTimeString 1231 1207 { 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 1234 1211 return [self shortStatusString]; 1235 1236 return [self etaString: [self isSeeding] ? [self etaRatio] : [self eta]];1237 1212 } 1238 1213 … … 1603 1578 downloadFolder: (NSString *) downloadFolder 1604 1579 useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder 1605 ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit1606 1580 waitToStart: (NSNumber *) waitToStart 1607 1581 groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers … … 1683 1657 1684 1658 tr_torrentSetCompletenessCallback(fHandle, completenessChangeCallback, self); 1659 tr_torrentSetRatioLimitHitCallback(fHandle, ratioLimitHitCallback, self); 1685 1660 1686 1661 fNameString = [[NSString alloc] initWithUTF8String: fInfo->name]; 1687 1662 fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString]; 1688 1663 1689 fRatioSetting = ratioSetting ? [ratioSetting intValue] : NSMixedState;1690 fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"];1691 1664 fFinishedSeeding = NO; 1692 1665 … … 1879 1852 1880 1853 [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 } 1882 1864 1883 1865 - (void) quickPause … … 1912 1894 } 1913 1895 1914 - (NSString *) etaString: (NSInteger) eta 1915 { 1896 - (NSString *) etaString 1897 { 1898 const NSInteger eta = [self eta]; 1916 1899 switch (eta) 1917 1900 {
Note: See TracChangeset
for help on using the changeset viewer.