Skip to content

Commit 2e19e87

Browse files
authored
update upgrade for Qt6 (#1410)
1. change upgrade url method to https. In the past this caused problems on windows (#580, #587). However, with Qt6 we are shipping plugins for native TLS libraries (windows SChannel, macos Secure Transport) as well as OpenSSL. Qt will fall back on the native plugin if required. 2. skip all the use count statistics if the user has disabled them, i.e. babelData_.reportStatistics_ is false. 3. implement clazy QString allocation optimizations. 4. delete redundant QDateTime constructor. 5. use default initializers. 6. delete obsolete manual redirection code. 7. delete unused variable.
1 parent a7cd1c9 commit 2e19e87

File tree

2 files changed

+41
-62
lines changed

2 files changed

+41
-62
lines changed

gui/upgrade.cc

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ static const bool testing = false;
5454
UpgradeCheck::UpgradeCheck(QWidget* parent, QList<Format>& formatList,
5555
BabelData& bd) :
5656
QObject(parent),
57-
manager_(nullptr),
58-
replyId_(nullptr),
59-
upgradeUrl_(QUrl("http://www.gpsbabel.org/upgrade_check.html")),
6057
formatList_(formatList),
61-
updateStatus_(updateUnknown),
6258
babelData_(bd)
6359
{
6460
}
@@ -120,32 +116,34 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(
120116
args += "&os=" + getOsName();
121117
args += "&cpu=" + getCpuArchitecture();
122118
args += "&os_ver=" + getOsVersion();
123-
args += QString("&beta_ok=%1").arg(static_cast<int>(allowBeta));
119+
args += QStringLiteral("&beta_ok=%1").arg(static_cast<int>(allowBeta));
124120
args += "&lang=" + QLocale::languageToString(locale.language());
125121
args += "&last_checkin=" + lastCheckTime.toString(Qt::ISODate);
126-
args += QString("&ugcb=%1").arg(babelData_.upgradeCallbacks_);
127-
args += QString("&ugdec=%1").arg(babelData_.upgradeDeclines_);
128-
args += QString("&ugacc=%1").arg(babelData_.upgradeAccept_);
129-
args += QString("&ugoff=%1").arg(babelData_.upgradeOffers_);
130-
args += QString("&ugerr=%1").arg(babelData_.upgradeErrors_);
131-
args += QString("&rc=%1").arg(babelData_.runCount_);
132-
133-
int j = 0;
134-
135-
for (int i = 0; i < formatList_.size(); i++) {
136-
int rc = formatList_[i].getReadUseCount();
137-
int wc = formatList_[i].getWriteUseCount();
138-
QString formatName = formatList_[i].getName();
139-
if (rc != 0) {
140-
args += QString("&uc%1=rd/%2/%3").arg(j++).arg(formatName).arg(rc);
122+
args += QStringLiteral("&ugcb=%1").arg(babelData_.upgradeCallbacks_);
123+
args += QStringLiteral("&ugdec=%1").arg(babelData_.upgradeDeclines_);
124+
args += QStringLiteral("&ugacc=%1").arg(babelData_.upgradeAccept_);
125+
args += QStringLiteral("&ugoff=%1").arg(babelData_.upgradeOffers_);
126+
args += QStringLiteral("&ugerr=%1").arg(babelData_.upgradeErrors_);
127+
args += QStringLiteral("&rc=%1").arg(babelData_.runCount_);
128+
129+
if (babelData_.reportStatistics_) {
130+
int j = 0;
131+
132+
for (int i = 0; i < formatList_.size(); i++) {
133+
int rc = formatList_[i].getReadUseCount();
134+
int wc = formatList_[i].getWriteUseCount();
135+
QString formatName = formatList_[i].getName();
136+
if (rc != 0) {
137+
args += QStringLiteral("&uc%1=rd/%2/%3").arg(j++).arg(formatName).arg(rc);
138+
}
139+
if (wc != 0) {
140+
args += QStringLiteral("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc);
141+
}
141142
}
142-
if (wc != 0) {
143-
args += QString("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc);
143+
if (j != 0) {
144+
args += QStringLiteral("&uc=%1").arg(j);
144145
}
145146
}
146-
if ((j != 0) && babelData_.reportStatistics_) {
147-
args += QString("&uc=%1").arg(j);
148-
}
149147

150148
if (false && testing) {
151149
qDebug() << "Posting " << args;
@@ -179,8 +177,8 @@ bool UpgradeCheck::suggestUpgrade(const QString& from, const QString& to)
179177
qsizetype fromIndex = 0;
180178
qsizetype toIndex = 0;
181179
#endif
182-
QVersionNumber fromVersion = QVersionNumber::fromString(from, &fromIndex);
183-
QVersionNumber toVersion = QVersionNumber::fromString(to, &toIndex);
180+
QVersionNumber fromVersion = QVersionNumber::fromString(from, &fromIndex);
181+
QVersionNumber toVersion = QVersionNumber::fromString(to, &toIndex);
184182

185183
// We don't have to handle every possible range because the server won't
186184
// have more than a version or two live at any time.
@@ -223,25 +221,7 @@ void UpgradeCheck::httpRequestFinished(QNetworkReply* reply)
223221
return;
224222
}
225223

226-
// New post 1.4.4: Allow redirects in case a proxy server or something
227-
// slightly rewrites the post.
228-
// Note that adding port 80 to the url will cause a redirect, which is useful for testing.
229-
// Also you use gpsbabel.org instead of www.gpsbabel.org to generate redirects.
230-
QVariant attributeValue = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
231-
if (!attributeValue.isNull() && attributeValue.isValid()) {
232-
QUrl redirectUrl = attributeValue.toUrl();
233-
if (redirectUrl.isValid()) {
234-
if (testing) {
235-
qDebug() << "redirect to " << redirectUrl.toString();
236-
}
237-
// Change the url for the next update check.
238-
// TODO: kick off another update check.
239-
upgradeUrl_ = redirectUrl;
240-
replyId_ = nullptr;
241-
reply->deleteLater();
242-
return;
243-
}
244-
}
224+
// redirection is handled by the Network Access API automatically.
245225

246226
QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
247227
if (testing) {
@@ -286,30 +266,30 @@ void UpgradeCheck::httpRequestFinished(QNetworkReply* reply)
286266
QString upgradeText;
287267

288268
if (testing) {
289-
currentVersion_ = "1.3.1"; // for testing
269+
currentVersion_ = QStringLiteral("1.3.1"); // for testing
290270
}
291271

292272
bool allowBeta = true; // TODO: come from prefs or current version...
293273

294-
QDomNodeList upgrades = document.elementsByTagName("update");
274+
QDomNodeList upgrades = document.elementsByTagName(QStringLiteral("update"));
295275
QUrl downloadUrl;
296276
updateStatus_ = updateCurrent; // Current until proven guilty.
297277

298278
for (int i = 0; i < upgrades.length(); i++) {
299279
QDomNode upgradeNode = upgrades.item(i);
300280
QDomElement upgrade = upgradeNode.toElement();
301-
QString updateVersion = upgrade.attribute("version");
302-
if (upgrade.attribute("downloadURL").isEmpty()) {
303-
downloadUrl = "https://www.gpsbabel.org/download.html";
281+
QString updateVersion = upgrade.attribute(QStringLiteral("version"));
282+
if (upgrade.attribute(QStringLiteral("downloadURL")).isEmpty()) {
283+
downloadUrl = QStringLiteral("https://www.gpsbabel.org/download.html");
304284
} else {
305-
downloadUrl = upgrade.attribute("downloadURL");
285+
downloadUrl = upgrade.attribute(QStringLiteral("downloadURL"));
306286
}
307-
bool updateIsBeta = upgrade.attribute("type") == "beta";
308-
bool updateIsMajor = upgrade.attribute("type") == "major";
309-
bool updateIsMinor = upgrade.attribute("type") == "minor";
287+
bool updateIsBeta = upgrade.attribute(QStringLiteral("type")) == "beta";
288+
bool updateIsMajor = upgrade.attribute(QStringLiteral("type")) == "major";
289+
bool updateIsMinor = upgrade.attribute(QStringLiteral("type")) == "minor";
310290

311291
bool updateCandidate = updateIsMajor || updateIsMinor || (updateIsBeta && allowBeta);
312-
upgradeText = upgrade.firstChildElement("overview").text();
292+
upgradeText = upgrade.firstChildElement(QStringLiteral("overview")).text();
313293

314294
// String compare, not a numeric one. Server will return "best first".
315295
if (suggestUpgrade(currentVersion_, updateVersion) && updateCandidate) {
@@ -348,7 +328,7 @@ void UpgradeCheck::httpRequestFinished(QNetworkReply* reply)
348328
}
349329
}
350330

351-
upgradeWarningTime_ = QDateTime(QDateTime::currentDateTime());
331+
upgradeWarningTime_ = QDateTime::currentDateTime();
352332

353333
for (int i = 0; i < formatList_.size(); i++) {
354334
formatList_[i].zeroUseCounts();

gui/upgrade.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ class UpgradeCheck : public QObject
5252

5353
private:
5454
QString currentVersion_;
55-
QNetworkAccessManager* manager_;
56-
QNetworkReply* replyId_;
57-
QUrl upgradeUrl_;
58-
QString latestVersion_;
55+
QNetworkAccessManager* manager_{nullptr};
56+
QNetworkReply* replyId_{nullptr};
57+
QUrl upgradeUrl_{QStringLiteral("https://www.gpsbabel.org/upgrade_check.html")};
5958
QDateTime upgradeWarningTime_; // invalid time if this object never issued.
6059
QList<Format>& formatList_;
61-
updateStatus updateStatus_;
60+
updateStatus updateStatus_{updateUnknown};
6261
BabelData& babelData_;
6362

6463
static QString getOsName();

0 commit comments

Comments
 (0)