Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfQT/XspfQTInformationWindowController.m

Parent Directory Parent Directory | Revision Log Revision Log


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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26