Develop and Download Open Source Software

Browse Subversion Repository

Contents of /XspfManager/XspfMXspfObject.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 563 - (show annotations) (download)
Sat Mar 12 12:44:23 2011 UTC (13 years ago) by masakih
File size: 8120 byte(s)
[Fix] urlStringを復活。CoreDataでrequireだった。
1 //
2 // XspfMXspfObject.m
3 // XspfManager
4 //
5 // Created by Hori,Masaki on 09/11/01.
6 //
7
8 /*
9 This source code is release under the New BSD License.
10 Copyright (c) 2009-2010, masakih
11 All rights reserved.
12
13 ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に
14 限り、再頒布および使用が許可されます。
15
16 1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含
17 めること。
18 2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表
19 示、本条件一覧、および下記免責条項を含めること。
20 3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、
21 コントリビューターの名前を使用してはならない。
22 本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、
23 明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証
24 も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター
25 も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか
26 厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する
27 可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用
28 サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定
29 されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい
30 て、一切責任を負わないものとします。
31 -------------------------------------------------------------------
32 Copyright (c) 2009-2010, masakih
33 All rights reserved.
34
35 Redistribution and use in source and binary forms, with or without
36 modification, are permitted provided that the following conditions
37 are met:
38
39 1, Redistributions of source code must retain the above copyright
40 notice, this list of conditions and the following disclaimer.
41 2, Redistributions in binary form must reproduce the above copyright
42 notice, this list of conditions and the following disclaimer in
43 the documentation and/or other materials provided with the
44 distribution.
45 3, The names of its contributors may be used to endorse or promote
46 products derived from this software without specific prior
47 written permission.
48 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
51 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
52 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53 INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
56 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 POSSIBILITY OF SUCH DAMAGE.
60 */
61
62 #import "XspfMXspfObject.h"
63 #import "XspfMThumbnailData.h"
64
65 #import "XspfManager.h"
66 #import "XspfMCheckFileModifiedRequest.h"
67 #import "XspfMMovieLoadRequest.h"
68 #import "XspfLoadThumbnailRequest.h"
69
70 #import "NSPathUtilities-HMExtensions.h"
71 #import "NSURL-HMExtensions.h"
72
73 @interface XspfMXspfObject()
74 @property (retain) NSString * urlString;
75
76
77 @property (nonatomic, retain) NSData *primitiveAlias;
78 @property (nonatomic, retain) NSString *primitiveTitle;
79 @property (nonatomic, retain) NSDate *primitiveModificationDate;
80 @property (nonatomic, retain) NSImage *primitiveThumbnail;
81 @property (nonatomic, retain) NSNumber *primitiveDeleted;
82 @end
83
84 @implementation XspfMXspfObject
85
86 @dynamic registerDate;
87 @dynamic thumbnailData;
88 @dynamic urlString;
89 @dynamic modificationDate;
90 @dynamic lastPlayDate;
91 @dynamic movieNum;
92 @dynamic creationDate;
93 @dynamic alias;
94 @dynamic label;
95 @dynamic title;
96
97 @dynamic primitiveAlias;
98 @dynamic primitiveTitle;
99 @dynamic primitiveModificationDate;
100 @dynamic primitiveThumbnail;
101 @dynamic primitiveDeleted;
102
103
104 + (NSSet *)keyPathsForValuesAffectingAlias
105 {
106 return [NSSet setWithObjects:@"url", @"filePath", nil];
107 }
108
109 - (void)awakeFromFetch
110 {
111 [super awakeFromFetch];
112
113 id<HMChannel> channel = [[NSApp delegate] channel];
114 id<HMRequest> request = [XspfMCheckFileModifiedRequest requestWithObject:self];
115 [channel putRequest:request];
116 }
117
118 - (void)awakeFromInsert
119 {
120 id info = [NSEntityDescription insertNewObjectForEntityForName:@"Info"
121 inManagedObjectContext:[self managedObjectContext]];
122 [self setValue:info forKey:@"information"];
123 id thumbnailData = [NSEntityDescription insertNewObjectForEntityForName:@"ThumbnailData"
124 inManagedObjectContext:[self managedObjectContext]];
125 [self setValue:thumbnailData forKey:@"thumbnailData"];
126 }
127
128 - (NSURL *)url
129 {
130 NSString *path = self.filePath;
131 if(!path) return nil;
132 return [NSURL fileURLWithPath:path];
133 }
134 - (void)setUrl:(NSURL *)aURL
135 {
136 NSURL *curURL = self.url;
137 if(curURL && [curURL isEqualUsingLocalhost:aURL]) return;
138
139 self.alias = [[aURL path] aliasData];
140 self.urlString = [aURL absoluteString];
141 }
142
143 - (BOOL)deleted
144 {
145 [self willAccessValueForKey:@"deleted"];
146 NSNumber *deleted = self.primitiveDeleted;
147 [self didAccessValueForKey:@"deleted"];
148
149 return [deleted boolValue];
150 }
151 - (void)setDeleted:(BOOL)flag
152 {
153 NSNumber *deleted = [NSNumber numberWithBool:flag];
154 [self willChangeValueForKey:@"deleted"];
155 self.primitiveDeleted = deleted;
156 [self didChangeValueForKey:@"deleted"];
157 }
158
159 - (NSImage *)thumbnail
160 {
161 [self willAccessValueForKey:@"thumbnail"];
162 NSImage *thumbnail = self.primitiveThumbnail;
163 [self didAccessValueForKey:@"thumbnail"];
164
165 if(!thumbnail && !didPutLoadRequest) {
166 didPutLoadRequest = YES;
167 id<HMChannel> channel = [[NSApp delegate] channel];
168 id<HMRequest> request = [XspfLoadThumbnailRequest requestWithObject:self];
169 [channel putRequest:request];
170 }
171
172 return thumbnail;
173 }
174 - (void)setThumbnail:(NSImage *)aThumbnail
175 {
176 [self willAccessValueForKey:@"thumbnail"];
177 NSImage *thumbnail = self.primitiveThumbnail;
178 [self didAccessValueForKey:@"thumbnail"];
179 if([aThumbnail isEqual:thumbnail]) return;
180
181 [self willChangeValueForKey:@"thumbnail"];
182 self.primitiveThumbnail = aThumbnail;
183 [self didChangeValueForKey:@"thumbnail"];
184 self.thumbnailData.data = [aThumbnail TIFFRepresentation];
185 }
186
187 - (void)setModificationDate:(NSDate *)newDate
188 {
189 [self willAccessValueForKey:@"modificationDate"];
190 NSDate *oldDate = self.primitiveModificationDate;
191 [self didAccessValueForKey:@"modificationDate"];
192
193 // 更新日時に変更があれば、ファイル内容を確認し直す。
194 if(NSOrderedSame != [newDate compare:oldDate]) {
195 id<HMChannel> channel = [[NSApp delegate] channel];
196 id<HMRequest> request = [XspfMMovieLoadRequest requestWithObject:self];
197 [channel putRequest:request];
198 }
199
200 [self willChangeValueForKey:@"modificationDate"];
201 self.primitiveModificationDate = newDate;
202 [self didChangeValueForKey:@"modificationDate"];
203 }
204
205 - (NSString *)title
206 {
207 [self willAccessValueForKey:@"title"];
208 NSString *title = self.primitiveTitle;
209 [self didAccessValueForKey:@"title"];
210
211 if(title == nil || [title isEqualToString:@""]) {
212 NSString *aTitle = self.filePath;
213 aTitle = [aTitle lastPathComponent];
214 aTitle = [aTitle stringByDeletingPathExtension];
215 aTitle = [aTitle stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
216 if(aTitle) {
217 self.primitiveTitle = aTitle;
218 title = aTitle;
219 }
220 }
221
222 return title;
223 }
224 - (NSString *)filePath
225 {
226 return [self.alias resolvedPath];
227 }
228 @end

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