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()
90#ifdef PENCIL2D_NIGHTLY_BUILD
97void CheckUpdatesDialog::regularBuildCheck()
100 QUrl url(
"https://github.com/pencil2d/pencil/releases.atom");
106 mNetworkManager->
get(req);
110void CheckUpdatesDialog::nightlyBuildCheck()
112 mTitleLabel->
setText(
tr(
"<b>You are using a Pencil2D nightly build</b>"));
113 mDetailLabel->
setText(
tr(
"Please go %1 here %2 to check new nightly builds.")
114 .arg(
"<a href=\"https://www.pencil2d.org/download/#nightlybuild\">",
"</a>"));
121void CheckUpdatesDialog::networkErrorHappened()
123 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
124 mDetailLabel->
setText(
tr(
"Please check your internet connection and try again later.",
"error msg of check-for-update"));
130void CheckUpdatesDialog::networkResponseIsEmpty()
132 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
133 mDetailLabel->
setText(
tr(
"Network response is empty",
"error msg of check-for-update"));
139void CheckUpdatesDialog::invalidReleaseXml()
141 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
142 mDetailLabel->
setText(
tr(
"Couldn't retrieve the version information",
"error msg of check-for-update"));
148void CheckUpdatesDialog::networkRequestFinished(
QNetworkReply* reply)
157 networkErrorHappened();
162 if (releasesAtom.isEmpty())
164 networkResponseIsEmpty();
168 QString latestVersionString = getVersionNumberFromXml(releasesAtom);
169 if (latestVersionString ==
"0.0.1")
175 bool isNewVersionAvailable = compareVersion(APP_VERSION, latestVersionString);
176 if (isNewVersionAvailable)
178 mTitleLabel->
setText(
tr(
"<b>A new version of Pencil2D is available!</b>"));
179 mDetailLabel->
setText(
tr(
"Pencil2D %1 is now available -- you have %2. Would you like to download it?")
180 .arg(latestVersionString, APP_VERSION));
181 mProgressBar->
hide();
186 mTitleLabel->
setText(
tr(
"<b>Pencil2D is up to date</b>"));
187 mDetailLabel->
setText(
tr(
"Version %1").arg(APP_VERSION));
194bool CheckUpdatesDialog::compareVersion(
QString currentVersion,
QString latestVersion)
205 while (!xmlReader.atEnd() && !xmlReader.hasError())
210 while (!xmlReader.atEnd() && !xmlReader.hasError())
212 xmlReader.readNext();
215 QString titleTag = xmlReader.readElementText();
223 qDebug() << xmlReader.errorString();
229void CheckUpdatesDialog::gotoDownloadPage()
231 QString url =
"https://pencil2d.org/download";
235void 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)
QString fromUtf8(const char *str, int size)
QString & remove(int position, int n)
QString trimmed() const const
QVersionNumber fromString(const QString &string, int *suffixIndex)