Changeset 446
- Timestamp:
- Jun 23, 2006, 3:06:27 PM (16 years ago)
- Location:
- trunk/macosx
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Controller.h
r394 r446 134 134 - (void) ratioSingleChange: (NSNotification *) notification; 135 135 136 - (void) checkWaitingForFinished: (NSNotification *) notification; 137 136 138 - (void) sleepCallBack: (natural_t) messageType argument: 137 139 (void *) messageArgument; -
trunk/macosx/Controller.m
r442 r446 212 212 [nc addObserver: self selector: @selector(ratioGlobalChange:) 213 213 name: @"RatioGlobalChange" object: nil]; 214 215 [nc addObserver: self selector: @selector(checkWaitingForFinished:) 216 name: @"TorrentFinishedDownloading" object: nil]; 214 217 215 218 //timer to update the interface … … 318 321 if (code == NSOKButton) 319 322 { 323 //setup for autostart 324 NSString * startSetting = [fDefaults stringForKey: @"StartSetting"]; 325 BOOL waitToStart = [startSetting isEqualToString: @"Wait"]; 326 int desiredActive, active = 0; 327 if (waitToStart) 328 { 329 desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"]; 330 Torrent * tempTorrent; 331 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 332 while ((tempTorrent = [enumerator nextObject])) 333 if ([tempTorrent isActive] && ![tempTorrent isSeeding]) 334 active++; 335 } 336 320 337 [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]]; 321 if ( [fDefaults boolForKey: @"AutoStartDownload"])338 if ((waitToStart && active < desiredActive) || [startSetting isEqualToString: @"Start"]) 322 339 [torrent startTransfer]; 323 340 [fTorrents addObject: torrent]; … … 329 346 } 330 347 331 - (void) application: (NSApplication *) sender 332 openFiles: (NSArray *) filenames 333 { 334 BOOL autoStart = [fDefaults boolForKey: @"AutoStartDownload"]; 335 348 - (void) application: (NSApplication *) sender openFiles: (NSArray *) filenames 349 { 336 350 NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath; 351 352 //setup for autostart 353 NSString * startSetting = [fDefaults stringForKey: @"StartSetting"]; 354 BOOL waitToStart = [startSetting isEqualToString: @"Wait"]; 355 int desiredActive, active = 0; 356 if (waitToStart && ![downloadChoice isEqualToString: @"Ask"]) 357 { 358 desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"]; 359 Torrent * tempTorrent; 360 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 361 while ((tempTorrent = [enumerator nextObject])) 362 if ([tempTorrent isActive] && ![tempTorrent isSeeding]) 363 active++; 364 } 365 337 366 Torrent * torrent; 338 367 NSEnumerator * enumerator = [filenames objectEnumerator]; … … 342 371 continue; 343 372 344 / * Add it to the "File > Open Recent" menu */373 //add it to the "File > Open Recent" menu 345 374 [[NSDocumentController sharedDocumentController] 346 375 noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]]; … … 371 400 372 401 [torrent setDownloadFolder: folder]; 373 if (autoStart) 402 #warning should check if transfer was already done 403 if ((waitToStart && active < desiredActive) || [startSetting isEqualToString: @"Start"]) 404 { 374 405 [torrent startTransfer]; 406 active++; 407 } 375 408 [fTorrents addObject: torrent]; 376 409 } … … 503 536 active++; 504 537 505 if ( active > 0 && [fDefaults boolForKey: @"CheckRemove"])538 if (active > 0 && [fDefaults boolForKey: @"CheckRemove"]) 506 539 { 507 540 NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: … … 911 944 } 912 945 946 - (void) checkWaitingForFinished: (NSNotification *) notification 947 { 948 //don't try to start a transfer if there should be none waiting 949 if (![[fDefaults stringForKey: @"StartSetting"] isEqualToString: @"Wait"]) 950 return; 951 952 int desiredActive = [fDefaults integerForKey: @"WaitToStartNumber"], active = 0; 953 954 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 955 Torrent * torrent, * torrentToStart = nil; 956 while ((torrent = [enumerator nextObject])) 957 { 958 //ignore the torrent just stopped; for some reason it is not marked instantly as not active 959 if (torrent == [notification object]) 960 continue; 961 962 if ([torrent isActive]) 963 { 964 if (![torrent isSeeding]) 965 { 966 active++; 967 if (active >= desiredActive) 968 return; 969 } 970 } 971 else 972 { 973 if (!torrentToStart && [torrent waitingToStart]) 974 torrentToStart = torrent; 975 } 976 } 977 978 //since it hasn't returned, the queue amount has not been met 979 if (torrentToStart) 980 { 981 [torrentToStart startTransfer]; 982 [self updateUI: nil]; 983 } 984 } 985 913 986 - (int) numberOfRowsInTableView: (NSTableView *) t 914 987 { -
trunk/macosx/Defaults.plist
r425 r446 3 3 <plist version="1.0"> 4 4 <dict> 5 <key>AutoStartDownload</key>6 <true/>7 5 <key>BadgeDownloadRate</key> 8 6 <false/> … … 51 49 <key>Sort</key> 52 50 <string>Date</string> 51 <key>StartSetting</key> 52 <string>Start</string> 53 53 <key>StatusBar</key> 54 54 <true/> … … 59 59 <key>UseAdvancedBar</key> 60 60 <false/> 61 <key>WaitToStartNumber</key> 62 <integer>3</integer> 61 63 </dict> 62 64 </plist> -
trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib
r310 r446 6 6 ACTIONS = { 7 7 folderSheetShow = id; 8 setAutoStart = id;9 8 setBadge = id; 10 9 setDownloadLocation = id; … … 16 15 setRatioCheck = id; 17 16 setShowMessage = id; 17 setStartSetting = id; 18 18 setUpdate = id; 19 setWaitToStart = id; 19 20 }; 20 21 CLASS = PrefsController; 21 22 LANGUAGE = ObjC; 22 23 OUTLETS = { 23 fAutoStartCheck = NSButton;24 24 fBadgeDownloadRateCheck = NSButton; 25 25 fBadgeUploadRateCheck = NSButton; … … 36 36 fRatioField = NSTextField; 37 37 fRemoveCheck = NSButton; 38 fStartMatrix = NSMatrix; 38 39 fTransfersView = NSView; 39 40 fUpdatePopUp = NSPopUpButton; … … 41 42 fUploadCheck = NSButton; 42 43 fUploadField = NSTextField; 44 fWaitToStartField = NSTextField; 43 45 }; 44 46 SUPERCLASS = NSWindowController; -
trunk/macosx/English.lproj/PrefsWindow.nib/info.nib
r319 r446 8 8 <dict> 9 9 <key>28</key> 10 <string> 195 461 462212 0 0 1152 842 </string>10 <string>321 472 535 212 0 0 1152 842 </string> 11 11 <key>41</key> 12 <string> 345 427 462 3060 0 1152 842 </string>12 <string>286 392 535 345 0 0 1152 842 </string> 13 13 <key>66</key> 14 <string>3 45 526 462104 0 0 1152 842 </string>14 <string>321 526 535 104 0 0 1152 842 </string> 15 15 </dict> 16 16 <key>IBFramework Version</key> 17 17 <string>446.1</string> 18 <key>IBOpenObjects</key>19 <array>20 <integer>41</integer>21 </array>22 18 <key>IBSystem Version</key> 23 19 <string>8I127</string> -
trunk/macosx/InfoWindowController.m
r431 r446 409 409 - (void) setRatioCheck: (id) sender 410 410 { 411 NSButtonCell * selected = [fRatioMatrix selectedCell]; 412 int ratioSetting; 413 if (selected == [fRatioMatrix cellWithTag: RATIO_CHECK_TAG]) 411 int ratioSetting, tag = [[fRatioMatrix selectedCell] tag]; 412 if (tag == RATIO_CHECK_TAG) 414 413 ratioSetting = RATIO_CHECK; 415 else if ( selected == [fRatioMatrix cellWithTag: RATIO_NO_CHECK_TAG])414 else if (tag == RATIO_NO_CHECK_TAG) 416 415 ratioSetting = RATIO_NO_CHECK; 417 416 else … … 424 423 425 424 [self setRatioLimit: fRatioLimitField]; 426 [fRatioLimitField setEnabled: selected == [fRatioMatrix cellWithTag: RATIO_CHECK_TAG]];425 [fRatioLimitField setEnabled: tag == RATIO_CHECK_TAG]; 427 426 } 428 427 -
trunk/macosx/PrefsController.h
r382 r446 37 37 IBOutlet NSButton * fQuitCheck, * fRemoveCheck, 38 38 * fBadgeDownloadRateCheck, * fBadgeUploadRateCheck, 39 * f AutoStartCheck, * fCopyTorrentCheck, * fDeleteOriginalTorrentCheck;39 * fCopyTorrentCheck, * fDeleteOriginalTorrentCheck; 40 40 IBOutlet NSPopUpButton * fUpdatePopUp; 41 41 … … 45 45 IBOutlet NSButton * fRatioCheck; 46 46 IBOutlet NSTextField * fRatioField; 47 48 IBOutlet NSMatrix * fStartMatrix; 49 IBOutlet NSTextField * fWaitToStartField; 47 50 48 51 IBOutlet SUUpdater * fUpdater; … … 58 61 - (void) setUpdate: (id) sender; 59 62 - (void) checkUpdate; 60 - (void) setAutoStart: (id) sender; 63 64 65 - (void) setStartSetting: (id) sender; 66 - (void) setWaitToStart: (id) sender; 67 61 68 - (void) setMoveTorrent: (id) sender; 62 69 - (void) setDownloadLocation: (id) sender; -
trunk/macosx/PrefsController.m
r421 r446 31 31 #define DOWNLOAD_FOLDER 0 32 32 #define DOWNLOAD_TORRENT 2 33 #define DOWNLOAD_ASK 3 33 #define DOWNLOAD_ASK 3 34 35 #define START_YES_CHECK_TAG 0 36 #define START_WAIT_CHECK_TAG 1 37 #define START_NO_CHECK_TAG 2 34 38 35 39 #define UPDATE_DAILY 0 … … 143 147 [fBadgeUploadRateCheck setState: [fDefaults boolForKey: @"BadgeUploadRate"]]; 144 148 145 //set auto start 146 [fAutoStartCheck setState: [fDefaults boolForKey: @"AutoStartDownload"]]; 149 //set start setting 150 NSString * startSetting = [fDefaults stringForKey: @"StartSetting"]; 151 int tag; 152 if ([startSetting isEqualToString: @"Start"]) 153 tag = START_YES_CHECK_TAG; 154 else if ([startSetting isEqualToString: @"Wait"]) 155 tag = START_WAIT_CHECK_TAG; 156 else 157 tag = START_NO_CHECK_TAG; 158 159 [fStartMatrix selectCellWithTag: tag]; 160 [fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG]; 161 [fWaitToStartField setIntValue: [fDefaults integerForKey: @"WaitToStartNumber"]]; 147 162 148 163 //set private torrents … … 408 423 } 409 424 410 - (void) setAutoStart: (id) sender 411 { 412 [fDefaults setBool: [sender state] forKey: @"AutoStartDownload"]; 425 - (void) setStartSetting: (id) sender 426 { 427 NSString * startSetting; 428 429 int tag = [[fStartMatrix selectedCell] tag]; 430 if (tag == START_YES_CHECK_TAG) 431 startSetting = @"Start"; 432 else if (tag == START_WAIT_CHECK_TAG) 433 startSetting = @"Wait"; 434 else 435 startSetting = @"Manual"; 436 437 [fDefaults setObject: startSetting forKey: @"StartSetting"]; 438 439 [self setWaitToStart: fWaitToStartField]; 440 [fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG]; 441 } 442 443 - (void) setWaitToStart: (id) sender 444 { 445 int waitNumber = [sender intValue]; 446 if (![[sender stringValue] isEqualToString: [NSString stringWithInt: waitNumber]] || waitNumber < 1) 447 { 448 NSBeep(); 449 waitNumber = [fDefaults floatForKey: @"WaitToStartNumber"]; 450 [sender setIntValue: waitNumber]; 451 } 452 else 453 [fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"]; 454 455 #warning notification recheck 413 456 } 414 457 -
trunk/macosx/Torrent.h
r424 r446 50 50 int fStopRatioSetting; 51 51 float fRatioLimit; 52 BOOL fFinishedSeeding ;52 BOOL fFinishedSeeding, fWaitToStart; 53 53 } 54 54 … … 74 74 - (float) ratioLimit; 75 75 - (void) setRatioLimit: (float) limit; 76 77 - (void) setWaitToStart: (BOOL) wait; 78 - (BOOL) waitingToStart; 76 79 77 80 - (void) revealData; -
trunk/macosx/Torrent.m
r424 r446 31 31 privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent 32 32 date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting 33 ratioLimit: (NSNumber *) ratioLimit ;33 ratioLimit: (NSNumber *) ratioLimit waitToStart: (NSNumber *) waitToStart; 34 34 35 35 - (void) trashFile: (NSString *) path; … … 43 43 { 44 44 self = [self initWithHash: nil path: path lib: lib privateTorrent: nil publicTorrent: nil 45 date: nil stopRatioSetting: nil ratioLimit: nil ];45 date: nil stopRatioSetting: nil ratioLimit: nil waitToStart: nil]; 46 46 47 47 if (self) … … 61 61 date: [history objectForKey: @"Date"] 62 62 stopRatioSetting: [history objectForKey: @"StopRatioSetting"] 63 ratioLimit: [history objectForKey: @"RatioLimit"]]; 63 ratioLimit: [history objectForKey: @"RatioLimit"] 64 waitToStart: [history objectForKey: @"WaitToStart"]]; 64 65 65 66 if (self) … … 86 87 [self date], @"Date", 87 88 [NSNumber numberWithInt: fStopRatioSetting], @"StopRatioSetting", 88 [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit", nil]; 89 [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit", 90 [NSNumber numberWithBool: fWaitToStart], @"WaitToStart", nil]; 89 91 90 92 if (fPrivateTorrent) … … 159 161 { 160 162 case TR_STATUS_PAUSE: 161 [fStatusString setString: fFinishedSeeding ? @"Seeding Complete" : @"Paused"]; 163 if (fFinishedSeeding) 164 [fStatusString setString: @"Seeding complete"]; 165 else if (fWaitToStart) 166 [fStatusString setString: [@"Waiting to start" stringByAppendingEllipsis]]; 167 else 168 [fStatusString setString: @"Paused"]; 162 169 break; 163 170 … … 222 229 { 223 230 tr_torrentStart(fHandle); 231 224 232 fFinishedSeeding = NO; 233 fWaitToStart = NO; 225 234 } 226 235 } … … 229 238 { 230 239 if ([self isActive]) 240 { 241 BOOL wasSeeding = [self isSeeding]; 242 231 243 tr_torrentStop(fHandle); 244 245 if (!wasSeeding) 246 [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self]; 247 } 232 248 } 233 249 … … 241 257 { 242 258 if ((fResumeOnWake = [self isActive])) 243 [self stopTransfer];259 tr_torrentStop(fHandle); 244 260 } 245 261 … … 247 263 { 248 264 if (fResumeOnWake) 249 [self startTransfer];265 tr_torrentStart(fHandle); 250 266 } 251 267 … … 275 291 if (limit >= 0) 276 292 fRatioLimit = limit; 293 } 294 295 - (void) setWaitToStart: (BOOL) wait 296 { 297 fWaitToStart = wait; 298 } 299 300 - (BOOL) waitingToStart 301 { 302 return fWaitToStart; 277 303 } 278 304 … … 425 451 - (BOOL) justFinished 426 452 { 427 return tr_getFinished(fHandle); 453 BOOL finished = tr_getFinished(fHandle); 454 if (finished) 455 [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self]; 456 457 return finished; 428 458 } 429 459 … … 529 559 privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent 530 560 date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting 531 ratioLimit: (NSNumber *) ratioLimit 561 ratioLimit: (NSNumber *) ratioLimit waitToStart: (NSNumber *) waitToStart 532 562 { 533 563 if (!(self = [super init])) … … 564 594 fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"]; 565 595 fFinishedSeeding = NO; 596 597 fWaitToStart = waitToStart ? [waitToStart boolValue] 598 : [[fDefaults stringForKey: @"StartSetting"] isEqualToString: @"Wait"]; 566 599 567 600 NSString * fileType = fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension];
Note: See TracChangeset
for help on using the changeset viewer.