From 24fbb3b7aca8dd5b957397a046d3cb71a00b324c Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 21 Oct 2018 13:33:13 +0200 Subject: add automatic update checking (closes #33) --- src/tikzit.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/tikzit.cpp') diff --git a/src/tikzit.cpp b/src/tikzit.cpp index fc81739..5d1fef4 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include // application-level instance of Tikzit Tikzit *tikzit; @@ -119,6 +122,10 @@ void Tikzit::init() } setCheckForUpdates(check.toBool()); + + if (check.toBool()) { + checkForUpdates(); + } } //QMenuBar *Tikzit::mainMenu() const @@ -352,12 +359,44 @@ void Tikzit::setCheckForUpdates(bool check) void Tikzit::checkForUpdates() { + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + connect(manager, SIGNAL(finished(QNetworkReply*)), + this, SLOT(updateReply(QNetworkReply*))); + manager->get(QNetworkRequest(QUrl("http://tikzit.github.io/latest-version.txt"))); } void Tikzit::updateReply(QNetworkReply *reply) { - + if (!reply->isReadable()) return; + + QByteArray data = reply->read(200); + QString strLatest = QString::fromUtf8(data).simplified(); + qDebug() << "got response:" << strLatest; + + QVersionNumber current = QVersionNumber::fromString(TIKZIT_VERSION).normalized(); + QVersionNumber latest = QVersionNumber::fromString(strLatest).normalized(); + + // check for an optional RC suffix. Any non-RC versions are considered later than RC versions. + QRegularExpression re("-[rR][cC]([0-9]+)$"); + QRegularExpressionMatch m; + m = re.match(TIKZIT_VERSION); + int rcCurrent = (m.hasMatch()) ? m.captured(1).toInt() : 1000; + m = re.match(strLatest); + int rcLatest = (m.hasMatch()) ? m.captured(1).toInt() : 1000; + + //qDebug() << "latest" << latest << "rc" << rcLatest; + //qDebug() << "current" << current << "rc" << rcCurrent; + + if (latest > current || (latest == current && rcLatest > rcCurrent)) { + QMessageBox::information(0, + tr("Update available"), + "

A new version of TikZiT is available!

" + "

current version: " TIKZIT_VERSION "
" + "latest version: " + strLatest + "

" + "

Download it now from: " + "tikzit.github.io.

"); + } } //StylePalette *Tikzit::stylePalette() const -- cgit v1.2.3