From 89c1a27700dff50d7c8c1cf76196abbec69f9024 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 15 Nov 2010 12:04:36 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0Quicklook=20support=20-=20used=20embedde?= =?UTF-8?q?d=20icon=20image=20via=20cid=20and=20mime=20type=20image/tiff?= =?UTF-8?q?=20-=20sql=20view=20now=20wraps=20long=20lines=20-=20improved?= =?UTF-8?q?=20general=20stability=20-=20QL=20now=20runs=20on=20main=20thre?= =?UTF-8?q?ad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit note: there're still some issues for which QL crashed mostly due NSAutoReleasePool releases - more investigations are needed; most of this issues are releted to long lines, icon caching, releasing ... --- .../SPQLPluginConnectionBundleTemplate.html | 2 +- .../SPQLPluginConnectionTemplate.html | 2 +- .../SPQLPluginContentFiltersTemplate.html | 2 +- .../SPQLPluginQueryFavoritesTemplate.html | 2 +- Resources/English.lproj/SPQLPluginSQLTemplate.html | 14 ++- .../SPQLPluginConnectionBundleTemplate.html | 2 +- .../German.lproj/SPQLPluginConnectionTemplate.html | 2 +- .../SPQLPluginContentFiltersTemplate.html | 2 +- .../SPQLPluginQueryFavoritesTemplate.html | 2 +- Resources/German.lproj/SPQLPluginSQLTemplate.html | 14 ++- Resources/Plists/Sequel Pro QLGenerator-Info.plist | 4 +- Source/GeneratePreviewForURL.m | 122 ++++++++++----------- 12 files changed, 89 insertions(+), 81 deletions(-) diff --git a/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html b/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html index c97fb4bc..b3348134 100644 --- a/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html +++ b/Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/English.lproj/SPQLPluginConnectionTemplate.html b/Resources/English.lproj/SPQLPluginConnectionTemplate.html index 48345fcb..7d8ea5ed 100644 --- a/Resources/English.lproj/SPQLPluginConnectionTemplate.html +++ b/Resources/English.lproj/SPQLPluginConnectionTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/English.lproj/SPQLPluginContentFiltersTemplate.html b/Resources/English.lproj/SPQLPluginContentFiltersTemplate.html index b6765826..710911c3 100644 --- a/Resources/English.lproj/SPQLPluginContentFiltersTemplate.html +++ b/Resources/English.lproj/SPQLPluginContentFiltersTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/English.lproj/SPQLPluginQueryFavoritesTemplate.html b/Resources/English.lproj/SPQLPluginQueryFavoritesTemplate.html index 5a04861d..2928617f 100644 --- a/Resources/English.lproj/SPQLPluginQueryFavoritesTemplate.html +++ b/Resources/English.lproj/SPQLPluginQueryFavoritesTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/English.lproj/SPQLPluginSQLTemplate.html b/Resources/English.lproj/SPQLPluginSQLTemplate.html index 65ba2a3c..31e182ec 100644 --- a/Resources/English.lproj/SPQLPluginSQLTemplate.html +++ b/Resources/English.lproj/SPQLPluginSQLTemplate.html @@ -7,6 +7,14 @@ body { font-family:'Lucida Grande'; font-size:10pt; } +pre { + font-family:'Monaco'; + font-size:9pt; +} +.wrappedPre { + font-family:'Monaco'; + font-size:9pt; +} @@ -14,7 +22,7 @@ body {
- +
@@ -25,8 +33,8 @@ size: %@
-
+
 %@
