summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-11 16:44:31 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-10-11 16:44:31 +0200
commitc78bc3be30b69bdabcb647dec75e45dabc81484c (patch)
treea194f9351b8fc38795d47ee2520396319fdc99ee
parent0f8c7ac6658514cb85f69e6bd5b162aaac022530 (diff)
ui: add software update check and dialogtrackhat-1.1p1
-rw-r--r--facetracknoir/software-update-dialog.hpp87
-rw-r--r--facetracknoir/software-update.ui118
-rw-r--r--facetracknoir/ui.cpp5
-rw-r--r--facetracknoir/ui.h2
4 files changed, 211 insertions, 1 deletions
diff --git a/facetracknoir/software-update-dialog.hpp b/facetracknoir/software-update-dialog.hpp
new file mode 100644
index 00000000..d6353396
--- /dev/null
+++ b/facetracknoir/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" volatile 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 != const_cast<const char*>(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*)));
+ }
+};
diff --git a/facetracknoir/software-update.ui b/facetracknoir/software-update.ui
new file mode 100644
index 00000000..07edf66c
--- /dev/null
+++ b/facetracknoir/software-update.ui
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UpdateDialog</class>
+ <widget class="QDialog" name="UpdateDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>385</width>
+ <height>187</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="font">
+ <font>
+ <pointsize>16</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Software update released</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QFrame" name="frame">
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <property name="lineWidth">
+ <number>0</number>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <property name="leftMargin">
+ <number>12</number>
+ </property>
+ <property name="topMargin">
+ <number>12</number>
+ </property>
+ <property name="rightMargin">
+ <number>12</number>
+ </property>
+ <property name="bottomMargin">
+ <number>12</number>
+ </property>
+ <property name="spacing">
+ <number>12</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Current version:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="ver_current">
+ <property name="text">
+ <string>TextLabel</string>
+ </property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Released version:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLabel" name="ver_new">
+ <property name="text">
+ <string>TextLabel</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <widget class="QCheckBox" name="disable_reminder">
+ <property name="text">
+ <string>Don't remind me again about this version</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp
index 1123d6d9..486cd2c4 100644
--- a/facetracknoir/ui.cpp
+++ b/facetracknoir/ui.cpp
@@ -25,7 +25,8 @@ MainWindow::MainWindow() :
pose_update_timer(this),
kbd_quit(QKeySequence("Ctrl+Q"), this),
no_feed_pixmap(":/images/no-feed.png"),
- is_refreshing_profiles(false)
+ is_refreshing_profiles(false),
+ update_query(this)
{
ui.setupUi(this);
@@ -92,6 +93,8 @@ MainWindow::MainWindow() :
QMessageBox::Ok, QMessageBox::NoButton);
ui.btnStartTracker->setFocus();
+
+ update_query.maybe_show_dialog();
}
void MainWindow::closeEvent(QCloseEvent *e)
diff --git a/facetracknoir/ui.h b/facetracknoir/ui.h
index 1b71b7f8..4d8bb1cc 100644
--- a/facetracknoir/ui.h
+++ b/facetracknoir/ui.h
@@ -29,6 +29,7 @@
#include "curve-config.h"
#include "options-dialog.hpp"
#include "process_detector.h"
+#include "facetracknoir/software-update-dialog.hpp"
using namespace options;
@@ -50,6 +51,7 @@ class MainWindow : public QMainWindow, private State
QMenu profile_menu;
bool is_refreshing_profiles;
QTimer save_timer;
+ update_dialog::query update_query;
mem<dylib> current_protocol()
{