Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfQT/XspfQTDocument.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33 - (hide annotations) (download)
Sun Sep 7 02:12:43 2008 UTC (15 years, 7 months ago) by masaki
Original Path: XspfQT/XspfDocument.m
File size: 5463 byte(s)
保存可能にした。
1 masaki 2 //
2     // MyDocument.m
3     // XspfQT
4     //
5     // Created by Hori,Masaki on 08/08/29.
6     // Copyright masakih 2008 . All rights reserved.
7     //
8    
9     #import "XspfDocument.h"
10 masaki 29 #import "XspfComponent.h"
11 masaki 2 #import "XspfMovieWindowController.h"
12     #import "XspfPlayListWindowController.h"
13    
14     @interface XspfDocument (Private)
15 masaki 29 - (void)setTrackList:(XspfComponent *)newList;
16     - (XspfComponent *)trackList;
17 masaki 31 - (NSXMLDocument *)XMLDocument;
18     - (NSData *)outputData;
19 masaki 2 @end
20    
21     @implementation XspfDocument
22    
23     - (id)init
24     {
25     self = [super init];
26     if (self) {
27    
28     // Add your subclass-specific initialization here.
29     // If an error occurs here, send a [self release] message and return nil.
30    
31     }
32     return self;
33     }
34    
35     - (void)makeWindowControllers
36     {
37     playListWindowController = [[XspfPlayListWindowController alloc] init];
38     [self addWindowController:playListWindowController];
39    
40 masaki 33 movieWindowController = [[XspfMovieWindowController alloc] init];
41 masaki 2 [self addWindowController:movieWindowController];
42     [movieWindowController setQtMovie:[[self trackList] qtMovie]];
43     }
44     //- (NSString *)windowNibName
45     //{
46     // // Override returning the nib file name of the document
47     // // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
48     // return @"MyDocument";
49     //}
50    
51     - (void)windowControllerDidLoadNib:(NSWindowController *)windowController
52     {
53     [super windowControllerDidLoadNib:windowController];
54     // Add any code here that needs to be executed once the windowController has loaded the document's window.
55     // [self setQtMovie:[[self trackList] qtMovie]];
56     }
57    
58     - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
59     {
60     // Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
61    
62     // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
63    
64     // For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
65 masaki 31
66     return [self outputData];
67     //
68     //
69     //
70    
71 masaki 2 if ( outError != NULL ) {
72     *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
73     }
74     return nil;
75     }
76    
77     - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
78     {
79     // Insert code here to read your document from the given data of the specified type. If the given outError != NULL, ensure that you set *outError when returning NO.
80    
81     // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
82    
83     // For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.
84    
85     NSError *error = nil;
86 masaki 10 NSXMLDocument *d = [[[NSXMLDocument alloc] initWithData:data
87     options:0
88     error:&error] autorelease];
89 masaki 2 NSXMLElement *root = [d rootElement];
90    
91     NSArray *trackListElems;
92 masaki 14 trackListElems = [root elementsForName:@"trackList"];
93     if(!trackListElems || [trackListElems count] < 1) {
94 masaki 2 if ( outError != NULL ) {
95     *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
96     }
97     return NO;
98     }
99    
100 masaki 29 id t = [XspfComponent xspfComponemtWithXMLElement:[trackListElems objectAtIndex:0]];
101 masaki 2 [t setTitle:[[[self fileURL] path] lastPathComponent]];
102     [self setTrackList:t];
103     // NSLog(@"trackList -> %@", trackList);
104    
105     // [self setQtMovie:[[self trackList] qtMovie]];
106    
107     return YES;
108     }
109    
110     - (void)dealloc
111     {
112     [trackList release];
113     [playListWindowController release];
114    
115     [super dealloc];
116     }
117     - (NSString *)displayName
118     {
119     NSString *trackTitle = [[[self trackList] currentTrack] title];
120     if(trackTitle) {
121     return [NSString stringWithFormat:@"%@ - %@",
122     [super displayName], trackTitle];
123     }
124    
125     return [super displayName];
126     }
127 masaki 33 - (IBAction)togglePlayAndPause:(id)sender
128     {
129     [movieWindowController togglePlayAndPause:sender];
130     }
131 masaki 2 - (IBAction)showPlayList:(id)sender
132     {
133     [playListWindowController showWindow:self];
134     }
135    
136 masaki 29 - (void)setTrackList:(XspfComponent *)newList
137 masaki 2 {
138     if(trackList == newList) return;
139    
140     [trackList autorelease];
141     trackList = [newList retain];
142     }
143 masaki 29 - (XspfComponent *)trackList
144 masaki 2 {
145     return trackList;
146     }
147    
148     - (void)setPlayTrackindex:(unsigned)index
149     {
150 masaki 29 [[self trackList] setSelectionIndex:index];
151 masaki 2 }
152 masaki 31
153     - (NSData *)outputData
154     {
155     return [[self XMLDocument] XMLDataWithOptions:NSXMLNodePrettyPrint];
156     }
157     - (NSXMLDocument *)XMLDocument;
158     {
159     id element = [[self trackList] XMLElement];
160    
161     id root = [NSXMLElement elementWithName:@"playlist"];
162     [root addChild:element];
163     [root addAttribute:[NSXMLNode attributeWithName:@"version"
164     stringValue:@"0"]];
165     [root addAttribute:[NSXMLNode attributeWithName:@"xmlns"
166     stringValue:@"http://xspf.org/ns/0/"]];
167    
168    
169     id d = [[[NSXMLDocument alloc] initWithRootElement:root] autorelease];
170     [d setVersion:@"1.0"];
171     [d setCharacterEncoding:@"UTF-8"];
172    
173     return d;
174     }
175     - (IBAction)dump:(id)sender
176     {
177     NSString *s = [[[NSString alloc] initWithData:[self outputData]
178     encoding:NSUTF8StringEncoding] autorelease];
179    
180     NSLog(@"%@", s);
181     }
182 masaki 2 @end
183    

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