Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfQT/XspfQTInformationWindowController.m

Parent Directory Parent Directory | Revision Log Revision Log


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

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