VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIVersion.cpp@ 103977

Last change on this file since 103977 was 103793, checked in by vboxsync, 9 months ago

FE/Qt: UICommon: Move versioning related functionality to UIVersion / UIVersionInfo; Rework user cases accordingly.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/* $Id: UIVersion.cpp 103793 2024-03-11 19:17:31Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVersion class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 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
52UIVersion::UIVersion()
53 : m_x(-1)
54 , m_y(-1)
55 , m_z(-1)
56{
57}
58
59UIVersion::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
79bool UIVersion::isValid() const
80{
81 return (m_x != -1)
82 && (m_y != -1)
83 && (m_z != -1);
84}
85
86bool 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
94bool UIVersion::operator<(const UIVersion &other) const
95{
96 return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) < 0;
97}
98
99bool UIVersion::operator<=(const UIVersion &other) const
100{
101 return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) <= 0;
102}
103
104bool UIVersion::operator>(const UIVersion &other) const
105{
106 return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) > 0;
107}
108
109bool UIVersion::operator>=(const UIVersion &other) const
110{
111 return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) >= 0;
112}
113
114QString 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
120UIVersion 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 */
146QString UIVersionInfo::s_strBrandingConfigFilePath = QString();
147
148/* static */
149QString UIVersionInfo::qtRTVersionString()
150{
151 return QString::fromLatin1(qVersion());
152}
153
154/* static */
155uint 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 */
164uint UIVersionInfo::qtRTMajorVersion()
165{
166 return qtRTVersionString().section('.', 0, 0).toInt();
167}
168
169/* static */
170uint UIVersionInfo::qtRTMinorVersion()
171{
172 return qtRTVersionString().section('.', 1, 1).toInt();
173}
174
175/* static */
176uint UIVersionInfo::qtRTRevisionNumber()
177{
178 return qtRTVersionString().section('.', 2, 2).toInt();
179}
180
181/* static */
182QString UIVersionInfo::qtCTVersionString()
183{
184 return QString::fromLatin1(QT_VERSION_STR);
185}
186
187/* static */
188uint 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 */
197QString UIVersionInfo::vboxVersionString()
198{
199 const CVirtualBox comVBox = gpGlobalSession->virtualBox();
200 return comVBox.GetVersion();
201}
202
203/* static */
204QString UIVersionInfo::vboxVersionStringNormalized()
205{
206 const CVirtualBox comVBox = gpGlobalSession->virtualBox();
207 return comVBox.GetVersionNormalized();
208}
209
210/* static */
211bool UIVersionInfo::isBeta()
212{
213 return vboxVersionString().contains(QRegularExpression("BETA|ALPHA", QRegularExpression::CaseInsensitiveOption));
214}
215
216/* static */
217bool UIVersionInfo::showBetaLabel()
218{
219 return isBeta()
220 && !gEDataManager->preventBetaBuildLavel();
221}
222
223/* static */
224bool 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 */
239QString UIVersionInfo::brandingGetKey(QString strKey)
240{
241 QSettings settings(s_strBrandingConfigFilePath, QSettings::IniFormat);
242 return settings.value(QString("%1").arg(strKey)).toString();
243}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette