aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-15 12:04:36 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-15 12:04:36 +0000
commit89c1a27700dff50d7c8c1cf76196abbec69f9024 (patch)
tree8d20f5a00ac09050e2010af3db0546b3f2e19374
parent6ca2488a6679f574368a5b7475875f410cb7ec69 (diff)
downloadsequelpro-89c1a27700dff50d7c8c1cf76196abbec69f9024.tar.gz
sequelpro-89c1a27700dff50d7c8c1cf76196abbec69f9024.tar.bz2
sequelpro-89c1a27700dff50d7c8c1cf76196abbec69f9024.zip
• Quicklook support
- used embedded icon image via cid and mime type image/tiff - sql view now wraps long lines - improved general stability - QL now runs on main thread 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 ...
-rw-r--r--Resources/English.lproj/SPQLPluginConnectionBundleTemplate.html2
-rw-r--r--Resources/English.lproj/SPQLPluginConnectionTemplate.html2
-rw-r--r--Resources/English.lproj/SPQLPluginContentFiltersTemplate.html2
-rw-r--r--Resources/English.lproj/SPQLPluginQueryFavoritesTemplate.html2
-rw-r--r--Resources/English.lproj/SPQLPluginSQLTemplate.html14
-rw-r--r--Resources/German.lproj/SPQLPluginConnectionBundleTemplate.html2
-rw-r--r--Resources/German.lproj/SPQLPluginConnectionTemplate.html2
-rw-r--r--Resources/German.lproj/SPQLPluginContentFiltersTemplate.html2
-rw-r--r--Resources/German.lproj/SPQLPluginQueryFavoritesTemplate.html2
-rw-r--r--Resources/German.lproj/SPQLPluginSQLTemplate.html14
-rw-r--r--Resources/Plists/Sequel Pro QLGenerator-Info.plist4
-rw-r--r--Source/GeneratePreviewForURL.m122
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 {
<table>
<tr>
<td valign="right">
-<img width="128" height="128" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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 {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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 {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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 {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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;
+}
</style>
</head>
<body>
@@ -14,7 +22,7 @@ body {
<table>
<tr>
<td valign="right">
-<img width="128" height="128" src="data:image/auto;base64,%@">
+<img width="128" height="128" src="cid:icon.tiff">
</td>
<td>
<center>
@@ -25,8 +33,8 @@ size: %@
</tr>
</table>
</center>
-<pre>
+<span class="wrappedPre">
%@
-</pre>
+</span>
</body>
</html>
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 {
<table>
<tr>
<td valign="right">
-<img width="128" heigth="128" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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 {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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 {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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 {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
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;
+}
</style>
</head>
<body>
@@ -14,7 +22,7 @@ body {
<table>
<tr>
<td valign="right">
-<img width="128" heigth="128" src="data:image/auto;base64,%@">
+<img width="128" heigth="128" src="cid:icon.tiff">
</td>
<td>
<center>
@@ -25,8 +33,8 @@ Größe: %@
</tr>
</table>
</center>
-<pre>
+<span class="wrappedPre">
%@
-</pre>
+</span>
</body>
</html>
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 @@
<key>CFPlugInUnloadFunction</key>
<string></string>
<key>QLNeedsToBeRunInMainThread</key>
- <false/>
+ <true/>
<key>QLPreviewHeight</key>
<integer>280</integer>
<key>QLPreviewWidth</key>
<integer>600</integer>
<key>QLSupportsConcurrentRequests</key>
- <false/>
+ <true/>
<key>QLThumbnailMinimumSize</key>
<real>17</real>
</dict>
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:@"&nbsp;"],
@@ -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:@"<font color=%@>%@</font>", tokenColor, [sqlText substringWithRange:tokenRange]];
+ [sqlHTML appendFormat:@"<font color=%@>%@</font>", 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:@"&nbsp;&nbsp;&nbsp;&nbsp;"] stringByReplacingOccurrencesOfString:@"\n" withString:@"<br>"]
+ ];
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;
}