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/gui/mainmenu.cpp | 4 ++-- src/tikzit.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- src/tikzit.h | 4 ++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index b530f58..8166c59 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -255,10 +255,10 @@ void MainMenu::on_actionAbout_triggered() void MainMenu::on_actionCheck_for_updates_automatically_triggered() { - qDebug() << "check automatically:" << ui.actionCheck_for_updates_automatically->isChecked(); + tikzit->setCheckForUpdates(ui.actionCheck_for_updates_automatically->isChecked()); } void MainMenu::on_actionCheck_now_triggered() { - qDebug() << "check now"; + tikzit->checkForUpdates(); } 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 diff --git a/src/tikzit.h b/src/tikzit.h index 87599e7..635ee5e 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -49,7 +49,7 @@ #ifndef TIKZIT_H #define TIKZIT_H -#define TIKZIT_VERSION "2.0-rc1" +#define TIKZIT_VERSION "2.0-rc3" #include "mainwindow.h" #include "mainmenu.h" @@ -69,7 +69,7 @@ #include #include #include -#include +#include // Number of pixels between (0,0) and (1,0) at 100% zoom level. This should be // divisible by 8 to avoid rounding errors with e.g. grid-snapping. -- cgit v1.2.3