18 #include "checkupdatesdialog.h"
19 #include <QNetworkReply>
20 #include <QNetworkAccessManager>
21 #include <QHBoxLayout>
22 #include <QVBoxLayout>
24 #include <QProgressBar>
25 #include <QPushButton>
26 #include <QDesktopServices>
27 #include <QVersionNumber>
28 #include <QXmlStreamReader>
33 CheckUpdatesDialog::CheckUpdatesDialog()
44 mTitleLabel->
setText(
tr(
"Checking for Updates...",
"status description in the check-for-update dialog"));
60 hButtonLayout->
addWidget(mDownloadButton);
81 CheckUpdatesDialog::~CheckUpdatesDialog()
86 void CheckUpdatesDialog::startChecking()
95 void CheckUpdatesDialog::regularBuildCheck()
98 QUrl url(
"https://github.com/pencil2d/pencil/releases.atom");
104 mNetworkManager->
get(req);
108 void CheckUpdatesDialog::nightlyBuildCheck()
110 mTitleLabel->
setText(
tr(
"<b>You are using a Pencil2D nightly build</b>"));
111 mDetailLabel->
setText(
tr(
"Please go %1 here %2 to check new nightly builds.")
112 .arg(
"<a href=\"https://www.pencil2d.org/download/#nightlybuild\">").arg(
"</a>"));
119 void CheckUpdatesDialog::networkErrorHappened()
121 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
122 mDetailLabel->
setText(
tr(
"Please check your internet connection and try again later.",
"error msg of check-for-update"));
128 void CheckUpdatesDialog::networkResponseIsEmpty()
130 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
131 mDetailLabel->
setText(
tr(
"Network response is empty",
"error msg of check-for-update"));
137 void CheckUpdatesDialog::invalidReleaseXml()
139 mTitleLabel->
setText(
tr(
"<b>An error occurred while checking for updates</b>",
"error msg of check-for-update"));
140 mDetailLabel->
setText(
tr(
"Couldn't retrieve the version information",
"error msg of check-for-update"));
146 void CheckUpdatesDialog::networkRequestFinished(
QNetworkReply* reply)
155 networkErrorHappened();
160 if (releasesAtom.isEmpty())
162 networkResponseIsEmpty();
166 QString latestVersionString = getVersionNumberFromXml(releasesAtom);
167 if (latestVersionString ==
"0.0.1")
173 bool isNewVersionAvailable = compareVersion(APP_VERSION, latestVersionString);
174 if (isNewVersionAvailable)
176 mTitleLabel->
setText(
tr(
"<b>A new version of Pencil2D is available!</b>"));
177 mDetailLabel->
setText(
tr(
"Pencil2D %1 is now available -- you have %2. Would you like to download it?")
178 .arg(latestVersionString)
180 mProgressBar->
hide();
185 mTitleLabel->
setText(
tr(
"<b>Pencil2D is up to date</b>"));
186 mDetailLabel->
setText(
tr(
"Version %1").arg(APP_VERSION));
193 bool CheckUpdatesDialog::compareVersion(
QString currentVersion,
QString latestVersion)
204 while (!xmlReader.atEnd() && !xmlReader.hasError())
209 while (!xmlReader.atEnd() && !xmlReader.hasError())
211 xmlReader.readNext();
212 if (xmlReader.name() ==
"title")
214 QString titleTag = xmlReader.readElementText();
222 qDebug() << xmlReader.errorString();
228 void CheckUpdatesDialog::gotoDownloadPage()
230 QString url =
"https://pencil2d.org/download";
234 void CheckUpdatesDialog::closeDialog()
QVersionNumber fromString(const QString &string, int *suffixIndex)
void setMaximum(int maximum)
void addSpacerItem(QSpacerItem *spacerItem)
void setUrl(const QUrl &url)
QString errorString() const const
void setOpenExternalLinks(bool open)
void setPixmap(const QPixmap &)
QString & remove(int position, int n)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setMinimum(int minimum)
QString fromUtf8(const char *str, int size)
void setText(const QString &)
void finished(QNetworkReply *reply)
QNetworkReply::NetworkError error() const const
QNetworkReply * get(const QNetworkRequest &request)
bool openUrl(const QUrl &url)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setTextVisible(bool visible)
void setRange(int minimum, int maximum)
void setWordWrap(bool on)
void addLayout(QLayout *layout, int stretch)