OSTC firmware update prompt: use the stable changelog files

Heinrichs Weikamp is giving us stable URLs from which we can get the
latest stable version. The parsing is a bit simplistic, but it seems to
work.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-12-28 07:37:11 -08:00
parent 542ff7fc36
commit 0be0cdb046
3 changed files with 18 additions and 9 deletions

View file

@ -190,18 +190,26 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
settings.endGroup(); settings.endGroup();
} }
OstcFirmwareCheck::OstcFirmwareCheck() OstcFirmwareCheck::OstcFirmwareCheck(QString product)
{ {
hwVersionPage.mainFrame()->load(QUrl("http://www.heinrichsweikamp.com/?id=162")); QUrl url;
if (product == "OSTC 3")
url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc3_changelog.txt");
else if (product == "OSTC Sport")
url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc_sport_changelog.txt");
else // not one of the known dive computers
return;
hwVersionPage.mainFrame()->load(url);
connect(&hwVersionPage, SIGNAL(loadFinished(bool)), this, SLOT(parseOstcFwVersion())); connect(&hwVersionPage, SIGNAL(loadFinished(bool)), this, SLOT(parseOstcFwVersion()));
} }
void OstcFirmwareCheck::parseOstcFwVersion() void OstcFirmwareCheck::parseOstcFwVersion()
{ {
QWebElement parse = hwVersionPage.mainFrame()->documentElement(); QString parse = hwVersionPage.mainFrame()->toPlainText();
QWebElement result = parse.findFirst("div[id=content_firmware_headline_typ0]"); int firstOpenBracket = parse.indexOf('[');
latestFirmwareAvailable = result.toPlainText().trimmed().replace("stable", ""); int firstCloseBracket = parse.indexOf(']');
qDebug() << "Latest OSTC 3 Version" << latestFirmwareAvailable; latestFirmwareAvailable = parse.mid(firstOpenBracket + 1, firstCloseBracket - firstOpenBracket -1);
qDebug() << "latest firmware available" << latestFirmwareAvailable;
} }
void OstcFirmwareCheck::checkLatest(QWidget *parent, uint32_t firmwareOnDevice) void OstcFirmwareCheck::checkLatest(QWidget *parent, uint32_t firmwareOnDevice)

View file

@ -106,7 +106,7 @@ class OstcFirmwareCheck : QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OstcFirmwareCheck(); explicit OstcFirmwareCheck(QString product);
void checkLatest(QWidget *parent, uint32_t firmwareOnDevice); void checkLatest(QWidget *parent, uint32_t firmwareOnDevice);
public public
slots: slots:

View file

@ -304,8 +304,9 @@ void DownloadFromDCWidget::on_ok_clicked()
thread->start(); thread->start();
if (ui.product->currentText() == "OSTC 3" || ui.product->currentText() == "OSTC sport") QString product(ui.product->currentText());
ostcFirmwareCheck = new OstcFirmwareCheck(); if (product == "OSTC 3" || product == "OSTC Sport")
ostcFirmwareCheck = new OstcFirmwareCheck(product);
} }
bool DownloadFromDCWidget::preferDownloaded() bool DownloadFromDCWidget::preferDownloaded()