| | 43 | |
|---|
| | 44 | @interface SPApplicationController(Private) |
|---|
| | 45 | |
|---|
| | 46 | - (SPRemoteContext)_remoteContext; |
|---|
| | 47 | - (void)_handleRemoteAction:(SPRemoteAction)action; |
|---|
| | 48 | |
|---|
| | 49 | @end |
|---|
| | 50 | |
|---|
| | 51 | |
|---|
| | 52 | @implementation SPApplicationController(Private) |
|---|
| | 53 | |
|---|
| | 54 | - (SPRemoteContext)_remoteContext { |
|---|
| | 55 | SPMovieController *movieController; |
|---|
| | 56 | id delegate; |
|---|
| | 57 | |
|---|
| | 58 | delegate = [[NSApp keyWindow] delegate]; |
|---|
| | 59 | |
|---|
| | 60 | if([delegate isKindOfClass:[SPPlayerController class]]) { |
|---|
| | 61 | return SPRemotePlayer; |
|---|
| | 62 | } |
|---|
| | 63 | else if([delegate isKindOfClass:[SPDrillController class]]) { |
|---|
| | 64 | movieController = [delegate movieController]; |
|---|
| | 65 | |
|---|
| | 66 | if([movieController isInFullscreen]) |
|---|
| | 67 | return SPRemoteFullscreenPlayer; |
|---|
| | 68 | else |
|---|
| | 69 | return SPRemoteDrillView; |
|---|
| | 70 | } |
|---|
| | 71 | else if([delegate isKindOfClass:[SPPlaylistController class]]) { |
|---|
| | 72 | return SPRemotePlaylist; |
|---|
| | 73 | } |
|---|
| | 74 | |
|---|
| | 75 | return SPRemoteNone; |
|---|
| | 76 | } |
|---|
| | 77 | |
|---|
| | 78 | |
|---|
| | 79 | |
|---|
| | 80 | - (void)_handleRemoteAction:(SPRemoteAction)action { |
|---|
| | 81 | SPMovieController *movieController; |
|---|
| | 82 | double rate; |
|---|
| | 83 | id delegate; |
|---|
| | 84 | |
|---|
| | 85 | delegate = [[NSApp keyWindow] delegate]; |
|---|
| | 86 | |
|---|
| | 87 | if([delegate isKindOfClass:[SPPlayerController class]] || [delegate isKindOfClass:[SPDrillController class]]) |
|---|
| | 88 | movieController = [delegate movieController]; |
|---|
| | 89 | else |
|---|
| | 90 | movieController = NULL; |
|---|
| | 91 | |
|---|
| | 92 | switch(action) { |
|---|
| | 93 | case SPRemoteDoNothing: |
|---|
| | 94 | break; |
|---|
| | 95 | |
|---|
| | 96 | case SPRemoteUp: |
|---|
| | 97 | [delegate moveSelectionUp]; |
|---|
| | 98 | break; |
|---|
| | 99 | |
|---|
| | 100 | case SPRemoteDown: |
|---|
| | 101 | [delegate moveSelectionDown]; |
|---|
| | 102 | break; |
|---|
| | 103 | |
|---|
| | 104 | case SPRemoteRight: |
|---|
| | 105 | [delegate openSelection]; |
|---|
| | 106 | break; |
|---|
| | 107 | |
|---|
| | 108 | case SPRemoteLeft: |
|---|
| | 109 | [delegate closeSelection]; |
|---|
| | 110 | break; |
|---|
| | 111 | |
|---|
| | 112 | case SPRemoteEnter: |
|---|
| | 113 | [delegate openSelection]; |
|---|
| | 114 | break; |
|---|
| | 115 | |
|---|
| | 116 | case SPRemotePlay: |
|---|
| | 117 | [movieController playAtRate:1.0]; |
|---|
| | 118 | break; |
|---|
| | 119 | |
|---|
| | 120 | case SPRemotePlayOrPause: |
|---|
| | 121 | [movieController play]; |
|---|
| | 122 | break; |
|---|
| | 123 | |
|---|
| | 124 | case SPRemotePause: |
|---|
| | 125 | [movieController stop]; |
|---|
| | 126 | break; |
|---|
| | 127 | |
|---|
| | 128 | case SPRemoteStop: |
|---|
| | 129 | [movieController stop]; |
|---|
| | 130 | break; |
|---|
| | 131 | |
|---|
| | 132 | case SPRemoteNext: |
|---|
| | 133 | [movieController openNext]; |
|---|
| | 134 | break; |
|---|
| | 135 | |
|---|
| | 136 | case SPRemotePrevious: |
|---|
| | 137 | [movieController openPrevious]; |
|---|
| | 138 | break; |
|---|
| | 139 | |
|---|
| | 140 | case SPRemoteBack: |
|---|
| | 141 | if([movieController isInFullscreen]) |
|---|
| | 142 | [delegate closeWindow]; |
|---|
| | 143 | else |
|---|
| | 144 | [delegate closeSelection]; |
|---|
| | 145 | break; |
|---|
| | 146 | |
|---|
| | 147 | case SPRemoteScanForward: |
|---|
| | 148 | rate = [SPSettings doubleForKey:SPFastForwardFactor]; |
|---|
| | 149 | |
|---|
| | 150 | [movieController playAtRate:rate]; |
|---|
| | 151 | break; |
|---|
| | 152 | |
|---|
| | 153 | case SPRemoteScanBackward: |
|---|
| | 154 | rate = [SPSettings doubleForKey:SPFastForwardFactor]; |
|---|
| | 155 | |
|---|
| | 156 | [movieController playAtRate:-rate]; |
|---|
| | 157 | break; |
|---|
| | 158 | |
|---|
| | 159 | case SPRemoteStepForward: |
|---|
| | 160 | [movieController stepForward]; |
|---|
| | 161 | break; |
|---|
| | 162 | |
|---|
| | 163 | case SPRemoteStepBackward: |
|---|
| | 164 | [movieController stepBackward]; |
|---|
| | 165 | break; |
|---|
| | 166 | |
|---|
| | 167 | case SPRemoteCycleSubtitleTracks: |
|---|
| | 168 | [movieController cycleSubtitleTracksForwards:YES]; |
|---|
| | 169 | break; |
|---|
| | 170 | |
|---|
| | 171 | case SPRemoteCycleAudioTracks: |
|---|
| | 172 | [movieController cycleAudioTracksForwards:YES]; |
|---|
| | 173 | break; |
|---|
| | 174 | |
|---|
| | 175 | case SPRemoteEject: |
|---|
| | 176 | [[NSWorkspace sharedWorkspace] ejectCDDrive]; |
|---|
| | 177 | break; |
|---|
| | 178 | |
|---|
| | 179 | case SPRemoteShowHUD: |
|---|
| | 180 | [movieController orderFrontFullscreenHUDWindow]; |
|---|
| | 181 | break; |
|---|
| | 182 | |
|---|
| | 183 | case SPRemoteDisplayTime: |
|---|
| | 184 | [movieController flashCurrentTime]; |
|---|
| | 185 | break; |
|---|
| | 186 | |
|---|
| | 187 | case SPRemoteShowDrillView: |
|---|
| | 188 | [[SPDrillController drillController] showWindow:self]; |
|---|
| | 189 | break; |
|---|
| | 190 | |
|---|
| | 191 | case SPRemoteHideDrillView: |
|---|
| | 192 | [delegate closeWindow]; |
|---|
| | 193 | break; |
|---|
| | 194 | |
|---|
| | 195 | case SPRemoteCloseFullscreenMovie: |
|---|
| | 196 | [delegate closeWindow]; |
|---|
| | 197 | break; |
|---|
| | 198 | } |
|---|
| | 199 | } |
|---|
| | 200 | |
|---|
| | 201 | @end |
|---|
| | 202 | |
|---|
| | 203 | |
|---|
| | 204 | |
|---|
| 212 | | - (void)appleRemotePressedButton:(SPAppleRemoteButton)button down:(BOOL)down { |
|---|
| 213 | | SPMovieController *movieController; |
|---|
| 214 | | id delegate; |
|---|
| 215 | | double rate; |
|---|
| 216 | | |
|---|
| 217 | | delegate = [[NSApp keyWindow] delegate]; |
|---|
| 218 | | |
|---|
| 219 | | if([delegate isKindOfClass:[SPPlayerController class]] || [delegate isKindOfClass:[SPDrillController class]]) { |
|---|
| 220 | | movieController = [delegate movieController]; |
|---|
| 221 | | |
|---|
| 222 | | if([delegate isKindOfClass:[SPDrillController class]] && |
|---|
| 223 | | (![movieController isInFullscreen] || |
|---|
| 224 | | button == SPAppleRemoteButtonMenu)) { |
|---|
| 225 | | if(button == SPAppleRemoteButtonPlay || button == SPAppleRemoteButtonRight) |
|---|
| 226 | | [delegate openSelection]; |
|---|
| 227 | | else if(button == SPAppleRemoteButtonVolumeMinus && down) |
|---|
| 228 | | [delegate moveSelectionDown]; |
|---|
| 229 | | else if(button == SPAppleRemoteButtonVolumePlus && down) |
|---|
| 230 | | [delegate moveSelectionUp]; |
|---|
| 231 | | else if(button == SPAppleRemoteButtonLeft) |
|---|
| 232 | | [delegate closeSelection]; |
|---|
| 233 | | else if(button == SPAppleRemoteButtonMenu) |
|---|
| 234 | | [delegate closeWindow]; |
|---|
| 235 | | } else { |
|---|
| 236 | | if(button == SPAppleRemoteButtonPlay) |
|---|
| 237 | | [movieController play]; |
|---|
| 238 | | else if(button == SPAppleRemoteButtonLeft) |
|---|
| 239 | | [movieController openPrevious]; |
|---|
| 240 | | else if(button == SPAppleRemoteButtonRight) |
|---|
| 241 | | [movieController openNext]; |
|---|
| 242 | | else if(button == SPAppleRemoteButtonVolumeMinus) |
|---|
| 243 | | [movieController cycleSubtitleTracksForwards:YES]; |
|---|
| 244 | | else if(button == SPAppleRemoteButtonVolumePlus) |
|---|
| 245 | | [movieController cycleAudioTracksForwards:YES]; |
|---|
| 246 | | else if(button == SPAppleRemoteButtonMenu) { |
|---|
| 247 | | if(![movieController isInFullscreen]) |
|---|
| 248 | | [[SPDrillController drillController] showWindow:self]; |
|---|
| 249 | | } |
|---|
| 250 | | else if(button == SPAppleRemoteButtonLeftHold || button == SPAppleRemoteButtonRightHold) { |
|---|
| 251 | | if(down) { |
|---|
| 252 | | rate = [SPSettings doubleForKey:SPFastForwardFactor]; |
|---|
| 253 | | |
|---|
| 254 | | [movieController playAtRate:(button == SPAppleRemoteButtonRightHold) ? rate : -rate]; |
|---|
| 255 | | } else { |
|---|
| 256 | | [movieController playAtRate:1.0]; |
|---|
| 257 | | } |
|---|
| 258 | | } |
|---|
| 259 | | } |
|---|
| 260 | | } |
|---|
| 261 | | else if([delegate isKindOfClass:[SPPlaylistController class]]) { |
|---|
| 262 | | if(button == SPAppleRemoteButtonPlay) |
|---|
| 263 | | [(SPPlaylistController *) delegate open:self]; |
|---|
| 264 | | else if(button == SPAppleRemoteButtonVolumeMinus && down) |
|---|
| 265 | | [delegate moveSelectionDown]; |
|---|
| 266 | | else if(button == SPAppleRemoteButtonVolumePlus && down) |
|---|
| 267 | | [delegate moveSelectionUp]; |
|---|
| 268 | | else if(button == SPAppleRemoteButtonLeft) |
|---|
| 269 | | [delegate closeSelection]; |
|---|
| 270 | | else if(button == SPAppleRemoteButtonRight) |
|---|
| 271 | | [delegate openSelection]; |
|---|
| 272 | | else if(button == SPAppleRemoteButtonMenu) |
|---|
| 273 | | [[SPDrillController drillController] showWindow:self]; |
|---|
| 274 | | } |
|---|
| 275 | | else if(button == SPAppleRemoteButtonMenu) { |
|---|
| 276 | | [[SPDrillController drillController] showWindow:self]; |
|---|
| 277 | | } |
|---|
| 278 | | |
|---|
| | 374 | - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)selector { |
|---|
| | 375 | if(selector == @selector(insertNewline:)) { |
|---|
| | 376 | [self openURLOK:self]; |
|---|
| | 377 | |
|---|
| | 378 | return YES; |
|---|
| | 379 | } |
|---|
| | 380 | else if(selector == @selector(cancelOperation:)) { |
|---|
| | 381 | [_openURLPanel performClose:self]; |
|---|
| | 382 | |
|---|
| | 383 | return YES; |
|---|
| | 384 | } |
|---|
| | 385 | |
|---|
| | 386 | return NO; |
|---|
| | 387 | } |
|---|
| | 388 | |
|---|
| | 389 | |
|---|
| | 390 | |
|---|
| | 391 | #pragma mark - |
|---|
| | 392 | |
|---|
| | 393 | - (void)appleRemotePressedButton:(SPAppleRemoteButton)button { |
|---|
| | 394 | SPRemoteAction action; |
|---|
| | 395 | |
|---|
| | 396 | action = [[SPAppleRemote sharedRemote] actionForButton:button inContext:[self _remoteContext]]; |
|---|
| | 397 | |
|---|
| | 398 | [self _handleRemoteAction:action]; |
|---|
| | 399 | |
|---|
| 331 | | if([delegate isKindOfClass:[SPDrillController class]] && |
|---|
| 332 | | (![movieController isInFullscreen] || |
|---|
| 333 | | button == SPPS3RemoteButtonTopMenu || |
|---|
| 334 | | button == SPPS3RemoteButtonStop || |
|---|
| 335 | | button == SPPS3RemoteButtonReturn || |
|---|
| 336 | | button == SPPS3RemoteButtonX || |
|---|
| 337 | | button == SPPS3RemoteButtonBack)) { |
|---|
| 338 | | if(button == SPPS3RemoteButtonEnter || button == SPPS3RemoteButtonRight) |
|---|
| 339 | | [delegate openSelection]; |
|---|
| 340 | | else if(button == SPPS3RemoteButtonDown) |
|---|
| 341 | | [delegate moveSelectionDown]; |
|---|
| 342 | | else if(button == SPPS3RemoteButtonUp) |
|---|
| 343 | | [delegate moveSelectionUp]; |
|---|
| 344 | | else if(button == SPPS3RemoteButtonLeft) |
|---|
| 345 | | [delegate closeSelection]; |
|---|
| 346 | | else if(button == SPPS3RemoteButtonReturn || button == SPPS3RemoteButtonX || button == SPPS3RemoteButtonBack) { |
|---|
| 347 | | if([movieController isInFullscreen]) |
|---|
| 348 | | [delegate closeWindow]; |
|---|
| 349 | | else |
|---|
| 350 | | [delegate closeSelection]; |
|---|
| 351 | | } |
|---|
| 352 | | else if(button == SPPS3RemoteButtonStop) { |
|---|
| 353 | | if([movieController isInFullscreen]) |
|---|
| 354 | | [delegate closeWindow]; |
|---|
| 355 | | } |
|---|
| 356 | | else if(button == SPPS3RemoteButtonTopMenu) |
|---|
| 357 | | [delegate closeWindow]; |
|---|
| 358 | | } else { |
|---|
| 359 | | if(button == SPPS3RemoteButtonPlay) |
|---|
| 360 | | [movieController playAtRate:1.0]; |
|---|
| 361 | | else if(button == SPPS3RemoteButtonPause || button == SPPS3RemoteButtonStop) |
|---|
| 362 | | [movieController stop]; |
|---|
| 363 | | else if(button == SPPS3RemoteButtonAudio) |
|---|
| 364 | | [movieController cycleAudioTracksForwards:YES]; |
|---|
| 365 | | else if(button == SPPS3RemoteButtonSubtitle) |
|---|
| 366 | | [movieController cycleSubtitleTracksForwards:YES]; |
|---|
| 367 | | else if(button == SPPS3RemoteButtonTime || button == SPPS3RemoteButtonDisplay) |
|---|
| 368 | | [movieController flashCurrentTime]; |
|---|
| 369 | | else if(button == SPPS3RemoteButtonTopMenu) { |
|---|
| 370 | | if(![movieController isInFullscreen]) |
|---|
| 371 | | [[SPDrillController drillController] showWindow:self]; |
|---|
| 372 | | } |
|---|
| 373 | | else if(button == SPPS3RemoteButtonPopUpMenu) |
|---|
| 374 | | [movieController orderFrontFullscreenHUDWindow]; |
|---|
| 375 | | else if(button == SPPS3RemoteButtonPrevious) |
|---|
| 376 | | [movieController openPrevious]; |
|---|
| 377 | | else if(button == SPPS3RemoteButtonNext) |
|---|
| 378 | | [movieController openNext]; |
|---|
| 379 | | else if(button == SPPS3RemoteButtonStepBackward) |
|---|
| 380 | | [movieController stepBackward]; |
|---|
| 381 | | else if(button == SPPS3RemoteButtonStepForward) |
|---|
| 382 | | [movieController stepForward]; |
|---|
| 383 | | else if(button == SPPS3RemoteButtonScanBackward || button == SPPS3RemoteButtonScanForward) { |
|---|
| 384 | | rate = [SPSettings doubleForKey:SPFastForwardFactor]; |
|---|
| 385 | | |
|---|
| 386 | | [movieController playAtRate:(button == SPPS3RemoteButtonScanForward) ? rate : -rate]; |
|---|
| 387 | | } |
|---|
| 388 | | } |
|---|
| 389 | | } |
|---|
| 390 | | else if([delegate isKindOfClass:[SPPlaylistController class]]) { |
|---|
| 391 | | if(button == SPPS3RemoteButtonEnter) |
|---|
| 392 | | [(SPPlaylistController *) delegate open:self]; |
|---|
| 393 | | else if(button == SPPS3RemoteButtonDown) |
|---|
| 394 | | [delegate moveSelectionDown]; |
|---|
| 395 | | else if(button == SPPS3RemoteButtonUp) |
|---|
| 396 | | [delegate moveSelectionUp]; |
|---|
| 397 | | else if(button == SPPS3RemoteButtonLeft) |
|---|
| 398 | | [delegate closeSelection]; |
|---|
| 399 | | else if(button == SPPS3RemoteButtonRight) |
|---|
| 400 | | [delegate openSelection]; |
|---|
| 401 | | else if(button == SPPS3RemoteButtonTopMenu) |
|---|
| 402 | | [[SPDrillController drillController] showWindow:self]; |
|---|
| 403 | | } |
|---|
| 404 | | else if(button == SPPS3RemoteButtonTopMenu) { |
|---|
| 405 | | [[SPDrillController drillController] showWindow:self]; |
|---|
| 406 | | } |
|---|
| | 439 | if([movieController rate] > 1.0) |
|---|
| | 440 | [movieController playAtRate:1.0]; |
|---|
| | 441 | } |
|---|
| | 442 | |
|---|
| | 443 | _holdingAppleRemoteButton = NO; |
|---|
| | 444 | } |
|---|
| | 445 | |
|---|
| | 446 | |
|---|
| | 447 | |
|---|
| | 448 | #pragma mark - |
|---|
| | 449 | |
|---|
| | 450 | - (void)PS3RemotePressedButton:(SPPS3RemoteButton)button { |
|---|
| | 451 | SPRemoteAction action; |
|---|
| | 452 | |
|---|
| | 453 | action = [[SPPS3Remote sharedRemote] actionForButton:button inContext:[self _remoteContext]]; |
|---|
| | 454 | |
|---|
| | 455 | [self _handleRemoteAction:action]; |
|---|
| 427 | | delegate = [[NSApp keyWindow] delegate]; |
|---|
| 428 | | |
|---|
| 429 | | if([delegate isKindOfClass:[SPPlayerController class]] || [delegate isKindOfClass:[SPDrillController class]]) { |
|---|
| 430 | | movieController = [delegate movieController]; |
|---|
| 431 | | |
|---|
| 432 | | if([button intValue] == SPPS3RemoteButtonDown) |
|---|
| 433 | | [delegate moveSelectionDown]; |
|---|
| 434 | | else if([button intValue] == SPPS3RemoteButtonUp) |
|---|
| 435 | | [delegate moveSelectionUp]; |
|---|
| 436 | | else if([button intValue] == SPPS3RemoteButtonStepBackward) |
|---|
| 437 | | [movieController stepBackward]; |
|---|
| 438 | | else if([button intValue] == SPPS3RemoteButtonStepForward) |
|---|
| 439 | | [movieController stepForward]; |
|---|
| 440 | | } |
|---|
| 441 | | else if([delegate isKindOfClass:[SPPlaylistController class]]) { |
|---|
| 442 | | if([button intValue] == SPPS3RemoteButtonDown) |
|---|
| 443 | | [delegate moveSelectionDown]; |
|---|
| 444 | | else if([button intValue] == SPPS3RemoteButtonUp) |
|---|
| 445 | | [delegate moveSelectionUp]; |
|---|
| 446 | | } |
|---|
| | 475 | action = [[SPPS3Remote sharedRemote] actionForButton:[button intValue] inContext:[self _remoteContext]]; |
|---|
| | 476 | |
|---|
| | 477 | [self _handleRemoteAction:action]; |
|---|
| 463 | | switch(button) { |
|---|
| 464 | | case SPWiiRemoteButton1: NSLog(@"pressed button 1"); break; |
|---|
| 465 | | case SPWiiRemoteButton2: NSLog(@"pressed button 2"); break; |
|---|
| 466 | | case SPWiiRemoteButtonB: NSLog(@"pressed button B"); break; |
|---|
| 467 | | case SPWiiRemoteButtonA: NSLog(@"pressed button A"); break; |
|---|
| 468 | | case SPWiiRemoteButtonMinus: NSLog(@"pressed button minus"); break; |
|---|
| 469 | | case SPWiiRemoteButtonHome: NSLog(@"pressed button home"); break; |
|---|
| 470 | | case SPWiiRemoteButtonLeft: NSLog(@"pressed button left"); break; |
|---|
| 471 | | case SPWiiRemoteButtonRight: NSLog(@"pressed button right"); break; |
|---|
| 472 | | case SPWiiRemoteButtonDown: NSLog(@"pressed button down"); break; |
|---|
| 473 | | case SPWiiRemoteButtonUp: NSLog(@"pressed button up"); break; |
|---|
| 474 | | case SPWiiRemoteButtonPlus: NSLog(@"pressed button plus"); break; |
|---|
| 475 | | } |
|---|
| | 496 | SPRemoteAction action; |
|---|
| | 497 | |
|---|
| | 498 | action = [[SPWiiRemote sharedRemote] actionForButton:button inContext:[self _remoteContext]]; |
|---|
| | 499 | |
|---|
| | 500 | [self _handleRemoteAction:action]; |
|---|
| | 501 | |
|---|
| | 502 | _holdingWiiRemoteButton = NO; |
|---|