From eb47e318f357bdb5c105f785de8643d653b93d8c Mon Sep 17 00:00:00 2001 From: vspader Date: Sat, 17 Feb 2007 15:58:39 +0000 Subject: [PATCH] Drop from iTunes support, thanks to Aaron VonderHaar --- Changelog | 4 ++++ Playlist/DNDArrayController.h | 1 + Playlist/DNDArrayController.m | 7 +++++- Playlist/PlaylistController.m | 41 +++++++++++++++++++++++++++++++---- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 53b8be3b0..4927ee291 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +0.06 +---- +Drag from iTunes support. (Aaron VonderHaar) + 0.05 ---- Wavpack length should be reported correctly. diff --git a/Playlist/DNDArrayController.h b/Playlist/DNDArrayController.h index 93cbaa8b8..98eafba8a 100755 --- a/Playlist/DNDArrayController.h +++ b/Playlist/DNDArrayController.h @@ -2,6 +2,7 @@ #import extern NSString *MovedRowsType; +extern NSString *iTunesDropType; @interface DNDArrayController : NSArrayController { diff --git a/Playlist/DNDArrayController.m b/Playlist/DNDArrayController.m index 55f2d826c..e8c0576a8 100755 --- a/Playlist/DNDArrayController.m +++ b/Playlist/DNDArrayController.m @@ -5,12 +5,17 @@ NSString *MovedRowsType = @"MOVED_ROWS_TYPE"; +// @"CorePasteboardFlavorType 0x6974756E" is the "itun" type representing an iTunes plist +NSString *iTunesDropType = @"CorePasteboardFlavorType 0x6974756E"; - (void)awakeFromNib { // register for drag and drop NSLog(@"AWOKE"); - [tableView registerForDraggedTypes:[NSArray arrayWithObjects:MovedRowsType, NSFilenamesPboardType, nil]]; + + [tableView registerForDraggedTypes:[NSArray arrayWithObjects:MovedRowsType, NSFilenamesPboardType, + iTunesDropType, nil]]; + // [tableView setVerticalMotionCanBeginDrag:YES]; // [tableView setAllowsMultipleSelection:NO]; // [super awakeFromNib]; diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 01b02a0ba..52b9d02de 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -229,11 +229,44 @@ if (row < 0) row = 0; + + // Determine the type of object that was dropped + NSArray *supportedtypes = [NSArray arrayWithObjects:NSFilenamesPboardType, iTunesDropType, nil]; + NSPasteboard *pboard = [info draggingPasteboard]; + NSString *bestType = [pboard availableTypeFromArray:supportedtypes]; + + // Get files from a normal file drop (such as from Finder) + if ([bestType isEqualToString:NSFilenamesPboardType]) { + NSArray *files = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType]; + + NSLog(@"INSERTING PATHS: %@", files); + [self insertPaths:files atIndex:row sort:YES]; + } + + // Get files from an iTunes drop + if ([bestType isEqualToString:iTunesDropType]) { + NSDictionary *iTunesDict = [pboard propertyListForType:iTunesDropType]; + NSDictionary *tracks = [iTunesDict valueForKey:@"Tracks"]; - NSArray *files = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType]; - NSLog(@"INSERTING PATHS: %@", files); - [self insertPaths:files atIndex:row sort:YES]; - + // Convert the iTunes URLs to filenames + NSMutableArray *files = [[NSMutableArray alloc] init]; + NSEnumerator *e = [[tracks allValues] objectEnumerator]; + NSDictionary *trackInfo; + NSURL *url; + while (trackInfo = [e nextObject]) { + url = [[NSURL alloc] initWithString:[trackInfo valueForKey:@"Location"]]; + if ([url isFileURL]) { + [files addObject:[url path]]; + } + + [url release]; + } + + NSLog(@"INSERTING ITUNES PATHS: %@", files); + [self insertPaths:files atIndex:row sort:YES]; + [files release]; + } + NSLog(@"UPDATING"); [self updateIndexesFromRow:row]; [self updateTotalTime];