diff options
-rw-r--r-- | Source/SPDataAdditions.h | 33 | ||||
-rw-r--r-- | Source/SPDataAdditions.m | 105 | ||||
-rw-r--r-- | Source/TableContent.h | 2 | ||||
-rw-r--r-- | Source/TableContent.m | 74 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 6 |
5 files changed, 152 insertions, 68 deletions
diff --git a/Source/SPDataAdditions.h b/Source/SPDataAdditions.h new file mode 100644 index 00000000..5f51213e --- /dev/null +++ b/Source/SPDataAdditions.h @@ -0,0 +1,33 @@ +// +// $Id: SPDataAdditions.m 866 2009-06-15 16:05:54Z bibiko $ +// +// SPDataAdditions.m +// sequel-pro +// +// Created by Hans-Jörg Bibiko on June 19, 2009 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import <Cocoa/Cocoa.h> + + +@interface NSData (SPDataAdditions) + +- (NSString *) base64EncodingWithLineLength:(unsigned int)lineLength; + + +@end diff --git a/Source/SPDataAdditions.m b/Source/SPDataAdditions.m new file mode 100644 index 00000000..166288e5 --- /dev/null +++ b/Source/SPDataAdditions.m @@ -0,0 +1,105 @@ +// +// $Id: SPDataAdditions.m 891 2009-06-19 10:01:14Z bibiko $ +// +// SPDataAdditions.m +// sequel-pro +// +// Created by Hans-Jörg Bibiko on June 19, 2009 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "SPDataAdditions.h" + +static char base64encodingTable[64] = { +'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', +'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', +'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', +'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; + + +@implementation NSData (SPDataAdditions) + +/* + * Derived from http://colloquy.info/project/browser/trunk/NSDataAdditions.m?rev=1576 + * Created by khammond on Mon Oct 29 2001. + * Formatted by Timothy Hatcher on Sun Jul 4 2004. + * Copyright (c) 2001 Kyle Hammond. All rights reserved. + * Original development by Dave Winer. + * + * Convert self to a base64 encoded NSString + */ +- (NSString *) base64EncodingWithLineLength:(unsigned int)lineLength { + + const unsigned char *bytes = [self bytes]; + unsigned long ixtext = 0; + unsigned long lentext = [self length]; + long ctremaining = 0; + unsigned char inbuf[3], outbuf[4]; + short i = 0; + short charsonline = 0, ctcopy = 0; + unsigned long ix = 0; + + NSMutableString *base64 = [NSMutableString stringWithCapacity:lentext]; + + while(1) { + ctremaining = lentext - ixtext; + if( ctremaining <= 0 ) break; + + for( i = 0; i < 3; i++ ) { + ix = ixtext + i; + if( ix < lentext ) inbuf[i] = bytes[ix]; + else inbuf [i] = 0; + } + + outbuf [0] = (inbuf [0] & 0xFC) >> 2; + outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4); + outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6); + outbuf [3] = inbuf [2] & 0x3F; + ctcopy = 4; + + switch( ctremaining ) { + case 1: + ctcopy = 2; + break; + case 2: + ctcopy = 3; + break; + } + + for( i = 0; i < ctcopy; i++ ) + [base64 appendFormat:@"%c", base64encodingTable[outbuf[i]]]; + + for( i = ctcopy; i < 4; i++ ) + [base64 appendFormat:@"%c",'=']; + + ixtext += 3; + charsonline += 4; + + if( lineLength > 0 ) { + if (charsonline >= lineLength) { + charsonline = 0; + [base64 appendString:@"\n"]; + } + } + } + + return base64; +} + + + +@end diff --git a/Source/TableContent.h b/Source/TableContent.h index 80305fca..dcb527ca 100644 --- a/Source/TableContent.h +++ b/Source/TableContent.h @@ -110,8 +110,6 @@ - (NSArray *)currentResult; - (NSArray *)currentDataResult; -- (NSString *) base64EncodingOfData:(NSData*)data withLineLength:(unsigned int)lineLength; - //additional methods - (void)setConnection:(CMMCPConnection *)theConnection; - (IBAction)setCompareTypes:(id)sender; diff --git a/Source/TableContent.m b/Source/TableContent.m index 319b46ae..06f7899a 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -38,17 +38,10 @@ #import "SPStringAdditions.h" #import "SPArrayAdditions.h" #import "SPTextViewAdditions.h" +#import "SPDataAdditions.h" #import "QLPreviewPanel.h" -static char encodingTable[64] = { -'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', -'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', -'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', -'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; - - - @implementation TableContent /** @@ -1291,7 +1284,7 @@ static char encodingTable[64] = { [tempRow removeAllObjects]; enumerator = [tableColumns objectEnumerator]; while ( (tableColumn = [enumerator nextObject]) ) { - id o = [[fullResult objectAtIndex:i] objectForKey:[[tableColumn headerCell] stringValue]]; + id o = [NSArrayObjectAtIndex(fullResult, i) objectForKey:[[tableColumn headerCell] stringValue]]; if([o isKindOfClass:[NSNull class]]) [tempRow addObject:@"NULL"]; else if([o isKindOfClass:[NSString class]]) @@ -1299,7 +1292,12 @@ static char encodingTable[64] = { else { NSImage *image = [[NSImage alloc] initWithData:o]; if(image) { - [tempRow addObject:[NSString stringWithFormat:@"<IMG WIDTH='100' SRC=\"data:image/auto;base64,%@\">", [self base64EncodingOfData: o withLineLength:0]]]; + int imageWidth = [image size].width; + if (imageWidth > 100) imageWidth = 100; + [tempRow addObject:[NSString stringWithFormat: + @"<IMG WIDTH='%d' SRC=\"data:image/auto;base64,%@\">", + imageWidth, + [[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0]]]; } else { [tempRow addObject:@"<BLOB>"]; } @@ -1311,62 +1309,6 @@ static char encodingTable[64] = { return currentResult; } -- (NSString *) base64EncodingOfData:(NSData*)data withLineLength:(unsigned int)lineLength { - const unsigned char *bytes = [data bytes]; - NSMutableString *result = [NSMutableString stringWithCapacity:[data length]]; - unsigned long ixtext = 0; - unsigned long lentext = [data length]; - long ctremaining = 0; - unsigned char inbuf[3], outbuf[4]; - short i = 0; - short charsonline = 0, ctcopy = 0; - unsigned long ix = 0; - - while( YES ) { - ctremaining = lentext - ixtext; - if( ctremaining <= 0 ) break; - - for( i = 0; i < 3; i++ ) { - ix = ixtext + i; - if( ix < lentext ) inbuf[i] = bytes[ix]; - else inbuf [i] = 0; - } - - outbuf [0] = (inbuf [0] & 0xFC) >> 2; - outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4); - outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6); - outbuf [3] = inbuf [2] & 0x3F; - ctcopy = 4; - - switch( ctremaining ) { - case 1: - ctcopy = 2; - break; - case 2: - ctcopy = 3; - break; - } - - for( i = 0; i < ctcopy; i++ ) - [result appendFormat:@"%c", encodingTable[outbuf[i]]]; - - for( i = ctcopy; i < 4; i++ ) - [result appendFormat:@"%c",'=']; - - ixtext += 3; - charsonline += 4; - - if( lineLength > 0 ) { - if (charsonline >= lineLength) { - charsonline = 0; - [result appendString:@"\n"]; - } - } - } - - return result; -} - //getter methods - (NSArray *)currentResult /* diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 3e283c81..6680c2ca 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -149,6 +149,7 @@ B5EAC0FD0EC87FF900CC579C /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5EAC0FC0EC87FF900CC579C /* Security.framework */; }; B5F4F7810F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff in Resources */ = {isa = PBXBuildFile; fileRef = B5F4F7800F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff */; }; BC1847EA0FE6EC8400094BFB /* SPEditSheetTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = BC1847E90FE6EC8400094BFB /* SPEditSheetTextView.m */; }; + BC2C16D40FEBEDF10003993B /* SPDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = BC2C16D30FEBEDF10003993B /* SPDataAdditions.m */; }; BC2C8E220FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html in Resources */ = {isa = PBXBuildFile; fileRef = BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */; }; BCD0AD490FBBFC340066EA5C /* SPSQLTokenizer.l in Sources */ = {isa = PBXBuildFile; fileRef = BCD0AD480FBBFC340066EA5C /* SPSQLTokenizer.l */; }; /* End PBXBuildFile section */ @@ -403,6 +404,8 @@ B5F4F7800F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "toolbar-switch-to-procedures.tiff"; sourceTree = "<group>"; }; BC1847E80FE6EC8400094BFB /* SPEditSheetTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPEditSheetTextView.h; sourceTree = "<group>"; }; BC1847E90FE6EC8400094BFB /* SPEditSheetTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPEditSheetTextView.m; sourceTree = "<group>"; }; + BC2C16D20FEBEDF10003993B /* SPDataAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDataAdditions.h; sourceTree = "<group>"; }; + BC2C16D30FEBEDF10003993B /* SPDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDataAdditions.m; sourceTree = "<group>"; }; BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "sequel-pro-mysql-help-template.html"; sourceTree = "<group>"; }; BCD0AD480FBBFC340066EA5C /* SPSQLTokenizer.l */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.lex; path = SPSQLTokenizer.l; sourceTree = "<group>"; }; BCD0AD4A0FBBFC480066EA5C /* SPSQLTokenizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPSQLTokenizer.h; sourceTree = "<group>"; }; @@ -883,6 +886,8 @@ B52460D60F8EF92300171639 /* SPTextViewAdditions.m */, B57747D70F7A8990003B34F9 /* SPWindowAdditions.h */, B57747D80F7A8990003B34F9 /* SPWindowAdditions.m */, + BC2C16D20FEBEDF10003993B /* SPDataAdditions.h */, + BC2C16D30FEBEDF10003993B /* SPDataAdditions.m */, ); name = "Category Additions"; sourceTree = "<group>"; @@ -1162,6 +1167,7 @@ 58CDB3300FCE138D00F8ACA3 /* SPSSHTunnel.m in Sources */, 29A1B7E50FD1293A000B88E8 /* SPPrintAccessory.m in Sources */, BC1847EA0FE6EC8400094BFB /* SPEditSheetTextView.m in Sources */, + BC2C16D40FEBEDF10003993B /* SPDataAdditions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |