From c78bc3be30b69bdabcb647dec75e45dabc81484c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 11 Oct 2015 16:44:31 +0200 Subject: ui: add software update check and dialog --- facetracknoir/software-update-dialog.hpp | 87 +++++++++++++++++++++++ facetracknoir/software-update.ui | 118 +++++++++++++++++++++++++++++++ facetracknoir/ui.cpp | 5 +- facetracknoir/ui.h | 2 + 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 facetracknoir/software-update-dialog.hpp create mode 100644 facetracknoir/software-update.ui 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 +#include +#include +#include +#include +#include +#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(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(opentrack_version)); + ui.ver_new->setTextFormat(Qt::RichText); + ui.ver_new->setText("" + new_version + ""); + 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 @@ + + + UpdateDialog + + + + 0 + 0 + 385 + 187 + + + + Dialog + + + + + + + 16 + + + + Software update released + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 12 + + + 12 + + + 12 + + + 12 + + + 12 + + + + + Current version: + + + + + + + TextLabel + + + true + + + + + + + Released version: + + + + + + + TextLabel + + + + + + + Don't remind me again about this version + + + + + + + + + + QDialogButtonBox::Close + + + + + + + + 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 current_protocol() { -- cgit v1.2.3