| 1 |
// |
| 2 |
// XspfQTAppDelegate.m |
| 3 |
// XspfQT |
| 4 |
// |
| 5 |
// Created by Hori,Masaki on 08/08/31. |
| 6 |
// |
| 7 |
|
| 8 |
/* |
| 9 |
This source code is release under the New BSD License. |
| 10 |
Copyright (c) 2008-2010, masakih |
| 11 |
All rights reserved. |
| 12 |
|
| 13 |
ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に |
| 14 |
限り、再頒布および使用が許可されます。 |
| 15 |
|
| 16 |
1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含 |
| 17 |
めること。 |
| 18 |
2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表 |
| 19 |
示、本条件一覧、および下記免責条項を含めること。 |
| 20 |
3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、 |
| 21 |
コントリビューターの名前を使用してはならない。 |
| 22 |
本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、 |
| 23 |
明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証 |
| 24 |
も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター |
| 25 |
も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか |
| 26 |
厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する |
| 27 |
可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用 |
| 28 |
サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定 |
| 29 |
されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい |
| 30 |
て、一切責任を負わないものとします。 |
| 31 |
------------------------------------------------------------------- |
| 32 |
Copyright (c) 2008-2010, masakih |
| 33 |
All rights reserved. |
| 34 |
|
| 35 |
Redistribution and use in source and binary forms, with or without |
| 36 |
modification, are permitted provided that the following conditions |
| 37 |
are met: |
| 38 |
|
| 39 |
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 |
*/ |
| 61 |
|
| 62 |
#import "XspfQTAppDelegate.h" |
| 63 |
|
| 64 |
#import "XspfQTPreference.h" |
| 65 |
#import "XspfQTValueTransformers.h" |
| 66 |
#import "XspfQTInformationWindowController.h" |
| 67 |
#import "XspfQTPreferenceWindowController.h" |
| 68 |
|
| 69 |
|
| 70 |
#import "XspfMAppleRemoteSupport.h" |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
@implementation XspfQTAppDelegate |
| 75 |
|
| 76 |
+ (void)initialize |
| 77 |
{ |
| 78 |
[XspfQTPreference sharedInstance]; |
| 79 |
} |
| 80 |
|
| 81 |
- (void)awakeFromNib |
| 82 |
{ |
| 83 |
appleRemoteSupprt = [[XspfMAppleRemoteSupport alloc] init]; |
| 84 |
|
| 85 |
|
| 86 |
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 87 |
[nc addObserver:self |
| 88 |
selector:@selector(windowDidBecomeMain:) |
| 89 |
name:NSWindowDidBecomeMainNotification |
| 90 |
object:nil]; |
| 91 |
[nc addObserver:self |
| 92 |
selector:@selector(windowWillClose:) |
| 93 |
name:NSWindowWillCloseNotification |
| 94 |
object:nil]; |
| 95 |
} |
| 96 |
- (void)dealloc |
| 97 |
{ |
| 98 |
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 99 |
[nc removeObserver:self]; |
| 100 |
|
| 101 |
[appleRemoteSupprt release]; |
| 102 |
|
| 103 |
[super dealloc]; |
| 104 |
} |
| 105 |
|
| 106 |
#pragma mark ### Actions ### |
| 107 |
- (IBAction)playedTrack:(id)sender |
| 108 |
{ |
| 109 |
// do noting. |
| 110 |
} |
| 111 |
- (IBAction)openInformationPanel:(id)sender |
| 112 |
{ |
| 113 |
XspfQTInformationWindowController *wc; |
| 114 |
wc = [XspfQTInformationWindowController sharedInstance]; |
| 115 |
[wc showWindow:sender]; |
| 116 |
} |
| 117 |
- (IBAction)showPreferenceWindow:(id)sender |
| 118 |
{ |
| 119 |
XspfQTPreferenceWindowController *pw; |
| 120 |
pw = [XspfQTPreferenceWindowController sharedInstance]; |
| 121 |
[pw showWindow:self]; |
| 122 |
} |
| 123 |
- (IBAction)togglePlayAndPause:(id)sender |
| 124 |
{ |
| 125 |
id windowController = [mainWindowStore windowController]; |
| 126 |
if(![windowController respondsToSelector:@selector(togglePlayAndPause:)]) return; |
| 127 |
[windowController togglePlayAndPause:sender]; |
| 128 |
} |
| 129 |
- (IBAction)nextTrack:(id)sender |
| 130 |
{ |
| 131 |
id windowController = [mainWindowStore windowController]; |
| 132 |
if(![windowController respondsToSelector:@selector(nextTrack:)]) return; |
| 133 |
[[mainWindowStore windowController] nextTrack:sender]; |
| 134 |
} |
| 135 |
- (IBAction)previousTrack:(id)sender |
| 136 |
{ |
| 137 |
id windowController = [mainWindowStore windowController]; |
| 138 |
if(![windowController respondsToSelector:@selector(previousTrack:)]) return; |
| 139 |
[[mainWindowStore windowController] previousTrack:sender]; |
| 140 |
} |
| 141 |
|
| 142 |
#pragma mark ### NSMenu valivation ### |
| 143 |
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem |
| 144 |
{ |
| 145 |
SEL action = [menuItem action]; |
| 146 |
|
| 147 |
id windowController = [mainWindowStore windowController]; |
| 148 |
if(action == @selector(togglePlayAndPause:)) { |
| 149 |
if(![windowController respondsToSelector:@selector(togglePlayAndPause:)]) return NO; |
| 150 |
} |
| 151 |
if(action == @selector(nextTrack:)) { |
| 152 |
if(![windowController respondsToSelector:@selector(nextTrack:)]) return NO; |
| 153 |
} |
| 154 |
if(action == @selector(previousTrack:)) { |
| 155 |
if(![windowController respondsToSelector:@selector(previousTrack:)]) return NO; |
| 156 |
} |
| 157 |
if(action == @selector(showPreferenceWindow:)) return YES; |
| 158 |
|
| 159 |
if([menuItem tag] == 10000) { |
| 160 |
NSWindow *m = mainWindowStore; |
| 161 |
if(!m) { |
| 162 |
m = [NSApp mainWindow]; |
| 163 |
} |
| 164 |
NSString *title = [m valueForKeyPath:@"windowController.document.trackList.currentTrack.title"]; |
| 165 |
if(title) { |
| 166 |
[menuItem setTitle:[NSString stringWithFormat:@"%@ played", title]]; |
| 167 |
} else { |
| 168 |
[menuItem setTitle:@"Played Track Title"]; |
| 169 |
} |
| 170 |
return NO; |
| 171 |
} |
| 172 |
if(!mainWindowStore) { |
| 173 |
return NO; |
| 174 |
} |
| 175 |
|
| 176 |
return YES; |
| 177 |
} |
| 178 |
|
| 179 |
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender |
| 180 |
{ |
| 181 |
return NO; |
| 182 |
} |
| 183 |
|
| 184 |
- (void)storeMainWindow |
| 185 |
{ |
| 186 |
mainWindowStore = [NSApp mainWindow]; |
| 187 |
} |
| 188 |
- (void)unsaveMainWindow |
| 189 |
{ |
| 190 |
mainWindowStore = nil; |
| 191 |
} |
| 192 |
- (void)applicationWillHide:(NSNotification *)notification |
| 193 |
{ |
| 194 |
[self storeMainWindow]; |
| 195 |
} |
| 196 |
- (void)applicationWillResignActive:(NSNotification *)notification |
| 197 |
{ |
| 198 |
[self storeMainWindow]; |
| 199 |
} |
| 200 |
- (void)applicationDidUnhide:(NSNotification *)notification |
| 201 |
{ |
| 202 |
[self unsaveMainWindow]; |
| 203 |
} |
| 204 |
- (void)applicationDidBecomeActive:(NSNotification *)notification |
| 205 |
{ |
| 206 |
[self unsaveMainWindow]; |
| 207 |
} |
| 208 |
|
| 209 |
- (void)windowDidBecomeMain:(NSNotification *)notification |
| 210 |
{ |
| 211 |
[self storeMainWindow]; |
| 212 |
} |
| 213 |
- (void)windowWillClose:(NSNotification *)notification |
| 214 |
{ |
| 215 |
[self unsaveMainWindow]; |
| 216 |
} |
| 217 |
|
| 218 |
@end |