1 | /* $Id: UIVersion.cpp 78655 2019-05-22 10:55:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVersion class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QStringList>
|
---|
20 |
|
---|
21 | /* GUI includes: */
|
---|
22 | #include "UIVersion.h"
|
---|
23 |
|
---|
24 | /* Other VBox includes: */
|
---|
25 | #include <iprt/string.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | UIVersion::UIVersion()
|
---|
29 | : m_x(-1)
|
---|
30 | , m_y(-1)
|
---|
31 | , m_z(-1)
|
---|
32 | {
|
---|
33 | }
|
---|
34 |
|
---|
35 | UIVersion::UIVersion(const QString &strFullVersionInfo)
|
---|
36 | : m_x(-1)
|
---|
37 | , m_y(-1)
|
---|
38 | , m_z(-1)
|
---|
39 | {
|
---|
40 | const QStringList fullVersionInfo = strFullVersionInfo.split('_');
|
---|
41 | if (fullVersionInfo.size() > 0)
|
---|
42 | {
|
---|
43 | const QStringList versionIndexes = fullVersionInfo.at(0).split('.');
|
---|
44 | if (versionIndexes.size() > 0)
|
---|
45 | m_x = versionIndexes[0].toInt();
|
---|
46 | if (versionIndexes.size() > 1)
|
---|
47 | m_y = versionIndexes[1].toInt();
|
---|
48 | if (versionIndexes.size() > 2)
|
---|
49 | m_z = versionIndexes[2].toInt();
|
---|
50 | }
|
---|
51 | if (fullVersionInfo.size() > 1)
|
---|
52 | m_strPostfix = fullVersionInfo.at(1);
|
---|
53 | }
|
---|
54 |
|
---|
55 | UIVersion &UIVersion::operator=(const UIVersion &another)
|
---|
56 | {
|
---|
57 | m_x = another.x();
|
---|
58 | m_y = another.y();
|
---|
59 | m_z = another.z();
|
---|
60 | m_strPostfix = another.postfix();
|
---|
61 | return *this;
|
---|
62 | }
|
---|
63 |
|
---|
64 | bool UIVersion::isValid() const
|
---|
65 | {
|
---|
66 | return (m_x != -1)
|
---|
67 | && (m_y != -1)
|
---|
68 | && (m_z != -1);
|
---|
69 | }
|
---|
70 |
|
---|
71 | bool UIVersion::equal(const UIVersion &other) const
|
---|
72 | {
|
---|
73 | return (m_x == other.m_x)
|
---|
74 | && (m_y == other.m_y)
|
---|
75 | && (m_z == other.m_z)
|
---|
76 | && (m_strPostfix == other.m_strPostfix);
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool UIVersion::operator<(const UIVersion &other) const
|
---|
80 | {
|
---|
81 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) < 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 | bool UIVersion::operator<=(const UIVersion &other) const
|
---|
85 | {
|
---|
86 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) <= 0;
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool UIVersion::operator>(const UIVersion &other) const
|
---|
90 | {
|
---|
91 | return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) > 0;
|
---|
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 | QString UIVersion::toString() const
|
---|
100 | {
|
---|
101 | return m_strPostfix.isEmpty() ? QString("%1.%2.%3").arg(m_x).arg(m_y).arg(m_z)
|
---|
102 | : QString("%1.%2.%3_%4").arg(m_x).arg(m_y).arg(m_z).arg(m_strPostfix);
|
---|
103 | }
|
---|
104 |
|
---|
105 | UIVersion UIVersion::effectiveReleasedVersion() const
|
---|
106 | {
|
---|
107 | /* First, we just copy the current one: */
|
---|
108 | UIVersion version = *this;
|
---|
109 |
|
---|
110 | /* If this version being developed: */
|
---|
111 | if (version.z() % 2 == 1)
|
---|
112 | {
|
---|
113 | /* If this version being developed on release branch (we guess the right one): */
|
---|
114 | if (version.z() < 97)
|
---|
115 | version.setZ(version.z() - 1);
|
---|
116 | /* If this version being developed on trunk (we use hardcoded one for now): */
|
---|
117 | else
|
---|
118 | version.setZ(8); /* Current .z for 6.0.z */
|
---|
119 | }
|
---|
120 |
|
---|
121 | /* Finally, we just return that we have: */
|
---|
122 | return version;
|
---|
123 | }
|
---|