Changeset 421
- Timestamp:
- Jun 21, 2006, 2:07:56 PM (16 years ago)
- Location:
- trunk/macosx
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Controller.m
r419 r421 46 46 #define GROWL_PATH @"/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app" 47 47 48 static void sleepCallBack( 49 natural_t messageType, void * messageArgument 48 static void sleepCallBack(void * controller, io_service_t y, 49 natural_t messageType, void * messageArgument) 50 50 { 51 51 Controller * c = controller; … … 135 135 [NSArray arrayWithObject: NSFilenamesPboardType]]; 136 136 137 // Register for sleep notifications137 //register for sleep notifications 138 138 IONotificationPortRef notify; 139 io_object_t anIterator; 140 if (fRootPort = IORegisterForSystemPower(self, & notify, 141 sleepCallBack, & anIterator)) 142 { 143 CFRunLoopAddSource( CFRunLoopGetCurrent(), 144 IONotificationPortGetRunLoopSource( notify ), 145 kCFRunLoopCommonModes ); 139 io_object_t iterator; 140 if (fRootPort = IORegisterForSystemPower(self, & notify, sleepCallBack, & iterator)) 141 { 142 CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), 143 kCFRunLoopCommonModes); 146 144 } 147 145 else … … 260 258 @"There are %d active transfers. Do you really want to quit?", active]; 261 259 262 NSBeginAlertSheet(@"Confirm Quit", 263 @"Quit", @"Cancel", nil, 264 fWindow, self, 260 NSBeginAlertSheet(@"Confirm Quit", @"Quit", @"Cancel", nil, fWindow, self, 265 261 @selector(quitSheetDidEnd:returnCode:contextInfo:), 266 262 nil, nil, message); … … 317 313 } 318 314 319 - (void) folderChoiceClosed: (NSOpenPanel *) sreturnCode: (int) code315 - (void) folderChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code 320 316 contextInfo: (Torrent *) torrent 321 317 { 322 318 if (code == NSOKButton) 323 319 { 324 [torrent setDownloadFolder: [[ sfilenames] objectAtIndex: 0]];320 [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]]; 325 321 if ([fDefaults boolForKey: @"AutoStartDownload"]) 326 322 [torrent start]; … … 423 419 - (void) open: (NSArray *) files 424 420 { 425 [self performSelectorOnMainThread: @selector(cantFindAName:) 426 withObject: files waitUntilDone: NO]; 421 [self performSelectorOnMainThread: @selector(openFromSheet:) withObject: files waitUntilDone: NO]; 427 422 } 428 423 … … 470 465 unsigned int i; 471 466 for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) 472 { 473 torrent = [fTorrents objectAtIndex: i]; 474 [torrent start]; 475 } 467 [[fTorrents objectAtIndex: i] start]; 476 468 477 469 [self updateUI: nil]; … … 492 484 - (void) stopTorrentWithIndex: (NSIndexSet *) indexSet 493 485 { 486 unsigned int i; 494 487 Torrent * torrent; 495 unsigned int i;496 488 for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) 497 489 { … … 521 513 torrents, @"Torrents", 522 514 [NSNumber numberWithBool: deleteData], @"DeleteData", 523 [NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent", 524 nil]; 515 [NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent", nil]; 525 516 526 517 NSString * title, * message; … … 551 542 NSBeginAlertSheet(title, 552 543 @"Remove", @"Cancel", nil, fWindow, self, 553 @selector(removeSheetDidEnd:returnCode:contextInfo:), 554 nil, dict, message); 544 @selector(removeSheetDidEnd:returnCode:contextInfo:), nil, dict, message); 555 545 } 556 546 else … … 723 713 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 724 714 Torrent * torrent; 725 while ( ( torrent = [enumerator nextObject] ))715 while ((torrent = [enumerator nextObject])) 726 716 { 727 717 [torrent update]; 728 718 729 if ( [torrent justFinished])719 if ([torrent justFinished]) 730 720 { 731 / * Notifications */721 //notifications 732 722 [self notifyGrowl: [torrent name]]; 733 if ( ![fWindow isKeyWindow])723 if (![fWindow isKeyWindow]) 734 724 fCompleted++; 735 725 } … … 741 731 [fTableView reloadData]; 742 732 743 // Update the global DL/UL rates733 //update the global DL/UL rates 744 734 float downloadRate, uploadRate; 745 735 tr_torrentRates(fLib, & downloadRate, & uploadRate); … … 1127 1117 Torrent * torrent; 1128 1118 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 1129 while ( ( torrent = [enumerator nextObject] ))1130 if ( [torrent isActive])1119 while ((torrent = [enumerator nextObject])) 1120 if ([torrent isActive]) 1131 1121 return YES; 1132 1122 return NO; … … 1138 1128 Torrent * torrent; 1139 1129 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 1140 while ( ( torrent = [enumerator nextObject] ))1141 if ( [torrent isPaused])1130 while ((torrent = [enumerator nextObject])) 1131 if ([torrent isPaused]) 1142 1132 return YES; 1143 1133 return NO; … … 1152 1142 1153 1143 for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) 1154 { 1155 torrent = [fTorrents objectAtIndex: i]; 1156 if ([torrent isActive]) 1144 if ([[fTorrents objectAtIndex: i] isActive]) 1157 1145 return YES; 1158 }1159 1146 return NO; 1160 1147 } … … 1163 1150 if ([ident isEqualToString: TOOLBAR_RESUME_SELECTED]) 1164 1151 { 1165 Torrent * torrent;1166 1152 NSIndexSet * indexSet = [fTableView selectedRowIndexes]; 1167 1153 unsigned int i; 1168 1154 1169 1155 for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) 1170 { 1171 torrent = [fTorrents objectAtIndex: i]; 1172 if ([torrent isPaused]) 1156 if ([[fTorrents objectAtIndex: i] isPaused]) 1173 1157 return YES; 1174 }1175 1158 return NO; 1176 1159 } … … 1215 1198 Torrent * torrent; 1216 1199 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 1217 while ( ( torrent = [enumerator nextObject] ))1218 if ( [torrent isPaused])1200 while ((torrent = [enumerator nextObject])) 1201 if ([torrent isPaused]) 1219 1202 return YES; 1220 1203 return NO; … … 1226 1209 Torrent * torrent; 1227 1210 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 1228 while ( ( torrent = [enumerator nextObject] ))1229 if ( [torrent isActive])1211 while ((torrent = [enumerator nextObject])) 1212 if ([torrent isActive]) 1230 1213 return YES; 1231 1214 return NO; … … 1242 1225 { 1243 1226 BOOL active = NO, 1244 canDelete = !(action == @selector(removeDeleteTorrent:) 1245 || action == @selector(removeDeleteBoth:)); 1227 canDelete = action != @selector(removeDeleteTorrent:) && action != @selector(removeDeleteBoth:); 1246 1228 Torrent * torrent; 1247 1229 NSIndexSet * indexSet = [fTableView selectedRowIndexes]; … … 1275 1257 { 1276 1258 if ([title hasSuffix: ellipsis]) 1277 [menuItem setTitle: [title substringToIndex: 1278 [title rangeOfString: ellipsis].location]]; 1259 [menuItem setTitle: [title substringToIndex: [title rangeOfString: ellipsis].location]]; 1279 1260 } 1280 1261 … … 1441 1422 NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript]; 1442 1423 NSDictionary * error; 1443 if (![appleScript executeAndReturnError: & error])1424 if (![appleScript executeAndReturnError: & error]) 1444 1425 NSLog(@"Growl notify failed"); 1445 1426 [appleScript release]; … … 1465 1446 NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript]; 1466 1447 NSDictionary * error; 1467 if (![appleScript executeAndReturnError: & error])1448 if (![appleScript executeAndReturnError: & error]) 1468 1449 NSLog(@"Growl registration failed"); 1469 1450 [appleScript release]; -
trunk/macosx/FileTableView.m
r376 r421 40 40 { 41 41 if (![self isRowSelected: row]) 42 [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] 43 byExtendingSelection: NO]; 42 [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO]; 44 43 } 45 44 else -
trunk/macosx/PrefsController.m
r394 r421 26 26 #import "StringAdditions.h" 27 27 28 #define MIN_PORT 29 #define MAX_PORT 28 #define MIN_PORT 1 29 #define MAX_PORT 65535 30 30 31 31 #define DOWNLOAD_FOLDER 0 … … 33 33 #define DOWNLOAD_ASK 3 34 34 35 #define UPDATE_DAILY 36 #define UPDATE_WEEKLY 37 #define UPDATE_NEVER 35 #define UPDATE_DAILY 0 36 #define UPDATE_WEEKLY 1 37 #define UPDATE_NEVER 2 38 38 39 39 #define TOOLBAR_GENERAL @"General" … … 49 49 - (void) setPrefView: (NSView *) view; 50 50 51 - (void) folderSheetClosed: (NSOpenPanel *) s returnCode: (int) code 52 contextInfo: (void *) info; 51 - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info; 53 52 - (void) updatePopUp; 54 53 … … 86 85 87 86 //set download folder 88 NSString * downloadChoice 87 NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; 89 88 fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]; 90 89 [fDownloadFolder retain]; … … 101 100 int bindPort = [fDefaults integerForKey: @"BindPort"]; 102 101 [fPortField setIntValue: bindPort]; 103 fHandle = handle; 104 tr_setBindPort( fHandle, bindPort ); 102 tr_setBindPort(fHandle, bindPort); 105 103 106 104 //checks for old version upload speed of -1 … … 119 117 [fUploadField setEnabled: checkUpload]; 120 118 121 tr_setUploadLimit( fHandle, checkUpload ? uploadLimit : -1);119 tr_setUploadLimit(fHandle, checkUpload ? uploadLimit : -1); 122 120 123 121 //set download limit … … 129 127 [fDownloadField setEnabled: checkDownload]; 130 128 131 tr_setDownloadLimit( fHandle, checkDownload ? downloadLimit : -1);129 tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1); 132 130 133 131 //set ratio limit … … 254 252 255 253 int limit = [sender intValue]; 256 if (![[sender stringValue] isEqualToString: 257 [NSString stringWithFormat: @"%d", limit]] 254 if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] 258 255 || limit < 0) 259 256 { … … 264 261 else 265 262 { 266 if( sender == fUploadField ) 267 tr_setUploadLimit( fHandle, 268 ( [fUploadCheck state] == NSOffState ) ? -1 : limit ); 263 if (sender == fUploadField) 264 tr_setUploadLimit(fHandle, [fUploadCheck state] == NSOffState ? -1 : limit); 269 265 else 270 tr_setDownloadLimit( fHandle, 271 ( [fDownloadCheck state] == NSOffState ) ? -1 : limit ); 266 tr_setDownloadLimit(fHandle, [fDownloadCheck state] == NSOffState ? -1 : limit); 272 267 273 268 [fDefaults setInteger: limit forKey: key]; … … 278 273 [NSNumber numberWithInt: limit], @"Limit", 279 274 type, @"Type", nil]; 280 [[NSNotificationCenter defaultCenter] postNotificationName: 281 @"LimitGlobalChange" object: dict]; 275 [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange" object: dict]; 282 276 } 283 277 … … 306 300 - (void) setLimitEnabled: (BOOL) enable type: (NSString *) type 307 301 { 308 NSButton * check = [type isEqualToString: @"Upload"] 309 ? fUploadCheck : fDownloadCheck; 302 NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck; 310 303 [check setState: enable ? NSOnState : NSOffState]; 311 304 [self setLimitCheck: check]; … … 332 325 { 333 326 float ratioLimit = [sender floatValue]; 334 if (![[sender stringValue] isEqualToString: 335 [NSString stringWithFormat: @"%.2f", ratioLimit]] 327 if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]] 336 328 || ratioLimit < 0) 337 329 { … … 346 338 [NSNumber numberWithBool: [fRatioCheck state]], @"Enable", 347 339 [NSNumber numberWithFloat: ratioLimit], @"Ratio", nil]; 348 [[NSNotificationCenter defaultCenter] postNotificationName: 349 @"RatioGlobalChange" object: dict]; 340 [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: dict]; 350 341 } 351 342 … … 443 434 { 444 435 //Download folder 445 switch ( [fFolderPopUp indexOfSelectedItem])436 switch ([fFolderPopUp indexOfSelectedItem]) 446 437 { 447 438 case DOWNLOAD_FOLDER: … … 466 457 NSOpenPanel * panel = [NSOpenPanel openPanel]; 467 458 468 [panel setPrompt: 469 [panel setAllowsMultipleSelection: 470 [panel setCanChooseFiles: 471 [panel setCanChooseDirectories: 459 [panel setPrompt: @"Select"]; 460 [panel setAllowsMultipleSelection: NO]; 461 [panel setCanChooseFiles: NO]; 462 [panel setCanChooseDirectories: YES]; 472 463 473 464 [panel beginSheetForDirectory: nil file: nil types: nil … … 513 504 } 514 505 515 - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code 516 contextInfo: (void *) info 506 - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info 517 507 { 518 508 if (code == NSOKButton) … … 532 522 //reset if cancelled 533 523 NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; 534 if( [downloadChoice isEqualToString: @"Constant"] ) 535 { 524 if ([downloadChoice isEqualToString: @"Constant"]) 536 525 [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; 537 } 538 else if( [downloadChoice isEqualToString: @"Torrent"] ) 539 { 526 else if ([downloadChoice isEqualToString: @"Torrent"]) 540 527 [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT]; 541 }542 528 else 543 {544 529 [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK]; 545 }546 530 } 547 531 } -
trunk/macosx/StringAdditions.m
r357 r421 69 69 if (size < 10240) 70 70 /* 1.00 to 9.99 XB */ 71 value = [NSString stringWithFormat: @"%lld.%02lld", 72 size / 1024, ( size % 1024 ) * 100 / 1024]; 71 value = [NSString stringWithFormat: @"%lld.%02lld", size / 1024, ( size % 1024 ) * 100 / 1024]; 73 72 else if (size < 102400) 74 73 /* 10.0 to 99.9 XB */ 75 value = [NSString stringWithFormat: @"%lld.%lld", 76 size / 1024, ( size % 1024 ) * 10 / 1024]; 74 value = [NSString stringWithFormat: @"%lld.%lld", size / 1024, ( size % 1024 ) * 10 / 1024]; 77 75 else 78 76 /* 100+ XB */ … … 84 82 + (NSString *) stringForSpeed: (float) speed 85 83 { 86 return [[self stringForSpeedAbbrev: speed] 87 stringByAppendingString: @"B/s"]; 84 return [[self stringForSpeedAbbrev: speed] stringByAppendingString: @"B/s"]; 88 85 } 89 86 -
trunk/macosx/Torrent.h
r418 r421 101 101 102 102 - (float) progress; 103 - (int) eta; 104 103 105 - (BOOL) isActive; 104 106 - (BOOL) isSeeding; -
trunk/macosx/Torrent.m
r419 r421 42 42 - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib 43 43 { 44 self = [self initWithHash: nil path: path lib: lib 45 privateTorrent: nil publicTorrent: nil 44 self = [self initWithHash: nil path: path lib: lib privateTorrent: nil publicTorrent: nil 46 45 date: nil stopRatioSetting: nil ratioLimit: nil]; 47 46 … … 68 67 NSString * downloadFolder; 69 68 if (!(downloadFolder = [history objectForKey: @"DownloadFolder"])) 70 downloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] 71 stringByExpandingTildeInPath]; 69 downloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]; 72 70 [self setDownloadFolder: downloadFolder]; 73 71 … … 101 99 - (void) dealloc 102 100 { 103 if ( fHandle)104 { 105 tr_torrentClose( fLib, fHandle);101 if (fHandle) 102 { 103 tr_torrentClose(fLib, fHandle); 106 104 107 105 if (fPublicTorrentLocation) … … 119 117 - (void) setDownloadFolder: (NSString *) path 120 118 { 121 tr_torrentSetFolder( fHandle, [path UTF8String]);119 tr_torrentSetFolder(fHandle, [path UTF8String]); 122 120 } 123 121 124 122 - (NSString *) downloadFolder 125 123 { 126 return [NSString stringWithUTF8String: tr_torrentGetFolder( fHandle)];124 return [NSString stringWithUTF8String: tr_torrentGetFolder(fHandle)]; 127 125 } 128 126 129 127 - (void) getAvailability: (int8_t *) tab size: (int) size 130 128 { 131 tr_torrentAvailability( fHandle, tab, size);129 tr_torrentAvailability(fHandle, tab, size); 132 130 } 133 131 134 132 - (void) update 135 133 { 136 fStat = tr_torrentStat( fHandle ); 137 138 if ([self isSeeding] 139 && ((fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit) 134 fStat = tr_torrentStat(fHandle); 135 136 if ([self isSeeding] && ((fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit) 140 137 || (fStopRatioSetting == RATIO_GLOBAL && [fDefaults boolForKey: @"RatioCheck"] 141 138 && [self ratio] >= [fDefaults floatForKey: @"RatioLimit"]))) … … 145 142 fFinishedSeeding = YES; 146 143 147 fStat = tr_torrentStat( fHandle);144 fStat = tr_torrentStat(fHandle); 148 145 149 146 [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentRatioChanged" object: self]; … … 159 156 [NSString stringForRatioWithDownload: [self downloadedTotal] upload: [self uploadedTotal]]]; 160 157 161 switch ( fStat->status)158 switch (fStat->status) 162 159 { 163 160 case TR_STATUS_PAUSE: … … 172 169 [fStatusString setString: @""]; 173 170 [fStatusString appendFormat: 174 @"Downloading from %d of %d peer%s", 175 [self peersUploading], [self totalPeers], 171 @"Downloading from %d of %d peer%s", [self peersUploading], [self totalPeers], 176 172 ([self totalPeers] == 1) ? "" : "s"]; 177 173 178 int eta = fStat->eta;174 int eta = [self eta]; 179 175 if (eta < 0) 180 176 [fProgressString appendString: @" - remaining time unknown"]; … … 223 219 - (void) start 224 220 { 225 if ( fStat->status & TR_STATUS_INACTIVE)226 { 227 tr_torrentStart( fHandle);221 if (![self isActive]) 222 { 223 tr_torrentStart(fHandle); 228 224 fFinishedSeeding = NO; 229 225 } … … 232 228 - (void) stop 233 229 { 234 if( fStat->status & TR_STATUS_ACTIVE ) 235 { 236 tr_torrentStop( fHandle ); 237 } 230 if ([self isActive]) 231 tr_torrentStop(fHandle); 238 232 } 239 233 … … 246 240 - (void) sleep 247 241 { 248 if( ( fResumeOnWake = ( fStat->status & TR_STATUS_ACTIVE ) ) ) 249 { 242 if ((fResumeOnWake = [self isActive])) 250 243 [self stop]; 251 }252 244 } 253 245 254 246 - (void) wakeUp 255 247 { 256 if( fResumeOnWake ) 257 { 248 if (fResumeOnWake) 258 249 [self start]; 259 }260 250 } 261 251 … … 289 279 - (void) reveal 290 280 { 291 [[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] 292 inFileViewerRootedAtPath: nil]; 281 [[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] inFileViewerRootedAtPath: nil]; 293 282 } 294 283 … … 326 315 - (NSString *) tracker 327 316 { 328 return [NSString stringWithFormat: @"%s:%d", 329 fInfo->trackerAddress, fInfo->trackerPort]; 317 return [NSString stringWithFormat: @"%s:%d", fInfo->trackerAddress, fInfo->trackerPort]; 330 318 } 331 319 … … 415 403 } 416 404 405 - (int) eta 406 { 407 return fStat->eta; 408 } 409 417 410 - (BOOL) isActive 418 411 { 419 return ( fStat->status & TR_STATUS_ACTIVE );412 return fStat->status & TR_STATUS_ACTIVE; 420 413 } 421 414 422 415 - (BOOL) isSeeding 423 416 { 424 return ( fStat->status == TR_STATUS_SEED );417 return fStat->status == TR_STATUS_SEED; 425 418 } 426 419 427 420 - (BOOL) isPaused 428 421 { 429 return ( fStat->status == TR_STATUS_PAUSE );422 return fStat->status == TR_STATUS_PAUSE; 430 423 } 431 424 432 425 - (BOOL) justFinished 433 426 { 434 return tr_getFinished( fHandle);427 return tr_getFinished(fHandle); 435 428 } 436 429 … … 514 507 - (NSNumber *) stateSortKey 515 508 { 516 if ( fStat->status & TR_STATUS_INACTIVE)509 if (![self isActive]) 517 510 return [NSNumber numberWithInt: 0]; 518 else if ( fStat->status == TR_STATUS_SEED)511 else if ([self isSeeding]) 519 512 return [NSNumber numberWithInt: 1]; 520 513 else … … 572 565 fFinishedSeeding = NO; 573 566 574 NSString * fileType = fInfo->multifile ? 575 NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension]; 567 NSString * fileType = fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension]; 576 568 fIcon = [[NSWorkspace sharedWorkspace] iconForFileType: fileType]; 577 569 [fIcon retain]; -
trunk/macosx/TorrentTableView.m
r419 r421 71 71 } 72 72 73 - (void) mouseDown: (NSEvent *) e 74 { 75 fClickPoint = [self convertPoint: [e locationInWindow] fromView: nil]; 76 int row = [self rowAtPoint: fClickPoint]; 77 78 if( [e modifierFlags] & NSAlternateKeyMask ) 73 - (void) mouseDown: (NSEvent *) event 74 { 75 fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil]; 76 77 if ([event modifierFlags] & NSAlternateKeyMask) 79 78 { 80 79 [fController advancedChanged: self]; 81 fClickPoint = NSMakePoint( 0, 0 ); 82 } 83 else if( ![self pointInPauseRect: fClickPoint] && 84 ![self pointInRevealRect: fClickPoint] ) 85 [super mouseDown: e]; 80 fClickPoint = NSZeroPoint; 81 } 82 else if (![self pointInPauseRect: fClickPoint] && ![self pointInRevealRect: fClickPoint]) 83 [super mouseDown: event]; 86 84 else; 87 85 … … 89 87 } 90 88 91 - (void) mouseUp: (NSEvent *) e 92 { 93 NSPoint point; 94 int row; 95 bool sameRow; 96 Torrent * torrent; 97 98 point = [self convertPoint: [e locationInWindow] fromView: nil]; 99 row = [self rowAtPoint: point]; 100 sameRow = row == [self rowAtPoint: fClickPoint]; 101 102 if( sameRow && [self pointInPauseRect: point] 103 && [self pointInPauseRect: fClickPoint] ) 104 { 105 torrent = [fTorrents objectAtIndex: row]; 106 107 if( [torrent isPaused] ) 89 - (void) mouseUp: (NSEvent *) event 90 { 91 NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil]; 92 int row = [self rowAtPoint: point]; 93 BOOL sameRow = row == [self rowAtPoint: fClickPoint]; 94 95 if (sameRow && [self pointInPauseRect: point] && [self pointInPauseRect: fClickPoint]) 96 { 97 Torrent * torrent = [fTorrents objectAtIndex: row]; 98 99 if ([torrent isPaused]) 108 100 [fController resumeTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]]; 109 else if ( [torrent isActive])101 else if ([torrent isActive]) 110 102 [fController stopTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]]; 111 103 else; 112 104 } 113 else if( sameRow && [self pointInRevealRect: point] 114 && [self pointInRevealRect: fClickPoint] ) 105 else if (sameRow && [self pointInRevealRect: point] && [self pointInRevealRect: fClickPoint]) 115 106 [[fTorrents objectAtIndex: row] reveal]; 116 else if ([e clickCount] == 2)107 else if ([event clickCount] == 2) 117 108 { 118 109 if ([self pointInIconRect: point]) … … 123 114 else; 124 115 125 [super mouseUp: e ];126 127 fClickPoint = NS MakePoint( 0, 0 );116 [super mouseUp: event]; 117 118 fClickPoint = NSZeroPoint; 128 119 [self display]; 129 120 } 130 121 131 - (NSMenu *) menuForEvent: (NSEvent *) e 132 { 133 int row = [self rowAtPoint: [self convertPoint: [e locationInWindow] fromView: nil]];122 - (NSMenu *) menuForEvent: (NSEvent *) event 123 { 124 int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]]; 134 125 135 126 if (row >= 0) 136 127 { 137 128 if (![self isRowSelected: row]) 138 [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] 139 byExtendingSelection: NO]; 129 [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO]; 140 130 141 131 return fContextRow; … … 150 140 - (void) drawRect: (NSRect) r 151 141 { 152 unsigned i;153 142 NSRect rect; 143 Torrent * torrent; 154 144 NSImage * image; 155 Torrent * torrent;156 145 157 146 [super drawRect: r]; 158 147 159 for( i = 0; i < [fTorrents count]; i++ ) 148 int i; 149 for (i = 0; i < [fTorrents count]; i++) 160 150 { 161 151 torrent = [fTorrents objectAtIndex: i]; … … 172 162 { 173 163 [image setFlipped: YES]; 174 [image drawAtPoint: rect.origin fromRect: 175 NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) operation: 176 NSCompositeSourceOver fraction: 1.0]; 164 [image drawAtPoint: rect.origin fromRect: NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) 165 operation: NSCompositeSourceOver fraction: 1.0]; 177 166 } 178 167 … … 180 169 image = NSPointInRect(fClickPoint, rect) ? fRevealOnIcon : fRevealOffIcon; 181 170 [image setFlipped: YES]; 182 [image drawAtPoint: rect.origin fromRect: 183 NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) operation: 184 NSCompositeSourceOver fraction: 1.0]; 171 [image drawAtPoint: rect.origin fromRect: NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) 172 operation: NSCompositeSourceOver fraction: 1.0]; 185 173 } 186 174 } … … 192 180 - (NSRect) pauseRectForRow: (int) row 193 181 { 194 NSRect cellRect = [self frameOfCellAtColumn: 195 [self columnWithIdentifier: @"Torrent"] row: row]; 182 NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; 196 183 197 184 return NSMakeRect(cellRect.origin.x + cellRect.size.width … … 202 189 - (NSRect) revealRectForRow: (int) row 203 190 { 204 NSRect cellRect = [self frameOfCellAtColumn: 205 [self columnWithIdentifier: @"Torrent"] row: row]; 206 207 return NSMakeRect(cellRect.origin.x + cellRect.size.width 208 - AREA_CENTER + DISTANCE_FROM_CENTER, 191 NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; 192 193 return NSMakeRect(cellRect.origin.x + cellRect.size.width - AREA_CENTER + DISTANCE_FROM_CENTER, 209 194 cellRect.origin.y + BUTTON_TO_TOP, BUTTON_WIDTH, BUTTON_WIDTH); 210 195 } … … 216 201 return NO; 217 202 218 NSRect cellRect = [self frameOfCellAtColumn: 219 [self columnWithIdentifier: @"Torrent"] row: row]; 203 NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; 220 204 NSSize iconSize = [[[fTorrents objectAtIndex: row] iconFlipped] size]; 221 205 222 206 NSRect iconRect = NSMakeRect(cellRect.origin.x + 3.0, cellRect.origin.y 223 + (cellRect.size.height - iconSize.height) * 0.5, 224 iconSize.width, iconSize.height); 207 + (cellRect.size.height - iconSize.height) * 0.5, iconSize.width, iconSize.height); 225 208 226 209 return NSPointInRect(point, iconRect);
Note: See TracChangeset
for help on using the changeset viewer.