@@ -54,11 +54,7 @@ static const bool testing = false;
5454UpgradeCheck::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 ();
0 commit comments