| 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 |
|
|
#import "XspfTrackList.h" |
| 11 |
|
|
#import "XspfMovieWindowController.h" |
| 12 |
|
|
#import "XspfPlayListWindowController.h" |
| 13 |
|
|
|
| 14 |
|
|
@interface XspfDocument (Private) |
| 15 |
|
|
- (void)setTrackList:(XspfTrackList *)newList; |
| 16 |
|
|
- (XspfTrackList *)trackList; |
| 17 |
|
|
@end |
| 18 |
|
|
|
| 19 |
|
|
@implementation XspfDocument |
| 20 |
|
|
|
| 21 |
|
|
- (id)init |
| 22 |
|
|
{ |
| 23 |
|
|
self = [super init]; |
| 24 |
|
|
if (self) { |
| 25 |
|
|
|
| 26 |
|
|
// Add your subclass-specific initialization here. |
| 27 |
|
|
// If an error occurs here, send a [self release] message and return nil. |
| 28 |
|
|
|
| 29 |
|
|
} |
| 30 |
|
|
return self; |
| 31 |
|
|
} |
| 32 |
|
|
|
| 33 |
|
|
- (void)makeWindowControllers |
| 34 |
|
|
{ |
| 35 |
|
|
playListWindowController = [[XspfPlayListWindowController alloc] init]; |
| 36 |
|
|
[self addWindowController:playListWindowController]; |
| 37 |
|
|
|
| 38 |
masaki |
10 |
id movieWindowController = [[[XspfMovieWindowController alloc] init] autorelease]; |
| 39 |
masaki |
2 |
[self addWindowController:movieWindowController]; |
| 40 |
|
|
[movieWindowController setQtMovie:[[self trackList] qtMovie]]; |
| 41 |
|
|
} |
| 42 |
|
|
//- (NSString *)windowNibName |
| 43 |
|
|
//{ |
| 44 |
|
|
// // Override returning the nib file name of the document |
| 45 |
|
|
// // 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. |
| 46 |
|
|
// return @"MyDocument"; |
| 47 |
|
|
//} |
| 48 |
|
|
|
| 49 |
|
|
- (void)windowControllerDidLoadNib:(NSWindowController *)windowController |
| 50 |
|
|
{ |
| 51 |
|
|
[super windowControllerDidLoadNib:windowController]; |
| 52 |
|
|
// Add any code here that needs to be executed once the windowController has loaded the document's window. |
| 53 |
|
|
// [self setQtMovie:[[self trackList] qtMovie]]; |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
|
|
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError |
| 57 |
|
|
{ |
| 58 |
|
|
// 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. |
| 59 |
|
|
|
| 60 |
|
|
// You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead. |
| 61 |
|
|
|
| 62 |
|
|
// 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. |
| 63 |
|
|
|
| 64 |
|
|
if ( outError != NULL ) { |
| 65 |
|
|
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; |
| 66 |
|
|
} |
| 67 |
|
|
return nil; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError |
| 71 |
|
|
{ |
| 72 |
|
|
// 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. |
| 73 |
|
|
|
| 74 |
|
|
// You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead. |
| 75 |
|
|
|
| 76 |
|
|
// 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. |
| 77 |
|
|
|
| 78 |
|
|
NSError *error = nil; |
| 79 |
masaki |
10 |
NSXMLDocument *d = [[[NSXMLDocument alloc] initWithData:data |
| 80 |
|
|
options:0 |
| 81 |
|
|
error:&error] autorelease]; |
| 82 |
masaki |
2 |
NSXMLElement *root = [d rootElement]; |
| 83 |
|
|
|
| 84 |
|
|
NSArray *trackListElems; |
| 85 |
masaki |
14 |
trackListElems = [root elementsForName:@"trackList"]; |
| 86 |
|
|
if(!trackListElems || [trackListElems count] < 1) { |
| 87 |
masaki |
2 |
if ( outError != NULL ) { |
| 88 |
|
|
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; |
| 89 |
|
|
} |
| 90 |
|
|
return NO; |
| 91 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
|
id t = [XspfTrackList xspfComponemtWithXMLElement:[trackListElems objectAtIndex:0]]; |
| 94 |
|
|
[t setTitle:[[[self fileURL] path] lastPathComponent]]; |
| 95 |
|
|
[self setTrackList:t]; |
| 96 |
|
|
// NSLog(@"trackList -> %@", trackList); |
| 97 |
|
|
|
| 98 |
|
|
// [self setQtMovie:[[self trackList] qtMovie]]; |
| 99 |
|
|
|
| 100 |
|
|
return YES; |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
- (void)dealloc |
| 104 |
|
|
{ |
| 105 |
|
|
[trackList release]; |
| 106 |
|
|
[playListWindowController release]; |
| 107 |
|
|
|
| 108 |
|
|
[super dealloc]; |
| 109 |
|
|
} |
| 110 |
|
|
- (NSString *)displayName |
| 111 |
|
|
{ |
| 112 |
|
|
NSString *trackTitle = [[[self trackList] currentTrack] title]; |
| 113 |
|
|
if(trackTitle) { |
| 114 |
|
|
return [NSString stringWithFormat:@"%@ - %@", |
| 115 |
|
|
[super displayName], trackTitle]; |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
return [super displayName]; |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
- (IBAction)showPlayList:(id)sender |
| 122 |
|
|
{ |
| 123 |
|
|
[playListWindowController showWindow:self]; |
| 124 |
|
|
} |
| 125 |
|
|
|
| 126 |
|
|
- (void)setTrackList:(XspfTrackList *)newList |
| 127 |
|
|
{ |
| 128 |
|
|
if(trackList == newList) return; |
| 129 |
|
|
|
| 130 |
|
|
[trackList autorelease]; |
| 131 |
|
|
trackList = [newList retain]; |
| 132 |
|
|
} |
| 133 |
|
|
- (XspfTrackList *)trackList |
| 134 |
|
|
{ |
| 135 |
|
|
return trackList; |
| 136 |
|
|
} |
| 137 |
|
|
|
| 138 |
|
|
- (void)setPlayTrackindex:(unsigned)index |
| 139 |
|
|
{ |
| 140 |
|
|
[[self trackList] setCurrentIndex:index]; |
| 141 |
|
|
} |
| 142 |
|
|
@end |
| 143 |
|
|
|