Drop from iTunes support, thanks to Aaron VonderHaar

CQTexperiment
vspader 2007-02-17 15:58:39 +00:00
parent dfe73fd554
commit eb47e318f3
4 changed files with 48 additions and 5 deletions

View File

@ -1,3 +1,7 @@
0.06
----
Drag from iTunes support. (Aaron VonderHaar)
0.05
----
Wavpack length should be reported correctly.

View File

@ -2,6 +2,7 @@
#import <Cocoa/Cocoa.h>
extern NSString *MovedRowsType;
extern NSString *iTunesDropType;
@interface DNDArrayController : NSArrayController
{

View File

@ -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];

View File

@ -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];