aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPColorSelectorView.h2
-rw-r--r--Source/SPColorSelectorView.m141
-rw-r--r--Source/SPConnectionControllerDelegate.m8
-rw-r--r--Source/SPFavoriteTextFieldCell.h3
-rw-r--r--Source/SPFavoriteTextFieldCell.m87
-rw-r--r--Source/SPFavoritesOutlineView.h5
-rw-r--r--Source/SPFavoritesOutlineView.m7
-rw-r--r--Source/SPOSInfo.h50
-rw-r--r--Source/SPOSInfo.m94
-rw-r--r--Source/SPSSHTunnel.m6
-rw-r--r--Source/SPWindowController.h2
-rw-r--r--Source/SPWindowController.m7
12 files changed, 329 insertions, 83 deletions
diff --git a/Source/SPColorSelectorView.h b/Source/SPColorSelectorView.h
index b3d9325e..925034a3 100644
--- a/Source/SPColorSelectorView.h
+++ b/Source/SPColorSelectorView.h
@@ -57,6 +57,8 @@
IBOutlet id delegate;
NSArray *colorList;
+
+ BOOL isOSAtLeast10_9_0;
}
@property (nonatomic,readwrite,assign) NSInteger selectedTag;
diff --git a/Source/SPColorSelectorView.m b/Source/SPColorSelectorView.m
index f2eade86..ba577170 100644
--- a/Source/SPColorSelectorView.m
+++ b/Source/SPColorSelectorView.m
@@ -41,10 +41,13 @@
// More info at <https://github.com/sequelpro/sequelpro>
#import "SPColorSelectorView.h"
+#import "SPOSInfo.h"
@interface SPColorSelectorView (Private)
- (void)setupTrackingAreas;
+- (void)_drawDotBevelStyleWithGradient:(NSGradient *)gradient insideRect:(NSRect)colorSquareRect;
+- (void)_drawDotFlatStyleWithColor:(NSColor *)color insideRect:(NSRect)colorSquareRect;
@end
@@ -86,6 +89,8 @@ enum trackingAreaIDs
//set ourselves as observer of selectedTag (need to mark view dirty)
[self addObserver:self forKeyPath:@"selectedTag" options:0 context:nil];
+
+ isOSAtLeast10_9_0 = [SPOSInfo isOSVersionAtLeastMajor:10 minor:9 patch:0];
}
return self;
@@ -126,9 +131,9 @@ enum trackingAreaIDs
- (NSRect)rectForColorViewAtIndex:(NSInteger)index
{
CGFloat baseY = 2.0;
- CGFloat baseX = 2.0;
+ CGFloat baseX = 3.0;
- CGFloat marginR = 5.0;
+ CGFloat marginR = 7.0;
CGFloat width = 16.0;
CGFloat height = 16.0;
@@ -138,46 +143,20 @@ enum trackingAreaIDs
switch (index)
{
case kTrackingAreaNone:
- returnRect = NSMakeRect(baseX, baseY, width, height);
- break;
-
case kTrackingArea0:
- returnRect = NSMakeRect(baseX + 1 * (width + marginR), baseY, width, height);
- break;
-
case kTrackingArea1:
- returnRect = NSMakeRect(baseX + 2 * (width + marginR), baseY, width, height);
- break;
-
case kTrackingArea2:
- returnRect = NSMakeRect(baseX + 3 * (width + marginR), baseY, width, height);
- break;
-
case kTrackingArea3:
- returnRect = NSMakeRect(baseX + 4 * (width + marginR), baseY, width, height);
- break;
-
case kTrackingArea4:
- returnRect = NSMakeRect(baseX + 5 * (width + marginR), baseY, width, height);
- break;
-
case kTrackingArea5:
- returnRect = NSMakeRect(baseX + 6 * (width + marginR), baseY, width, height);
- break;
-
case kTrackingArea6:
- returnRect = NSMakeRect(baseX + 7 * (width + marginR), baseY, width, height);
+ returnRect = NSMakeRect(baseX + (index + 1) * (width + marginR), baseY, width, height);
break;
}
return returnRect;
}
-// -------------------------------------------------------------------------------
-// Returns the color gradient corresponding to the tag. These colours were
-// chosen to appear similar to those in Aperture 3.
-// -------------------------------------------------------------------------------
-
- (NSGradient *)gradientForTag:(NSInteger)colorTag
{
NSGradient *gradient = nil;
@@ -289,53 +268,79 @@ enum trackingAreaIDs
[left setLineWidth:3.0];
[left setLineCapStyle:NSButtLineCapStyle];
- [left moveToPoint:NSMakePoint(colorSquareRect.origin.x + 4.0, colorSquareRect.origin.y + 4.0)];
+ [left moveToPoint:NSMakePoint(colorSquareRect.origin.x + 4.0, colorSquareRect.origin.y + 4.0)];
[left lineToPoint:NSMakePoint(colorSquareRect.origin.x + 12.0, colorSquareRect.origin.y + 12.0)];
- [left moveToPoint:NSMakePoint(colorSquareRect.origin.x + 12.0, colorSquareRect.origin.y + 4.0)];
- [left lineToPoint:NSMakePoint(colorSquareRect.origin.x + 4.0, colorSquareRect.origin.y + 12.0)];
+ [left moveToPoint:NSMakePoint(colorSquareRect.origin.x + 12.0, colorSquareRect.origin.y + 4.0)];
+ [left lineToPoint:NSMakePoint(colorSquareRect.origin.x + 4.0, colorSquareRect.origin.y + 12.0)];
[left stroke];
}
else {
- // draw the gradient dot
- NSGradient *gradient = [self gradientForTag:index];
- NSRect dotRect = NSInsetRect(colorSquareRect, 2.0, 2.0);
- NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:dotRect];
- [gradient drawInBezierPath:circlePath angle:-90.0];
-
- // draw a highlight
-
- // top edge outline
- gradient = [[NSGradient alloc] initWithColorsAndLocations:
- [NSColor colorWithCalibratedWhite:1.0 alpha:0.18], 0.0,
- [NSColor colorWithCalibratedWhite:1.0 alpha:0.0], 0.6, nil];
- circlePath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(dotRect, 1.0, 1.0)];
- [circlePath appendBezierPath:[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(dotRect.origin.x+1.0, dotRect.origin.y-2.0, dotRect.size.width-2.0, dotRect.size.height)]];
- [circlePath setWindingRule:NSEvenOddWindingRule];
- [gradient drawInBezierPath:circlePath angle:-90.0];
- [gradient release];
-
- // top center gloss
- gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.18]
- endingColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.0]];
- [gradient drawFromCenter:NSMakePoint(NSMidX(dotRect), NSMaxY(dotRect) - 2.0)
- radius:0.0
- toCenter:NSMakePoint(NSMidX(dotRect), NSMaxY(dotRect) - 2.0)
- radius:4.0
- options:0];
- [gradient release];
-
- // draw a dark outline
- circlePath = [NSBezierPath bezierPathWithOvalInRect:dotRect];
- gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.12]
- endingColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.46]];
- [circlePath appendBezierPath:[NSBezierPath bezierPathWithOvalInRect:NSInsetRect(dotRect, 1.0, 1.0)]];
- [circlePath setWindingRule:NSEvenOddWindingRule];
- [gradient drawInBezierPath:circlePath angle:-90.0];
- [gradient release];
+ if(!isOSAtLeast10_9_0) {
+ NSGradient *gradient = [self gradientForTag:index];
+ [self _drawDotBevelStyleWithGradient:gradient insideRect:colorSquareRect];
+ }
+ else {
+ NSColor *baseColor = (NSColor *)[colorList objectAtIndex:index];
+ [self _drawDotFlatStyleWithColor:baseColor insideRect:colorSquareRect];
+ }
}
}
}
+- (void)_drawDotBevelStyleWithGradient:(NSGradient *)gradient insideRect:(NSRect)colorSquareRect
+{
+ // draw the gradient dot
+ NSRect dotRect = NSInsetRect(colorSquareRect, 2.0, 2.0);
+ NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:dotRect];
+ [gradient drawInBezierPath:circlePath angle:-90.0];
+
+ // draw a highlight
+
+ // top edge outline
+ NSGradient *grad = [[NSGradient alloc] initWithColorsAndLocations:
+ [NSColor colorWithCalibratedWhite:1.0 alpha:0.18], 0.0,
+ [NSColor colorWithCalibratedWhite:1.0 alpha:0.0], 0.6, nil];
+ circlePath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(dotRect, 1.0, 1.0)];
+ [circlePath appendBezierPath:[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(dotRect.origin.x+1.0, dotRect.origin.y-2.0, dotRect.size.width-2.0, dotRect.size.height)]];
+ [circlePath setWindingRule:NSEvenOddWindingRule];
+ [grad drawInBezierPath:circlePath angle:-90.0];
+ [grad release];
+
+ // top center gloss
+ NSGradient *grad2 = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.18]
+ endingColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.0]];
+ [grad2 drawFromCenter:NSMakePoint(NSMidX(dotRect), NSMaxY(dotRect) - 2.0)
+ radius:0.0
+ toCenter:NSMakePoint(NSMidX(dotRect), NSMaxY(dotRect) - 2.0)
+ radius:4.0
+ options:0];
+ [grad2 release];
+
+ // draw a dark outline
+ circlePath = [NSBezierPath bezierPathWithOvalInRect:dotRect];
+ NSGradient *grad3 = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.12]
+ endingColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.46]];
+ [circlePath appendBezierPath:[NSBezierPath bezierPathWithOvalInRect:NSInsetRect(dotRect, 1.0, 1.0)]];
+ [circlePath setWindingRule:NSEvenOddWindingRule];
+ [grad3 drawInBezierPath:circlePath angle:-90.0];
+ [grad3 release];
+}
+
+- (void)_drawDotFlatStyleWithColor:(NSColor *)color insideRect:(NSRect)colorSquareRect
+{
+ CGFloat h,s,b,a;
+ [color getHue:&h saturation:&s brightness:&b alpha:&a];
+
+ NSRect dotRect = NSInsetRect(colorSquareRect, 2.0, 2.0);
+ NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:dotRect];
+ [[NSColor colorWithCalibratedHue:h saturation:s*1.21 brightness:b*1.1 alpha:a] set];
+ [circlePath fill];
+
+ [[color shadowWithLevel:0.15f] set];
+ [circlePath setLineWidth:1.0f];
+ [circlePath stroke];
+}
+
#pragma mark -
#pragma mark Mouse Handling
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
index a28a27b7..8cef86e9 100644
--- a/Source/SPConnectionControllerDelegate.m
+++ b/Source/SPConnectionControllerDelegate.m
@@ -32,6 +32,7 @@
#ifndef SP_CODA
#import "SPFavoritesController.h"
#import "SPTableTextFieldCell.h"
+#import "SPFavoriteTextFieldCell.h"
#import "SPPreferenceController.h"
#import "SPGeneralPreferencePane.h"
#import "SPAppController.h"
@@ -39,6 +40,7 @@
#import "SPGroupNode.h"
#import "SPTreeNode.h"
#import "SPFavoritesOutlineView.h"
+#import "SPFavoriteColorSupport.h"
#endif
#ifndef SP_CODA
@@ -171,6 +173,12 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
}
else {
[(SPTableTextFieldCell *)cell setImage:[NSImage imageNamed:SPDatabaseImage]];
+ NSColor *bgColor = nil;
+ NSNumber *colorIndexObj = [[[node representedObject] nodeFavorite] objectForKey:SPFavoriteColorIndexKey];
+ if(colorIndexObj != nil) {
+ bgColor = [[SPFavoriteColorSupport sharedInstance] colorForIndex:[colorIndexObj integerValue]];
+ }
+ [(SPFavoriteTextFieldCell *)cell setLabelColor:bgColor];
}
}
diff --git a/Source/SPFavoriteTextFieldCell.h b/Source/SPFavoriteTextFieldCell.h
index afc32bcb..0e900636 100644
--- a/Source/SPFavoriteTextFieldCell.h
+++ b/Source/SPFavoriteTextFieldCell.h
@@ -33,9 +33,12 @@
@interface SPFavoriteTextFieldCell : ImageAndTextCell
{
BOOL drawsDividerUnderCell;
+ NSColor *labelColor;
}
- (BOOL)drawsDividerUnderCell;
- (void)setDrawsDividerUnderCell:(BOOL)drawsDivider;
+@property(copy)NSColor *labelColor;
+
@end
diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m
index 41511c8c..cf9f6a05 100644
--- a/Source/SPFavoriteTextFieldCell.m
+++ b/Source/SPFavoriteTextFieldCell.m
@@ -29,6 +29,9 @@
// More info at <https://github.com/sequelpro/sequelpro>
#import "SPFavoriteTextFieldCell.h"
+#import "SPOSInfo.h"
+
+extern BOOL isOSAtLeast10_10_0(void);
@implementation SPFavoriteTextFieldCell
@@ -46,6 +49,7 @@
SPFavoriteTextFieldCell *cell = (SPFavoriteTextFieldCell *)[super copyWithZone:zone];
cell->drawsDividerUnderCell = drawsDividerUnderCell;
+ cell->labelColor = nil; //TODO copying the color sometimes causes a drawing bug
return cell;
}
@@ -68,8 +72,79 @@
drawsDividerUnderCell = drawsDivider;
}
+@synthesize labelColor;
+
#pragma mark -
+- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
+{
+ if(labelColor) {
+ CGFloat round = (cellFrame.size.height/2);
+ NSBezierPath *bg = [NSBezierPath bezierPathWithRoundedRect:cellFrame xRadius:round yRadius:round];
+
+ if(isOSAtLeast10_10_0()) {
+ CGFloat h,s,b,a;
+ [labelColor getHue:&h saturation:&s brightness:&b alpha:&a];
+
+ [[NSColor colorWithCalibratedHue:h saturation:s*1.21 brightness:b*1.1 alpha:a] set];
+ [bg fill];
+ }
+ else {
+ // Draw main background gradient
+ NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations:
+ [labelColor highlightWithLevel:0.33], 0.0,
+ labelColor, 0.5,
+ [labelColor shadowWithLevel:0.15], 1.0, nil];
+ [gradient drawInBezierPath:bg angle:90.0];
+ [gradient release];
+
+ //replace the shadow color of the highlighted item (the default is dark blue)
+ if([self isHighlighted]) {
+ NSMutableAttributedString *mas = [[self attributedStringValue] mutableCopy];
+ NSShadow *strShadow = [mas attribute:NSShadowAttributeName atIndex:0 effectiveRange:NULL];
+ if(strShadow) {
+ [strShadow setShadowColor:[labelColor shadowWithLevel:0.4]];
+ [self setAttributedStringValue:mas];
+ }
+ [mas release];
+ }
+
+ // Add a little border at the top half (technically this is an inner shadow)
+ CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+
+ NSShadow* shadow = [[NSShadow alloc] init];
+ [shadow setShadowColor:labelColor];
+ [shadow setShadowOffset: NSMakeSize(0.1, -1.2)];
+ [shadow setShadowBlurRadius: 1];
+
+ [NSGraphicsContext saveGraphicsState];
+ NSRectClip([bg bounds]);
+ CGContextSetShadowWithColor(context, CGSizeZero, 0, NULL);
+
+ CGContextSetAlpha(context, [[shadow shadowColor] alphaComponent]);
+ CGContextBeginTransparencyLayer(context, NULL);
+ {
+ [shadow set];
+
+ CGContextSetBlendMode(context, kCGBlendModeSourceOut);
+ CGContextBeginTransparencyLayer(context, NULL);
+
+ [[shadow shadowColor] setFill];
+ [bg fill];
+
+ CGContextEndTransparencyLayer(context);
+ }
+ CGContextEndTransparencyLayer(context);
+ [NSGraphicsContext restoreGraphicsState];
+
+ [shadow release];
+ }
+ }
+
+ [super drawWithFrame:cellFrame inView:controlView];
+}
+
+
/**
* Draws the actual cell, with a divider if appropriate.
*/
@@ -110,4 +185,16 @@
}
}
+- (void)dealloc
+{
+ [self setLabelColor:nil];
+
+ [super dealloc];
+}
+
@end
+
+BOOL isOSAtLeast10_10_0() {
+ const BOOL value = [SPOSInfo isOSVersionAtLeastMajor:10 minor:10 patch:0];
+ return value;
+}
diff --git a/Source/SPFavoritesOutlineView.h b/Source/SPFavoritesOutlineView.h
index 8a671f3c..2c3d475c 100644
--- a/Source/SPFavoritesOutlineView.h
+++ b/Source/SPFavoritesOutlineView.h
@@ -28,10 +28,11 @@
//
// More info at <https://github.com/sequelpro/sequelpro>
+#import "SPOSInfo.h"
+
@interface SPFavoritesOutlineView : NSOutlineView
{
- SInt32 systemVersion;
-
+ BOOL isOSVersionAtLeast10_7_0;
BOOL justGainedFocus;
}
diff --git a/Source/SPFavoritesOutlineView.m b/Source/SPFavoritesOutlineView.m
index 01eb7b04..2e111925 100644
--- a/Source/SPFavoritesOutlineView.m
+++ b/Source/SPFavoritesOutlineView.m
@@ -39,8 +39,7 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 6;
- (void)awakeFromNib
{
- systemVersion = 0;
- Gestalt(gestaltSystemVersion, &systemVersion);
+ isOSVersionAtLeast10_7_0 = [SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0];
}
- (BOOL)acceptsFirstResponder
@@ -129,7 +128,7 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 6;
NSRect superFrame = [super frameOfCellAtColumn:columnIndex row:rowIndex];
// On system versions lower than Lion, don't alter padding
- if (systemVersion < 0x1070) {
+ if (!isOSVersionAtLeast10_7_0) {
return superFrame;
}
@@ -159,7 +158,7 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 6;
}
// On versions of Lion or above, amend the padding appropriately
- if (systemVersion >= 0x1070) {
+ if (isOSVersionAtLeast10_7_0) {
return NSMakeRect(superFrame.origin.x + SPFavoritesOutlineViewUnindent, superFrame.origin.y, superFrame.size.width, superFrame.size.height);
}
diff --git a/Source/SPOSInfo.h b/Source/SPOSInfo.h
new file mode 100644
index 00000000..8b5bb65b
--- /dev/null
+++ b/Source/SPOSInfo.h
@@ -0,0 +1,50 @@
+//
+// SPOSInfo.h
+// sequel-pro
+//
+// Created by Max Lohrmann on 14.02.15.
+// Copyright (c) 2015 Max Lohrmann. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// More info at <https://github.com/sequelpro/sequelpro>
+
+#import <Foundation/Foundation.h>
+
+typedef struct {
+ NSInteger major;
+ NSInteger minor;
+ NSInteger patch;
+} SPOSVersion;
+
+/**
+ * Compare two OS versions similar to strcmp()
+ * @param left One operand
+ * @param right The other operand
+ * @return A negative value if left < right, 0 is both are equal, a postive value if left > right
+ */
+int SPOSVersionCompare(SPOSVersion left, SPOSVersion right);
+
+@interface SPOSInfo : NSObject
++ (SPOSVersion)osVersion;
++ (BOOL)isOSVersionAtLeastMajor:(NSInteger)major minor:(NSInteger)minor patch:(NSInteger)patch;
+@end
diff --git a/Source/SPOSInfo.m b/Source/SPOSInfo.m
new file mode 100644
index 00000000..8d91c067
--- /dev/null
+++ b/Source/SPOSInfo.m
@@ -0,0 +1,94 @@
+//
+// SPOSInfo.m
+// sequel-pro
+//
+// Created by Max Lohrmann on 14.02.15.
+// Copyright (c) 2015 Max Lohrmann. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// More info at <https://github.com/sequelpro/sequelpro>
+
+#import "SPOSInfo.h"
+
+#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_10
+// This code is available since 10.8 but public only since 10.10
+typedef struct {
+ NSInteger majorVersion;
+ NSInteger minorVersion;
+ NSInteger patchVersion;
+} NSOperatingSystemVersion;
+
+@interface NSProcessInfo ()
+- (NSOperatingSystemVersion)operatingSystemVersion;
+- (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version;
+@end
+
+#endif
+
+int SPOSVersionCompare(SPOSVersion left, SPOSVersion right)
+{
+ if(left.major != right.major) return (left.major < right.major)? -1 : 1;
+ if(left.minor != right.minor) return (left.minor < right.minor)? -1 : 1;
+ if(left.patch != right.patch) return (left.patch < right.patch)? -1 : 1;
+ return 0;
+}
+
+@implementation SPOSInfo
+
++ (SPOSVersion)osVersion
+{
+ NSProcessInfo *procInfo = [NSProcessInfo processInfo];
+ if([procInfo respondsToSelector:@selector(operatingSystemVersion)]) {
+ NSOperatingSystemVersion nsVer = [procInfo operatingSystemVersion];
+ //structs cannot be casted per C standard
+ SPOSVersion spVer = {nsVer.majorVersion,nsVer.minorVersion,nsVer.patchVersion};
+ return spVer;
+ }
+ else {
+ SInt32 versionMajor = 0;
+ SInt32 versionMinor = 0;
+ SInt32 versionPatch = 0;
+ Gestalt(gestaltSystemVersionMajor, &versionMajor);
+ Gestalt(gestaltSystemVersionMinor, &versionMinor);
+ Gestalt(gestaltSystemVersionBugFix, &versionPatch);
+
+ SPOSVersion spVer = {versionMajor,versionMinor,versionPatch};
+ return spVer;
+ }
+}
+
++ (BOOL)isOSVersionAtLeastMajor:(NSInteger)major minor:(NSInteger)minor patch:(NSInteger)patch
+{
+ NSProcessInfo *procInfo = [NSProcessInfo processInfo];
+ if([procInfo respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)]) {
+ NSOperatingSystemVersion nsVer = {major,minor,patch};
+ return [procInfo isOperatingSystemAtLeastVersion:nsVer];
+ }
+ else {
+ SPOSVersion runningVersion = [self osVersion];
+ SPOSVersion referenceVersion = {major, minor, patch};
+ return (SPOSVersionCompare(runningVersion, referenceVersion) >= 0);
+ }
+}
+
+@end
diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m
index 3b58d331..e09d0ce2 100644
--- a/Source/SPSSHTunnel.m
+++ b/Source/SPSSHTunnel.m
@@ -35,6 +35,7 @@
#import "SPKeychain.h"
#import "SPAlertSheets.h"
#import "SPThreadAdditions.h"
+#import "SPOSInfo.h"
#import <netinet/in.h>
#import <CommonCrypto/CommonDigest.h>
@@ -55,8 +56,7 @@
if (!theHost || !targetPort || !targetHost) return nil;
if ((self = [super init])) {
- SInt32 systemVersion = 0;
- Gestalt(gestaltSystemVersion, &systemVersion);
+ BOOL isOSVersionAtLeast10_7_0 = [SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0];
// Store the connection settings as appropriate
sshHost = [[NSString alloc] initWithString:theHost];
@@ -74,7 +74,7 @@
// Enable connection muxing on 10.7+, but only if a preference is enabled; this is because
// muxing causes connection instability for a large number of users (see Issue #1457)
- connectionMuxingEnabled = (systemVersion >= 0x1070) && [[NSUserDefaults standardUserDefaults] boolForKey:SPSSHEnableMuxingPreference];
+ connectionMuxingEnabled = isOSVersionAtLeast10_7_0 && [[NSUserDefaults standardUserDefaults] boolForKey:SPSSHEnableMuxingPreference];
// Set up a connection for use by the tunnel process
tunnelConnectionName = [[NSString alloc] initWithFormat:@"SequelPro-%lu", (unsigned long)[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]];
diff --git a/Source/SPWindowController.h b/Source/SPWindowController.h
index 8697e738..c99a2ff2 100644
--- a/Source/SPWindowController.h
+++ b/Source/SPWindowController.h
@@ -37,7 +37,7 @@
IBOutlet NSTabView *tabView;
NSClipView *titleBarLineHidingView;
- SInt32 systemVersion;
+ BOOL isOSVersionAtLeast10_7_0;
NSMenuItem *closeWindowMenuItem;
NSMenuItem *closeTabMenuItem;
diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m
index 58afeb16..db94f5ce 100644
--- a/Source/SPWindowController.m
+++ b/Source/SPWindowController.m
@@ -63,11 +63,8 @@ enum {
- (void)awakeFromNib
{
- systemVersion = 0;
selectedTableDocument = nil;
- Gestalt(gestaltSystemVersion, &systemVersion);
-
[[self window] setCollectionBehavior:[[self window] collectionBehavior] | NSWindowCollectionBehaviorFullScreenPrimary];
// Add a line to the window to hide the line below the title bar when the toolbar is collapsed
@@ -517,10 +514,10 @@ enum {
{
// Set the background colour to match the titlebar window state
if ((([[self window] isMainWindow] || [[[self window] attachedSheet] isMainWindow]) && [NSApp isActive])) {
- [titleBarLineHidingView setBackgroundColor:[NSColor colorWithCalibratedWhite:(systemVersion >= 0x1070) ? 0.66f : 0.63f alpha:1.0]];
+ [titleBarLineHidingView setBackgroundColor:[NSColor colorWithCalibratedWhite:(isOSVersionAtLeast10_7_0) ? 0.66f : 0.63f alpha:1.0]];
}
else {
- [titleBarLineHidingView setBackgroundColor:[NSColor colorWithCalibratedWhite:(systemVersion >= 0x1070) ? 0.87f : 0.84f alpha:1.0]];
+ [titleBarLineHidingView setBackgroundColor:[NSColor colorWithCalibratedWhite:(isOSVersionAtLeast10_7_0) ? 0.87f : 0.84f alpha:1.0]];
}
// If the window is fullscreen or the toolbar is showing, hide the view; otherwise show it