1 | /* $Id: UIVersion.cpp 98103 2023-01-17 14:15:46Z 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 <QStringList>
|
---|
30 |
|
---|
31 | /* GUI includes: */
|
---|
32 | #include "UIVersion.h"
|
---|
33 |
|
---|
34 | /* Other VBox includes: */
|
---|
35 | #include <iprt/string.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | UIVersion::UIVersion()
|
---|
39 | : m_x(-1)
|
---|
40 | , m_y(-1)
|
---|
41 | , m_z(-1)
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | UIVersion::UIVersion(const QString &strFullVersionInfo)
|
---|
46 | : m_x(-1)
|
---|
47 | , m_y(-1)
|
---|
48 | , m_z(-1)
|
---|
49 | {
|
---|
50 | const QStringList fullVersionInfo = strFullVersionInfo.split('_');
|
---|
51 | if (fullVersionInfo.size() > 0)
|
---|
52 | {
|
---|
53 | const QStringList versionIndexes = fullVersionInfo.at(0).split('.');
|
---|
54 | if (versionIndexes.size() > 0)
|
---|
55 | m_x = versionIndexes[0].toInt();
|
---|
56 | if (versionIndexes.size() > 1)
|
---|
57 | m_y = versionIndexes[1].toInt();
|
---|
58 | if (versionIndexes.size() > 2)
|
---|
59 | m_z = versionIndexes[2].toInt();
|
---|
60 | }
|
---|
61 | if (fullVersionInfo.size() > 1)
|
---|
62 | m_strPostfix = fullVersionInfo.at(1);
|
---|
63 | }
|
---|
64 |
|
---|
65 | bool UIVersion::isValid() const
|
---|
66 | {
|
---|
67 | return (m_x != -1)
|
---|
68 | && (m_y != -1)
|
---|
69 | && (m_z != -1);
|
---|
70 | }
|
---|
71 |
|
---|
72 | bool UIVersion::equal(const UIVersion &other) const
|
---|
73 | {
|
---|
74 | return (m_x == other.m_x)
|
---|
75 | && (m_y == other.m_y)
|
---|
76 | && (m_z == other.m_z)
|
---|
77 | && (m_strPostfix == other.m_strPostfix);
|
---|
78 | }
|
---|
79 |
|
---|
80 | bool UIVersion::operator<(const UIVersion &other) const
|
---|
81 | {
|
---|
82 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) < 0;
|
---|
83 | }
|
---|
84 |
|
---|
85 | bool UIVersion::operator<=(const UIVersion &other) const
|
---|
86 | {
|
---|
87 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) <= 0;
|
---|
88 | }
|
---|
89 |
|
---|
90 | bool UIVersion::operator>(const UIVersion &other) const
|
---|
91 | {
|
---|
92 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) > 0;
|
---|
93 | }
|
---|
94 |
|
---|
95 | bool UIVersion::operator>=(const UIVersion &other) const
|
---|
96 | {
|
---|
97 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) >= 0;
|
---|
98 | }
|
---|
99 |
|
---|
100 | QString UIVersion::toString() const
|
---|
101 | {
|
---|
102 | return m_strPostfix.isEmpty() ? QString("%1.%2.%3").arg(m_x).arg(m_y).arg(m_z)
|
---|
103 | : QString("%1.%2.%3_%4").arg(m_x).arg(m_y).arg(m_z).arg(m_strPostfix);
|
---|
104 | }
|
---|
105 |
|
---|
106 | UIVersion UIVersion::effectiveReleasedVersion() const
|
---|
107 | {
|
---|
108 | /* First, we just copy the current one: */
|
---|
109 | UIVersion version = *this;
|
---|
110 |
|
---|
111 | /* If this version being developed: */
|
---|
112 | if (version.z() % 2 == 1)
|
---|
113 | {
|
---|
114 | /* If this version being developed on release branch (we guess the right one): */
|
---|
115 | if (version.z() < 97)
|
---|
116 | version.setZ(version.z() - 1);
|
---|
117 | /* If this version being developed on trunk (we use hardcoded one for now): */
|
---|
118 | else
|
---|
119 | version.setZ(8); /* Current .z for 6.0.z */
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* Finally, we just return that we have: */
|
---|
123 | return version;
|
---|
124 | }
|
---|