1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

OP-1453 - Add code to query latest version from web and set up

properties that can be used by the main form to display an 'update
available' notification if latest version doesn't match the current one.
This commit is contained in:
dwillis 2014-08-23 02:05:12 +01:00
parent 657ec00d72
commit 139f9c5276
2 changed files with 41 additions and 2 deletions

View File

@ -45,6 +45,9 @@
#include <QtCore/QUrl>
#include <QtCore/QDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QtQuick>
#include <QQuickView>
#include <QQmlEngine>
@ -60,6 +63,7 @@ struct WelcomeModePrivate {
WelcomeModePrivate();
QQuickView *quickView;
QNetworkAccessManager* networkAccess;
};
WelcomeModePrivate::WelcomeModePrivate()
@ -68,18 +72,26 @@ WelcomeModePrivate::WelcomeModePrivate()
// --- WelcomeMode
WelcomeMode::WelcomeMode() :
m_d(new WelcomeModePrivate),
m_priority(Core::Constants::P_MODE_WELCOME)
m_priority(Core::Constants::P_MODE_WELCOME),
m_newVersionText("")
{
m_d->quickView = new QQuickView;
m_d->quickView->setResizeMode(QQuickView::SizeRootObjectToView);
m_d->quickView->engine()->rootContext()->setContextProperty("welcomePlugin", this);
m_d->quickView->setSource(QUrl("qrc:/welcome/qml/main.qml"));
m_container = NULL;
m_d->networkAccess = new QNetworkAccessManager;
m_d->networkAccess->get(QNetworkRequest(QUrl("http://www.openpilot.org/opver")));
connect(m_d->networkAccess, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkResponseReady(QNetworkReply*)));
}
WelcomeMode::~WelcomeMode()
{
delete m_d->quickView;
delete m_d->networkAccess;
delete m_d;
}
@ -135,4 +147,18 @@ void WelcomeMode::triggerAction(const QString &actionId)
{
Core::ModeManager::instance()->triggerAction(actionId);
}
void WelcomeMode::networkResponseReady(QNetworkReply* reply)
{
if(reply != NULL)
{
QString version(reply->readAll());
if(version != VersionInfo::revision())
{
m_newVersionText = tr("(Update Available: %1)").arg(version);
emit newVersionTextChanged();
}
}
}
} // namespace Welcome

View File

@ -38,6 +38,7 @@
QT_BEGIN_NAMESPACE
class QWidget;
class QUrl;
class QNetworkReply;
QT_END_NAMESPACE
namespace Welcome {
@ -46,6 +47,7 @@ struct WelcomeModePrivate;
class WELCOME_EXPORT WelcomeMode : public Core::IMode {
Q_OBJECT
Q_PROPERTY(QString versionString READ versionString)
Q_PROPERTY(QString newVersionText READ newVersionText NOTIFY newVersionTextChanged)
public:
WelcomeMode();
@ -69,8 +71,15 @@ public:
}
QString versionString() const
{
return tr("OpenPilot GCS Version: %1").arg(VersionInfo::revision().left(60));
return tr("OpenPilot GCS Version: %1").arg(VersionInfo::revision());
}
QString newVersionText() const
{
return m_newVersionText;
}
signals:
void newVersionTextChanged();
public slots:
void openUrl(const QString &url);
@ -81,6 +90,10 @@ private:
QWidget *m_container;
WelcomeModePrivate *m_d;
int m_priority;
QString m_newVersionText;
private slots:
void networkResponseReady(QNetworkReply* reply);
};
} // namespace Welcome