diff --git a/ground/openpilotgcs/src/plugins/welcome/qml/main.qml b/ground/openpilotgcs/src/plugins/welcome/qml/main.qml index 7a58a8fa3..7425d906d 100644 --- a/ground/openpilotgcs/src/plugins/welcome/qml/main.qml +++ b/ground/openpilotgcs/src/plugins/welcome/qml/main.qml @@ -30,10 +30,10 @@ Rectangle { anchors.horizontalCenter: parent.horizontalCenter // distribute a vertical space between the icons blocks an community widget as: // top - 48% - Icons - 27% - CommunityWidget - 25% - bottom - y: (parent.height - buttons.height - communityPanel.height) * 0.48 + y: (parent.height - buttons.height - communityPanel.height - versionInfo.height) * 0.48 width: parent.width height: 600 - spacing: (parent.height - buttons.height - communityPanel.height) * 0.1 + spacing: (parent.height - buttons.height - communityPanel.height - versionInfo.height) * 0.1 Row { //if the buttons grid overlaps vertically with the wizard buttons, @@ -109,5 +109,43 @@ Rectangle { width: Math.min(sourceSize.width, container.width) height: Math.min(450, container.height*0.5) } + + Row { + id: versionInfo + + height: 18 + anchors.horizontalCenter: parent.horizontalCenter + width: textOpVersion.width + textOpVersionAvailable.width + spacing: 16 + + Text { + id: textOpVersion + color: "#c4c0c0" + text: welcomePlugin.versionString + verticalAlignment: Text.AlignTop + anchors.left: parent.anchors.left + font.bold: true + styleColor: "#00000000" + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 14 + } + Text { + id: textOpVersionAvailable + color: "#5fcf07" + text: welcomePlugin.newVersionText + anchors.rightMargin: 0 + font.bold: true + styleColor: "#00000000" + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 14 + anchors.left: textOpVersion.right + + MouseArea{ + width: parent.width + height: parent.height + onClicked: welcomePlugin.openUrl("http://wiki.openpilot.org/display/BUILDS/OpenPilot+Software+Downloads") + } + } + } } } diff --git a/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri b/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri index 7f369f632..04c4323a7 100644 --- a/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri +++ b/ground/openpilotgcs/src/plugins/welcome/welcome_dependencies.pri @@ -1,2 +1,3 @@ include(../../plugins/coreplugin/coreplugin.pri) include(../../libs/utils/utils.pri) +include(../../libs/version_info/version_info.pri) diff --git a/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp b/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp index 381fd226a..090a77d85 100644 --- a/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp +++ b/ground/openpilotgcs/src/plugins/welcome/welcomemode.cpp @@ -45,6 +45,9 @@ #include #include +#include +#include + #include #include #include @@ -68,13 +71,32 @@ 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; + + QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager; + + // Only attempt to request our version info if the network is accessible + if(networkAccessManager->networkAccessible() == QNetworkAccessManager::Accessible) + { + connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkResponseReady(QNetworkReply*))); + + // This will delete the network access manager instance when we're done + connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)), networkAccessManager, SLOT(deleteLater())); + + networkAccessManager->get(QNetworkRequest(QUrl("http://www.openpilot.org/opver"))); + } + else + { + // No network, can delete this now as we don't need it. + delete networkAccessManager; + } } WelcomeMode::~WelcomeMode() @@ -135,4 +157,21 @@ void WelcomeMode::triggerAction(const QString &actionId) { Core::ModeManager::instance()->triggerAction(actionId); } + +void WelcomeMode::networkResponseReady(QNetworkReply* reply) +{ + if(reply != NULL) + { + QString version(reply->readAll()); + version = version.trimmed(); + + reply->deleteLater(); + + if(version != VersionInfo::tagOrHash8()) + { + m_newVersionText = tr("(Update Available: %1)").arg(version); + emit newVersionTextChanged(); + } + } +} } // namespace Welcome diff --git a/ground/openpilotgcs/src/plugins/welcome/welcomemode.h b/ground/openpilotgcs/src/plugins/welcome/welcomemode.h index b6e837cc9..ab85912b9 100644 --- a/ground/openpilotgcs/src/plugins/welcome/welcomemode.h +++ b/ground/openpilotgcs/src/plugins/welcome/welcomemode.h @@ -29,6 +29,7 @@ #ifndef WELCOMEMODE_H #define WELCOMEMODE_H +#include "version_info/version_info.h" #include "welcome_global.h" #include @@ -37,6 +38,7 @@ QT_BEGIN_NAMESPACE class QWidget; class QUrl; +class QNetworkReply; QT_END_NAMESPACE namespace Welcome { @@ -44,6 +46,8 @@ 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(); @@ -65,6 +69,17 @@ public: { m_priority = priority; } + QString versionString() const + { + return tr("OpenPilot GCS Version: %1 ").arg(VersionInfo::tagOrHash8()); + } + QString newVersionText() const + { + return m_newVersionText; + } + +signals: + void newVersionTextChanged(); public slots: void openUrl(const QString &url); @@ -75,6 +90,10 @@ private: QWidget *m_container; WelcomeModePrivate *m_d; int m_priority; + QString m_newVersionText; + + private slots: + void networkResponseReady(QNetworkReply* reply); }; } // namespace Welcome