summaryrefslogtreecommitdiffhomepage
path: root/gui/software-update-dialog.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-30 09:01:32 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-10-30 09:01:32 +0100
commitd785d3616500d5846ac8c5f5a6347da832a593b4 (patch)
treeac670a125c5b880ad7e4b4f24a8635da4e66f0da /gui/software-update-dialog.hpp
parent232c2ba8aca7900eaa950c48813ddfaca8a749a8 (diff)
parent9b736d361bcde7a2ddaf3fe54b471c0e658e94f4 (diff)
Merge branch 'unstable' into trackhat
* unstable: cmake: cleanup hydra rename gui directory move to subdirectory-based build system cmake: switch to GNU CC 5.2.0 in mingw-w64 toolchain file rift-080: forgot ovr_Initialize() rift 025: fix name
Diffstat (limited to 'gui/software-update-dialog.hpp')
-rw-r--r--gui/software-update-dialog.hpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/gui/software-update-dialog.hpp b/gui/software-update-dialog.hpp
new file mode 100644
index 00000000..fe132402
--- /dev/null
+++ b/gui/software-update-dialog.hpp
@@ -0,0 +1,87 @@
+#pragma once
+
+#include <QtNetwork>
+#include <QDialog>
+#include <QSettings>
+#include <QString>
+#include <QRegExp>
+#include <functional>
+#include "ui_software-update.h"
+#include "opentrack/options.hpp"
+
+extern "C" const char* opentrack_version;
+
+class update_dialog : public QDialog
+{
+ Q_OBJECT
+public:
+ struct query
+ {
+ query(QWidget* parent) : parent(parent), qnam(parent) {}
+
+ QWidget* parent;
+ QNetworkAccessManager qnam;
+ QByteArray buf;
+ QNetworkReply* r;
+ void on_finished()
+ {
+ if (r->error() != QNetworkReply::NoError)
+ {
+ qDebug() << "update error" << r->errorString();
+ return;
+ }
+ QString str(buf);
+ QRegExp re("OPENTRACK_VERSION([a-zA-Z0-9_.-]+)");
+ int idx = re.indexIn(str);
+ if (idx != -1)
+ {
+ str = re.cap(1);
+ QSettings s(OPENTRACK_ORG);
+ QString quiet_version = s.value("quiet-update-version").toString();
+
+ if (!str.isEmpty() && str != opentrack_version && str != quiet_version)
+ {
+ qDebug() << "update version" << str;
+ update_dialog dlg(parent, *this, str);
+ dlg.show();
+ dlg.raise();
+ dlg.exec();
+ if (dlg.ui.disable_reminder->isChecked())
+ s.setValue("quiet-update-version", str);
+ }
+ }
+ buf.clear();
+ r->deleteLater();
+ }
+ void on_ready()
+ {
+ buf.append(r->readAll());
+ }
+ void maybe_show_dialog()
+ {
+ static auto uri = QStringLiteral("http://www.trackhat.org/#!opentrackversion/c1oxn");
+ r = qnam.get(QNetworkRequest(uri));
+
+ QObject::connect(r, &QNetworkReply::finished, [&]() { on_finished(); });
+ QObject::connect(r, &QNetworkReply::readyRead, [&]() { on_ready(); });
+ }
+ };
+private:
+ Ui::UpdateDialog ui;
+ query& q;
+private slots:
+ void close(QAbstractButton*)
+ {
+ QDialog::close();
+ }
+public:
+ update_dialog(QWidget* parent, query& q, const QString& new_version) : QDialog(parent), q(q)
+ {
+ ui.setupUi(this);
+ ui.ver_current->setText(const_cast<const char*>(opentrack_version));
+ ui.ver_new->setTextFormat(Qt::RichText);
+ ui.ver_new->setText("<a href='http://www.trackhat.org/#!trackhat-opentrack/c1jzc'>" + new_version + "</a>");
+ ui.ver_new->setOpenExternalLinks(true);
+ connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close(QAbstractButton*)));
+ }
+};