Permalink
Browse files

EyeTunes addPlaylistWithName

  • Loading branch information...
1 parent 11bc378 commit 557c4133b4fdd82b50e6591b0a9e9a1895032954 Kaspars committed Mar 7, 2011
Showing with 77 additions and 4 deletions.
  1. +2 −0 ETEyeTunes.h
  2. +56 −0 ETEyeTunes.m
  3. +12 −4 EyeTunes.xcodeproj/project.pbxproj
  4. +7 −0 main.m
View
@@ -109,6 +109,8 @@
- (id)addTrack:(NSURL *)fromLocation toPlaylist:(ETPlaylist *)playlist;
+- (ETPlaylist*)addPlaylistWithName:(NSString*)name;
+
// TODO: - (id)convertTrack:(id)trackReference;
// TODO: - (void)refresh:(id)fileTrack;
// TODO: - (void)update:(id)iPod;
View
@@ -785,4 +785,60 @@ - (BOOL) versionLessThan:(unsigned int)version
return !!(currentVersion < version);
}
+- (ETPlaylist*)addPlaylistWithName:(NSString*)name
+{
+ OSErr err;
+ AppleEvent getEvent, replyEvent;
+ AEDescList replyObject;
+ ETPlaylist* playlist;
+ NSString *gizmo = [NSString stringWithFormat:@"kocl:type('cPly'), prdt: {pnam:'utxt'(\"%@\")}", name];
+
+ AEBuildError buildError;
+ err = AEBuildAppleEvent(kAECoreSuite, // class
+ kAECreateElement, // ID
+ typeApplSignature, // address type
+ &targetApplCode, // address data
+ sizeof(targetApplCode), // address length
+ kAutoGenerateReturnID, // return ID
+ kAnyTransactionID, //transaction ID
+ &getEvent, // result
+ &buildError, // error
+ [gizmo UTF8String]);
+
+ if (err != noErr) {
+ ETLog(@"Error creating Apple Event: %d", err);
+ return nil;
+ }
+
+ err = AESendMessage(&getEvent, &replyEvent, kAEWaitReply + kAENeverInteract, kAEDefaultTimeout);
+ if (err != noErr) {
+ ETLog(@"Error sending AppleEvent: %d", err);
+ goto cleanup_get_event;
+ }
+
+ err = AEGetParamDesc(&replyEvent, keyDirectObject, typeWildCard, &replyObject);
+ if (err != noErr) {
+ ETLog(@"Error extracting from reply event: %d", err);
+ goto cleanup_reply_event;
+ }
+
+ {
+ Handle d;
+ AEPrintDescToHandle(&replyObject, &d);
+ CFStringRef s = CFStringCreateWithFormat(NULL,NULL,CFSTR("%s"),*d);
+ CFShow(s);
+ if (s) CFRelease(s);
+ DisposeHandle(d);
+ }
+
+ playlist = [[[ETPlaylist alloc] initWithDescriptor:&replyObject] autorelease];
+
+cleanup_reply_event:
+ AEDisposeDesc(&replyEvent);
+cleanup_get_event:
+ AEDisposeDesc(&getEvent);
+
+ return playlist;
+}
+
@end
@@ -48,6 +48,10 @@
0396209A0C0DE71600786326 /* NSString+LongLongValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 039620980C0DE71600786326 /* NSString+LongLongValue.m */; };
039620AC0C0DE78200786326 /* EyeTunes.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* EyeTunes.framework */; };
039620C80C0DE7CC00786326 /* EyeTunes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* EyeTunes.framework */; };
+ 638ADA371325160700B02DFB /* ETRootUserPlaylist.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2AB89A0E97A88800178457 /* ETRootUserPlaylist.m */; };
+ 638ADA391325160700B02DFB /* ETUserPlaylistEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = DD233EAB0E66FCC4004B210F /* ETUserPlaylistEnumerator.m */; };
+ 638ADA3D1325160700B02DFB /* ETPlaylistCache.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEBCBB70E8D0DAD00219086 /* ETPlaylistCache.m */; };
+ 638ADA3F1325160700B02DFB /* NSNumber+ETPlaylistNameSorting.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEBCD330E8D245000219086 /* NSNumber+ETPlaylistNameSorting.m */; };
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
DD233EB70E66FD45004B210F /* ETUserPlaylistEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = DD233EAB0E66FCC4004B210F /* ETUserPlaylistEnumerator.m */; };
DD233EB80E66FD45004B210F /* ETUserPlaylistEnumerator.h in Headers */ = {isa = PBXBuildFile; fileRef = DD233EAA0E66FCC4004B210F /* ETUserPlaylistEnumerator.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -423,15 +427,19 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 037310E30C15D98E004AAA53 /* NSString+LongLongValue.m in Sources */,
037310CB0C15D92A004AAA53 /* ETEyeTunes.m in Sources */,
- 031B486908843CF90086F24B /* main.m in Sources */,
035B70BB0885537800D0B89E /* ETTrack.m in Sources */,
032CE8540886594100F33185 /* ETAppleEventObject.m in Sources */,
032CEB730886E48100F33185 /* ETPlaylist.m in Sources */,
032E44AF098A4F2B00C55ECB /* ETTrackEnumerator.m in Sources */,
032E476C098A8FDF00C55ECB /* ETPlaylistEnumerator.m in Sources */,
+ 638ADA371325160700B02DFB /* ETRootUserPlaylist.m in Sources */,
+ 638ADA391325160700B02DFB /* ETUserPlaylistEnumerator.m in Sources */,
030BF9AF098CFFD100D68616 /* ETDebug.m in Sources */,
+ 037310E30C15D98E004AAA53 /* NSString+LongLongValue.m in Sources */,
+ 638ADA3D1325160700B02DFB /* ETPlaylistCache.m in Sources */,
+ 638ADA3F1325160700B02DFB /* NSNumber+ETPlaylistNameSorting.m in Sources */,
+ 031B486908843CF90086F24B /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -571,7 +579,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
- GCC_PREPROCESSOR_DEFINITIONS = "";
+ GCC_PREPROCESSOR_DEFINITIONS = ET_DEBUG;
INSTALL_PATH = /usr/local/bin;
KEEP_PRIVATE_EXTERNS = YES;
OTHER_CFLAGS = "";
@@ -602,7 +610,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
- GCC_PREPROCESSOR_DEFINITIONS = "";
+ GCC_PREPROCESSOR_DEFINITIONS = ET_DEBUG;
INSTALL_PATH = /usr/local/bin;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = (
View
@@ -156,6 +156,12 @@ void rename_chinese_tracks(EyeTunes *e) {
}
}
+void test_create_playlist(EyeTunes *e) {
+ ETPlaylist *playlist = [e addPlaylistWithName:@"test3"];
+ NSLog(@"created playlist %@", [playlist name]);
+}
+
+
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
EyeTunes *e = [EyeTunes sharedInstance];
@@ -171,6 +177,7 @@ int main (int argc, const char * argv[]) {
test_track_persistent_id(e);
//rename_chinese_tracks(e);
+ //test_create_playlist(e);
[pool release];
return 0;

0 comments on commit 557c413

Please sign in to comment.