| 1 |
masaki |
63 |
// |
| 2 |
|
|
// XspfQTInformationWindowController.m |
| 3 |
|
|
// XspfQT |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 08/09/14. |
| 6 |
|
|
// Copyright 2008 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfQTInformationWindowController.h" |
| 10 |
masaki |
72 |
#import "XspfQTDocument.h" |
| 11 |
masaki |
63 |
|
| 12 |
|
|
|
| 13 |
masaki |
149 |
static NSString *const XspfDocumentQtMovieKeyPath = @"trackList.qtMovie"; |
| 14 |
|
|
|
| 15 |
masaki |
63 |
@implementation XspfQTInformationWindowController |
| 16 |
|
|
static XspfQTInformationWindowController *sharedInstance = nil; |
| 17 |
|
|
|
| 18 |
|
|
+ (XspfQTInformationWindowController *)sharedInstance |
| 19 |
|
|
{ |
| 20 |
|
|
@synchronized(self) { |
| 21 |
|
|
if (sharedInstance == nil) { |
| 22 |
|
|
[[self alloc] init]; // assignment not done here |
| 23 |
|
|
} |
| 24 |
|
|
} |
| 25 |
|
|
return sharedInstance; |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
|
+ (id)allocWithZone:(NSZone *)zone |
| 29 |
|
|
{ |
| 30 |
|
|
@synchronized(self) { |
| 31 |
|
|
if (sharedInstance == nil) { |
| 32 |
|
|
sharedInstance = [super allocWithZone:zone]; |
| 33 |
|
|
return sharedInstance; // assignment and return on first allocation |
| 34 |
|
|
} |
| 35 |
|
|
} |
| 36 |
|
|
return nil; //on subsequent allocation attempts return nil |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
|
- (id)copyWithZone:(NSZone *)zone |
| 40 |
|
|
{ |
| 41 |
|
|
return self; |
| 42 |
|
|
} |
| 43 |
|
|
|
| 44 |
|
|
- (id)retain |
| 45 |
|
|
{ |
| 46 |
|
|
return self; |
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
|
- (unsigned)retainCount |
| 50 |
|
|
{ |
| 51 |
|
|
return UINT_MAX; //denotes an object that cannot be released |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
|
- (void)release |
| 55 |
|
|
{ |
| 56 |
|
|
//do nothing |
| 57 |
|
|
} |
| 58 |
|
|
|
| 59 |
|
|
- (id)autorelease |
| 60 |
|
|
{ |
| 61 |
|
|
return self; |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
|
#pragma mark- |
| 65 |
|
|
- (id)init |
| 66 |
|
|
{ |
| 67 |
|
|
[super initWithWindowNibName:@"XspfQTImformation"]; |
| 68 |
|
|
observedDocs = [[NSMutableArray array] retain]; |
| 69 |
|
|
return self; |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
masaki |
110 |
- (void)notify |
| 73 |
|
|
{ |
| 74 |
|
|
[self willChangeValueForKey:@"movieAttributes"]; |
| 75 |
masaki |
133 |
[self performSelector:@selector(didChangeValueForKey:) |
| 76 |
|
|
withObject:@"movieAttributes" |
| 77 |
|
|
afterDelay:0.0]; |
| 78 |
masaki |
110 |
[self willChangeValueForKey:@"currentTrack"]; |
| 79 |
masaki |
133 |
[self performSelector:@selector(didChangeValueForKey:) |
| 80 |
|
|
withObject:@"currentTrack" |
| 81 |
|
|
afterDelay:0.0]; |
| 82 |
masaki |
136 |
[self willChangeValueForKey:@"soundTrackAttributes"]; |
| 83 |
|
|
[self performSelector:@selector(didChangeValueForKey:) |
| 84 |
|
|
withObject:@"soundTrackAttributes" |
| 85 |
|
|
afterDelay:0.0]; |
| 86 |
|
|
[self willChangeValueForKey:@"videoTrackAttributes"]; |
| 87 |
|
|
[self performSelector:@selector(didChangeValueForKey:) |
| 88 |
|
|
withObject:@"videoTrackAttributes" |
| 89 |
|
|
afterDelay:0.0]; |
| 90 |
masaki |
110 |
} |
| 91 |
|
|
|
| 92 |
masaki |
63 |
- (void)windowDidLoad |
| 93 |
|
|
{ |
| 94 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 95 |
|
|
[nc addObserver:self |
| 96 |
|
|
selector:@selector(notifee:) |
| 97 |
|
|
name:NSWindowDidBecomeMainNotification |
| 98 |
|
|
object:nil]; |
| 99 |
|
|
[nc addObserver:self |
| 100 |
|
|
selector:@selector(notifee:) |
| 101 |
|
|
name:NSWindowDidResignMainNotification |
| 102 |
|
|
object:nil]; |
| 103 |
|
|
[nc addObserver:self |
| 104 |
|
|
selector:@selector(notifee:) |
| 105 |
masaki |
133 |
name:NSWindowDidResizeNotification |
| 106 |
|
|
object:nil]; |
| 107 |
|
|
|
| 108 |
masaki |
149 |
// [nc addObserver:self |
| 109 |
|
|
// selector:@selector(notifee:) |
| 110 |
|
|
// name:NSApplicationDidBecomeActiveNotification |
| 111 |
|
|
// object:NSApp]; |
| 112 |
|
|
// [nc addObserver:self |
| 113 |
|
|
// selector:@selector(notifee:) |
| 114 |
|
|
// name:NSApplicationDidHideNotification |
| 115 |
|
|
// object:NSApp]; |
| 116 |
masaki |
133 |
|
| 117 |
masaki |
63 |
[nc addObserver:self |
| 118 |
|
|
selector:@selector(xspfDocumentWillCloseNotification:) |
| 119 |
masaki |
72 |
name:XspfQTDocumentWillCloseNotification |
| 120 |
masaki |
63 |
object:nil]; |
| 121 |
|
|
|
| 122 |
|
|
} |
| 123 |
|
|
- (void)dealloc |
| 124 |
|
|
{ |
| 125 |
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
| 126 |
|
|
[nc removeObserver:self]; |
| 127 |
|
|
|
| 128 |
|
|
[observedDocs release]; |
| 129 |
|
|
|
| 130 |
|
|
[super dealloc]; |
| 131 |
|
|
} |
| 132 |
|
|
|
| 133 |
masaki |
136 |
- (void)addObservingDocument:(id)doc |
| 134 |
masaki |
63 |
{ |
| 135 |
masaki |
136 |
if(!doc) return; |
| 136 |
masaki |
63 |
|
| 137 |
|
|
if(![observedDocs containsObject:doc]) { |
| 138 |
|
|
[doc addObserver:self |
| 139 |
masaki |
149 |
forKeyPath:XspfDocumentQtMovieKeyPath |
| 140 |
masaki |
63 |
options:0 |
| 141 |
|
|
context:NULL]; |
| 142 |
|
|
[observedDocs addObject:doc]; |
| 143 |
|
|
} |
| 144 |
masaki |
136 |
} |
| 145 |
|
|
- (id)currentTrack |
| 146 |
|
|
{ |
| 147 |
|
|
id doc = [[NSDocumentController sharedDocumentController] currentDocument]; |
| 148 |
|
|
if(!doc) return nil; |
| 149 |
|
|
[self addObservingDocument:doc]; |
| 150 |
masaki |
63 |
|
| 151 |
|
|
return [doc valueForKeyPath:@"trackList.currentTrack"]; |
| 152 |
|
|
} |
| 153 |
|
|
- (id)movieAttributes |
| 154 |
|
|
{ |
| 155 |
|
|
id doc = [[NSDocumentController sharedDocumentController] currentDocument]; |
| 156 |
|
|
if(!doc) return nil; |
| 157 |
masaki |
136 |
[self addObservingDocument:doc]; |
| 158 |
masaki |
63 |
|
| 159 |
|
|
return [doc valueForKeyPath:@"trackList.qtMovie.movieAttributes"]; |
| 160 |
|
|
} |
| 161 |
masaki |
149 |
|
| 162 |
|
|
- (id)trackAttributesByType:(NSString *)type |
| 163 |
masaki |
136 |
{ |
| 164 |
|
|
id doc = [[NSDocumentController sharedDocumentController] currentDocument]; |
| 165 |
|
|
if(!doc) return nil; |
| 166 |
|
|
[self addObservingDocument:doc]; |
| 167 |
|
|
|
| 168 |
masaki |
149 |
id movie = [doc valueForKeyPath:XspfDocumentQtMovieKeyPath]; |
| 169 |
|
|
NSArray *tracks = [movie tracksOfMediaType:type]; |
| 170 |
|
|
if(!tracks || [tracks count] == 0) return nil; |
| 171 |
masaki |
136 |
|
| 172 |
masaki |
149 |
return [[tracks objectAtIndex:0] trackAttributes]; |
| 173 |
masaki |
136 |
} |
| 174 |
masaki |
149 |
- (id)soundTrackAttributes |
| 175 |
|
|
{ |
| 176 |
|
|
return [self trackAttributesByType:QTMediaTypeSound]; |
| 177 |
|
|
} |
| 178 |
masaki |
136 |
- (id)videoTrackAttributes |
| 179 |
|
|
{ |
| 180 |
masaki |
149 |
return [self trackAttributesByType:QTMediaTypeVideo]; |
| 181 |
masaki |
136 |
} |
| 182 |
|
|
|
| 183 |
masaki |
63 |
- (void)observeValueForKeyPath:(NSString *)keyPath |
| 184 |
|
|
ofObject:(id)object |
| 185 |
|
|
change:(NSDictionary *)change |
| 186 |
|
|
context:(void *)context |
| 187 |
|
|
{ |
| 188 |
masaki |
149 |
if([keyPath isEqualToString:XspfDocumentQtMovieKeyPath]) { |
| 189 |
masaki |
110 |
[self notify]; |
| 190 |
masaki |
63 |
} |
| 191 |
|
|
} |
| 192 |
|
|
|
| 193 |
|
|
- (void)xspfDocumentWillCloseNotification:(id)notification |
| 194 |
|
|
{ |
| 195 |
|
|
id doc = [notification object]; |
| 196 |
|
|
|
| 197 |
masaki |
110 |
if(![observedDocs containsObject:doc]) return; |
| 198 |
|
|
|
| 199 |
masaki |
149 |
[doc removeObserver:self forKeyPath:XspfDocumentQtMovieKeyPath]; |
| 200 |
masaki |
63 |
[observedDocs removeObject:doc]; |
| 201 |
|
|
[docController setContent:nil]; |
| 202 |
masaki |
110 |
[currentTrackController setContent:nil]; |
| 203 |
|
|
|
| 204 |
|
|
[self notify]; |
| 205 |
masaki |
63 |
} |
| 206 |
|
|
- (void)notifee:(id)notification |
| 207 |
|
|
{ |
| 208 |
masaki |
110 |
[self notify]; |
| 209 |
masaki |
63 |
} |
| 210 |
|
|
|
| 211 |
|
|
@end |