-
+ diff --git a/Resources/German.lproj/SPQLPluginConnectionBundleTemplate.html b/Resources/German.lproj/SPQLPluginConnectionBundleTemplate.html index 6dea8846..01ccffd7 100644 --- a/Resources/German.lproj/SPQLPluginConnectionBundleTemplate.html +++ b/Resources/German.lproj/SPQLPluginConnectionBundleTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/German.lproj/SPQLPluginConnectionTemplate.html b/Resources/German.lproj/SPQLPluginConnectionTemplate.html index c1e3dc45..e5a9de41 100644 --- a/Resources/German.lproj/SPQLPluginConnectionTemplate.html +++ b/Resources/German.lproj/SPQLPluginConnectionTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/German.lproj/SPQLPluginContentFiltersTemplate.html b/Resources/German.lproj/SPQLPluginContentFiltersTemplate.html index cc3d2828..834fa6c7 100644 --- a/Resources/German.lproj/SPQLPluginContentFiltersTemplate.html +++ b/Resources/German.lproj/SPQLPluginContentFiltersTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/German.lproj/SPQLPluginQueryFavoritesTemplate.html b/Resources/German.lproj/SPQLPluginQueryFavoritesTemplate.html index 64494a9d..ad9a6403 100644 --- a/Resources/German.lproj/SPQLPluginQueryFavoritesTemplate.html +++ b/Resources/German.lproj/SPQLPluginQueryFavoritesTemplate.html @@ -14,7 +14,7 @@ body {
- +
diff --git a/Resources/German.lproj/SPQLPluginSQLTemplate.html b/Resources/German.lproj/SPQLPluginSQLTemplate.html index 41bff669..0ace0250 100644 --- a/Resources/German.lproj/SPQLPluginSQLTemplate.html +++ b/Resources/German.lproj/SPQLPluginSQLTemplate.html @@ -7,6 +7,14 @@ body { font-family:'Lucida Grande'; font-size:10pt; } +pre { + font-family:'Monaco'; + font-size:9pt; +} +.wrappedPre { + font-family:'Monaco'; + font-size:9pt; +} @@ -14,7 +22,7 @@ body {
- +
@@ -25,8 +33,8 @@ Größe: %@
-
+
 %@
-
+ diff --git a/Resources/Plists/Sequel Pro QLGenerator-Info.plist b/Resources/Plists/Sequel Pro QLGenerator-Info.plist index 59418aad..9fb710ab 100644 --- a/Resources/Plists/Sequel Pro QLGenerator-Info.plist +++ b/Resources/Plists/Sequel Pro QLGenerator-Info.plist @@ -50,13 +50,13 @@ CFPlugInUnloadFunction QLNeedsToBeRunInMainThread - + QLPreviewHeight 280 QLPreviewWidth 600 QLSupportsConcurrentRequests - + QLThumbnailMinimumSize 17 diff --git a/Source/GeneratePreviewForURL.m b/Source/GeneratePreviewForURL.m index 0fd6514d..d31c8a55 100644 --- a/Source/GeneratePreviewForURL.m +++ b/Source/GeneratePreviewForURL.m @@ -53,11 +53,11 @@ YY_BUFFER_STATE yy_scan_string (const char *); OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSURL *myURL = (NSURL *)url; NSString *urlExtension = [[[myURL path] pathExtension] lowercaseString]; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSError *templateReadError = nil; if (QLPreviewRequestIsCancelled(preview)) { @@ -65,14 +65,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, return noErr; } - // Get current Sequel Pro's set of file icons - NSArray *iconImages = [[[NSWorkspace sharedWorkspace] iconForFile:[myURL path]] representations]; - - // just in case - if(!iconImages || [iconImages count] < 1) - iconImages = [NSArray arrayWithObject:[NSImage imageNamed:NSImageNameStopProgressTemplate]]; - - NSMutableString *html; + NSString *html = @""; NSString *template = nil; if (QLPreviewRequestIsCancelled(preview)) { @@ -87,12 +80,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, // Dispatch different fiel extensions if([urlExtension isEqualToString:@"spf"]) { - NSImage *iconImage; - if([iconImages count] > 0) - iconImage = [iconImages objectAtIndex:1]; - else - iconImage = [iconImages objectAtIndex:0]; - NSError *readError = nil; NSString *convError = nil; NSPropertyListFormat format; @@ -105,7 +92,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { if(spf) [spf release], spf = nil; - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } @@ -117,7 +103,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, if (template == nil || ![template length] || templateReadError != nil) { if(spf) [spf release], spf = nil; - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } @@ -153,8 +138,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, } // compose the html - html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template, - [[iconImage TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0], + html = [NSString stringWithFormat:template, [spf objectForKey:@"rdbms_type"], [spf objectForKey:@"rdbms_version"], [name stringByReplacingOccurrencesOfString:@" " withString:@" "], @@ -164,57 +148,41 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, [NSString stringForByteSize:[[fileAttributes objectForKey:NSFileSize] longLongValue]], [dateFormatter stringFromDate:[fileAttributes fileModificationDate]], autoConnect - ]]; + ]; [dateFormatter release]; } else if([[spf objectForKey:@"format"] isEqualToString:@"content filters"]) { - NSImage *iconImage; - if([iconImages count] > 0) - iconImage = [iconImages objectAtIndex:1]; - else - iconImage = [iconImages objectAtIndex:0]; - template = [NSString stringWithContentsOfFile:[[NSBundle bundleWithIdentifier:@"com.google.code.sequel-pro.qlgenerator"] pathForResource:@"SPQLPluginContentFiltersTemplate" ofType:@"html"] encoding:NSUTF8StringEncoding error:&templateReadError]; if (template == nil || ![template length] || templateReadError != nil) { if(spf) [spf release], spf = nil; - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } // compose the html - html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template, - [[iconImage TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0], + html = [NSString stringWithFormat:template, [NSString stringWithContentsOfFile:[myURL path] encoding:NSUTF8StringEncoding error:nil] - ]]; + ]; } else if([[spf objectForKey:@"format"] isEqualToString:@"query favorites"]) { - NSImage *iconImage; - if([iconImages count] > 0) - iconImage = [iconImages objectAtIndex:1]; - else - iconImage = [iconImages objectAtIndex:0]; - template = [NSString stringWithContentsOfFile:[[NSBundle bundleWithIdentifier:@"com.google.code.sequel-pro.qlgenerator"] pathForResource:@"SPQLPluginQueryFavoritesTemplate" ofType:@"html"] encoding:NSUTF8StringEncoding error:&templateReadError]; if (template == nil || ![template length] || templateReadError != nil) { if(spf) [spf release], spf = nil; - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } // compose the html - html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template, - [[iconImage TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0], + html = [NSString stringWithFormat:template, [NSString stringWithContentsOfFile:[myURL path] encoding:NSUTF8StringEncoding error:nil] - ]]; + ]; } [spf release]; @@ -223,13 +191,10 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, else if([urlExtension isEqualToString:@"spfs"]) { - NSImage *iconImage = [iconImages objectAtIndex:0]; - template = [NSString stringWithContentsOfFile:[[NSBundle bundleWithIdentifier:@"com.google.code.sequel-pro.qlgenerator"] pathForResource:@"SPQLPluginConnectionBundleTemplate" ofType:@"html"] encoding:NSUTF8StringEncoding error:&templateReadError]; if (template == nil || ![template length] || templateReadError != nil) { - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } @@ -238,7 +203,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, encoding:NSUTF8StringEncoding error:&templateReadError]; if (windowTemplate == nil || ![windowTemplate length] || templateReadError != nil) { - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } @@ -255,7 +219,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { if(spf) [spf release], spf = nil; - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } @@ -359,24 +322,20 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, if(connectionCounter > 1) previewHeight = 495; - html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template, - [[iconImage TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0], + html = [NSString stringWithFormat:template, connectionCounter, spfsHTML - ]]; + ]; } else if([urlExtension isEqualToString:@"sql"]) { - NSImage *iconImage = [iconImages objectAtIndex:0]; - template = [NSString stringWithContentsOfFile:[[NSBundle bundleWithIdentifier:@"com.google.code.sequel-pro.qlgenerator"] pathForResource:@"SPQLPluginSQLTemplate" ofType:@"html"] encoding:NSUTF8StringEncoding error:&templateReadError]; if (template == nil || ![template length] || templateReadError != nil) { - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } @@ -395,7 +354,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, // read the file and try to get a proper encoding NSString *sqlText = [[NSString alloc] initWithContentsOfFile:[myURL path] encoding:sqlEncoding error:&readError]; - NSMutableString *sqlHTML = [[NSMutableString alloc] init]; + NSMutableString *sqlHTML = [[NSMutableString alloc] initWithCapacity:[sqlText length]]; NSString *truncatedString = [[NSString alloc] init]; if(readError != nil) { @@ -464,48 +423,81 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, } tokenRange = NSMakeRange(yyuoffset, yyuleng); + if(skipFontTag) - [sqlHTML appendString:[sqlText substringWithRange:tokenRange]]; + [sqlHTML appendString:[[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; else - [sqlHTML appendFormat:@"%@", tokenColor, [sqlText substringWithRange:tokenRange]]; + [sqlHTML appendFormat:@"%@", tokenColor, [[sqlText substringWithRange:tokenRange] HTMLEscapeString]]; } [sqlHTML appendString:truncatedString]; [sqlText release]; [truncatedString release]; + } - html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template, - [[iconImage TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0], + html = [NSString stringWithFormat:template, [NSString stringForByteSize:[[fileAttributes objectForKey:NSFileSize] longLongValue]], - sqlHTML - ]]; - + [[sqlHTML stringByReplacingOccurrencesOfString:@"\t" withString:@"    "] stringByReplacingOccurrencesOfString:@"\n" withString:@"
"] + ]; previewHeight = 495; [sqlHTML release]; } else { // No file attributes were read, bail for safety reasons - if(html) [html release], html = nil; if(pool) [pool release], pool = nil; return noErr; } } - NSMutableDictionary *props; - props = [[[NSMutableDictionary alloc] init] autorelease]; + + NSMutableDictionary *props,*imgProps; + NSData *image; + + NSImage *iconImage; + + // Get current Sequel Pro's set of file icons + NSArray *iconImages = [[[NSWorkspace sharedWorkspace] iconForFile:[myURL path]] representations]; + + // just in case + if(!iconImages || [iconImages count] < 1) + iconImages = [NSArray arrayWithObject:[NSImage imageNamed:NSImageNameStopProgressTemplate]]; + + if([iconImages count] > 0) + iconImage = [iconImages objectAtIndex:1]; + else + iconImage = [iconImages objectAtIndex:0]; + + image = [[iconImage TIFFRepresentation] retain]; + + props = [[NSMutableDictionary alloc] init]; + imgProps = [[NSMutableDictionary alloc] init]; + [props setObject:[NSNumber numberWithInt:previewHeight] forKey:(NSString *)kQLPreviewPropertyHeightKey]; [props setObject:[NSNumber numberWithInt:600] forKey:(NSString *)kQLPreviewPropertyWidthKey]; + + if(image) { + [imgProps setObject:@"image/tiff" forKey:(NSString *)kQLPreviewPropertyMIMETypeKey]; + [imgProps setObject:image forKey:(NSString *)kQLPreviewPropertyAttachmentDataKey]; + } + + [props setObject:[NSDictionary dictionaryWithObject:imgProps forKey:@"icon.tiff"] forKey:(NSString *)kQLPreviewPropertyAttachmentsKey]; + [props setObject:@"UTF-8" forKey:(NSString *)kQLPreviewPropertyTextEncodingNameKey]; + [props setObject:@"text/html" forKey:(NSString *)kQLPreviewPropertyMIMETypeKey]; + QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding], kUTTypeHTML, (CFDictionaryRef)props ); - if(html) [html release], html = nil; - if(pool) [pool release], pool = nil; + [props release]; + [imgProps release]; + if(image) [image release], image = nil; + [pool release]; + return noErr; } -- cgit v1.2.3