diff options
author | Max <post@wickenrode.com> | 2015-02-14 21:45:08 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-02-14 21:45:08 +0100 |
commit | fa28b26e418f6f5c2f47ec78f9b7ef4910155b96 (patch) | |
tree | fae4e9fd8b58e88fc89566bd15a5ddc4cf6396c4 /Source | |
parent | b1e32f6583f113c279dcde61f4f531d637118bdd (diff) | |
download | sequelpro-fa28b26e418f6f5c2f47ec78f9b7ef4910155b96.tar.gz sequelpro-fa28b26e418f6f5c2f47ec78f9b7ef4910155b96.tar.bz2 sequelpro-fa28b26e418f6f5c2f47ec78f9b7ef4910155b96.zip |
Move some duplicate code into a new class
(This also affects PSMSequelProTabStyle, but see the comment there why it is left unchanged)
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPFavoritesOutlineView.h | 5 | ||||
-rw-r--r-- | Source/SPFavoritesOutlineView.m | 7 | ||||
-rw-r--r-- | Source/SPOSInfo.h | 50 | ||||
-rw-r--r-- | Source/SPOSInfo.m | 94 | ||||
-rw-r--r-- | Source/SPSSHTunnel.m | 6 | ||||
-rw-r--r-- | Source/SPWindowController.h | 2 | ||||
-rw-r--r-- | Source/SPWindowController.m | 7 |
7 files changed, 156 insertions, 15 deletions
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..5608e4cf --- /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 major; + NSInteger minor; + NSInteger patch; +} 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 |