| 1 |
masaki |
2 |
// |
| 2 |
masaki |
72 |
// XspfQTAppDelegate.m |
| 3 |
masaki |
2 |
// XspfQT |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 08/08/31. |
| 6 |
|
|
// Copyright 2008 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
masaki |
72 |
#import "XspfQTAppDelegate.h" |
| 10 |
masaki |
205 |
|
| 11 |
|
|
#import "XspfQTPreference.h" |
| 12 |
masaki |
72 |
#import "XspfQTValueTransformers.h" |
| 13 |
masaki |
63 |
#import "XspfQTInformationWindowController.h" |
| 14 |
masaki |
184 |
#import "XspfQTPreferenceWindowController.h" |
| 15 |
masaki |
2 |
|
| 16 |
masaki |
201 |
|
| 17 |
masaki |
72 |
@implementation XspfQTAppDelegate |
| 18 |
masaki |
2 |
|
| 19 |
|
|
+ (void)initialize |
| 20 |
|
|
{ |
| 21 |
|
|
[NSValueTransformer setValueTransformer:[[[XspfQTTimeTransformer alloc] init] autorelease] |
| 22 |
|
|
forName:@"XspfQTTimeTransformer"]; |
| 23 |
|
|
[NSValueTransformer setValueTransformer:[[[XspfQTTimeDateTransformer alloc] init] autorelease] |
| 24 |
|
|
forName:@"XspfQTTimeDateTransformer"]; |
| 25 |
masaki |
133 |
[NSValueTransformer setValueTransformer:[[[XspfQTSizeToStringTransformer alloc] init] autorelease] |
| 26 |
|
|
forName:@"XspfQTSizeToStringTransformer"]; |
| 27 |
masaki |
137 |
[NSValueTransformer setValueTransformer:[[[XspfQTFileSizeStringTransformer alloc] init] autorelease] |
| 28 |
|
|
forName:@"XspfQTFileSizeStringTransformer"]; |
| 29 |
masaki |
205 |
|
| 30 |
|
|
[XspfQTPreference sharedInstance]; |
| 31 |
masaki |
2 |
} |
| 32 |
|
|
|
| 33 |
masaki |
50 |
- (void)awakeFromNib |
| 34 |
|
|
{ |
| 35 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 36 |
|
|
[nc addObserver:self |
| 37 |
|
|
selector:@selector(windowDidBecomeMain:) |
| 38 |
|
|
name:NSWindowDidBecomeMainNotification |
| 39 |
|
|
object:nil]; |
| 40 |
|
|
[nc addObserver:self |
| 41 |
|
|
selector:@selector(windowWillClose:) |
| 42 |
|
|
name:NSWindowWillCloseNotification |
| 43 |
|
|
object:nil]; |
| 44 |
|
|
} |
| 45 |
|
|
- (void)dealloc |
| 46 |
|
|
{ |
| 47 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 48 |
|
|
[nc removeObserver:self]; |
| 49 |
|
|
|
| 50 |
|
|
[super dealloc]; |
| 51 |
|
|
} |
| 52 |
masaki |
204 |
|
| 53 |
masaki |
50 |
#pragma mark ### Actions ### |
| 54 |
|
|
- (IBAction)playedTrack:(id)sender |
| 55 |
|
|
{ |
| 56 |
|
|
// do noting. |
| 57 |
|
|
} |
| 58 |
masaki |
63 |
- (IBAction)openInformationPanel:(id)sender |
| 59 |
|
|
{ |
| 60 |
|
|
XspfQTInformationWindowController *wc; |
| 61 |
|
|
wc = [XspfQTInformationWindowController sharedInstance]; |
| 62 |
|
|
[wc showWindow:sender]; |
| 63 |
|
|
} |
| 64 |
masaki |
184 |
- (IBAction)showPreferenceWindow:(id)sender |
| 65 |
|
|
{ |
| 66 |
|
|
XspfQTPreferenceWindowController *pw; |
| 67 |
|
|
pw = [XspfQTPreferenceWindowController sharedInstance]; |
| 68 |
|
|
[pw showWindow:self]; |
| 69 |
|
|
} |
| 70 |
masaki |
63 |
- (IBAction)togglePlayAndPause:(id)sender |
| 71 |
|
|
{ |
| 72 |
|
|
[[mainWindowStore windowController] togglePlayAndPause:sender]; |
| 73 |
|
|
} |
| 74 |
|
|
- (IBAction)nextTrack:(id)sender |
| 75 |
|
|
{ |
| 76 |
|
|
[[mainWindowStore windowController] nextTrack:sender]; |
| 77 |
|
|
} |
| 78 |
|
|
- (IBAction)previousTrack:(id)sender |
| 79 |
|
|
{ |
| 80 |
|
|
[[mainWindowStore windowController] previousTrack:sender]; |
| 81 |
|
|
} |
| 82 |
masaki |
50 |
|
| 83 |
|
|
#pragma mark ### NSMenu valivation ### |
| 84 |
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem |
| 85 |
|
|
{ |
| 86 |
masaki |
63 |
if([menuItem action] == @selector(openInformationPanel:)) { |
| 87 |
|
|
return YES; |
| 88 |
|
|
} |
| 89 |
masaki |
184 |
if([menuItem action] == @selector(showPreferenceWindow:)) { |
| 90 |
|
|
return YES; |
| 91 |
|
|
} |
| 92 |
masaki |
63 |
|
| 93 |
masaki |
50 |
if([menuItem tag] == 10000) { |
| 94 |
|
|
NSWindow *m = mainWindowStore; |
| 95 |
|
|
if(!m) { |
| 96 |
|
|
m = [NSApp mainWindow]; |
| 97 |
|
|
} |
| 98 |
|
|
NSString *title = [m valueForKeyPath:@"windowController.document.trackList.currentTrack.title"]; |
| 99 |
|
|
if(title) { |
| 100 |
|
|
[menuItem setTitle:[NSString stringWithFormat:@"%@ played", title]]; |
| 101 |
|
|
} else { |
| 102 |
|
|
[menuItem setTitle:@"Played Track Title"]; |
| 103 |
|
|
} |
| 104 |
|
|
return NO; |
| 105 |
|
|
} |
| 106 |
|
|
if(!mainWindowStore) { |
| 107 |
|
|
return NO; |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
return YES; |
| 111 |
|
|
} |
| 112 |
|
|
|
| 113 |
masaki |
2 |
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender |
| 114 |
|
|
{ |
| 115 |
|
|
return NO; |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
masaki |
50 |
- (void)storeMainWindow |
| 119 |
|
|
{ |
| 120 |
|
|
mainWindowStore = [NSApp mainWindow]; |
| 121 |
|
|
} |
| 122 |
|
|
- (void)unsaveMainWindow |
| 123 |
|
|
{ |
| 124 |
|
|
mainWindowStore = nil; |
| 125 |
|
|
} |
| 126 |
|
|
- (void)applicationWillHide:(NSNotification *)notification |
| 127 |
|
|
{ |
| 128 |
|
|
[self storeMainWindow]; |
| 129 |
|
|
} |
| 130 |
|
|
- (void)applicationWillResignActive:(NSNotification *)notification |
| 131 |
|
|
{ |
| 132 |
|
|
[self storeMainWindow]; |
| 133 |
|
|
} |
| 134 |
|
|
- (void)applicationDidUnhide:(NSNotification *)notification |
| 135 |
|
|
{ |
| 136 |
|
|
[self unsaveMainWindow]; |
| 137 |
|
|
} |
| 138 |
|
|
- (void)applicationDidBecomeActive:(NSNotification *)notification |
| 139 |
|
|
{ |
| 140 |
|
|
[self unsaveMainWindow]; |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
- (void)windowDidBecomeMain:(NSNotification *)notification |
| 144 |
|
|
{ |
| 145 |
|
|
[self storeMainWindow]; |
| 146 |
|
|
} |
| 147 |
|
|
- (void)windowWillClose:(NSNotification *)notification |
| 148 |
|
|
{ |
| 149 |
|
|
[self unsaveMainWindow]; |
| 150 |
|
|
} |
| 151 |
|
|
|
| 152 |
masaki |
2 |
@end |