diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 34 | ||||
-rw-r--r-- | src/corelib/global/qsysinfo.h | 1 | ||||
-rw-r--r-- | src/corelib/kernel/kernel.pri | 24 | ||||
-rw-r--r-- | src/corelib/kernel/qcore_mac_objc.mm | 67 | ||||
-rw-r--r-- | src/corelib/kernel/qcore_mac_p.h | 8 | ||||
-rw-r--r-- | src/tools/bootstrap/bootstrap.pro | 12 |
6 files changed, 80 insertions, 66 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index f526387eb4..c15cee1e3b 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1854,16 +1854,14 @@ Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) { QSysInfo::MacVersion QSysInfo::macVersion() { + const QAppleOperatingSystemVersion version = qt_apple_os_version(); // qtcore_mac_objc.mm #if defined(Q_OS_OSX) - SInt32 gestalt_version; - if (Gestalt(gestaltSystemVersionMinor, &gestalt_version) == noErr) { - // add 2 because OS X 10.0 is 0x02 in the enum - return QSysInfo::MacVersion(gestalt_version + 2); - } + return QSysInfo::MacVersion(Q_MV_OSX(version.major, version.minor)); #elif defined(Q_OS_IOS) - return qt_ios_version(); // qtcore_mac_objc.mm -#endif + return QSysInfo::MacVersion(Q_MV_IOS(version.major, version.minor)); +#else return QSysInfo::MV_Unknown; +#endif } const QSysInfo::MacVersion QSysInfo::MacintoshVersion = QSysInfo::macVersion(); @@ -2502,25 +2500,9 @@ QString QSysInfo::productType() */ QString QSysInfo::productVersion() { -#if defined(Q_OS_IOS) - int major = (int(MacintoshVersion) >> 4) & 0xf; - int minor = int(MacintoshVersion) & 0xf; - if (Q_LIKELY(major < 10 && minor < 10)) { - char buf[4] = { char(major + '0'), '.', char(minor + '0'), '\0' }; - return QString::fromLatin1(buf, 3); - } - return QString::number(major) + QLatin1Char('.') + QString::number(minor); -#elif defined(Q_OS_OSX) - int minor = int(MacintoshVersion) - 2; // we're not running on Mac OS 9 - Q_ASSERT(minor < 100); - char buf[] = "10.0\0"; - if (Q_LIKELY(minor < 10)) { - buf[3] += minor; - } else { - buf[3] += minor / 10; - buf[4] = '0' + minor % 10; - } - return QString::fromLatin1(buf); +#if defined(Q_OS_MAC) + const QAppleOperatingSystemVersion version = qt_apple_os_version(); + return QString::number(version.major) + QLatin1Char('.') + QString::number(version.minor); #elif defined(Q_OS_WIN) const char *version = winVer_helper(); if (version) diff --git a/src/corelib/global/qsysinfo.h b/src/corelib/global/qsysinfo.h index 3a443938f9..d4b9072e93 100644 --- a/src/corelib/global/qsysinfo.h +++ b/src/corelib/global/qsysinfo.h @@ -120,6 +120,7 @@ public: #endif #ifdef Q_OS_MAC +# define Q_MV_OSX(major, minor) (major == 10 ? minor + 2 : (major == 9 ? 1 : 0)) # define Q_MV_IOS(major, minor) (QSysInfo::MV_IOS | major << 4 | minor) enum MacVersion { MV_Unknown = 0x0000, diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index 819c10e99f..3324d20dae 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -99,20 +99,22 @@ winrt { } mac { + HEADERS += \ + kernel/qcore_mac_p.h + SOURCES += \ - kernel/qcoreapplication_mac.cpp -} + kernel/qcoreapplication_mac.cpp \ + kernel/qcore_mac.cpp + + OBJECTIVE_SOURCES += \ + kernel/qcore_mac_objc.mm + + LIBS_PRIVATE += -framework Foundation -mac:!nacl { - HEADERS += \ - kernel/qcore_mac_p.h - SOURCES += \ - kernel/qcore_mac.cpp - OBJECTIVE_SOURCES += \ - kernel/qcore_mac_objc.mm + osx: LIBS_PRIVATE += -framework CoreServices - # We need UIKit for UIDevice - ios: LIBS_PRIVATE += -framework UIKit + # We need UIKit for UIDevice + ios: LIBS_PRIVATE += -framework UIKit } nacl { diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 73f8296021..8ac062a154 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -1,6 +1,7 @@ /**************************************************************************** ** - ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). + ** Copyright (C) 2014 Petroules Corporation. ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -47,6 +48,8 @@ QT_BEGIN_NAMESPACE +typedef qint16 (*GestaltFunction)(quint32 selector, qint32 *response); + NSString *QCFString::toNSString(const QString &string) { // The const cast below is safe: CfStringRef is immutable and so is NSString. @@ -58,31 +61,49 @@ QString QCFString::toQString(const NSString *nsstr) return toQString(reinterpret_cast<CFStringRef>(nsstr)); } -#ifdef Q_OS_IOS -QSysInfo::MacVersion qt_ios_version() +QAppleOperatingSystemVersion qt_apple_os_version() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - int major = 0, minor = 0; - NSArray *components = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; - switch ([components count]) { - case 3: - // We don't care about the patch version - case 2: - minor = [[components objectAtIndex:1] intValue]; - // fall through - case 1: - major = [[components objectAtIndex:0] intValue]; - break; - default: - Q_UNREACHABLE(); + QAppleOperatingSystemVersion v = {0, 0, 0}; +#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_8_0) + if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) { + NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion; + v.major = osv.majorVersion; + v.minor = osv.minorVersion; + v.patch = osv.patchVersion; + return v; } - - [pool release]; - - return QSysInfo::MacVersion(Q_MV_IOS(major, minor)); -} #endif + // Use temporary variables so we can return 0.0.0 (unknown version) + // in case of an error partway through determining the OS version + qint32 major = 0, minor = 0, patch = 0; +#if defined(Q_OS_IOS) + @autoreleasepool { + NSArray *parts = [UIDevice.currentDevice.systemVersion componentsSeparatedByString:@"."]; + major = parts.count > 0 ? [[parts objectAtIndex:0] intValue] : 0; + minor = parts.count > 1 ? [[parts objectAtIndex:1] intValue] : 0; + patch = parts.count > 2 ? [[parts objectAtIndex:2] intValue] : 0; + } +#elif defined(Q_OS_OSX) + static GestaltFunction pGestalt = 0; + if (!pGestalt) { + CFBundleRef b = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.CoreServices")); + pGestalt = reinterpret_cast<GestaltFunction>(CFBundleGetFunctionPointerForName(b, + CFSTR("Gestalt"))); + } + if (!pGestalt) + return v; + if (pGestalt('sys1', &major) != 0) + return v; + if (pGestalt('sys2', &minor) != 0) + return v; + if (pGestalt('sys3', &patch) != 0) + return v; +#endif + v.major = major; + v.minor = minor; + v.patch = patch; + return v; +} QT_END_NAMESPACE diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index e92a2d2978..4df300e72f 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -143,9 +143,11 @@ private: QString string; }; -#ifdef Q_OS_IOS -QSysInfo::MacVersion qt_ios_version(); -#endif +typedef struct { + int major, minor, patch; +} QAppleOperatingSystemVersion; + +QAppleOperatingSystemVersion qt_apple_os_version(); QT_END_NAMESPACE diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro index 2b58bff8f3..3924ecfa7f 100644 --- a/src/tools/bootstrap/bootstrap.pro +++ b/src/tools/bootstrap/bootstrap.pro @@ -130,9 +130,15 @@ win32:SOURCES += ../../corelib/io/qfilesystemengine_win.cpp \ ../../corelib/plugin/qsystemlibrary.cpp \ mac { - SOURCES += ../../corelib/kernel/qcoreapplication_mac.cpp \ - ../../corelib/kernel/qcore_mac.cpp - LIBS += -framework CoreServices + SOURCES += \ + ../../corelib/kernel/qcoreapplication_mac.cpp \ + ../../corelib/kernel/qcore_mac.cpp + OBJECTIVE_SOURCES += \ + ../../corelib/kernel/qcore_mac_objc.mm + + LIBS += -framework Foundation + osx: LIBS_PRIVATE += -framework CoreServices + ios: LIBS_PRIVATE += -framework UIKit } macx { |