From fa28b26e418f6f5c2f47ec78f9b7ef4910155b96 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 14 Feb 2015 21:45:08 +0100 Subject: Move some duplicate code into a new class (This also affects PSMSequelProTabStyle, but see the comment there why it is left unchanged) --- Source/SPFavoritesOutlineView.h | 5 +- Source/SPFavoritesOutlineView.m | 7 ++- Source/SPOSInfo.h | 50 +++++++++++++++++++ Source/SPOSInfo.m | 94 ++++++++++++++++++++++++++++++++++++ Source/SPSSHTunnel.m | 6 +-- Source/SPWindowController.h | 2 +- Source/SPWindowController.m | 7 +-- sequel-pro.xcodeproj/project.pbxproj | 6 +++ 8 files changed, 162 insertions(+), 15 deletions(-) create mode 100644 Source/SPOSInfo.h create mode 100644 Source/SPOSInfo.m 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 +#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 + +#import + +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 + +#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 #import @@ -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 diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 41e05352..86377750 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -188,6 +188,7 @@ 50D3C35D1A77217800B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; }; 50E217B318174246009D3580 /* SPColorSelectorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E217B218174246009D3580 /* SPColorSelectorView.m */; }; 50E217B618174280009D3580 /* SPFavoriteColorSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E217B518174280009D3580 /* SPFavoriteColorSupport.m */; }; + 50EAB5B81A8FBB08008F627A /* SPOSInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EAB5B71A8FBB08008F627A /* SPOSInfo.m */; }; 5806B76411A991EC00813A88 /* SPDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5806B76311A991EC00813A88 /* SPDocumentController.m */; }; 580E8DB711EA774B000D8427 /* SequelProTabClose_Pressed.png in Resources */ = {isa = PBXBuildFile; fileRef = 580E8DAB11EA772C000D8427 /* SequelProTabClose_Pressed.png */; }; 580E8DB811EA774B000D8427 /* SequelProTabClose_Rollover.png in Resources */ = {isa = PBXBuildFile; fileRef = 580E8DAC11EA772C000D8427 /* SequelProTabClose_Rollover.png */; }; @@ -899,6 +900,8 @@ 50E217B218174246009D3580 /* SPColorSelectorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPColorSelectorView.m; sourceTree = ""; }; 50E217B418174280009D3580 /* SPFavoriteColorSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoriteColorSupport.h; sourceTree = ""; }; 50E217B518174280009D3580 /* SPFavoriteColorSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFavoriteColorSupport.m; sourceTree = ""; }; + 50EAB5B61A8FBB08008F627A /* SPOSInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPOSInfo.h; sourceTree = ""; }; + 50EAB5B71A8FBB08008F627A /* SPOSInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPOSInfo.m; sourceTree = ""; }; 5806B76211A991EC00813A88 /* SPDocumentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDocumentController.h; sourceTree = ""; }; 5806B76311A991EC00813A88 /* SPDocumentController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDocumentController.m; sourceTree = ""; }; 580E8DAB11EA772C000D8427 /* SequelProTabClose_Pressed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = SequelProTabClose_Pressed.png; sourceTree = ""; }; @@ -2535,6 +2538,8 @@ 50E217B518174280009D3580 /* SPFavoriteColorSupport.m */, 58DA8861103E15B5000B98DF /* SPLogger.h */, 58DA8862103E15B5000B98DF /* SPLogger.m */, + 50EAB5B61A8FBB08008F627A /* SPOSInfo.h */, + 50EAB5B71A8FBB08008F627A /* SPOSInfo.m */, ); name = "Debugging & Support"; sourceTree = ""; @@ -3171,6 +3176,7 @@ BCA6271C1031B9D40047E5D5 /* SPTooltip.m in Sources */, 58DA8863103E15B5000B98DF /* SPLogger.m in Sources */, BC01BCCF104024BE006BDEE7 /* SPEncodingPopupAccessory.m in Sources */, + 50EAB5B81A8FBB08008F627A /* SPOSInfo.m in Sources */, 173C4366104455E0001F3A30 /* SPQueryFavoriteManager.m in Sources */, 173C44D81044A6B0001F3A30 /* SPOutlineView.m in Sources */, 17F5B1511048C4E400FC794F /* SPCSVExporter.m in Sources */, -- cgit v1.2.3