18#include "checkupdatesdialog.h"
20#include <QNetworkReply>
21#include <QNetworkAccessManager>
25#include <QProgressBar>
27#include <QDesktopServices>
28#include <QRegularExpression>
29#include <QVersionNumber>
30#include <QXmlStreamReader>
35CheckUpdatesDialog::CheckUpdatesDialog()
46 mTitleLabel->
setText(
tr(
"Checking for Updates...",
"status description in the check-for-update dialog"));
62 hButtonLayout->
addWidget(mDownloadButton);
83CheckUpdatesDialog::~CheckUpdatesDialog()
88void CheckUpdatesDialog::startChecking()
91 if (version.startsWith(
"99.0.0")) {
93 }
else if (version ==
"0.0.0.0") {
100void CheckUpdatesDialog::regularBuildCheck()
103 QUrl url(
"https://github.com/pencil2d/pencil/releases.atom");
109 mNetworkManager->
get(req);
113void CheckUpdatesDialog::nightlyBuildCheck()
115 mTitleLabel->
setText(
tr(
"<b>You are using a Pencil2D nightly build</b>"));
116 mDetailLabel->
setText(
tr(
"Please go %1 here %2 to check new nightly builds.")
117 .arg(
"<a href=\"https://www.pencil2d.org/download/nightly/\">",
"</a>"));
124void CheckUpdatesDialog::networkErrorHappened()
126 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
127 mDetailLabel->
setText(
tr(
"Please check your internet connection and try again later.",
"error msg of check-for-update"));
133void CheckUpdatesDialog::networkResponseIsEmpty()
135 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
136 mDetailLabel->
setText(
tr(
"Network response is empty",
"error msg of check-for-update"));
142void CheckUpdatesDialog::invalidReleaseXml()
144 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
145 mDetailLabel->
setText(
tr(
"Couldn't retrieve the version information",
"error msg of check-for-update"));
151void CheckUpdatesDialog::networkRequestFinished(
QNetworkReply* reply)
160 networkErrorHappened();
165 if (releasesAtom.isEmpty())
167 networkResponseIsEmpty();
171 QString latestVersionString = getVersionNumberFromXml(releasesAtom);
172 if (latestVersionString ==
"0.0.1")
178 bool isNewVersionAvailable = compareVersion(APP_VERSION, latestVersionString);
179 if (isNewVersionAvailable)
181 mTitleLabel->
setText(
tr(
"<b>A new version of Pencil2D is available!</b>"));
182 mDetailLabel->
setText(
tr(
"Pencil2D %1 is now available -- you have %2. Would you like to download it?")
183 .arg(latestVersionString, APP_VERSION));
184 mProgressBar->
hide();
189 mTitleLabel->
setText(
tr(
"<b>Pencil2D is up to date</b>"));
190 mDetailLabel->
setText(
tr(
"Version %1").arg(APP_VERSION));
197bool CheckUpdatesDialog::compareVersion(
QString currentVersion,
QString latestVersion)
208 while (!xmlReader.atEnd() && !xmlReader.hasError())
213 while (!xmlReader.atEnd() && !xmlReader.hasError())
215 xmlReader.readNext();
218 QString title = xmlReader.readElementText();
221 if (!title.
contains(
"Release Candidate")) {
230 qDebug() << xmlReader.errorString();
236void CheckUpdatesDialog::gotoDownloadPage()
238 QString url =
"https://pencil2d.org/download";
242void CheckUpdatesDialog::closeDialog()
void addLayout(QLayout *layout, int stretch)
void addSpacerItem(QSpacerItem *spacerItem)
bool openUrl(const QUrl &url)
QString errorString() const const
void setOpenExternalLinks(bool open)
void setPixmap(const QPixmap &)
void setText(const QString &)
void setWordWrap(bool on)
void finished(QNetworkReply *reply)
QNetworkReply * get(const QNetworkRequest &request)
QNetworkReply::NetworkError error() const const
void setUrl(const QUrl &url)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setMaximum(int maximum)
void setMinimum(int minimum)
void setRange(int minimum, int maximum)
void setTextVisible(bool visible)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString fromUtf8(const char *str, int size)
QString & remove(int position, int n)
QString trimmed() const const
QVersionNumber fromString(const QString &string, int *suffixIndex)