Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfQT/XspfQTInformationWindowController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 161 - (hide annotations) (download)
Tue Mar 3 14:47:03 2009 UTC (15 years, 1 month ago) by masaki
File size: 4515 byte(s)
KVCの依存関係を利用し簡略化。
不要なNotificationのオブザーブを削除。

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 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     - (id)currentTrack
138     {
139     id doc = [[NSDocumentController sharedDocumentController] currentDocument];
140     if(!doc) return nil;
141     [self addObservingDocument:doc];
142 masaki 63
143     return [doc valueForKeyPath:@"trackList.currentTrack"];
144     }
145     - (id)movieAttributes
146     {
147     id doc = [[NSDocumentController sharedDocumentController] currentDocument];
148     if(!doc) return nil;
149 masaki 136 [self addObservingDocument:doc];
150 masaki 63
151     return [doc valueForKeyPath:@"trackList.qtMovie.movieAttributes"];
152     }
153 masaki 149
154     - (id)trackAttributesByType:(NSString *)type
155 masaki 136 {
156     id doc = [[NSDocumentController sharedDocumentController] currentDocument];
157     if(!doc) return nil;
158     [self addObservingDocument:doc];
159    
160 masaki 149 id movie = [doc valueForKeyPath:XspfDocumentQtMovieKeyPath];
161     NSArray *tracks = [movie tracksOfMediaType:type];
162     if(!tracks || [tracks count] == 0) return nil;
163 masaki 136
164 masaki 149 return [[tracks objectAtIndex:0] trackAttributes];
165 masaki 136 }
166 masaki 149 - (id)soundTrackAttributes
167     {
168     return [self trackAttributesByType:QTMediaTypeSound];
169     }
170 masaki 136 - (id)videoTrackAttributes
171     {
172 masaki 149 return [self trackAttributesByType:QTMediaTypeVideo];
173 masaki 136 }
174    
175 masaki 63 - (void)observeValueForKeyPath:(NSString *)keyPath
176     ofObject:(id)object
177     change:(NSDictionary *)change
178     context:(void *)context
179     {
180 masaki 149 if([keyPath isEqualToString:XspfDocumentQtMovieKeyPath]) {
181 masaki 110 [self notify];
182 masaki 63 }
183     }
184    
185     - (void)xspfDocumentWillCloseNotification:(id)notification
186     {
187     id doc = [notification object];
188    
189 masaki 110 if(![observedDocs containsObject:doc]) return;
190    
191 masaki 149 [doc removeObserver:self forKeyPath:XspfDocumentQtMovieKeyPath];
192 masaki 63 [observedDocs removeObject:doc];
193     [docController setContent:nil];
194 masaki 110 [currentTrackController setContent:nil];
195    
196     [self notify];
197 masaki 63 }
198     - (void)notifee:(id)notification
199     {
200 masaki 110 [self notify];
201 masaki 63 }
202    
203     @end

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