diff options
-rw-r--r-- | opentrack/lang/nl_NL.ts | 27 | ||||
-rw-r--r-- | opentrack/lang/ru_RU.ts | 27 | ||||
-rw-r--r-- | opentrack/lang/stub.ts | 27 | ||||
-rw-r--r-- | opentrack/lang/zh_CN.ts | 27 | ||||
-rw-r--r-- | opentrack/main-window.cpp | 4 | ||||
-rw-r--r-- | opentrack/main-window.hpp | 4 | ||||
-rw-r--r-- | opentrack/software-update-dialog.cpp | 65 | ||||
-rw-r--r-- | opentrack/software-update-dialog.hpp | 34 | ||||
-rw-r--r-- | opentrack/software-update.ui | 118 |
9 files changed, 333 insertions, 0 deletions
diff --git a/opentrack/lang/nl_NL.ts b/opentrack/lang/nl_NL.ts index 15acd701..d69141cd 100644 --- a/opentrack/lang/nl_NL.ts +++ b/opentrack/lang/nl_NL.ts @@ -13,6 +13,33 @@ </message> </context> <context> + <name>UpdateDialog</name> + <message> + <source>Dialog</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Software update released</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Current version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>TextLabel</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Released version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Don't remind me again about this version</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>main_window</name> <message> <source>Profile</source> diff --git a/opentrack/lang/ru_RU.ts b/opentrack/lang/ru_RU.ts index c869bae8..860e68fb 100644 --- a/opentrack/lang/ru_RU.ts +++ b/opentrack/lang/ru_RU.ts @@ -13,6 +13,33 @@ </message> </context> <context> + <name>UpdateDialog</name> + <message> + <source>Dialog</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Software update released</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Current version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>TextLabel</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Released version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Don't remind me again about this version</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>main_window</name> <message> <source>Create new empty config</source> diff --git a/opentrack/lang/stub.ts b/opentrack/lang/stub.ts index 66917925..7727ab29 100644 --- a/opentrack/lang/stub.ts +++ b/opentrack/lang/stub.ts @@ -13,6 +13,33 @@ </message> </context> <context> + <name>UpdateDialog</name> + <message> + <source>Dialog</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Software update released</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Current version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>TextLabel</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Released version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Don't remind me again about this version</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>main_window</name> <message> <source>Profile</source> diff --git a/opentrack/lang/zh_CN.ts b/opentrack/lang/zh_CN.ts index fd9ea20f..b3764a8f 100644 --- a/opentrack/lang/zh_CN.ts +++ b/opentrack/lang/zh_CN.ts @@ -13,6 +13,33 @@ </message> </context> <context> + <name>UpdateDialog</name> + <message> + <source>Dialog</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Software update released</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Current version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>TextLabel</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Released version:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Don't remind me again about this version</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>main_window</name> <message> <source>Profile</source> diff --git a/opentrack/main-window.cpp b/opentrack/main-window.cpp index b879e773..fd16a2c6 100644 --- a/opentrack/main-window.cpp +++ b/opentrack/main-window.cpp @@ -18,6 +18,7 @@ #include "compat/math.hpp" #include "compat/sysexits.hpp" #include "opentrack/defs.hpp" +#include "software-update-dialog.hpp" #include <cstring> #include <utility> @@ -67,6 +68,9 @@ main_window::main_window() : State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH) connect(&*s.b, &options::bundle_::saving, this, &main_window::register_shortcuts); ui.btnStartTracker->setFocus(); + + updater = std::make_unique<update_query>(this); + updater->maybe_show_dialog(); } void main_window::init_shortcuts() diff --git a/opentrack/main-window.hpp b/opentrack/main-window.hpp index ddb6b725..1ccef358 100644 --- a/opentrack/main-window.hpp +++ b/opentrack/main-window.hpp @@ -34,6 +34,8 @@ #include "ui_main-window.h" +class update_query; + class main_window final : public QMainWindow, private State { Q_DECLARE_TR_FUNCTIONS(main_window) @@ -78,6 +80,8 @@ class main_window final : public QMainWindow, private State qt_signal<void> toggle_tracker { this, &main_window::toggle_tracker_, Qt::QueuedConnection }; qt_signal<void> restart_tracker { this, &main_window::restart_tracker_, Qt::QueuedConnection }; + std::unique_ptr<update_query> updater; + public: void init_dylibs(); void init_tray_menu(); diff --git a/opentrack/software-update-dialog.cpp b/opentrack/software-update-dialog.cpp new file mode 100644 index 00000000..ccdf2f0e --- /dev/null +++ b/opentrack/software-update-dialog.cpp @@ -0,0 +1,65 @@ +#include "software-update-dialog.hpp" + +update_dialog::update_dialog(QWidget* parent, update_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='https://www.trackhat.org/trackhat-opentrack'>" + new_version + "</a>"); + ui.ver_new->setOpenExternalLinks(true); + connect(ui.buttonBox, &QDialogButtonBox::clicked, this, &update_dialog::close); +} + +void update_query::on_finished() +{ + if (!t.isActive()) + return; + t.stop(); + if (r->error() != QNetworkReply::NoError) + { + qDebug() << "updater: error" << r->error() << r->errorString(); + return; + } + QString str(buf); + QRegExp re("SOFTWARE-UPDATE-V2: ([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() << "updater: new version" << str; + update_dialog dlg(qobject_cast<QWidget*>(parent()), *this, str); + dlg.show(); + dlg.raise(); + dlg.exec(); + if (dlg.ui.disable_reminder->isChecked()) + s.setValue("quiet-update-version", str); + } + } + else + { + if (buf.isEmpty()) + qDebug() << "updater: empty response"; + else + qDebug() << "updater: can't parse response"; + } + buf.clear(); + r->deleteLater(); +} + +void update_query::maybe_show_dialog() +{ + t.stop(); + t.setSingleShot(true); + t.start(1000 * 10); + + r = qnam.get(QNetworkRequest(QStringLiteral("https://www.trackhat.org/thotversion"))); + + QObject::connect(r, &QIODevice::readyRead, this, &update_query::on_ready); + QObject::connect(r, &QNetworkReply::finished, this, &update_query::on_finished); +} diff --git a/opentrack/software-update-dialog.hpp b/opentrack/software-update-dialog.hpp new file mode 100644 index 00000000..1e150e62 --- /dev/null +++ b/opentrack/software-update-dialog.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include <QtNetwork> +#include <QDialog> +#include <QTimer> +#include "ui_software-update.h" + +extern "C" const char* const opentrack_version; + +class update_query final : public QObject +{ + Q_OBJECT +public: + explicit update_query(QWidget* parent) : QObject{parent} {} + + QNetworkReply* r = nullptr; + QNetworkAccessManager qnam{this}; + QByteArray buf; + QTimer t{this}; + + void on_finished(); + void on_ready() { buf.append(r->readAll()); } + void maybe_show_dialog(); +}; + +class update_dialog : QDialog +{ + Q_OBJECT + friend class update_query; +private: + Ui::UpdateDialog ui; + update_query& q; + update_dialog(QWidget* parent, update_query& q, const QString& new_version); +}; diff --git a/opentrack/software-update.ui b/opentrack/software-update.ui new file mode 100644 index 00000000..07edf66c --- /dev/null +++ b/opentrack/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> |