summaryrefslogtreecommitdiffhomepage
path: root/opentrack/software-update-dialog.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-05-06 19:44:07 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-05-10 05:01:33 +0200
commita6c4bab412e45c327c32e56fb77e235bbc9f9d84 (patch)
tree12807acd9911c5e9ef75e255277400a9672ff998 /opentrack/software-update-dialog.cpp
parent178a4b316e75d1edf17024b05b39452be88cdac4 (diff)
trackhat: add software update check
Diffstat (limited to 'opentrack/software-update-dialog.cpp')
-rw-r--r--opentrack/software-update-dialog.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/opentrack/software-update-dialog.cpp b/opentrack/software-update-dialog.cpp
new file mode 100644
index 00000000..45e41738
--- /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 (abort)
+ return;
+ if (r->error() != QNetworkReply::NoError)
+ {
+ qDebug() << "update 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() << "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 update_query::maybe_show_dialog()
+{
+ QEventLoop ev;
+ QTimer t{&ev}; t.setSingleShot(true);
+ t.start(1000 * 10);
+ QObject::connect(&t, &QTimer::timeout, [this, &ev] {
+ abort = true;
+ ev.quit();
+ });
+
+ r = qnam.get(QNetworkRequest(QStringLiteral("https://www.trackhat.org/thotversion")));
+
+ QObject::connect(r, &QIODevice::readyRead, [this] { on_ready(); });
+ QObject::connect(r, &QNetworkReply::finished, [&]() {
+ on_finished();
+ ev.quit();
+ });
+ ev.exec();
+}