Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update upgrade for Qt6 #1410

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 37 additions & 57 deletions gui/upgrade.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ static const bool testing = false;
UpgradeCheck::UpgradeCheck(QWidget* parent, QList<Format>& formatList,
BabelData& bd) :
QObject(parent),
manager_(nullptr),
replyId_(nullptr),
upgradeUrl_(QUrl("http://www.gpsbabel.org/upgrade_check.html")),
formatList_(formatList),
updateStatus_(updateUnknown),
babelData_(bd)
{
}
Expand Down Expand Up @@ -120,32 +116,34 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(
args += "&os=" + getOsName();
args += "&cpu=" + getCpuArchitecture();
args += "&os_ver=" + getOsVersion();
args += QString("&beta_ok=%1").arg(static_cast<int>(allowBeta));
args += QStringLiteral("&beta_ok=%1").arg(static_cast<int>(allowBeta));
args += "&lang=" + QLocale::languageToString(locale.language());
args += "&last_checkin=" + lastCheckTime.toString(Qt::ISODate);
args += QString("&ugcb=%1").arg(babelData_.upgradeCallbacks_);
args += QString("&ugdec=%1").arg(babelData_.upgradeDeclines_);
args += QString("&ugacc=%1").arg(babelData_.upgradeAccept_);
args += QString("&ugoff=%1").arg(babelData_.upgradeOffers_);
args += QString("&ugerr=%1").arg(babelData_.upgradeErrors_);
args += QString("&rc=%1").arg(babelData_.runCount_);

int j = 0;

for (int i = 0; i < formatList_.size(); i++) {
int rc = formatList_[i].getReadUseCount();
int wc = formatList_[i].getWriteUseCount();
QString formatName = formatList_[i].getName();
if (rc != 0) {
args += QString("&uc%1=rd/%2/%3").arg(j++).arg(formatName).arg(rc);
args += QStringLiteral("&ugcb=%1").arg(babelData_.upgradeCallbacks_);
args += QStringLiteral("&ugdec=%1").arg(babelData_.upgradeDeclines_);
args += QStringLiteral("&ugacc=%1").arg(babelData_.upgradeAccept_);
args += QStringLiteral("&ugoff=%1").arg(babelData_.upgradeOffers_);
args += QStringLiteral("&ugerr=%1").arg(babelData_.upgradeErrors_);
args += QStringLiteral("&rc=%1").arg(babelData_.runCount_);

if (babelData_.reportStatistics_) {
int j = 0;

for (int i = 0; i < formatList_.size(); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have any other reason to touch this, please consider:

for (const auto& entry : formatList_)
and them making the formatList[i] below into entry...and/or just moving rc and wc into the one place they seem to be used.

If you're tired of looking at this, that's OK, too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments. I have lost count of the number of times I have started to modernize the loops in the GUI. I think I will defer this for a more global solution for the GUI.

int rc = formatList_[i].getReadUseCount();
int wc = formatList_[i].getWriteUseCount();
QString formatName = formatList_[i].getName();
if (rc != 0) {
args += QStringLiteral("&uc%1=rd/%2/%3").arg(j++).arg(formatName).arg(rc);
}
if (wc != 0) {
args += QStringLiteral("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc);
}
}
if (wc != 0) {
args += QString("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc);
if (j != 0) {
args += QStringLiteral("&uc=%1").arg(j);
}
}
if ((j != 0) && babelData_.reportStatistics_) {
args += QString("&uc=%1").arg(j);
}

if (false && testing) {
qDebug() << "Posting " << args;
Expand Down Expand Up @@ -179,8 +177,8 @@ bool UpgradeCheck::suggestUpgrade(const QString& from, const QString& to)
qsizetype fromIndex = 0;
qsizetype toIndex = 0;
#endif
QVersionNumber fromVersion = QVersionNumber::fromString(from, &fromIndex);
QVersionNumber toVersion = QVersionNumber::fromString(to, &toIndex);
QVersionNumber fromVersion = QVersionNumber::fromString(from, &fromIndex);
QVersionNumber toVersion = QVersionNumber::fromString(to, &toIndex);

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

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

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

if (testing) {
currentVersion_ = "1.3.1"; // for testing
currentVersion_ = QStringLiteral("1.3.1"); // for testing
}

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

QDomNodeList upgrades = document.elementsByTagName("update");
QDomNodeList upgrades = document.elementsByTagName(QStringLiteral("update"));
QUrl downloadUrl;
updateStatus_ = updateCurrent; // Current until proven guilty.

for (int i = 0; i < upgrades.length(); i++) {
QDomNode upgradeNode = upgrades.item(i);
QDomElement upgrade = upgradeNode.toElement();
QString updateVersion = upgrade.attribute("version");
if (upgrade.attribute("downloadURL").isEmpty()) {
downloadUrl = "https://www.gpsbabel.org/download.html";
QString updateVersion = upgrade.attribute(QStringLiteral("version"));
if (upgrade.attribute(QStringLiteral("downloadURL")).isEmpty()) {
downloadUrl = QStringLiteral("https://www.gpsbabel.org/download.html");
} else {
downloadUrl = upgrade.attribute("downloadURL");
downloadUrl = upgrade.attribute(QStringLiteral("downloadURL"));
}
bool updateIsBeta = upgrade.attribute("type") == "beta";
bool updateIsMajor = upgrade.attribute("type") == "major";
bool updateIsMinor = upgrade.attribute("type") == "minor";
bool updateIsBeta = upgrade.attribute(QStringLiteral("type")) == "beta";
bool updateIsMajor = upgrade.attribute(QStringLiteral("type")) == "major";
bool updateIsMinor = upgrade.attribute(QStringLiteral("type")) == "minor";

bool updateCandidate = updateIsMajor || updateIsMinor || (updateIsBeta && allowBeta);
upgradeText = upgrade.firstChildElement("overview").text();
upgradeText = upgrade.firstChildElement(QStringLiteral("overview")).text();

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

upgradeWarningTime_ = QDateTime(QDateTime::currentDateTime());
upgradeWarningTime_ = QDateTime::currentDateTime();

for (int i = 0; i < formatList_.size(); i++) {
formatList_[i].zeroUseCounts();
Expand Down
9 changes: 4 additions & 5 deletions gui/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ class UpgradeCheck : public QObject

private:
QString currentVersion_;
QNetworkAccessManager* manager_;
QNetworkReply* replyId_;
QUrl upgradeUrl_;
QString latestVersion_;
QNetworkAccessManager* manager_{nullptr};
QNetworkReply* replyId_{nullptr};
QUrl upgradeUrl_{QStringLiteral("https://www.gpsbabel.org/upgrade_check.html")};
QDateTime upgradeWarningTime_; // invalid time if this object never issued.
QList<Format>& formatList_;
updateStatus updateStatus_;
updateStatus updateStatus_{updateUnknown};
BabelData& babelData_;

static QString getOsName();
Expand Down
Loading