From efb173e1d4d9b4d29815cb0e7b45b6686cc92169 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 8 Jan 2014 21:20:43 -0600 Subject: [PATCH] Preliminary update dialog work --- interface/resources/styles/update_dialog.qss | 0 interface/src/Application.cpp | 58 +++++++++++++++++--- interface/src/Application.h | 4 +- interface/src/ui/UpdateDialog.cpp | 40 ++++++++++++++ interface/src/ui/UpdateDialog.h | 38 +++++++++++++ 5 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 interface/resources/styles/update_dialog.qss create mode 100644 interface/src/ui/UpdateDialog.cpp create mode 100644 interface/src/ui/UpdateDialog.h diff --git a/interface/resources/styles/update_dialog.qss b/interface/resources/styles/update_dialog.qss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1cdef9f0fe..4a762e4fc3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -195,6 +196,18 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + #ifdef Q_WS_X11 + _operatingSystem = "ubuntu"; + #endif + + #ifdef Q_WS_WIN + _operatingSystem = "win"; + #endif + + #ifdef Q_WS_MACX + _operatingSystem = "mac"; + #endif + checkVersion(); qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); @@ -1419,6 +1432,7 @@ void Application::idle() { } } } + void Application::terminate() { // Close serial port // close(serial_fd); @@ -4542,7 +4556,7 @@ void Application::toggleLogDialog() { } } -void Application::loadLatestVersionDetails() { +void Application::checkVersion() { QUrl url("https://a-tower.below92.com/version.xml"); QNetworkAccessManager *downloadXML = new QNetworkAccessManager(this); QNetworkRequest request(url); @@ -4552,28 +4566,56 @@ void Application::loadLatestVersionDetails() { } void Application::parseVersionXml(QNetworkReply *reply) { + QString _releaseDate; + QString _releaseNotes; + QString _downloadLink; + QXmlStreamReader xml(reply); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); if (token == QXmlStreamReader::StartElement) { + + if (xml.name() == "ReleaseDate") { + xml.readNext(); + _releaseDate = xml.text().toString(); + } + + if (xml.name() == "ReleaseNotes") { + xml.readNext(); + _releaseNotes = xml.text().toString(); + } + if (xml.name() == "Version") { xml.readNext(); _latestVersion = xml.text().toString(); - qDebug("################ Version found %s\n", _latestVersion.toStdString().c_str()); } } } + + if (applicationVersion() != _latestVersion) { + + } + + displayUpdateDialog(); } -void Application::checkVersion() { - loadLatestVersionDetails(); +void Application::displayUpdateDialog() { + int _windowWidth = 500; + int _windowHeigth = 300; + QString _windowTitle = "Newer build available"; - // This is a very rudimentary check, if this version is not equal to latest then you need to get it - // unless you're coming from the future. + QPushButton *download = new QPushButton("Download"); + QPushButton *ignore = new QPushButton("Ignore this version"); + QPushButton *close = new QPushButton("Close"); + + QWidget *updateDialog = new QWidget; + updateDialog->setFixedWidth(_windowWidth); + updateDialog->setFixedHeight(_windowHeigth); + updateDialog->setWindowTitle(_windowTitle); + + updateDialog->show(); - //if (applicationVersion() != 0 && applicationVersion() != this->_latestVersion) { - //} } diff --git a/interface/src/Application.h b/interface/src/Application.h index a02f136d3d..99873d4b57 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -69,6 +69,7 @@ #include "ui/RearMirrorTools.h" #include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" +#include "ui/UpdateDialog.h" #include "FileLogger.h" #include "ParticleTreeRenderer.h" #include "ParticleEditHandle.h" @@ -215,8 +216,8 @@ public: // Get XML with version information and parse it // Display dialog when version is not the latest and allow for new version download from link - void loadLatestVersionDetails(); void checkVersion(); + void displayUpdateDialog(); public slots: void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data); @@ -521,6 +522,7 @@ private: FileLogger* _logger; QString _latestVersion; + QString _operatingSystem; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp new file mode 100644 index 0000000000..c76cad7701 --- /dev/null +++ b/interface/src/ui/UpdateDialog.cpp @@ -0,0 +1,40 @@ +// +// UpdateDialog.cpp +// interface +// +// Created by Leonardo Murillo on 1/8/14. +// Copyright (c) 2013, 2014 High Fidelity, Inc. All rights reserved. +// + +#include +#include +#include + +#include "SharedUtil.h" +#include "UpdateDialog.h" + +const int buttonWidth = 120; +const int buttonHeight = 40; + +const QString dialogTitle = "Update Required"; +const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ + Please download and install the most recent release to access the latest \ + features and bug fixes.").arg("1", "2"); + +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString downloadURL) : QDialog(parent, Qt::Dialog) { + setWindowTitle(dialogTitle); + _releaseNotes = new QLabel(this); + _releaseNotes->setText(releaseNotes); + + _updateRequired = new QLabel(this); + _updateRequired->setText(updateRequired); + + _downloadButton = new QPushButton("Download", this); + _downloadButton->setObjectName("downloadButton"); + _skipButton = new QPushButton("Skip Version", this); + _skipButton->setObjectName("skipButton"); + _closeButton = new QPushButton("Close", this); + _closeButton->setObjectName("closeButton"); + + +} \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h new file mode 100644 index 0000000000..9a1bfff1c4 --- /dev/null +++ b/interface/src/ui/UpdateDialog.h @@ -0,0 +1,38 @@ +// +// UpdateDialog.h +// interface +// +// Created by Leonardo Murillo on 1/8/14. +// Copyright (c) 2013, 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__UpdateDialog__ +#define __hifi__UpdateDialog__ + +#include +#include +#include + +#include + +class UpdateDialog : public QDialog { + Q_OBJECT + +public: + UpdateDialog(QWidget*, QString releaseNotes, QString downloadURL); + ~UpdateDialog(); + +private: + QLabel *_updateRequired; + QLabel *_releaseNotes; + QPushButton *_downloadButton; + QPushButton *_skipButton; + QPushButton *_closeButton; + +private slots: + void handleDownload(); + void handleIgnore(); + void handleClose(); +}; + +#endif /* defined(__hifi__UpdateDialog__) */