| 1 |
#include <AvailabilityMacros.h> |
|---|
| 2 |
|
|---|
| 3 |
#include <CoreFoundation/CoreFoundation.h> |
|---|
| 4 |
#include <CoreServices/CoreServices.h> |
|---|
| 5 |
#import <Foundation/Foundation.h> |
|---|
| 6 |
|
|---|
| 7 |
Boolean GetMetadataForFile( void *thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFStringRef pathToFile ) { |
|---|
| 8 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 9 |
|
|---|
| 10 |
NSMutableDictionary *returnDict = (NSMutableDictionary *) attributes; |
|---|
| 11 |
NSURL *file = [NSURL fileURLWithPath:(NSString *) pathToFile]; |
|---|
| 12 |
NSString *title = [[(NSString *) pathToFile lastPathComponent] stringByDeletingPathExtension]; |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
[returnDict setObject:title forKey:(NSString *) kMDItemTitle]; |
|---|
| 16 |
|
|---|
| 17 |
NSError *error = nil; |
|---|
| 18 |
NSXMLDocument *transcript = [[[NSXMLDocument alloc] initWithContentsOfURL:file options:NSXMLDocumentTidyXML error:&error] autorelease]; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
NSDate *dateStarted = nil; |
|---|
| 22 |
NSArray *xpathResult = [transcript nodesForXPath:@"/log[1]/@began" error:&error]; |
|---|
| 23 |
|
|---|
| 24 |
if( ! [xpathResult count] ) |
|---|
| 25 |
xpathResult = [transcript nodesForXPath:@"/log[1]/envelope[1]/message[1]/@received" error:&error]; |
|---|
| 26 |
|
|---|
| 27 |
if( [xpathResult count] ) { |
|---|
| 28 |
dateStarted = [NSDate dateWithString:[[xpathResult objectAtIndex:0] stringValue]]; |
|---|
| 29 |
[returnDict setObject:dateStarted forKey:(NSString *) kMDItemContentCreationDate]; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
NSDate *lastMessageDate = nil; |
|---|
| 34 |
|
|---|
| 35 |
xpathResult = [transcript nodesForXPath:@"/log[1]/envelope[last()]/message[last()]/@received" error:&error]; |
|---|
| 36 |
if( [xpathResult count] ) { |
|---|
| 37 |
lastMessageDate = [NSDate dateWithString:[[xpathResult objectAtIndex:0] stringValue]]; |
|---|
| 38 |
[returnDict setObject:lastMessageDate forKey:(NSString *) kMDItemContentModificationDate]; |
|---|
| 39 |
[returnDict setObject:lastMessageDate forKey:(NSString *) kMDItemLastUsedDate]; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
if( lastMessageDate && dateStarted ) { |
|---|
| 43 |
|
|---|
| 44 |
NSTimeInterval logDuration = [lastMessageDate timeIntervalSinceDate:dateStarted]; |
|---|
| 45 |
[returnDict setObject:[NSNumber numberWithInt:logDuration] forKey:(NSString *) kMDItemDurationSeconds]; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
NSDateFormatter *formatter = [[[NSDateFormatter alloc] initWithDateFormat:@"" allowNaturalLanguage:NO] autorelease]; |
|---|
| 49 |
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4]; |
|---|
| 50 |
[formatter setDateStyle:NSDateFormatterShortStyle]; |
|---|
| 51 |
[formatter setTimeStyle:NSDateFormatterShortStyle]; |
|---|
| 52 |
|
|---|
| 53 |
NSString *coverageWording = [NSString stringWithFormat:@"%@ - %@", [formatter stringFromDate:dateStarted], [formatter stringFromDate:lastMessageDate]]; |
|---|
| 54 |
[returnDict setObject:coverageWording forKey:(NSString *) kMDItemCoverage]; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
xpathResult = [transcript nodesForXPath:@"/log[1]/@source" error:&error]; |
|---|
| 59 |
NSString *fromURL = nil; |
|---|
| 60 |
if( [xpathResult count] ) { |
|---|
| 61 |
fromURL = [[xpathResult objectAtIndex:0] stringValue]; |
|---|
| 62 |
[returnDict setObject:fromURL forKey:(NSString *) kMDItemWhereFroms]; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
NSMutableArray *participants = [NSMutableArray array]; |
|---|
| 67 |
NSArray *participantNodes = [transcript nodesForXPath:@"/log[1]/envelope/sender" error:&error]; |
|---|
| 68 |
NSEnumerator *enumerator = [participantNodes objectEnumerator]; |
|---|
| 69 |
NSXMLNode *participantNode = nil; |
|---|
| 70 |
|
|---|
| 71 |
while( ( participantNode = [enumerator nextObject] ) ) { |
|---|
| 72 |
NSString *nickname = [participantNode stringValue]; |
|---|
| 73 |
if( ! [participants containsObject:nickname] ) |
|---|
| 74 |
[participants addObject:nickname]; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
[returnDict setObject:participants forKey:(NSString *) kMDItemContributors]; |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
xpathResult = [transcript nodesForXPath:@"/log[1]/envelope/message/text()" error:&error]; |
|---|
| 81 |
NSString *textSummaryClipping = [xpathResult componentsJoinedByString:@" "]; |
|---|
| 82 |
[returnDict setObject:textSummaryClipping forKey:(NSString *) kMDItemTextContent]; |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
[returnDict setObject:[NSArray arrayWithObject:@"transcript"] forKey:(NSString *) kMDItemKind]; |
|---|
| 86 |
[returnDict setObject:[NSArray arrayWithObject:@"Colloquy"] forKey:(NSString *) kMDItemCreator]; |
|---|
| 87 |
|
|---|
| 88 |
[pool release]; |
|---|
| 89 |
|
|---|
| 90 |
return TRUE; |
|---|
| 91 |
} |
|---|