1 | /* $Id: UIVersion.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVersion class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QDir>
|
---|
31 | #include <QFile>
|
---|
32 | #include <QRegularExpression>
|
---|
33 | #include <QSettings>
|
---|
34 | #include <QStringList>
|
---|
35 |
|
---|
36 | /* GUI includes: */
|
---|
37 | #include "UIExtraDataManager.h"
|
---|
38 | #include "UIGlobalSession.h"
|
---|
39 | #include "UIVersion.h"
|
---|
40 |
|
---|
41 | /* COM includes: */
|
---|
42 | #include "CVirtualBox.h"
|
---|
43 |
|
---|
44 | /* Other VBox includes: */
|
---|
45 | #include <iprt/string.h>
|
---|
46 |
|
---|
47 |
|
---|
48 | /*********************************************************************************************************************************
|
---|
49 | * Class UIVersion implementation. *
|
---|
50 | *********************************************************************************************************************************/
|
---|
51 |
|
---|
52 | UIVersion::UIVersion()
|
---|
53 | : m_x(-1)
|
---|
54 | , m_y(-1)
|
---|
55 | , m_z(-1)
|
---|
56 | {
|
---|
57 | }
|
---|
58 |
|
---|
59 | UIVersion::UIVersion(const QString &strFullVersionInfo)
|
---|
60 | : m_x(-1)
|
---|
61 | , m_y(-1)
|
---|
62 | , m_z(-1)
|
---|
63 | {
|
---|
64 | const QStringList fullVersionInfo = strFullVersionInfo.split('_');
|
---|
65 | if (fullVersionInfo.size() > 0)
|
---|
66 | {
|
---|
67 | const QStringList versionIndexes = fullVersionInfo.at(0).split('.');
|
---|
68 | if (versionIndexes.size() > 0)
|
---|
69 | m_x = versionIndexes[0].toInt();
|
---|
70 | if (versionIndexes.size() > 1)
|
---|
71 | m_y = versionIndexes[1].toInt();
|
---|
72 | if (versionIndexes.size() > 2)
|
---|
73 | m_z = versionIndexes[2].toInt();
|
---|
74 | }
|
---|
75 | if (fullVersionInfo.size() > 1)
|
---|
76 | m_strPostfix = fullVersionInfo.at(1);
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool UIVersion::isValid() const
|
---|
80 | {
|
---|
81 | return (m_x != -1)
|
---|
82 | && (m_y != -1)
|
---|
83 | && (m_z != -1);
|
---|
84 | }
|
---|
85 |
|
---|
86 | bool UIVersion::equal(const UIVersion &other) const
|
---|
87 | {
|
---|
88 | return (m_x == other.m_x)
|
---|
89 | && (m_y == other.m_y)
|
---|
90 | && (m_z == other.m_z)
|
---|
91 | && (m_strPostfix == other.m_strPostfix);
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool UIVersion::operator<(const UIVersion &other) const
|
---|
95 | {
|
---|
96 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) < 0;
|
---|
97 | }
|
---|
98 |
|
---|
99 | bool UIVersion::operator<=(const UIVersion &other) const
|
---|
100 | {
|
---|
101 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) <= 0;
|
---|
102 | }
|
---|
103 |
|
---|
104 | bool UIVersion::operator>(const UIVersion &other) const
|
---|
105 | {
|
---|
106 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) > 0;
|
---|
107 | }
|
---|
108 |
|
---|
109 | bool UIVersion::operator>=(const UIVersion &other) const
|
---|
110 | {
|
---|
111 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) >= 0;
|
---|
112 | }
|
---|
113 |
|
---|
114 | QString UIVersion::toString() const
|
---|
115 | {
|
---|
116 | return m_strPostfix.isEmpty() ? QString("%1.%2.%3").arg(m_x).arg(m_y).arg(m_z)
|
---|
117 | : QString("%1.%2.%3_%4").arg(m_x).arg(m_y).arg(m_z).arg(m_strPostfix);
|
---|
118 | }
|
---|
119 |
|
---|
120 | UIVersion UIVersion::effectiveReleasedVersion() const
|
---|
121 | {
|
---|
122 | /* First, we just copy the current one: */
|
---|
123 | UIVersion version = *this;
|
---|
124 |
|
---|
125 | /* If this version being developed: */
|
---|
126 | if (version.z() % 2 == 1)
|
---|
127 | {
|
---|
128 | /* If this version being developed on release branch (we guess the right one): */
|
---|
129 | if (version.z() < 97)
|
---|
130 | version.setZ(version.z() - 1);
|
---|
131 | /* If this version being developed on trunk (we use hardcoded one for now): */
|
---|
132 | else
|
---|
133 | version.setZ(8); /* Current .z for 6.0.z */
|
---|
134 | }
|
---|
135 |
|
---|
136 | /* Finally, we just return that we have: */
|
---|
137 | return version;
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | /*********************************************************************************************************************************
|
---|
142 | * Class UIVersionInfo implementation. *
|
---|
143 | *********************************************************************************************************************************/
|
---|
144 |
|
---|
145 | /* static */
|
---|
146 | QString UIVersionInfo::s_strBrandingConfigFilePath = QString();
|
---|
147 |
|
---|
148 | /* static */
|
---|
149 | QString UIVersionInfo::qtRTVersionString()
|
---|
150 | {
|
---|
151 | return QString::fromLatin1(qVersion());
|
---|
152 | }
|
---|
153 |
|
---|
154 | /* static */
|
---|
155 | uint UIVersionInfo::qtRTVersion()
|
---|
156 | {
|
---|
157 | const QString strVersionRT = qtRTVersionString();
|
---|
158 | return (strVersionRT.section('.', 0, 0).toInt() << 16) +
|
---|
159 | (strVersionRT.section('.', 1, 1).toInt() << 8) +
|
---|
160 | strVersionRT.section('.', 2, 2).toInt();
|
---|
161 | }
|
---|
162 |
|
---|
163 | /* static */
|
---|
164 | uint UIVersionInfo::qtRTMajorVersion()
|
---|
165 | {
|
---|
166 | return qtRTVersionString().section('.', 0, 0).toInt();
|
---|
167 | }
|
---|
168 |
|
---|
169 | /* static */
|
---|
170 | uint UIVersionInfo::qtRTMinorVersion()
|
---|
171 | {
|
---|
172 | return qtRTVersionString().section('.', 1, 1).toInt();
|
---|
173 | }
|
---|
174 |
|
---|
175 | /* static */
|
---|
176 | uint UIVersionInfo::qtRTRevisionNumber()
|
---|
177 | {
|
---|
178 | return qtRTVersionString().section('.', 2, 2).toInt();
|
---|
179 | }
|
---|
180 |
|
---|
181 | /* static */
|
---|
182 | QString UIVersionInfo::qtCTVersionString()
|
---|
183 | {
|
---|
184 | return QString::fromLatin1(QT_VERSION_STR);
|
---|
185 | }
|
---|
186 |
|
---|
187 | /* static */
|
---|
188 | uint UIVersionInfo::qtCTVersion()
|
---|
189 | {
|
---|
190 | const QString strVersionCompiled = qtCTVersionString();
|
---|
191 | return (strVersionCompiled.section('.', 0, 0).toInt() << 16)
|
---|
192 | + (strVersionCompiled.section('.', 1, 1).toInt() << 8)
|
---|
193 | + strVersionCompiled.section('.', 2, 2).toInt();
|
---|
194 | }
|
---|
195 |
|
---|
196 | /* static */
|
---|
197 | QString UIVersionInfo::vboxVersionString()
|
---|
198 | {
|
---|
199 | const CVirtualBox comVBox = gpGlobalSession->virtualBox();
|
---|
200 | return comVBox.GetVersion();
|
---|
201 | }
|
---|
202 |
|
---|
203 | /* static */
|
---|
204 | QString UIVersionInfo::vboxVersionStringNormalized()
|
---|
205 | {
|
---|
206 | const CVirtualBox comVBox = gpGlobalSession->virtualBox();
|
---|
207 | return comVBox.GetVersionNormalized();
|
---|
208 | }
|
---|
209 |
|
---|
210 | /* static */
|
---|
211 | bool UIVersionInfo::isBeta()
|
---|
212 | {
|
---|
213 | return vboxVersionString().contains(QRegularExpression("BETA|ALPHA", QRegularExpression::CaseInsensitiveOption));
|
---|
214 | }
|
---|
215 |
|
---|
216 | /* static */
|
---|
217 | bool UIVersionInfo::showBetaLabel()
|
---|
218 | {
|
---|
219 | return isBeta()
|
---|
220 | && !gEDataManager->preventBetaBuildLabel();
|
---|
221 | }
|
---|
222 |
|
---|
223 | /* static */
|
---|
224 | bool UIVersionInfo::brandingIsActive(bool fForce /* = false */)
|
---|
225 | {
|
---|
226 | if (fForce)
|
---|
227 | return true;
|
---|
228 |
|
---|
229 | if (s_strBrandingConfigFilePath.isEmpty())
|
---|
230 | {
|
---|
231 | s_strBrandingConfigFilePath = QDir(QApplication::applicationDirPath()).absolutePath();
|
---|
232 | s_strBrandingConfigFilePath += "/custom/custom.ini";
|
---|
233 | }
|
---|
234 |
|
---|
235 | return QFile::exists(s_strBrandingConfigFilePath);
|
---|
236 | }
|
---|
237 |
|
---|
238 | /* static */
|
---|
239 | QString UIVersionInfo::brandingGetKey(QString strKey)
|
---|
240 | {
|
---|
241 | QSettings settings(s_strBrandingConfigFilePath, QSettings::IniFormat);
|
---|
242 | return settings.value(QString("%1").arg(strKey)).toString();
|
---|
243 | }
|
---|