| 1 |
masaki |
2 |
// |
| 2 |
masaki |
72 |
// XspfQTAppDelegate.m |
| 3 |
masaki |
2 |
// XspfQT |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 08/08/31. |
| 6 |
|
|
// |
| 7 |
|
|
|
| 8 |
masakih |
312 |
/* |
| 9 |
masakih |
316 |
This source code is release under the New BSD License. |
| 10 |
masakih |
312 |
Copyright (c) 2008-2010, masakih |
| 11 |
|
|
All rights reserved. |
| 12 |
|
|
|
| 13 |
masakih |
316 |
ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に |
| 14 |
|
|
限り、再頒布および使用が許可されます。 |
| 15 |
|
|
|
| 16 |
|
|
1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含 |
| 17 |
|
|
めること。 |
| 18 |
|
|
2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表 |
| 19 |
|
|
示、本条件一覧、および下記免責条項を含めること。 |
| 20 |
|
|
3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、 |
| 21 |
|
|
コントリビューターの名前を使用してはならない。 |
| 22 |
|
|
本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、 |
| 23 |
|
|
明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証 |
| 24 |
|
|
も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター |
| 25 |
|
|
も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか |
| 26 |
|
|
厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する |
| 27 |
|
|
可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用 |
| 28 |
|
|
サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定 |
| 29 |
|
|
されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい |
| 30 |
|
|
て、一切責任を負わないものとします。 |
| 31 |
masakih |
312 |
------------------------------------------------------------------- |
| 32 |
|
|
Copyright (c) 2008-2010, masakih |
| 33 |
|
|
All rights reserved. |
| 34 |
|
|
|
| 35 |
masakih |
316 |
Redistribution and use in source and binary forms, with or without |
| 36 |
|
|
modification, are permitted provided that the following conditions |
| 37 |
|
|
are met: |
| 38 |
masakih |
312 |
|
| 39 |
masakih |
316 |
1, Redistributions of source code must retain the above copyright |
| 40 |
|
|
notice, this list of conditions and the following disclaimer. |
| 41 |
|
|
2, Redistributions in binary form must reproduce the above copyright |
| 42 |
|
|
notice, this list of conditions and the following disclaimer in |
| 43 |
|
|
the documentation and/or other materials provided with the |
| 44 |
|
|
distribution. |
| 45 |
|
|
3, The names of its contributors may be used to endorse or promote |
| 46 |
|
|
products derived from this software without specific prior |
| 47 |
|
|
written permission. |
| 48 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 49 |
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 50 |
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 51 |
|
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 52 |
|
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 53 |
|
|
INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 54 |
|
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 55 |
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 56 |
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 57 |
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 58 |
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 59 |
|
|
POSSIBILITY OF SUCH DAMAGE. |
| 60 |
masakih |
312 |
*/ |
| 61 |
|
|
|
| 62 |
masaki |
72 |
#import "XspfQTAppDelegate.h" |
| 63 |
masaki |
205 |
|
| 64 |
|
|
#import "XspfQTPreference.h" |
| 65 |
masaki |
72 |
#import "XspfQTValueTransformers.h" |
| 66 |
masaki |
63 |
#import "XspfQTInformationWindowController.h" |
| 67 |
masaki |
184 |
#import "XspfQTPreferenceWindowController.h" |
| 68 |
masaki |
2 |
|
| 69 |
masaki |
201 |
|
| 70 |
masakih |
322 |
#import "AppleRemote.h" |
| 71 |
|
|
#import "MultiClickRemoteBehavior.h" |
| 72 |
|
|
|
| 73 |
|
|
|
| 74 |
masaki |
72 |
@implementation XspfQTAppDelegate |
| 75 |
masakih |
322 |
@synthesize remoteControl; |
| 76 |
masaki |
2 |
|
| 77 |
masakih |
322 |
|
| 78 |
masaki |
2 |
+ (void)initialize |
| 79 |
|
|
{ |
| 80 |
masaki |
205 |
[XspfQTPreference sharedInstance]; |
| 81 |
masaki |
2 |
} |
| 82 |
|
|
|
| 83 |
masaki |
50 |
- (void)awakeFromNib |
| 84 |
|
|
{ |
| 85 |
masakih |
322 |
self.remoteControl = [[[AppleRemote alloc] initWithDelegate: self] autorelease]; |
| 86 |
|
|
|
| 87 |
|
|
remoteBehavior = [MultiClickRemoteBehavior new]; |
| 88 |
|
|
[remoteBehavior setDelegate:self]; |
| 89 |
|
|
[remoteControl setDelegate:remoteBehavior]; |
| 90 |
|
|
|
| 91 |
masaki |
50 |
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 92 |
|
|
[nc addObserver:self |
| 93 |
|
|
selector:@selector(windowDidBecomeMain:) |
| 94 |
|
|
name:NSWindowDidBecomeMainNotification |
| 95 |
|
|
object:nil]; |
| 96 |
|
|
[nc addObserver:self |
| 97 |
|
|
selector:@selector(windowWillClose:) |
| 98 |
|
|
name:NSWindowWillCloseNotification |
| 99 |
|
|
object:nil]; |
| 100 |
|
|
} |
| 101 |
|
|
- (void)dealloc |
| 102 |
|
|
{ |
| 103 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 104 |
|
|
[nc removeObserver:self]; |
| 105 |
|
|
|
| 106 |
masakih |
322 |
self.remoteControl = nil; |
| 107 |
|
|
[remoteBehavior autorelease]; |
| 108 |
|
|
|
| 109 |
masaki |
50 |
[super dealloc]; |
| 110 |
|
|
} |
| 111 |
masaki |
204 |
|
| 112 |
masaki |
50 |
#pragma mark ### Actions ### |
| 113 |
|
|
- (IBAction)playedTrack:(id)sender |
| 114 |
|
|
{ |
| 115 |
|
|
// do noting. |
| 116 |
|
|
} |
| 117 |
masaki |
63 |
- (IBAction)openInformationPanel:(id)sender |
| 118 |
|
|
{ |
| 119 |
|
|
XspfQTInformationWindowController *wc; |
| 120 |
|
|
wc = [XspfQTInformationWindowController sharedInstance]; |
| 121 |
|
|
[wc showWindow:sender]; |
| 122 |
|
|
} |
| 123 |
masaki |
184 |
- (IBAction)showPreferenceWindow:(id)sender |
| 124 |
|
|
{ |
| 125 |
|
|
XspfQTPreferenceWindowController *pw; |
| 126 |
|
|
pw = [XspfQTPreferenceWindowController sharedInstance]; |
| 127 |
|
|
[pw showWindow:self]; |
| 128 |
|
|
} |
| 129 |
masaki |
63 |
- (IBAction)togglePlayAndPause:(id)sender |
| 130 |
|
|
{ |
| 131 |
masakih |
310 |
id windowController = [mainWindowStore windowController]; |
| 132 |
|
|
if(![windowController respondsToSelector:@selector(togglePlayAndPause:)]) return; |
| 133 |
|
|
[windowController togglePlayAndPause:sender]; |
| 134 |
masaki |
63 |
} |
| 135 |
|
|
- (IBAction)nextTrack:(id)sender |
| 136 |
|
|
{ |
| 137 |
masakih |
310 |
id windowController = [mainWindowStore windowController]; |
| 138 |
|
|
if(![windowController respondsToSelector:@selector(nextTrack:)]) return; |
| 139 |
masaki |
63 |
[[mainWindowStore windowController] nextTrack:sender]; |
| 140 |
|
|
} |
| 141 |
|
|
- (IBAction)previousTrack:(id)sender |
| 142 |
|
|
{ |
| 143 |
masakih |
310 |
id windowController = [mainWindowStore windowController]; |
| 144 |
|
|
if(![windowController respondsToSelector:@selector(previousTrack:)]) return; |
| 145 |
masaki |
63 |
[[mainWindowStore windowController] previousTrack:sender]; |
| 146 |
|
|
} |
| 147 |
masaki |
50 |
|
| 148 |
|
|
#pragma mark ### NSMenu valivation ### |
| 149 |
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem |
| 150 |
|
|
{ |
| 151 |
masakih |
310 |
id windowController = [mainWindowStore windowController]; |
| 152 |
|
|
if([menuItem action] == @selector(togglePlayAndPause:)) { |
| 153 |
|
|
if(![windowController respondsToSelector:@selector(togglePlayAndPause:)]) return NO; |
| 154 |
masaki |
63 |
} |
| 155 |
masakih |
310 |
if([menuItem action] == @selector(nextTrack:)) { |
| 156 |
|
|
if(![windowController respondsToSelector:@selector(nextTrack:)]) return NO; |
| 157 |
masaki |
184 |
} |
| 158 |
masakih |
310 |
if([menuItem action] == @selector(previousTrack:)) { |
| 159 |
|
|
if(![windowController respondsToSelector:@selector(previousTrack:)]) return NO; |
| 160 |
|
|
} |
| 161 |
masaki |
63 |
|
| 162 |
masaki |
50 |
if([menuItem tag] == 10000) { |
| 163 |
|
|
NSWindow *m = mainWindowStore; |
| 164 |
|
|
if(!m) { |
| 165 |
|
|
m = [NSApp mainWindow]; |
| 166 |
|
|
} |
| 167 |
|
|
NSString *title = [m valueForKeyPath:@"windowController.document.trackList.currentTrack.title"]; |
| 168 |
|
|
if(title) { |
| 169 |
|
|
[menuItem setTitle:[NSString stringWithFormat:@"%@ played", title]]; |
| 170 |
|
|
} else { |
| 171 |
|
|
[menuItem setTitle:@"Played Track Title"]; |
| 172 |
|
|
} |
| 173 |
|
|
return NO; |
| 174 |
|
|
} |
| 175 |
|
|
if(!mainWindowStore) { |
| 176 |
|
|
return NO; |
| 177 |
|
|
} |
| 178 |
|
|
|
| 179 |
|
|
return YES; |
| 180 |
|
|
} |
| 181 |
|
|
|
| 182 |
masaki |
2 |
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender |
| 183 |
|
|
{ |
| 184 |
|
|
return NO; |
| 185 |
|
|
} |
| 186 |
|
|
|
| 187 |
masaki |
50 |
- (void)storeMainWindow |
| 188 |
|
|
{ |
| 189 |
|
|
mainWindowStore = [NSApp mainWindow]; |
| 190 |
|
|
} |
| 191 |
|
|
- (void)unsaveMainWindow |
| 192 |
|
|
{ |
| 193 |
|
|
mainWindowStore = nil; |
| 194 |
|
|
} |
| 195 |
|
|
- (void)applicationWillHide:(NSNotification *)notification |
| 196 |
|
|
{ |
| 197 |
|
|
[self storeMainWindow]; |
| 198 |
|
|
} |
| 199 |
|
|
- (void)applicationWillResignActive:(NSNotification *)notification |
| 200 |
|
|
{ |
| 201 |
|
|
[self storeMainWindow]; |
| 202 |
masakih |
322 |
[remoteControl stopListening:self]; |
| 203 |
masaki |
50 |
} |
| 204 |
masakih |
322 |
- (void)applicationWillBecomeActive:(NSNotification *)aNotification |
| 205 |
|
|
{ |
| 206 |
|
|
[remoteControl startListening:self]; |
| 207 |
|
|
} |
| 208 |
masaki |
50 |
- (void)applicationDidUnhide:(NSNotification *)notification |
| 209 |
|
|
{ |
| 210 |
|
|
[self unsaveMainWindow]; |
| 211 |
|
|
} |
| 212 |
|
|
- (void)applicationDidBecomeActive:(NSNotification *)notification |
| 213 |
|
|
{ |
| 214 |
|
|
[self unsaveMainWindow]; |
| 215 |
|
|
} |
| 216 |
|
|
|
| 217 |
|
|
- (void)windowDidBecomeMain:(NSNotification *)notification |
| 218 |
|
|
{ |
| 219 |
|
|
[self storeMainWindow]; |
| 220 |
|
|
} |
| 221 |
|
|
- (void)windowWillClose:(NSNotification *)notification |
| 222 |
|
|
{ |
| 223 |
|
|
[self unsaveMainWindow]; |
| 224 |
|
|
} |
| 225 |
|
|
|
| 226 |
masakih |
322 |
|
| 227 |
|
|
#pragma mark- |
| 228 |
|
|
#pragma mark#### Apple Remote Control Wrapper #### |
| 229 |
|
|
- (void)remoteButton:(RemoteControlEventIdentifier)identifier pressedDown:(BOOL)pressedDown clickCount:(unsigned int)clickCount |
| 230 |
|
|
{ |
| 231 |
|
|
|
| 232 |
|
|
SEL action = NULL; |
| 233 |
|
|
|
| 234 |
|
|
switch(identifier) { |
| 235 |
|
|
case kRemoteButtonPlus: |
| 236 |
|
|
if(pressedDown) |
| 237 |
|
|
action = @selector(turnUpVolume:); |
| 238 |
|
|
break; |
| 239 |
|
|
case kRemoteButtonMinus: |
| 240 |
|
|
if(pressedDown) |
| 241 |
|
|
action = @selector(turnDownVolume:); |
| 242 |
|
|
break; |
| 243 |
|
|
case kRemoteButtonMenu: |
| 244 |
|
|
if(pressedDown) |
| 245 |
|
|
action = @selector(toggleFullScreenMode:); |
| 246 |
|
|
break; |
| 247 |
|
|
case kRemoteButtonPlay: |
| 248 |
|
|
if(pressedDown) |
| 249 |
|
|
action = @selector(togglePlayAndPause:); |
| 250 |
|
|
break; |
| 251 |
|
|
case kRemoteButtonRight: |
| 252 |
|
|
if(pressedDown) |
| 253 |
|
|
action = @selector(nextTrack:); |
| 254 |
|
|
break; |
| 255 |
|
|
case kRemoteButtonLeft: |
| 256 |
|
|
if(pressedDown) |
| 257 |
|
|
action = @selector(previousTrack:); |
| 258 |
|
|
break; |
| 259 |
|
|
case kRemoteButtonRight_Hold: |
| 260 |
|
|
action = NULL; |
| 261 |
|
|
break; |
| 262 |
|
|
case kRemoteButtonLeft_Hold: |
| 263 |
|
|
action = NULL; |
| 264 |
|
|
break; |
| 265 |
|
|
case kRemoteButtonPlus_Hold: |
| 266 |
|
|
action = NULL; |
| 267 |
|
|
break; |
| 268 |
|
|
case kRemoteButtonMinus_Hold: |
| 269 |
|
|
action = NULL; |
| 270 |
|
|
break; |
| 271 |
|
|
case kRemoteButtonPlay_Hold: |
| 272 |
|
|
action = NULL; |
| 273 |
|
|
break; |
| 274 |
|
|
case kRemoteButtonMenu_Hold: |
| 275 |
|
|
action = @selector(showHidePlayList:); |
| 276 |
|
|
break; |
| 277 |
|
|
case kRemoteControl_Switched: |
| 278 |
|
|
action = NULL; |
| 279 |
|
|
break; |
| 280 |
|
|
default: |
| 281 |
|
|
NSLog(@"Unmapped event for button %d", identifier); |
| 282 |
|
|
break; |
| 283 |
|
|
} |
| 284 |
|
|
|
| 285 |
|
|
if(!action) return; |
| 286 |
|
|
|
| 287 |
|
|
[NSApp sendAction:action to:nil from:self]; |
| 288 |
|
|
} |
| 289 |
masaki |
2 |
@end |