Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfQT/XspfQTInformationWindowController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 171 - (hide annotations) (download)
Thu Mar 12 13:45:22 2009 UTC (15 years, 1 month ago) by masaki
File size: 4382 byte(s)
XspfQTComponentでQTMovieを扱うのをやめ、XspfQTDocument が管理するようにした。
それに伴い、様々な変更。
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 171 static NSString *const XspfDocumentQtMovieKeyPath = @"playingMovie";
14 masaki 149
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 158 + (NSSet *)keyPathsForValuesAffectingMovieAttributes
73     {
74     return [NSSet setWithObject:@"currentTrack"];
75     }
76     + (NSSet *)keyPathsForValuesAffectingSoundTrackAttributes
77     {
78     return [NSSet setWithObject:@"currentTrack"];
79     }
80     + (NSSet *)keyPathsForValuesAffectingVideoTrackAttributes
81     {
82     return [NSSet setWithObject:@"currentTrack"];
83     }
84 masaki 110 - (void)notify
85     {
86     [self willChangeValueForKey:@"currentTrack"];
87 masaki 133 [self performSelector:@selector(didChangeValueForKey:)
88     withObject:@"currentTrack"
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    
109 masaki 63 [nc addObserver:self
110     selector:@selector(xspfDocumentWillCloseNotification:)
111 masaki 72 name:XspfQTDocumentWillCloseNotification
112 masaki 63 object:nil];
113    
114     }
115     - (void)dealloc
116     {
117     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
118     [nc removeObserver:self];
119    
120     [observedDocs release];
121    
122     [super dealloc];
123     }
124    
125 masaki 136 - (void)addObservingDocument:(id)doc
126 masaki 63 {
127 masaki 136 if(!doc) return;
128 masaki 63
129     if(![observedDocs containsObject:doc]) {
130     [doc addObserver:self
131 masaki 149 forKeyPath:XspfDocumentQtMovieKeyPath
132 masaki 63 options:0
133     context:NULL];
134     [observedDocs addObject:doc];
135     }
136 masaki 136 }
137 masaki 171 - (id)currentDocument
138 masaki 136 {
139     id doc = [[NSDocumentController sharedDocumentController] currentDocument];
140     if(!doc) return nil;
141     [self addObservingDocument:doc];
142 masaki 63
143 masaki 171 return doc;
144     }
145     - (id)currentTrack
146     {
147     id doc = [self currentDocument];
148    
149 masaki 63 return [doc valueForKeyPath:@"trackList.currentTrack"];
150     }
151     - (id)movieAttributes
152     {
153 masaki 171 id doc = [self currentDocument];
154 masaki 63
155 masaki 171 return [doc valueForKeyPath:@"playingMovie.movieAttributes"];
156 masaki 63 }
157 masaki 149
158     - (id)trackAttributesByType:(NSString *)type
159 masaki 136 {
160 masaki 171 id doc = [self currentDocument];
161 masaki 136
162 masaki 149 id movie = [doc valueForKeyPath:XspfDocumentQtMovieKeyPath];
163     NSArray *tracks = [movie tracksOfMediaType:type];
164     if(!tracks || [tracks count] == 0) return nil;
165 masaki 136
166 masaki 149 return [[tracks objectAtIndex:0] trackAttributes];
167 masaki 136 }
168 masaki 149 - (id)soundTrackAttributes
169     {
170     return [self trackAttributesByType:QTMediaTypeSound];
171     }
172 masaki 136 - (id)videoTrackAttributes
173     {
174 masaki 149 return [self trackAttributesByType:QTMediaTypeVideo];
175 masaki 136 }
176    
177 masaki 63 - (void)observeValueForKeyPath:(NSString *)keyPath
178     ofObject:(id)object
179     change:(NSDictionary *)change
180     context:(void *)context
181     {
182 masaki 149 if([keyPath isEqualToString:XspfDocumentQtMovieKeyPath]) {
183 masaki 110 [self notify];
184 masaki 63 }
185     }
186    
187     - (void)xspfDocumentWillCloseNotification:(id)notification
188     {
189     id doc = [notification object];
190    
191 masaki 110 if(![observedDocs containsObject:doc]) return;
192    
193 masaki 149 [doc removeObserver:self forKeyPath:XspfDocumentQtMovieKeyPath];
194 masaki 63 [observedDocs removeObject:doc];
195     [docController setContent:nil];
196 masaki 110 [currentTrackController setContent:nil];
197    
198     [self notify];
199 masaki 63 }
200     - (void)notifee:(id)notification
201     {
202 masaki 110 [self notify];
203 masaki 63 }
204    
205     @end

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