Permalink
Browse files

Standardize on "comment" term, not "comments"

Add description, tags to flickr metadata/tooltip

Log when quicklookCGImage is being called on main thread, so we can possibly re-do things to queue it on a background thread

Start on converting metadata description to use NSAttributedString
  • Loading branch information...
danwood committed Sep 23, 2010
1 parent 5b8efe2 commit 11853ba65da6568669ec27d43de638d967df65bc
Showing with 95 additions and 36 deletions.
  1. +1 −0 IMBAudioFolderParser.m
  2. +15 −2 IMBFlickrNode.m
  3. +29 −2 IMBFlickrParser.m
  4. +1 −0 IMBImageCaptureParser.m
  5. +11 −11 IMBMovieFolderParser.m
  6. +1 −0 IMBNodeObject.m
  7. +1 −0 IMBObject.m
  8. +7 −7 IMBiPhotoVideoParser.m
  9. +9 −9 IMBiTunesParser.m
  10. +7 −0 NSString+iMedia.h
  11. +9 −1 NSString+iMedia.m
  12. +4 −4 NSURL+iMedia.m
View
@@ -57,6 +57,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "IMBTimecodeTransformer.h"
#import "IMBCommon.h"
#import "NSString+iMedia.h"
+#import "NSWorkspace+iMedia.h"
//----------------------------------------------------------------------------------------------------------------------
View
@@ -416,8 +416,21 @@ - (NSArray*) extractPhotosFromFlickrResponse: (NSDictionary*) response {
[metadata setObject:quickLookURL forKey:@"quickLookURL"];
// But give it a better 'description' without the nested item
- NSString *desc = [[photoDict objectForKey:@"description"] objectForKey:@"_text"];
- if (nil != desc) [metadata setObject:desc forKey:@"descriptionHTML"];
+ NSString *descHTML = [[photoDict objectForKey:@"description"] objectForKey:@"_text"];
+ if (descHTML)
+ {
+ NSData *HTMLData = [descHTML dataUsingEncoding:NSUTF8StringEncoding];
+ NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:NSUTF8StringEncoding] forKey:NSCharacterEncodingDocumentOption];
+ NSAttributedString *descAttributed = [[[NSAttributedString alloc] initWithHTML:HTMLData options:options documentAttributes:nil] autorelease];
+ if (descAttributed)
+ {
+ NSString *desc = [descAttributed string];
+ if (nil != desc) [metadata setObject:desc forKey:@"descriptionText"];
+ }
+#ifdef DEBUG
+ else NSLog(@"Unable to make attributed string out of %@", descHTML);
+#endif
+ }
NSString *can_download = [photoDict objectForKey:@"can_download"];
NSString *license = [photoDict objectForKey:@"license"];
View
@@ -454,7 +454,7 @@ - (void) loadMetadataForObject:(IMBObject*)inObject
{
IMBEnhancedObject* object = (IMBEnhancedObject*)inObject;
NSDictionary* metadata = object.preliminaryMetadata;
- NSString* description = [self metadataDescriptionForMetadata:metadata];
+ NSString* description = metadata ? [self metadataDescriptionForMetadata:metadata] : @"";
if ([NSThread isMainThread])
{
@@ -473,6 +473,9 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
{
BOOL canDownload = [[inMetadata objectForKey:@"can_download"] boolValue];
NSString* ownername = [inMetadata objectForKey:@"ownername"];
+ NSString* comment = [inMetadata objectForKey:@"descriptionText"];
+ NSString* tags = [inMetadata objectForKey:@"tags"];
+
NSString* info = [NSImage imageMetadataDescriptionForMetadata:inMetadata];
NSString* description = @"";
@@ -488,7 +491,7 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
@"Context menu item title to warn of not being downloadable")];
}
- if (ownername)
+ if (ownername && ![ownername isEqualToString:@""])
{
NSString* artist = NSLocalizedStringWithDefaultValue(
@"Artist",
@@ -506,6 +509,30 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
description = [description stringByAppendingFormat:@"%@",info];
}
+ if (comment && ![comment isEqualToString:@""])
+ {
+ NSString* commentLabel = NSLocalizedStringWithDefaultValue(
+ @"Comment",
+ nil,IMBBundle(),
+ @"Comment",
+ @"Comment label in metadataDescription");
+
+ description = [description stringByAppendingNewline];
+ description = [description stringByAppendingFormat:@"%@: %@",commentLabel,comment];
+ }
+
+ if (tags && ![tags isEqualToString:@""])
+ {
+ NSString* tagsLabel = NSLocalizedStringWithDefaultValue(
+ @"Tags",
+ nil,IMBBundle(),
+ @"Tags",
+ @"Tags (Flickr term for keywords) label in metadataDescription");
+
+ description = [description stringByAppendingNewline];
+ description = [description stringByAppendingFormat:@"%@: %@",tagsLabel,tags];
+ }
+
return description;
}
View
@@ -68,6 +68,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "NSImage+iMedia.h"
#import <Carbon/Carbon.h>
#import <Quartz/Quartz.h>
+#import "NSWorkspace+iMedia.h"
//----------------------------------------------------------------------------------------------------------------------
// Internal classes:
View
@@ -131,7 +131,7 @@ - (NSDictionary*) metadataForFileAtPath:(NSString*)inPath
CFNumberRef seconds = MDItemCopyAttribute(item,kMDItemDurationSeconds);
CFNumberRef width = MDItemCopyAttribute(item,kMDItemPixelWidth);
CFNumberRef height = MDItemCopyAttribute(item,kMDItemPixelHeight);
- CFStringRef comments = MDItemCopyAttribute(item,kMDItemFinderComment);
+ CFStringRef comment = MDItemCopyAttribute(item,kMDItemFinderComment);
@@ -153,10 +153,10 @@ - (NSDictionary*) metadataForFileAtPath:(NSString*)inPath
CFRelease(height);
}
- if (comments)
+ if (comment)
{
- [metadata setObject:(NSString*)comments forKey:@"comments"];
- CFRelease(comments);
+ [metadata setObject:(NSString*)comment forKey:@"comment"];
+ CFRelease(comment);
}
CFRelease(item);
@@ -179,7 +179,7 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
NSNumber* width = [inMetadata objectForKey:@"width"];
NSNumber* height = [inMetadata objectForKey:@"height"];
NSString *path = [inMetadata objectForKey:@"path"];
- NSString *comments = [inMetadata objectForKey:@"comments"];
+ NSString *comment = [inMetadata objectForKey:@"comment"];
NSString *UTI = [NSString UTIForFileAtPath:path];
NSString *kind = [NSString descriptionForUTI:UTI];
@@ -221,16 +221,16 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
description = [description stringByAppendingFormat:@"%@: %@",durationLabel,durationString];
}
- if (comments && ![comments isEqualToString:@""])
+ if (comment && ![comment isEqualToString:@""])
{
- NSString* commentsLabel = NSLocalizedStringWithDefaultValue(
- @"Comments",
+ NSString* commentLabel = NSLocalizedStringWithDefaultValue(
+ @"Comment",
nil,IMBBundle(),
- @"Comments",
- @"Comments label in metadataDescription");
+ @"Comment",
+ @"Comment label in metadataDescription");
description = [description stringByAppendingNewline];
- description = [description stringByAppendingFormat:@"%@: %@",commentsLabel,comments];
+ description = [description stringByAppendingFormat:@"%@: %@",commentLabel,comment];
}
return description;
View
@@ -54,6 +54,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "IMBNodeObject.h"
#import "IMBNode.h"
+#import "NSWorkspace+iMedia.h"
//----------------------------------------------------------------------------------------------------------------------
View
@@ -60,6 +60,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "IMBObjectFifoCache.h"
#import "NSString+iMedia.h"
#import "NSFileManager+iMedia.h"
+#import "NSWorkspace+iMedia.h"
//----------------------------------------------------------------------------------------------------------------------
View
@@ -138,7 +138,7 @@ - (NSString*) imageLocationForObject:(NSDictionary*)inObjectDict
- (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
{
- NSString *comments = [inMetadata objectForKey:@"Comment"];
+ NSString *comment = [inMetadata objectForKey:@"Comment"];
NSString *type = [inMetadata objectForKey:@"ImageType"]; // like MooV
NSString *UTI = [NSString UTIForFileType:type];
NSString *kind = [NSString descriptionForUTI:UTI];
@@ -185,16 +185,16 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
description = [description stringByAppendingFormat:@"%@: %@",durationLabel,durationString];
}
- if (comments && ![comments isEqualToString:@""])
+ if (comment && ![comment isEqualToString:@""])
{
- NSString* commentsLabel = NSLocalizedStringWithDefaultValue(
- @"Comments",
+ NSString* commentLabel = NSLocalizedStringWithDefaultValue(
+ @"Comment",
nil,IMBBundle(),
- @"Comments",
- @"Comments label in metadataDescription");
+ @"Comment",
+ @"Comment label in metadataDescription");
if (description.length > 0) description = [description stringByAppendingFormat:@"\n"];
- description = [description stringByAppendingFormat:@"%@: %@",commentsLabel,comments];
+ description = [description stringByAppendingFormat:@"%@: %@",commentLabel,comment];
}
return description;
View
@@ -686,8 +686,8 @@ - (void) populateNode:(IMBNode*)inNode playlists:(NSArray*)inPlaylists tracks:(N
NSString* genre = [trackDict objectForKey:@"Genre"];
if (genre) [metadata setObject:genre forKey:@"genre"];
- NSString* comments = [trackDict objectForKey:@"Comments"];
- if (comments) [metadata setObject:comments forKey:@"comments"];
+ NSString* comment = [trackDict objectForKey:@"Comment"];
+ if (comment) [metadata setObject:comment forKey:@"comment"];
object.metadataDescription = [self metadataDescriptionForMetadata:metadata];
}
@@ -709,7 +709,7 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
NSNumber* duration = [inMetadata objectForKey:@"duration"];
NSString* artist = [inMetadata objectForKey:@"artist"];
NSString* album = [inMetadata objectForKey:@"album"];
- NSString* comments = [inMetadata objectForKey:@"comments"];
+ NSString* comment = [inMetadata objectForKey:@"comment"];
NSString* kind = [inMetadata objectForKey:@"Kind"];
NSNumber* width = [inMetadata objectForKey:@"Video Width"];
NSNumber* height = [inMetadata objectForKey:@"Video Height"];
@@ -781,16 +781,16 @@ - (NSString*) metadataDescriptionForMetadata:(NSDictionary*)inMetadata
description = [description stringByAppendingFormat:@"%@: %@",durationLabel,durationString];
}
- if (comments)
+ if (comment)
{
- NSString* commentsLabel = NSLocalizedStringWithDefaultValue(
- @"Comments",
+ NSString* commentLabel = NSLocalizedStringWithDefaultValue(
+ @"Comment",
nil,IMBBundle(),
- @"Comments",
- @"Comments label in metadataDescription");
+ @"Comment",
+ @"Comment label in metadataDescription");
description = [description stringByAppendingNewline];
- description = [description stringByAppendingFormat:@"%@: %@",commentsLabel,comments];
+ description = [description stringByAppendingFormat:@"%@: %@",commentLabel,comment];
}
return description;
View
@@ -80,3 +80,10 @@
- (NSString*) stringByAppendingNewline;
@end
+
+@interface NSMutableString (iMedia)
+
+- (void)appendNewline;
+
+@end
+
View
@@ -371,7 +371,15 @@ - (NSString*) stringByAppendingNewline
return self;
}
-
+
@end
+@implementation NSMutableString (iMedia)
+
+- (void)appendNewline;
+{
+ [self appendString:@"\n"];
+}
+
+@end
View
@@ -57,10 +57,10 @@ @implementation NSURL (imedia)
- (CGImageRef) quicklookCGImage;
{
-// if ([NSThread isMainThread])
-// {
-// NSLog(@"Whoops, we're on main thread. %@", [[NSThread currentThread] name]);
-// }
+ if ([NSThread isMainThread])
+ {
+ NSLog(@"%s is being called on main thread. We probably want to re-do this for background thread", __FUNCTION__);
+ }
CGSize size = CGSizeMake(256.0,256.0);
CGImageRef image = QLThumbnailImageCreate(kCFAllocatorDefault,(CFURLRef)self,size,NULL);
return (CGImageRef) [NSMakeCollectable(image) autorelease];

0 comments on commit 11853ba

Please sign in to comment.