-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMetadataController.m
More file actions
575 lines (492 loc) · 18.9 KB
/
MetadataController.m
File metadata and controls
575 lines (492 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
//
// MetadataController.m
// Geotagalog
//
// Created by Nathan Vander Wilt on 6/4/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "MetadataController.h"
#import "TLPhotoLayer.h"
#import "TLPhotoSource.h"
#import "TLPhotoSourceItem.h"
#import "TLPhoto.h"
#import "TLTrackLayer.h"
#import "TLLocator.h"
#import "TLLocation.h"
#import "TLTimestamp.h"
#import "TLWaypoint.h"
#import "TLCocoaToolbag.h"
#include "TLGeometry.h"
static const TLCoordinateAccuracy allowableInaccuracy = 50.0;
static NSString* const TLMercatalogInternalPhotosPboardType = @"com.calftrail.mercatalog.photo.pboard";
static BOOL TLMercatalogWriteItemsToPasteboard(NSArray* items, NSPasteboard* pboard, id owner);
static NSArray* TLMercatalogItemsFromPasteboard(NSPasteboard* pboard);
static NSArray* TLMercatalogFilesFromPasteboard(NSPasteboard* pboard);
@interface NSObject (TLTrackSourceDefinition)
@property (nonatomic, readonly) NSSet* tracks;
@property (nonatomic, readonly) NSSet* waypoints;
@end
@interface MetadataController ()
@property (nonatomic, retain) TLLocator* locator;
@property (nonatomic, readwrite) BOOL readyForExport;
- (void)updateExportReady;
- (void)relocatePhotos;
- (void)locatePhotos:(NSSet*)photos;
- (BOOL)shouldGeotag:(TLPhotoSourceItem*)item;
- (NSUInteger)countGeotagged;
@end
@implementation MetadataController
@synthesize itemLayer;
@synthesize itemSource;
@synthesize locationLayer;
@synthesize locationSource;
@synthesize cameraError;
@synthesize cameraTimeZone;
@synthesize locator;
@synthesize readyForExport;
- (id)init {
self = [super init];
if (self) {
itemPhotos = [[NSMapTable mapTableWithStrongToStrongObjects] retain];
accurateItems = [NSMutableSet new];
TLLocator* theLocator = [[TLLocator new] autorelease];
[theLocator setDataSource:self];
[self setLocator:theLocator];
[self addObserver:self
forKeyPath:@"itemSource.items"
options:NSKeyValueObservingOptionNew
context:NULL];
[self addObserver:self
forKeyPath:@"itemSource.isCurrent"
options:NSKeyValueObservingOptionNew
context:NULL];
[self addObserver:self
forKeyPath:@"locationSource.tracks"
options:NSKeyValueObservingOptionNew
context:NULL];
[self addObserver:self
forKeyPath:@"locationSource.waypoints"
options:NSKeyValueObservingOptionNew
context:NULL];
[self addObserver:self
forKeyPath:@"cameraError"
options:NSKeyValueObservingOptionNew
context:NULL];
[self addObserver:self
forKeyPath:@"cameraTimeZone"
options:NSKeyValueObservingOptionNew
context:NULL];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self
forKeyPath:@"values.ExportAllItems"
options:NSKeyValueObservingOptionNew
context:NULL];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self
forKeyPath:@"values.LimitInaccurateGeotagging"
options:NSKeyValueObservingOptionNew
context:NULL];
}
return self;
}
- (void)awakeFromNib {
// ...
}
- (void)dealloc {
[self removeObserver:self forKeyPath:@"itemSource.items"];
[self removeObserver:self forKeyPath:@"itemSource.isCurrent"];
[self removeObserver:self forKeyPath:@"locationSource.tracks"];
[self removeObserver:self forKeyPath:@"locationSource.waypoints"];
[self removeObserver:self forKeyPath:@"cameraError"];
[self removeObserver:self forKeyPath:@"cameraTimeZone"];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.ExportAllItems"];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.LimitInaccurateGeotagging"];
[self setItemLayer:nil];
[self setItemSource:nil];
[self setLocationLayer:nil];
[self setLocationSource:nil];
[self setCameraTimeZone:nil];
[itemPhotos release];
[accurateItems release];
[[self locator] setDataSource:nil];
[self setLocator:nil];
[super dealloc];
}
#pragma mark KVO
- (void)observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context
{
(void)object;
(void)context;
//NSLog(@"observed %@: %@", keyPath, change);
BOOL shouldRelocateAll = NO;
BOOL didLocatePhotos = NO;
if ([keyPath isEqualToString:@"itemSource.items"]) {
if ([[change objectForKey:NSKeyValueChangeKindKey]
unsignedIntegerValue] == NSKeyValueChangeInsertion)
{
// we optimize insertion to avoid O(n^2) behaviour during file source load
NSSet* insertedPhotos = [change objectForKey:NSKeyValueChangeNewKey];
[self locatePhotos:insertedPhotos];
didLocatePhotos = YES;
}
else {
[[self itemLayer] setSelectedPhotos:nil];
[[self itemLayer] setDisplayedPhotos:nil];
shouldRelocateAll = YES;
}
}
else if ([keyPath isEqualToString:@"itemSource.isCurrent"] ||
[keyPath isEqualToString:@"values.ExportAllItems"])
{
[self updateExportReady];
}
else if ([keyPath isEqualToString:@"values.LimitInaccurateGeotagging"]) {
didLocatePhotos = YES;
[[self itemLayer] setMarkInaccuratePhotos:[[NSUserDefaults standardUserDefaults]
boolForKey:@"LimitInaccurateGeotagging"]];
}
else if ([keyPath isEqualToString:@"locationSource.tracks"]) {
shouldRelocateAll = YES;
[[self locator] reloadData];
[[self locationLayer] reloadData];
}
else if ([keyPath isEqualToString:@"locationSource.waypoints"]) {
[[self locationLayer] reloadData];
}
else if ([keyPath isEqualToString:@"cameraError"] ||
[keyPath isEqualToString:@"cameraTimeZone"])
{
shouldRelocateAll = YES;
}
if (shouldRelocateAll) {
[self relocatePhotos];
didLocatePhotos = YES;
}
if (didLocatePhotos) {
BOOL inaccurates = [itemPhotos count] > [accurateItems count];
[limitInaccuracyButton setEnabled:(inaccurates ? YES : NO)];
BOOL ungeotaggables = [[[self itemSource] items] count] > [self countGeotagged];
[exportAllButton setEnabled:(ungeotaggables ? YES : NO)];
[self updateExportReady];
}
}
#pragma mark Custom accessors
- (void)setItemLayer:(TLPhotoLayer*)newItemLayer {
if (newItemLayer == itemLayer) return;
[itemLayer setDataSource:nil];
[itemLayer setRegisteredDragTypes:nil];
[itemLayer release];
[newItemLayer setDataSource:self];
[newItemLayer setRegisteredDragTypes:
[NSArray arrayWithObjects:TLMercatalogInternalPhotosPboardType, NSFilenamesPboardType, nil]];
[newItemLayer setAccuracyThreshold:allowableInaccuracy];
[newItemLayer setMarkInaccuratePhotos:[[NSUserDefaults standardUserDefaults]
boolForKey:@"LimitInaccurateGeotagging"]];
itemLayer = [newItemLayer retain];
}
- (TLPhotoLayer*)itemLayer {
if (!itemLayer) {
[self setItemLayer:[[TLPhotoLayer new] autorelease]];
}
return itemLayer;
}
- (void)setLocationLayer:(TLTrackLayer*)newLocationLayer {
if (newLocationLayer == locationLayer) return;
[locationLayer setDataSource:nil];
[locationLayer release];
[newLocationLayer setDataSource:self];
locationLayer = [newLocationLayer retain];
}
- (TLTrackLayer*)locationLayer {
if (!locationLayer) {
[self setLocationLayer:[[TLTrackLayer new] autorelease]];
}
return locationLayer;
}
- (NSUInteger)countGeotagged {
BOOL rejectInaccurateLocations = [[NSUserDefaults standardUserDefaults]
boolForKey:@"LimitInaccurateGeotagging"];
return rejectInaccurateLocations ? [accurateItems count] : [itemPhotos count];
}
- (NSMapTable*)exportMetadata {
NSString* fullAppName = nil;
{
NSDictionary* appInfo = [[NSBundle mainBundle] infoDictionary];
NSString* appName = [appInfo objectForKey:(id)kCFBundleNameKey];
NSString* appVersion = [appInfo objectForKey:@"CFBundleShortVersionString"];
fullAppName = [NSString stringWithFormat:@"%@ v%@", appName, appVersion];
}
bool adjustTimestamps = !([[NSUserDefaults standardUserDefaults] boolForKey:@"DontAdjustTimestamps"]);
bool exportUngeotagged = ([exportAllButton isEnabled] && [exportAllButton intValue]);
bool tagInaccurates = !([[NSUserDefaults standardUserDefaults] boolForKey:@"LimitInaccurateGeotagging"]);
NSMapTable* itemMetadata = [NSMapTable mapTableWithStrongToStrongObjects];
for (TLPhotoSourceItem* item in [[self itemSource] items]) {
TLPhoto* photo = [itemPhotos objectForKey:item];
if (!photo) {
if (exportUngeotagged) [itemMetadata setObject:[NSNull null] forKey:item];
continue;
}
NSMutableDictionary* metadata = [NSMutableDictionary dictionary];
if ([accurateItems containsObject:item] || tagInaccurates) {
[metadata setObject:[photo location] forKey:TLMetadataLocationKey];
}
else if (!exportUngeotagged) {
continue;
}
if (adjustTimestamps) {
[metadata setObject:[photo timestamp] forKey:TLMetadataTimestampKey];
[metadata setObject:[photo timeZone] forKey:TLMetadataTimezoneKey];
}
if ([metadata count]) {
[metadata setObject:fullAppName forKey:TLMetadataSoftwareNameKey];
}
else {
metadata = (id)[NSNull null];
}
[itemMetadata setObject:metadata forKey:item];
}
return itemMetadata;
}
#pragma mark locationLayer/locator data source
- (NSArray*)trackLayer:(TLTrackLayer*)layer
tracksInBounds:(TLBounds)bounds
underProjection:(TLProjectionRef)proj
{
(void)layer;
(void)bounds;
(void)proj;
return [[[self locationSource] tracks] allObjects];
}
- (NSArray*)trackLayer:(TLTrackLayer*)layer
waypointsInBounds:(TLBounds)bounds
underProjection:(TLProjectionRef)proj
{
(void)layer;
(void)bounds;
(void)proj;
return [[[self locationSource] waypoints] allObjects];
}
- (NSSet*)locatorNeedsTracks:(TLLocator*)aLocator {
(void)aLocator;
return [[self locationSource] tracks];
}
#pragma mark itemLayer data source
- (NSArray*)photoLayer:(TLPhotoLayer*)layer
photosInBounds:(TLBounds)bounds
underProjection:(TLProjectionRef)proj
{
(void)layer;
(void)bounds;
(void)proj;
NSMutableArray* photos = [NSMutableArray array];
for (TLPhotoSourceItem* item in itemPhotos) {
TLPhoto* photo = [itemPhotos objectForKey:item];
[photos addObject:photo];
}
return photos;
}
#pragma mark mapLayer delegate methods
- (BOOL)photoLayer:(TLPhotoLayer*)layer
writePhotos:(NSArray*)photos
toPasteboard:(NSPasteboard*)pasteboard
{
(void)layer;
NSArray* items = [photos valueForKeyPath:@"self.item"];
NSAssert([items count] == [photos count], @"Did not properly extract items from dragged photos!");
return TLMercatalogWriteItemsToPasteboard(items, pasteboard, self);
}
- (TLLocation*)locationForMouseInMap:(CGPoint)targetPoint withInfo:(id < TLMapInfo >)mapInfo {
TLProjectionError err = TLProjectionErrorNone;
TLCoordinate mouseCoord = TLProjectionUnprojectPoint([mapInfo projection], targetPoint, &err);
if (err) return nil;
CGSize interactiveSize = [mapInfo significantInteractiveSize];
CGFloat interactiveDistance = TLSizeGetAverageWidth(interactiveSize);
TLCoordinateAccuracy mouseAccuracy = interactiveDistance / 2.0f;
return [TLLocation locationWithCoordinate:mouseCoord
horizontalAccuracy:mouseAccuracy];
}
- (NSSet*)timestampsForMouseInMap:(CGPoint)targetPoint withInfo:(id < TLMapInfo >)mapInfo {
TLLocation* mouseLocation = [self locationForMouseInMap:targetPoint withInfo:mapInfo];
if (!mouseLocation) return nil;
const double trackSnapFactor = 20.0f;
TLCoordinateAccuracy searchDistance = trackSnapFactor * [mouseLocation horizontalAccuracy];
TLLocation* searchLocation = [TLLocation locationWithCoordinate:[mouseLocation coordinate]
horizontalAccuracy:searchDistance];
return [[self locator] trackTimestampsAtLocation:searchLocation];
}
- (TLTimestamp*)timestampNearestPhoto:(TLPhoto*)firstPhoto inTimestamps:(NSSet*)timestamps {
NSDate* targetDate = [[firstPhoto timestamp] time];
TLTimestamp* closestTimestamp = nil;
NSTimeInterval closestInterval = 0.0;
for (TLTimestamp* timestamp in timestamps) {
NSTimeInterval interval = fabs([targetDate timeIntervalSinceDate:[timestamp time]]);
if (!closestTimestamp || interval < closestInterval) {
closestTimestamp = timestamp;
closestInterval = interval;
}
}
return closestTimestamp;
}
- (NSDragOperation)photoLayer:(TLPhotoLayer*)layer
validateDrop:(id < NSDraggingInfo >)dropInfo
withMapInfo:(id < TLMapInfo >)mapInfo
{
(void)layer;
NSPasteboard* pasteboard = [dropInfo draggingPasteboard];
NSArray* draggedItems = TLMercatalogItemsFromPasteboard(pasteboard);
if (![draggedItems count]) {
// check if files are being dropped
NSArray* filenames = TLMercatalogFilesFromPasteboard(pasteboard);
return [filenames count] ? NSDragOperationLink : NSDragOperationNone;
}
CGPoint mouseOnMap = [mapInfo convertWindowPointToMap:[dropInfo draggingLocation]];
NSSet* mouseTimestamps = [self timestampsForMouseInMap:mouseOnMap withInfo:mapInfo];
if ([mouseTimestamps count]) {
TLPhotoSourceItem* draggedItem = [draggedItems objectAtIndex:0];
TLPhoto* draggedPhoto = [itemPhotos objectForKey:draggedItem];
TLTimestamp* mouseTimestamp = [self timestampNearestPhoto:draggedPhoto
inTimestamps:mouseTimestamps];
/* Find which necessaryCameraError will make draggedPhoto have mouseTimestamp,
assuming: timestamp = timezone + error */
NSTimeInterval timestampOffset = [[mouseTimestamp time]
timeIntervalSinceDate:[[draggedPhoto timestamp] time]];
NSTimeInterval currentCameraError = [self cameraError];
NSTimeInterval necessaryCameraError = currentCameraError + timestampOffset;
[self setCameraError:necessaryCameraError];
}
return NSDragOperationPrivate;
}
- (void)delayedOpenFilenames:(NSArray*)filenames {
[[NSApp delegate] application:NSApp openFiles:filenames];
}
- (BOOL)photoLayer:(TLPhotoLayer*)layer
acceptDrop:(id < NSDraggingInfo >)dropInfo
withMapInfo:(id < TLMapInfo >)mapInfo
{
(void)layer;
(void)mapInfo;
NSPasteboard* pasteboard = [dropInfo draggingPasteboard];
NSArray* draggedItems = TLMercatalogItemsFromPasteboard(pasteboard);
if ([draggedItems count]) {
return YES;
}
else {
NSArray* filenames = TLMercatalogFilesFromPasteboard(pasteboard);
if ([filenames count] &&
[[NSApp delegate] respondsToSelector:@selector(application:openFiles:)])
{
/* NOTE: opening files can cause window to be closed, but Cocoa's drag infrastructure
still wants to send the zombie an -[NSWindow enableCursorRects:] message.
Delaying the open lets the drag complete before any dialogs might appear. */
//[[NSApp delegate] application:NSApp openFiles:filenames];
[self performSelector:@selector(delayedOpenFilenames:) withObject:filenames afterDelay:0.1];
return YES;
}
}
return NO;
}
#pragma mark Tagging helpers/accessors
- (BOOL)shouldGeotag:(TLPhotoSourceItem*)item {
NSSet* validExtensions = [TLPhotoSource geotaggableExtensions];
NSString* itemExtension = [[[item originalFilename] pathExtension] lowercaseString];
return ([validExtensions containsObject:itemExtension] &&
[[item metadata] objectForKey:TLMetadataTimestampKey]);
}
- (void)setLocationsForItems:(NSSet*)items
withCameraError:(NSTimeInterval)error
timeZone:(NSTimeZone*)timeZone
{
NSMapTable* photoTimestamps = [NSMapTable mapTableWithStrongToStrongObjects];
for (TLPhotoSourceItem* photoItem in items) {
if (![self shouldGeotag:photoItem]) {
[itemPhotos removeObjectForKey:photoItem];
[accurateItems removeObject:photoItem];
continue;
}
NSDate* originalDate = [[[photoItem metadata] objectForKey:TLMetadataTimestampKey] time];
NSTimeZone* originalTimeZone = [[photoItem metadata] objectForKey:TLMetadataTimezoneKey];
NSInteger tzDifference = ([timeZone secondsFromGMTForDate:originalDate] -
[originalTimeZone secondsFromGMTForDate:originalDate]);
NSTimeInterval totalError = error - tzDifference;
NSDate* correctedDate = [originalDate addTimeInterval:totalError];
TLTimestamp* timestamp = [TLTimestamp timestampWithTime:correctedDate
accuracy:TLTimestampAccuracyUnknown];
[photoTimestamps setObject:timestamp forKey:photoItem];
}
//if ([photoTimestamps count] > 1) NSLog(@"Geotagging %lu items.", (long unsigned)[photoTimestamps count]);
NSTimeZone* exportTimezone = [NSTimeZone systemTimeZone];
NSMapTable* photoLocations = [[self locator] locateTimestamps:photoTimestamps];
for (TLPhotoSourceItem* photoItem in photoLocations) {
TLPhoto* photo = [itemPhotos objectForKey:photoItem];
if (!photo) {
photo = [[[TLPhoto alloc] initWithItem:photoItem] autorelease];
[itemPhotos setObject:photo forKey:photoItem];
}
[photo setLocation:[photoLocations objectForKey:photoItem]];
[photo setTimestamp:[photoTimestamps objectForKey:photoItem]];
[photo setTimeZone:exportTimezone];
if ([[photo location] horizontalAccuracy] > allowableInaccuracy) {
[accurateItems removeObject:photoItem];
}
else {
[accurateItems addObject:photoItem];
}
}
}
- (void)locatePhotos:(NSSet*)photos {
// TODO: improve architecture so this isn't necessary
[[self itemLayer] setSelectedPhotos:nil];
[[self itemLayer] setDisplayedPhotos:nil];
[self setLocationsForItems:photos
withCameraError:[self cameraError]
timeZone:[self cameraTimeZone]];
[[self itemLayer] reloadData];
}
- (void)relocatePhotos {
// TODO: improve architecture so this isn't necessary
[[self itemLayer] setSelectedPhotos:nil];
[[self itemLayer] setDisplayedPhotos:nil];
[itemPhotos removeAllObjects];
[accurateItems removeAllObjects];
[self setLocationsForItems:[[self itemSource] items]
withCameraError:[self cameraError]
timeZone:[self cameraTimeZone]];
[[self itemLayer] reloadData];
}
- (void)updateExportReady {
BOOL sourceIsCurrent = [[self itemSource] isCurrent];
BOOL haveItemsForExport = ([self countGeotagged] ||
([exportAllButton isEnabled] && [exportAllButton intValue]));
[self setReadyForExport:(sourceIsCurrent && haveItemsForExport)];
}
@end
BOOL TLMercatalogWriteItemsToPasteboard(NSArray* items, NSPasteboard* pboard, id owner) {
NSArray* supportedDragTypes = [NSArray arrayWithObject:TLMercatalogInternalPhotosPboardType];
(void)[pboard declareTypes:supportedDragTypes owner:owner];
NSMutableArray* itemsPropertyList = [NSMutableArray arrayWithCapacity:[items count]];
for (id item in items) {
NSData* itemPtrData = [NSData dataWithBytes:&item length:sizeof(id)];
[itemsPropertyList addObject:itemPtrData];
}
return [pboard setPropertyList:itemsPropertyList
forType:TLMercatalogInternalPhotosPboardType];
}
NSArray* TLMercatalogItemsFromPasteboard(NSPasteboard* pboard) {
NSArray* internalDropTypes = [NSArray arrayWithObject:TLMercatalogInternalPhotosPboardType];
NSString* internalType = [pboard availableTypeFromArray:internalDropTypes];
if (!internalType) return nil;
NSArray* itemPointers= [pboard propertyListForType:internalType];
NSMutableArray* items = [NSMutableArray arrayWithCapacity:[itemPointers count]];
for (NSData* itemPtrData in itemPointers) {
id item = *(id*)[itemPtrData bytes];
[items addObject:item];
}
return items;
}
NSArray* TLMercatalogFilesFromPasteboard(NSPasteboard* pboard) {
NSArray* externalDropTypes = [NSArray arrayWithObject:NSFilenamesPboardType];
NSString* externalType = [pboard availableTypeFromArray:externalDropTypes];
if (!externalType) return nil;
return [pboard propertyListForType:externalType];
}