1 | /* $Id: UIUpdateDefs.cpp 79365 2019-06-26 15:57:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Update routine related implementations.
|
---|
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 <QCoreApplication>
|
---|
20 | #include <QStringList>
|
---|
21 |
|
---|
22 | /* GUI includes: */
|
---|
23 | #include "UICommon.h"
|
---|
24 | #include "UIUpdateDefs.h"
|
---|
25 |
|
---|
26 |
|
---|
27 | /* static: */
|
---|
28 | VBoxUpdateDayList VBoxUpdateData::m_dayList = VBoxUpdateDayList();
|
---|
29 |
|
---|
30 | /* static */
|
---|
31 | void VBoxUpdateData::populate()
|
---|
32 | {
|
---|
33 | /* Clear list initially: */
|
---|
34 | m_dayList.clear();
|
---|
35 |
|
---|
36 | // WORKAROUND:
|
---|
37 | // To avoid re-translation complexity
|
---|
38 | // all values will be retranslated separately.
|
---|
39 |
|
---|
40 | /* Separately retranslate each day: */
|
---|
41 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "1 day"), "1 d");
|
---|
42 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "2 days"), "2 d");
|
---|
43 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "3 days"), "3 d");
|
---|
44 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "4 days"), "4 d");
|
---|
45 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "5 days"), "5 d");
|
---|
46 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "6 days"), "6 d");
|
---|
47 |
|
---|
48 | /* Separately retranslate each week: */
|
---|
49 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "1 week"), "1 w");
|
---|
50 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "2 weeks"), "2 w");
|
---|
51 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "3 weeks"), "3 w");
|
---|
52 |
|
---|
53 | /* Separately retranslate each month: */
|
---|
54 | m_dayList << VBoxUpdateDay(QCoreApplication::translate("UIUpdateManager", "1 month"), "1 m");
|
---|
55 | }
|
---|
56 |
|
---|
57 | /* static */
|
---|
58 | QStringList VBoxUpdateData::list()
|
---|
59 | {
|
---|
60 | QStringList result;
|
---|
61 | for (int i = 0; i < m_dayList.size(); ++i)
|
---|
62 | result << m_dayList.at(i).val;
|
---|
63 | return result;
|
---|
64 | }
|
---|
65 |
|
---|
66 | VBoxUpdateData::VBoxUpdateData(const QString &strData)
|
---|
67 | : m_strData(strData)
|
---|
68 | , m_enmPeriodIndex(Period1Day)
|
---|
69 | , m_enmBranchIndex(BranchStable)
|
---|
70 | {
|
---|
71 | decode();
|
---|
72 | }
|
---|
73 |
|
---|
74 | VBoxUpdateData::VBoxUpdateData(PeriodType enmPeriodIndex, BranchType enmBranchIndex)
|
---|
75 | : m_strData(QString())
|
---|
76 | , m_enmPeriodIndex(enmPeriodIndex)
|
---|
77 | , m_enmBranchIndex(enmBranchIndex)
|
---|
78 | {
|
---|
79 | encode();
|
---|
80 | }
|
---|
81 |
|
---|
82 | bool VBoxUpdateData::isNoNeedToCheck() const
|
---|
83 | {
|
---|
84 | /* Return 'false' if Period == Never: */
|
---|
85 | return m_enmPeriodIndex == PeriodNever;
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool VBoxUpdateData::isNeedToCheck() const
|
---|
89 | {
|
---|
90 | /* Return 'false' if Period == Never: */
|
---|
91 | if (isNoNeedToCheck())
|
---|
92 | return false;
|
---|
93 |
|
---|
94 | /* Return 'true' if date of next check is today or missed: */
|
---|
95 | if (QDate::currentDate() >= m_date)
|
---|
96 | return true;
|
---|
97 |
|
---|
98 | /* Return 'true' if saved version value is NOT valid or NOT equal to current: */
|
---|
99 | if (!version().isValid() || version() != UIVersion(uiCommon().vboxVersionStringNormalized()))
|
---|
100 | return true;
|
---|
101 |
|
---|
102 | /* Return 'false' in all other cases: */
|
---|
103 | return false;
|
---|
104 | }
|
---|
105 |
|
---|
106 | QString VBoxUpdateData::data() const
|
---|
107 | {
|
---|
108 | return m_strData;
|
---|
109 | }
|
---|
110 |
|
---|
111 | VBoxUpdateData::PeriodType VBoxUpdateData::periodIndex() const
|
---|
112 | {
|
---|
113 | return m_enmPeriodIndex;
|
---|
114 | }
|
---|
115 |
|
---|
116 | QString VBoxUpdateData::date() const
|
---|
117 | {
|
---|
118 | return isNoNeedToCheck() ? QCoreApplication::translate("UIUpdateManager", "Never") : m_date.toString(Qt::LocaleDate);
|
---|
119 | }
|
---|
120 |
|
---|
121 | VBoxUpdateData::BranchType VBoxUpdateData::branchIndex() const
|
---|
122 | {
|
---|
123 | return m_enmBranchIndex;
|
---|
124 | }
|
---|
125 |
|
---|
126 | QString VBoxUpdateData::branchName() const
|
---|
127 | {
|
---|
128 | switch (m_enmBranchIndex)
|
---|
129 | {
|
---|
130 | case BranchStable:
|
---|
131 | return "stable";
|
---|
132 | case BranchAllRelease:
|
---|
133 | return "allrelease";
|
---|
134 | case BranchWithBetas:
|
---|
135 | return "withbetas";
|
---|
136 | }
|
---|
137 | return QString();
|
---|
138 | }
|
---|
139 |
|
---|
140 | UIVersion VBoxUpdateData::version() const
|
---|
141 | {
|
---|
142 | return m_version;
|
---|
143 | }
|
---|
144 |
|
---|
145 | void VBoxUpdateData::decode()
|
---|
146 | {
|
---|
147 | /* Parse standard values: */
|
---|
148 | if (m_strData == "never")
|
---|
149 | m_enmPeriodIndex = PeriodNever;
|
---|
150 | /* Parse other values: */
|
---|
151 | else
|
---|
152 | {
|
---|
153 | QStringList parser(m_strData.split(", ", QString::SkipEmptyParts));
|
---|
154 |
|
---|
155 | /* Parse 'period' value: */
|
---|
156 | if (parser.size() > 0)
|
---|
157 | {
|
---|
158 | if (m_dayList.isEmpty())
|
---|
159 | populate();
|
---|
160 | PeriodType index = (PeriodType)m_dayList.indexOf(VBoxUpdateDay(QString(), parser[0]));
|
---|
161 | m_enmPeriodIndex = index == PeriodUndefined ? Period1Day : index;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /* Parse 'date' value: */
|
---|
165 | if (parser.size() > 1)
|
---|
166 | {
|
---|
167 | QDate date = QDate::fromString(parser[1], Qt::ISODate);
|
---|
168 | m_date = date.isValid() ? date : QDate::currentDate();
|
---|
169 | }
|
---|
170 |
|
---|
171 | /* Parse 'branch' value: */
|
---|
172 | if (parser.size() > 2)
|
---|
173 | {
|
---|
174 | QString branch(parser[2]);
|
---|
175 | m_enmBranchIndex = branch == "withbetas" ? BranchWithBetas :
|
---|
176 | branch == "allrelease" ? BranchAllRelease : BranchStable;
|
---|
177 | }
|
---|
178 |
|
---|
179 | /* Parse 'version' value: */
|
---|
180 | if (parser.size() > 3)
|
---|
181 | {
|
---|
182 | m_version = UIVersion(parser[3]);
|
---|
183 | }
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | void VBoxUpdateData::encode()
|
---|
188 | {
|
---|
189 | /* Encode standard values: */
|
---|
190 | if (m_enmPeriodIndex == PeriodNever)
|
---|
191 | m_strData = "never";
|
---|
192 | /* Encode other values: */
|
---|
193 | else
|
---|
194 | {
|
---|
195 | /* Encode 'period' value: */
|
---|
196 | if (m_dayList.isEmpty())
|
---|
197 | populate();
|
---|
198 | QString remindPeriod = m_dayList[m_enmPeriodIndex].key;
|
---|
199 |
|
---|
200 | /* Encode 'date' value: */
|
---|
201 | m_date = QDate::currentDate();
|
---|
202 | QStringList parser(remindPeriod.split(' '));
|
---|
203 | if (parser[1] == "d")
|
---|
204 | m_date = m_date.addDays(parser[0].toInt());
|
---|
205 | else if (parser[1] == "w")
|
---|
206 | m_date = m_date.addDays(parser[0].toInt() * 7);
|
---|
207 | else if (parser[1] == "m")
|
---|
208 | m_date = m_date.addMonths(parser[0].toInt());
|
---|
209 | QString remindDate = m_date.toString(Qt::ISODate);
|
---|
210 |
|
---|
211 | /* Encode 'branch' value: */
|
---|
212 | QString branchValue = m_enmBranchIndex == BranchWithBetas ? "withbetas" :
|
---|
213 | m_enmBranchIndex == BranchAllRelease ? "allrelease" : "stable";
|
---|
214 |
|
---|
215 | /* Encode 'version' value: */
|
---|
216 | QString versionValue = UIVersion(uiCommon().vboxVersionStringNormalized()).toString();
|
---|
217 |
|
---|
218 | /* Composite m_strData: */
|
---|
219 | m_strData = QString("%1, %2, %3, %4").arg(remindPeriod, remindDate, branchValue, versionValue);
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|