| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include <QtCore/qglobal.h> |
| 41 | |
| 42 | #ifndef QOPERATINGSYSTEMVERSION_H |
| 43 | #define QOPERATINGSYSTEMVERSION_H |
| 44 | |
| 45 | QT_BEGIN_NAMESPACE |
| 46 | |
| 47 | class QString; |
| 48 | class QVersionNumber; |
| 49 | |
| 50 | class Q_CORE_EXPORT QOperatingSystemVersion |
| 51 | { |
| 52 | public: |
| 53 | enum OSType { |
| 54 | Unknown = 0, |
| 55 | Windows, |
| 56 | MacOS, |
| 57 | IOS, |
| 58 | TvOS, |
| 59 | WatchOS, |
| 60 | Android |
| 61 | }; |
| 62 | |
| 63 | static const QOperatingSystemVersion Windows7; |
| 64 | static const QOperatingSystemVersion Windows8; |
| 65 | static const QOperatingSystemVersion Windows8_1; |
| 66 | static const QOperatingSystemVersion Windows10; |
| 67 | |
| 68 | static const QOperatingSystemVersion OSXMavericks; |
| 69 | static const QOperatingSystemVersion OSXYosemite; |
| 70 | static const QOperatingSystemVersion OSXElCapitan; |
| 71 | static const QOperatingSystemVersion MacOSSierra; |
| 72 | static const QOperatingSystemVersion MacOSHighSierra; |
| 73 | static const QOperatingSystemVersion MacOSMojave; |
| 74 | static const QOperatingSystemVersion MacOSCatalina; |
| 75 | static const QOperatingSystemVersion MacOSBigSur; |
| 76 | |
| 77 | static const QOperatingSystemVersion AndroidJellyBean; |
| 78 | static const QOperatingSystemVersion AndroidJellyBean_MR1; |
| 79 | static const QOperatingSystemVersion AndroidJellyBean_MR2; |
| 80 | static const QOperatingSystemVersion AndroidKitKat; |
| 81 | static const QOperatingSystemVersion AndroidLollipop; |
| 82 | static const QOperatingSystemVersion AndroidLollipop_MR1; |
| 83 | static const QOperatingSystemVersion AndroidMarshmallow; |
| 84 | static const QOperatingSystemVersion AndroidNougat; |
| 85 | static const QOperatingSystemVersion AndroidNougat_MR1; |
| 86 | static const QOperatingSystemVersion AndroidOreo; |
| 87 | |
| 88 | Q_DECL_CONSTEXPR QOperatingSystemVersion(OSType osType, |
| 89 | int vmajor, int vminor = -1, int vmicro = -1) |
| 90 | : m_os(osType), |
| 91 | m_major(qMax(a: -1, b: vmajor)), |
| 92 | m_minor(vmajor < 0 ? -1 : qMax(a: -1, b: vminor)), |
| 93 | m_micro(vmajor < 0 || vminor < 0 ? -1 : qMax(a: -1, b: vmicro)) |
| 94 | { } |
| 95 | |
| 96 | static QOperatingSystemVersion current(); |
| 97 | |
| 98 | static Q_DECL_CONSTEXPR OSType currentType() |
| 99 | { |
| 100 | #if defined(Q_OS_WIN) |
| 101 | return Windows; |
| 102 | #elif defined(Q_OS_MACOS) |
| 103 | return MacOS; |
| 104 | #elif defined(Q_OS_IOS) |
| 105 | return IOS; |
| 106 | #elif defined(Q_OS_TVOS) |
| 107 | return TvOS; |
| 108 | #elif defined(Q_OS_WATCHOS) |
| 109 | return WatchOS; |
| 110 | #elif defined(Q_OS_ANDROID) |
| 111 | return Android; |
| 112 | #else |
| 113 | return Unknown; |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | Q_DECL_CONSTEXPR int majorVersion() const { return m_major; } |
| 118 | Q_DECL_CONSTEXPR int minorVersion() const { return m_minor; } |
| 119 | Q_DECL_CONSTEXPR int microVersion() const { return m_micro; } |
| 120 | |
| 121 | Q_DECL_CONSTEXPR int segmentCount() const |
| 122 | { return m_micro >= 0 ? 3 : m_minor >= 0 ? 2 : m_major >= 0 ? 1 : 0; } |
| 123 | |
| 124 | bool isAnyOfType(std::initializer_list<OSType> types) const; |
| 125 | Q_DECL_CONSTEXPR OSType type() const { return m_os; } |
| 126 | QString name() const; |
| 127 | |
| 128 | friend bool operator>(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs) |
| 129 | { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(v1: lhs, v2: rhs) > 0; } |
| 130 | |
| 131 | friend bool operator>=(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs) |
| 132 | { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(v1: lhs, v2: rhs) >= 0; } |
| 133 | |
| 134 | friend bool operator<(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs) |
| 135 | { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(v1: lhs, v2: rhs) < 0; } |
| 136 | |
| 137 | friend bool operator<=(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs) |
| 138 | { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(v1: lhs, v2: rhs) <= 0; } |
| 139 | |
| 140 | private: |
| 141 | QOperatingSystemVersion() = default; |
| 142 | OSType m_os; |
| 143 | int m_major; |
| 144 | int m_minor; |
| 145 | int m_micro; |
| 146 | |
| 147 | static int compare(const QOperatingSystemVersion &v1, const QOperatingSystemVersion &v2); |
| 148 | }; |
| 149 | Q_DECLARE_TYPEINFO(QOperatingSystemVersion, QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ? Q_RELOCATABLE_TYPE : Q_PRIMITIVE_TYPE); |
| 150 | |
| 151 | #ifndef QT_NO_DEBUG_STREAM |
| 152 | class QDebug; |
| 153 | Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QOperatingSystemVersion &ov); |
| 154 | #endif |
| 155 | |
| 156 | QT_END_NAMESPACE |
| 157 | |
| 158 | #endif // QOPERATINGSYSTEMVERSION_H |
| 159 | |