From cefdbc312640674ca1979fa71090224429886865 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 2 Jun 2015 19:32:03 -0600 Subject: [PATCH 01/12] Checkpoint auto updater --- interface/CMakeLists.txt | 2 +- interface/src/Application.cpp | 72 +------------ interface/src/Application.h | 8 -- interface/src/ui/UpdateDialog.cpp | 55 ---------- interface/src/ui/UpdateDialog.h | 31 ------ interface/ui/updateDialog.ui | 132 ----------------------- libraries/auto-update/CMakeLists.txt | 3 + libraries/auto-update/src/AutoUpdate.cpp | 87 +++++++++++++++ libraries/auto-update/src/AutoUpdate.h | 63 +++++++++++ 9 files changed, 158 insertions(+), 295 deletions(-) delete mode 100644 interface/src/ui/UpdateDialog.cpp delete mode 100644 interface/src/ui/UpdateDialog.h delete mode 100644 interface/ui/updateDialog.ui create mode 100644 libraries/auto-update/CMakeLists.txt create mode 100644 libraries/auto-update/src/AutoUpdate.cpp create mode 100644 libraries/auto-update/src/AutoUpdate.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a0b258fc10..99478e2b84 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -140,7 +140,7 @@ target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) # link required hifi libraries link_hifi_libraries(shared octree environment gpu model fbx networking entities avatars audio audio-client animation script-engine physics - render-utils entities-renderer ui) + render-utils entities-renderer ui auto-update) add_dependency_external_projects(sdl2) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 803955f02c..39d93986d8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -539,8 +540,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // allow you to move an entity around in your hand _entityEditSender.setPacketsPerSecond(3000); // super high!! - checkVersion(); - _overlays.init(); // do this before scripts load _runningScriptsWidget->setRunningScripts(getRunningScripts()); @@ -612,6 +611,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : ddeTracker->init(); connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); #endif + + AutoUpdate* applicationUpdater = new AutoUpdate; + applicationUpdater->checkForUpdate(); } @@ -4404,72 +4406,6 @@ void Application::toggleLogDialog() { } } -void Application::checkVersion() { - QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); - latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); - latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - QNetworkReply* reply = NetworkAccessManager::getInstance().get(latestVersionRequest); - connect(reply, SIGNAL(finished()), SLOT(parseVersionXml())); -} - -void Application::parseVersionXml() { - - #ifdef Q_OS_WIN32 - QString operatingSystem("win"); - #endif - - #ifdef Q_OS_MAC - QString operatingSystem("mac"); - #endif - - #ifdef Q_OS_LINUX - QString operatingSystem("ubuntu"); - #endif - - QString latestVersion; - QUrl downloadUrl; - QString releaseNotes("Unavailable"); - QNetworkReply* sender = qobject_cast(QObject::sender()); - - QXmlStreamReader xml(sender); - - while (!xml.atEnd() && !xml.hasError()) { - if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == operatingSystem) { - while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == operatingSystem)) { - if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name().toString() == "version") { - xml.readNext(); - latestVersion = xml.text().toString(); - } - if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name().toString() == "url") { - xml.readNext(); - downloadUrl = QUrl(xml.text().toString()); - } - xml.readNext(); - } - } - xml.readNext(); - } - - if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); - } - sender->deleteLater(); -} - -bool Application::shouldSkipVersion(QString latestVersion) { - QFile skipFile(SKIP_FILENAME); - skipFile.open(QIODevice::ReadWrite); - QString skipVersion(skipFile.readAll()); - return (skipVersion == latestVersion || applicationVersion() == "dev"); -} - -void Application::skipVersion(QString latestVersion) { - QFile skipFile(SKIP_FILENAME); - skipFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - skipFile.seek(0); - skipFile.write(latestVersion.toStdString().c_str()); -} - void Application::takeSnapshot() { QMediaPlayer* player = new QMediaPlayer(); QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); diff --git a/interface/src/Application.h b/interface/src/Application.h index b6efb6420b..2b3530531f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -66,7 +66,6 @@ #include "ui/SnapshotShareDialog.h" #include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" -#include "ui/UpdateDialog.h" #include "ui/overlays/Overlays.h" #include "ui/ApplicationOverlay.h" #include "ui/RunningScriptsWidget.h" @@ -311,8 +310,6 @@ public: NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; } - void skipVersion(QString latestVersion); - QStringList getRunningScripts() { return _scriptEnginesHash.keys(); } ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; } @@ -454,8 +451,6 @@ private slots: void restoreMirrorView(); void shrinkMirrorView(); - void parseVersionXml(); - void manageRunningScriptsWidgetVisibility(bool shown); void runTests(); @@ -624,9 +619,6 @@ private: FileLogger* _logger; - void checkVersion(); - void displayUpdateDialog(); - bool shouldSkipVersion(QString latestVersion); void takeSnapshot(); TouchEvent _lastTouchEvent; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp deleted file mode 100644 index 40b32d66e3..0000000000 --- a/interface/src/ui/UpdateDialog.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// -// UpdateDialog.cpp -// interface/src/ui -// -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include - -#include "ui_updateDialog.h" - -#include "Application.h" -#include "UpdateDialog.h" - - -UpdateDialog::UpdateDialog(QWidget *parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL) : - QDialog(parent), - _latestVersion(latestVersion), - _downloadUrl(downloadURL) -{ - Ui::Dialog dialogUI; - dialogUI.setupUi(this); - - QString updateRequired = QString("You are currently running build %1, the latest build released is %2." - "\n\nPlease download and install the most recent release to access the latest features and bug fixes.") - .arg(Application::getInstance()->applicationVersion(), latestVersion); - - setAttribute(Qt::WA_DeleteOnClose); - - QPushButton* downloadButton = findChild("downloadButton"); - QPushButton* skipButton = findChild("skipButton"); - QPushButton* closeButton = findChild("closeButton"); - QLabel* updateContent = findChild("updateContent"); - - updateContent->setText(updateRequired); - - connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); - connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip())); - connect(closeButton, SIGNAL(released()), this, SLOT(close())); - - QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection); -} - -void UpdateDialog::handleDownload() { - QDesktopServices::openUrl(_downloadUrl); - Application::getInstance()->quit(); -} - -void UpdateDialog::handleSkip() { - Application::getInstance()->skipVersion(_latestVersion); - this->close(); -} diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h deleted file mode 100644 index 15a97bf024..0000000000 --- a/interface/src/ui/UpdateDialog.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// UpdateDialog.h -// interface/src/ui -// -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_UpdateDialog_h -#define hifi_UpdateDialog_h - -#include - -class UpdateDialog : public QDialog { - Q_OBJECT - -public: - UpdateDialog(QWidget* parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL); - -private: - QString _latestVersion; - QUrl _downloadUrl; - -private slots: - void handleDownload(); - void handleSkip(); -}; - -#endif // hifi_UpdateDialog_h diff --git a/interface/ui/updateDialog.ui b/interface/ui/updateDialog.ui deleted file mode 100644 index fc375e17c2..0000000000 --- a/interface/ui/updateDialog.ui +++ /dev/null @@ -1,132 +0,0 @@ - - - Dialog - - - Qt::NonModal - - - - 0 - 0 - 750 - 213 - - - - PointingHandCursor - - - Update Required - - - background-color: rgb(255, 255, 255); - - - - - 50 - 20 - 641 - 111 - - - - - Arial - -1 - - - - font-family: Arial; -font-size: 20px; - - - - - - true - - - - - - 360 - 160 - 374 - 42 - - - - - - - PointingHandCursor - - - background-color: #333333; -border-width: 0; -border-radius: 9px; -border-radius: 9px; -font-family: Arial; -font-size: 18px; -font-weight: 100; -color: #b7b7b7; -width: 120px; -height: 40px; - - - Download - - - - - - - PointingHandCursor - - - background-color: #333333; -border-width: 0; -border-radius: 9px; -border-radius: 9px; -font-family: Arial; -font-size: 18px; -font-weight: 100; -color: #b7b7b7; -width: 120px; -height: 40px; - - - Skip Version - - - - - - - PointingHandCursor - - - background-color: #333333; -border-width: 0; -border-radius: 9px; -border-radius: 9px; -font-family: Arial; -font-size: 18px; -font-weight: 100; -color: #b7b7b7; -width: 120px; -height: 40px; - - - Close - - - - - - - - - diff --git a/libraries/auto-update/CMakeLists.txt b/libraries/auto-update/CMakeLists.txt new file mode 100644 index 0000000000..0419048169 --- /dev/null +++ b/libraries/auto-update/CMakeLists.txt @@ -0,0 +1,3 @@ +set(TARGET_NAME auto-update) +setup_hifi_library(Network) +link_hifi_libraries(shared networking) diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp new file mode 100644 index 0000000000..8132f2ee60 --- /dev/null +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -0,0 +1,87 @@ +// +// AutoUpdate.cpp +// libraries/auto-update/src +// +// Created by Leonardo Murillo on 6/1/2015. +// Copyright 2015 High Fidelity, Inc. +// +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include "AutoUpdate.h" + +AutoUpdate::AutoUpdate() { +#ifdef Q_OS_WIN32 + _operatingSystem = "windows"; +#endif +#ifdef Q_OS_MAC + _operatingSystem = "mac"; +#endif +#ifdef Q_OS_LINUX + _operatingSystem = "ubuntu"; +#endif +} + +AutoUpdate::~AutoUpdate() { + qDebug() << "[LEOTEST] The object is now destroyed"; +} + +void AutoUpdate::checkForUpdate() { + this->getLatestVersionData(); + +} + +void AutoUpdate::getLatestVersionData() { + QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); + QNetworkRequest latestVersionRequest(BUILDS_XML_URL); + latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); + QNetworkReply* reply = networkAccessManager.get(latestVersionRequest); + connect(reply, SIGNAL(finished()), this, SLOT(parseLatestVersionData())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleError(QNetworkReply::NetworkError))); +} + + +void AutoUpdate::parseLatestVersionData() { + QNetworkReply* sender = qobject_cast(QObject::sender()); + + QXmlStreamReader xml(sender); + + while (!xml.atEnd() && !xml.hasError()) { + if (xml.name().toString() == "project" && + xml.attributes().hasAttribute("name") && + xml.attributes().value("name").toString() == "interface") { + xml.readNext(); + + while (!xml.atEnd() && !xml.hasError() && xml.name().toString() != "project") { + if (xml.name().toString() == "platform" && + xml.attributes().hasAttribute("name") && + xml.attributes().value("name").toString() == _operatingSystem) { + xml.readNext(); + while (!xml.atEnd() && !xml.hasError() && + xml.name().toString() != "platform") { + + if (xml.name().toString() == "build" && xml.tokenType() != QXmlStreamReader::EndElement) { + xml.readNext(); + QString version = xml.readElementText(); + xml.readNext(); + QString url = xml.readElementText(); + qDebug() << "[LEOTEST] Release version " << version << " downloadable at: " << url; + } + + xml.readNext(); + } + } + xml.readNext(); + } + + } else { + xml.readNext(); + } + } + sender->deleteLater(); +} \ No newline at end of file diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h new file mode 100644 index 0000000000..ee0434fde8 --- /dev/null +++ b/libraries/auto-update/src/AutoUpdate.h @@ -0,0 +1,63 @@ +// +// AutoUpdate.h +// libraries/auto-update/src +// +// Created by Leonardo Murillo on 6/1/2015. +// Copyright 2015 High Fidelity, Inc. +// +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef __hifi__AutoUpdate__ +#define __hifi__AutoUpdate__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +const QUrl BUILDS_XML_URL("https://highfidelity.com/builds.xml"); + +class AutoUpdate : public QObject { + Q_OBJECT +public: + // Methods + AutoUpdate(); + ~AutoUpdate(); + + void checkForUpdate(); + QMap> getBuildData() { return _builds; } + void appendBuildData(int versionNumber, + QString downloadURL, + int pullRequestNumber, + QString releaseNotes); + +public slots: + +private: + // Members + QMap> _builds; + QString _operatingSystem; + + // Methods + void getLatestVersionData(); + void performAutoUpdate(); + void downloadUpdateVersion(); + +private slots: + void parseLatestVersionData(); +}; + +#endif /* defined(__hifi__AutoUpdate__) */ From ef27a7660c6bf9f81bf5866f0234ee51e324ed13 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 3 Jun 2015 10:31:33 -0600 Subject: [PATCH 02/12] Checkpoint: AutoUpdate reads data from builds.xml and stores it in a QMap --- libraries/auto-update/src/AutoUpdate.cpp | 59 ++++++++++++++++++++++-- libraries/auto-update/src/AutoUpdate.h | 16 +++++-- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp index 8132f2ee60..32d1845218 100644 --- a/libraries/auto-update/src/AutoUpdate.cpp +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -25,6 +25,7 @@ AutoUpdate::AutoUpdate() { #ifdef Q_OS_LINUX _operatingSystem = "ubuntu"; #endif + //connect(this, SIGNAL(latestVersionDataParsed()), this, SLOT(debugBuildData())); } AutoUpdate::~AutoUpdate() { @@ -51,6 +52,14 @@ void AutoUpdate::parseLatestVersionData() { QXmlStreamReader xml(sender); + int version; + QString downloadUrl; + QString releaseTime; + QString releaseNotes; + QString commitSha; + QString pullRequestNumber; + + while (!xml.atEnd() && !xml.hasError()) { if (xml.name().toString() == "project" && xml.attributes().hasAttribute("name") && @@ -67,10 +76,26 @@ void AutoUpdate::parseLatestVersionData() { if (xml.name().toString() == "build" && xml.tokenType() != QXmlStreamReader::EndElement) { xml.readNext(); - QString version = xml.readElementText(); + version = xml.readElementText().toInt(); xml.readNext(); - QString url = xml.readElementText(); - qDebug() << "[LEOTEST] Release version " << version << " downloadable at: " << url; + downloadUrl = xml.readElementText(); + xml.readNext(); + releaseTime = xml.readElementText(); + xml.readNext(); + if (xml.name().toString() == "notes" && xml.tokenType() != QXmlStreamReader::EndElement) { + xml.readNext(); + while (!xml.atEnd() && !xml.hasError() && xml.name().toString() != "notes") { + if (xml.name().toString() == "note" && xml.tokenType() != QXmlStreamReader::EndElement) { + releaseNotes = releaseNotes + "\n" + xml.readElementText(); + } + xml.readNext(); + } + } + xml.readNext(); + commitSha = xml.readElementText(); + xml.readNext(); + pullRequestNumber = xml.readElementText(); + appendBuildData(version, downloadUrl, releaseTime, releaseNotes, pullRequestNumber); } xml.readNext(); @@ -84,4 +109,32 @@ void AutoUpdate::parseLatestVersionData() { } } sender->deleteLater(); + emit latestVersionDataParsed(); +} + +void AutoUpdate::debugBuildData() { + qDebug() << "[LEOTEST] We finished parsing the xml build data"; + foreach (int key, _builds.keys()) { + qDebug() << "[LEOTEST] Build number: " << QString::number(key); + foreach (QString detailsKey, _builds[key].keys()) { + qDebug() << "[LEOTEST] Key: " << detailsKey << " Value: " << _builds[key][detailsKey]; + } + } +} + +void AutoUpdate::performAutoUpdate() { + +} + +void AutoUpdate::downloadUpdateVersion() { + +} + +void AutoUpdate::appendBuildData(int versionNumber, QString downloadURL, QString releaseTime, QString releaseNotes, QString pullRequestNumber) { + QMap thisBuildDetails; + thisBuildDetails.insert("downloadUrl", downloadURL); + thisBuildDetails.insert("releaseTime", releaseTime); + thisBuildDetails.insert("releaseNotes", releaseNotes); + thisBuildDetails.insert("pullRequestNumber", pullRequestNumber); + _builds.insert(versionNumber, thisBuildDetails); } \ No newline at end of file diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h index ee0434fde8..0ee9704ccb 100644 --- a/libraries/auto-update/src/AutoUpdate.h +++ b/libraries/auto-update/src/AutoUpdate.h @@ -38,11 +38,6 @@ public: ~AutoUpdate(); void checkForUpdate(); - QMap> getBuildData() { return _builds; } - void appendBuildData(int versionNumber, - QString downloadURL, - int pullRequestNumber, - QString releaseNotes); public slots: @@ -55,9 +50,20 @@ private: void getLatestVersionData(); void performAutoUpdate(); void downloadUpdateVersion(); + QMap> getBuildData() { return _builds; } + void appendBuildData(int versionNumber, + QString downloadURL, + QString releaseTime, + QString releaseNotes, + QString pullRequestNumber); private slots: void parseLatestVersionData(); + void debugBuildData(); + +signals: + void latestVersionDataParsed(); + }; #endif /* defined(__hifi__AutoUpdate__) */ From b60597aa90189ffaac26270644cfffdc4d857dc0 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 3 Jun 2015 19:38:54 -0600 Subject: [PATCH 03/12] AutoUpdate is now a singleton invoked via Dependency Manager, first steps towards QML update notification --- interface/resources/qml/UpdateDialog.qml | 19 ++++++++++++++ interface/src/Application.cpp | 5 +++- interface/src/ui/DialogsManager.cpp | 6 +++++ interface/src/ui/DialogsManager.h | 4 +++ interface/src/ui/UpdateDialog.cpp | 20 +++++++++++++++ interface/src/ui/UpdateDialog.h | 32 ++++++++++++++++++++++++ libraries/auto-update/src/AutoUpdate.cpp | 19 ++++++++++---- libraries/auto-update/src/AutoUpdate.h | 16 +++++++++--- 8 files changed, 111 insertions(+), 10 deletions(-) create mode 100644 interface/resources/qml/UpdateDialog.qml create mode 100644 interface/src/ui/UpdateDialog.cpp create mode 100644 interface/src/ui/UpdateDialog.h diff --git a/interface/resources/qml/UpdateDialog.qml b/interface/resources/qml/UpdateDialog.qml new file mode 100644 index 0000000000..4d564dd56d --- /dev/null +++ b/interface/resources/qml/UpdateDialog.qml @@ -0,0 +1,19 @@ +import Hifi 1.0 +import QtQuick 2.3 +import QtQuick.Controls.Styles 1.3 +import "controls" +import "styles" + +Rectangle { + id: page + width: 320; height: 480 + color: "lightgray" + + Text { + id: helloText + text: "Hello world!" + y: 30 + anchors.horizontalCenter: page.horizontalCenter + font.pointSize: 24; font.bold: true + } +} \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 39d93986d8..798e698f69 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -143,6 +143,7 @@ #include "ui/StandAloneJSConsole.h" #include "ui/Stats.h" #include "ui/AddressBarDialog.h" +#include "ui/UpdateDialog.h" // ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU #if defined(Q_OS_WIN) @@ -290,6 +291,7 @@ bool setupEssentials(int& argc, char** argv) { auto discoverabilityManager = DependencyManager::set(); auto sceneScriptingInterface = DependencyManager::set(); auto offscreenUi = DependencyManager::set(); + auto autoUpdate = DependencyManager::set(); return true; } @@ -612,7 +614,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); #endif - AutoUpdate* applicationUpdater = new AutoUpdate; + auto applicationUpdater = DependencyManager::get(); + connect(applicationUpdater.data(), SIGNAL(newVersionIsAvailable()), dialogsManager.data(), SLOT(showUpdateDialog())); applicationUpdater->checkForUpdate(); } diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 1170e3c3a6..ebb329fcfd 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -31,6 +31,7 @@ #include "OctreeStatsDialog.h" #include "PreferencesDialog.h" #include "ScriptEditorWindow.h" +#include "UpdateDialog.h" void DialogsManager::toggleAddressBar() { @@ -50,6 +51,11 @@ void DialogsManager::showLoginDialog() { LoginDialog::show(); } +void DialogsManager::showUpdateDialog() { + qDebug() << "[LEOTEST] We should be showing the update dialog"; + UpdateDialog::show(); +} + void DialogsManager::octreeStatsDetails() { if (!_octreeStatsDialog) { _octreeStatsDialog = new OctreeStatsDialog(qApp->getWindow(), qApp->getOcteeSceneStats()); diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index fc2dad072b..f22773a622 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -35,6 +35,7 @@ class ScriptEditorWindow; class QMessageBox; class AvatarAppearanceDialog; class DomainConnectionDialog; +class UpdateDialog; class DialogsManager : public QObject, public Dependency { Q_OBJECT @@ -64,6 +65,9 @@ public slots: void showIRCLink(); void changeAvatarAppearance(); void showDomainConnectionDialog(); + + // Application Update + void showUpdateDialog(); private slots: void toggleToolWindow(); diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp new file mode 100644 index 0000000000..27fd94fa64 --- /dev/null +++ b/interface/src/ui/UpdateDialog.cpp @@ -0,0 +1,20 @@ +// +// UpdateDialog.cpp +// hifi +// +// Created by Leonardo Murillo on 6/3/15. +// +// + +#include "UpdateDialog.h" +#include "DependencyManager.h" + +HIFI_QML_DEF(UpdateDialog) + +UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { + +} + +void UpdateDialog::hide() { + ((QQuickItem*)parent())->setEnabled(false); +} diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h new file mode 100644 index 0000000000..bfc69064dd --- /dev/null +++ b/interface/src/ui/UpdateDialog.h @@ -0,0 +1,32 @@ +// +// UpdateDialog.h +// hifi +// +// Created by Leonardo Murillo on 6/3/15. +// +// + +#pragma once +#ifndef __hifi__UpdateDialog__ +#define __hifi__UpdateDialog__ + +#include + +class UpdateDialog : public OffscreenQmlDialog { + Q_OBJECT + HIFI_QML_DECL + +public: + UpdateDialog(QQuickItem* parent = nullptr); + +signals: + +protected: + void hide(); + +private: + + +}; + +#endif /* defined(__hifi__UpdateDialog__) */ diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp index 32d1845218..2324e69a2e 100644 --- a/libraries/auto-update/src/AutoUpdate.cpp +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -25,7 +25,7 @@ AutoUpdate::AutoUpdate() { #ifdef Q_OS_LINUX _operatingSystem = "ubuntu"; #endif - //connect(this, SIGNAL(latestVersionDataParsed()), this, SLOT(debugBuildData())); + connect(this, SIGNAL(latestVersionDataParsed()), this, SLOT(checkVersionAndNotify())); } AutoUpdate::~AutoUpdate() { @@ -43,7 +43,6 @@ void AutoUpdate::getLatestVersionData() { latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); QNetworkReply* reply = networkAccessManager.get(latestVersionRequest); connect(reply, SIGNAL(finished()), this, SLOT(parseLatestVersionData())); - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleError(QNetworkReply::NetworkError))); } @@ -96,6 +95,7 @@ void AutoUpdate::parseLatestVersionData() { xml.readNext(); pullRequestNumber = xml.readElementText(); appendBuildData(version, downloadUrl, releaseTime, releaseNotes, pullRequestNumber); + releaseNotes = ""; } xml.readNext(); @@ -122,12 +122,21 @@ void AutoUpdate::debugBuildData() { } } -void AutoUpdate::performAutoUpdate() { +void AutoUpdate::checkVersionAndNotify() { + qDebug() << "[LEOTEST] We are checking and notifying for updates"; + int latestVersionAvailable = _builds.lastKey(); + if (QCoreApplication::applicationVersion() != "dev" && + QCoreApplication::applicationVersion().toInt() < latestVersionAvailable) { + emit newVersionIsAvailable(); + } +} + +void AutoUpdate::performAutoUpdate(int version) { } -void AutoUpdate::downloadUpdateVersion() { - +void AutoUpdate::downloadUpdateVersion(int version) { + emit newVersionIsDownloaded(); } void AutoUpdate::appendBuildData(int versionNumber, QString downloadURL, QString releaseTime, QString releaseNotes, QString pullRequestNumber) { diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h index 0ee9704ccb..d77bdc89da 100644 --- a/libraries/auto-update/src/AutoUpdate.h +++ b/libraries/auto-update/src/AutoUpdate.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -27,17 +28,22 @@ #include #include +#include + const QUrl BUILDS_XML_URL("https://highfidelity.com/builds.xml"); -class AutoUpdate : public QObject { +class AutoUpdate : public QObject, public Dependency { Q_OBJECT + SINGLETON_DEPENDENCY + public: // Methods AutoUpdate(); ~AutoUpdate(); void checkForUpdate(); + QMap> getBuildData() { return _builds; } public slots: @@ -48,9 +54,7 @@ private: // Methods void getLatestVersionData(); - void performAutoUpdate(); - void downloadUpdateVersion(); - QMap> getBuildData() { return _builds; } + void downloadUpdateVersion(int version); void appendBuildData(int versionNumber, QString downloadURL, QString releaseTime, @@ -60,9 +64,13 @@ private: private slots: void parseLatestVersionData(); void debugBuildData(); + void checkVersionAndNotify(); + void performAutoUpdate(int version); signals: void latestVersionDataParsed(); + void newVersionIsAvailable(); + void newVersionIsDownloaded(); }; From dea80d175756df43683d9d7137680617265a0210 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 5 Jun 2015 16:17:54 -0600 Subject: [PATCH 04/12] Styling update dialog and working towards passing build details from c++ to qml --- interface/resources/qml/UpdateDialog.qml | 73 ++++++++++++++++++++---- interface/src/ui/DialogsManager.cpp | 7 ++- interface/src/ui/DialogsManager.h | 1 + interface/src/ui/UpdateDialog.cpp | 27 +++++++++ interface/src/ui/UpdateDialog.h | 14 ++++- libraries/auto-update/src/AutoUpdate.cpp | 13 +++-- libraries/auto-update/src/AutoUpdate.h | 4 +- 7 files changed, 118 insertions(+), 21 deletions(-) diff --git a/interface/resources/qml/UpdateDialog.qml b/interface/resources/qml/UpdateDialog.qml index 4d564dd56d..884b243682 100644 --- a/interface/resources/qml/UpdateDialog.qml +++ b/interface/resources/qml/UpdateDialog.qml @@ -4,16 +4,67 @@ import QtQuick.Controls.Styles 1.3 import "controls" import "styles" -Rectangle { - id: page - width: 320; height: 480 - color: "lightgray" - - Text { - id: helloText - text: "Hello world!" - y: 30 - anchors.horizontalCenter: page.horizontalCenter - font.pointSize: 24; font.bold: true +Item { + id: updateDialog + implicitWidth: backgroundImage.width + implicitHeight: backgroundImage.height + releaseNotes.height + x: parent ? parent.width / 2 - width / 2 : 0 + y: parent ? parent.height / 2 - height / 2 : 0 + + Image { + id: backgroundImage + source: "../images/update-available.svg" + width: 576 + height: 80 + smooth: true + + Text { + id: updateAvailableTitle + text: "Update available" + color: "#000000" + x: 90 + y: 17 + } + + Text { + id: updateAvailableDetails + text: updateDialog.updateAvailableDetails + width: parent.width + anchors.top: updateAvailableTitle.bottom + anchors.topMargin: 3 + font.pixelSize: 15 + color: "#545454" + x: 90 + } } + + Rectangle { + id: releaseNotes + color: "#CCE8E8E8" + anchors.top: backgroundImage.bottom + anchors.topMargin: 0 + width: backgroundImage.width - 90 + height: releaseNotesContent.height + x: 50 + radius: 10 + + + TextEdit { + id: releaseNotesContent + readOnly: true + font.pixelSize: 13 + width: parent.width + x: 10 + y: 10 + color: "#111111" + text: + "These are the release notes: \n" + + "And some more text about what this includes: \n" + + "These are the release notes: \n" + + "And some more text about what this includes: \n" + + "These are the release notes: \n" + + "And some more text about what this includes: \n"; + } + } + } \ No newline at end of file diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index ebb329fcfd..45c9ea4151 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -53,7 +53,12 @@ void DialogsManager::showLoginDialog() { void DialogsManager::showUpdateDialog() { qDebug() << "[LEOTEST] We should be showing the update dialog"; - UpdateDialog::show(); + if (!_updateDialog) { + _updateDialog = new UpdateDialog(); + connect(_updateDialog, SIGNAL(closed()), _updateDialog, SLOT(deleteLater())); + _updateDialog->setUpdateAvailableDetails(""); + _updateDialog->show(); + } } void DialogsManager::octreeStatsDetails() { diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index f22773a622..7eb716b73c 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -105,6 +105,7 @@ private: QPointer _scriptEditor; QPointer _avatarAppearanceDialog; QPointer _domainConnectionDialog; + QPointer _updateDialog; }; #endif // hifi_DialogsManager_h diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 27fd94fa64..abd7587091 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -8,6 +8,7 @@ #include "UpdateDialog.h" #include "DependencyManager.h" +#include HIFI_QML_DEF(UpdateDialog) @@ -15,6 +16,32 @@ UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { } +UpdateDialog::~UpdateDialog() { +} + +void UpdateDialog::displayDialog() { + setUpdateAvailableDetails(""); + show(); +} + +void UpdateDialog::setUpdateAvailableDetails(const QString& updateAvailableDetails) { + if (updateAvailableDetails != _updateAvailableDetails) { + auto applicationUpdater = DependencyManager::get(); + foreach (int key, applicationUpdater.data()->getBuildData().keys()) { + qDebug() << "[LEOTEST] Build number: " << QString::number(key); + } + _updateAvailableDetails = "This is just a test " + QString::number(applicationUpdater.data()->getBuildData().lastKey()); + } +} + +QString UpdateDialog::updateAvailableDetails() const { + return _updateAvailableDetails; +} + void UpdateDialog::hide() { ((QQuickItem*)parent())->setEnabled(false); } + +void UpdateDialog::triggerBuildDownload(const int &buildNumber) { + qDebug() << "[LEOTEST] Triggering download of build number: " << QString::number(buildNumber); +} \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index bfc69064dd..23f2a0faf6 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -16,16 +16,28 @@ class UpdateDialog : public OffscreenQmlDialog { Q_OBJECT HIFI_QML_DECL + Q_PROPERTY(QString updateAvailableDetails READ updateAvailableDetails WRITE setUpdateAvailableDetails NOTIFY updateAvailableDetailsChanged) + public: UpdateDialog(QQuickItem* parent = nullptr); + ~UpdateDialog(); + + void displayDialog(); + void setUpdateAvailableDetails(const QString& updateAvailableDetails); + QString updateAvailableDetails() const; signals: + void updateAvailableDetailsChanged(); protected: void hide(); -private: +private: + QString _updateAvailableDetails; + +protected: + Q_INVOKABLE void triggerBuildDownload(const int& buildNumber); }; diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp index 2324e69a2e..093a7b5d86 100644 --- a/libraries/auto-update/src/AutoUpdate.cpp +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -26,6 +26,7 @@ AutoUpdate::AutoUpdate() { _operatingSystem = "ubuntu"; #endif connect(this, SIGNAL(latestVersionDataParsed()), this, SLOT(checkVersionAndNotify())); + _builds = new QMap>; } AutoUpdate::~AutoUpdate() { @@ -114,17 +115,17 @@ void AutoUpdate::parseLatestVersionData() { void AutoUpdate::debugBuildData() { qDebug() << "[LEOTEST] We finished parsing the xml build data"; - foreach (int key, _builds.keys()) { + foreach (int key, _builds->keys()) { qDebug() << "[LEOTEST] Build number: " << QString::number(key); - foreach (QString detailsKey, _builds[key].keys()) { - qDebug() << "[LEOTEST] Key: " << detailsKey << " Value: " << _builds[key][detailsKey]; - } + //foreach (QString detailsKey, _builds[key].keys()) { + // qDebug() << "[LEOTEST] Key: " << detailsKey << " Value: " << _builds[key][detailsKey]; + //} } } void AutoUpdate::checkVersionAndNotify() { qDebug() << "[LEOTEST] We are checking and notifying for updates"; - int latestVersionAvailable = _builds.lastKey(); + int latestVersionAvailable = _builds->lastKey(); if (QCoreApplication::applicationVersion() != "dev" && QCoreApplication::applicationVersion().toInt() < latestVersionAvailable) { emit newVersionIsAvailable(); @@ -145,5 +146,5 @@ void AutoUpdate::appendBuildData(int versionNumber, QString downloadURL, QString thisBuildDetails.insert("releaseTime", releaseTime); thisBuildDetails.insert("releaseNotes", releaseNotes); thisBuildDetails.insert("pullRequestNumber", pullRequestNumber); - _builds.insert(versionNumber, thisBuildDetails); + _builds->insert(versionNumber, thisBuildDetails); } \ No newline at end of file diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h index d77bdc89da..4b32d68c48 100644 --- a/libraries/auto-update/src/AutoUpdate.h +++ b/libraries/auto-update/src/AutoUpdate.h @@ -43,13 +43,13 @@ public: ~AutoUpdate(); void checkForUpdate(); - QMap> getBuildData() { return _builds; } + QMap> &getBuildData() { return *_builds; } public slots: private: // Members - QMap> _builds; + QMap> *_builds; QString _operatingSystem; // Methods From 68b419deecc5dfce78c32328f52ea41fad89da00 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 5 Jun 2015 17:11:32 -0600 Subject: [PATCH 05/12] Syncing --- interface/resources/qml/UpdateDialog.qml | 4 +++- interface/src/Application.cpp | 1 + interface/src/ui/UpdateDialog.cpp | 7 +++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/UpdateDialog.qml b/interface/resources/qml/UpdateDialog.qml index 884b243682..a7e91349a6 100644 --- a/interface/resources/qml/UpdateDialog.qml +++ b/interface/resources/qml/UpdateDialog.qml @@ -4,8 +4,10 @@ import QtQuick.Controls.Styles 1.3 import "controls" import "styles" -Item { +UpdateDialog { + HifiConstants { id: hifi } id: updateDialog + objectName: "UpdateDialog" implicitWidth: backgroundImage.width implicitHeight: backgroundImage.height + releaseNotes.height x: parent ? parent.width / 2 - width / 2 : 0 diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5480e34dd8..3ee470cc17 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -809,6 +809,7 @@ void Application::initializeUi() { LoginDialog::registerType(); MessageDialog::registerType(); VrMenu::registerType(); + UpdateDialog::registerType(); auto offscreenUi = DependencyManager::get(); offscreenUi->create(_glWidget->context()->contextHandle()); diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index abd7587091..14502f28fc 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -25,12 +25,11 @@ void UpdateDialog::displayDialog() { } void UpdateDialog::setUpdateAvailableDetails(const QString& updateAvailableDetails) { - if (updateAvailableDetails != _updateAvailableDetails) { + if (updateAvailableDetails == "") { auto applicationUpdater = DependencyManager::get(); - foreach (int key, applicationUpdater.data()->getBuildData().keys()) { - qDebug() << "[LEOTEST] Build number: " << QString::number(key); - } _updateAvailableDetails = "This is just a test " + QString::number(applicationUpdater.data()->getBuildData().lastKey()); + qDebug() << "[LEOTEST] We are updating the text in the dialog"; + emit updateAvailableDetailsChanged(); } } From bd85ce13124532d5be688241840fabbd47605f16 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 8 Jun 2015 13:55:28 -0600 Subject: [PATCH 06/12] Auto Update checkpoint - dialog is QML and populated with real data --- interface/resources/qml/UpdateDialog.qml | 151 ++++++++++++++--------- interface/src/ui/DialogsManager.cpp | 8 +- interface/src/ui/UpdateDialog.cpp | 28 ++--- interface/src/ui/UpdateDialog.h | 14 +-- libraries/auto-update/src/AutoUpdate.cpp | 8 +- 5 files changed, 123 insertions(+), 86 deletions(-) diff --git a/interface/resources/qml/UpdateDialog.qml b/interface/resources/qml/UpdateDialog.qml index a7e91349a6..a823bfff79 100644 --- a/interface/resources/qml/UpdateDialog.qml +++ b/interface/resources/qml/UpdateDialog.qml @@ -4,69 +4,108 @@ import QtQuick.Controls.Styles 1.3 import "controls" import "styles" -UpdateDialog { +DialogContainer { HifiConstants { id: hifi } - id: updateDialog + id: root objectName: "UpdateDialog" - implicitWidth: backgroundImage.width - implicitHeight: backgroundImage.height + releaseNotes.height + implicitWidth: updateDialog.width + implicitHeight: updateDialog.height x: parent ? parent.width / 2 - width / 2 : 0 y: parent ? parent.height / 2 - height / 2 : 0 - Image { - id: backgroundImage - source: "../images/update-available.svg" - width: 576 - height: 80 - smooth: true + UpdateDialog { + id: updateDialog - Text { - id: updateAvailableTitle - text: "Update available" - color: "#000000" - x: 90 - y: 17 - } + implicitWidth: backgroundRectangle.width + implicitHeight: backgroundRectangle.height - Text { - id: updateAvailableDetails - text: updateDialog.updateAvailableDetails - width: parent.width - anchors.top: updateAvailableTitle.bottom - anchors.topMargin: 3 - font.pixelSize: 15 - color: "#545454" - x: 90 + readonly property int inputWidth: 500 + readonly property int inputHeight: 60 + readonly property int borderWidth: 30 + readonly property int closeMargin: 16 + readonly property int inputSpacing: 16 + + Column { + id: mainContent + width: updateDialog.inputWidth + spacing: updateDialog.inputSpacing + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } + + Rectangle { + id: backgroundRectangle + color: "#2c86b1" + opacity: 0.85 + radius: updateDialog.closeMargin * 2 + + width: updateDialog.inputWidth + updateDialog.borderWidth * 2 + height: updateDialog.inputHeight * 6 + updateDialog.closeMargin * 2 + + Rectangle { + id: dialogTitle + width: updateDialog.inputWidth + height: updateDialog.inputHeight + radius: height / 2 + color: "#ebebeb" + + anchors { + top: parent.top + topMargin: updateDialog.inputSpacing + horizontalCenter: parent.horizontalCenter + } + + Text { + id: updateAvailableText + text: "Update Available" + anchors { + verticalCenter: parent.verticalCenter + left: parent.left + leftMargin: updateDialog.inputSpacing + } + } + + Text { + text: updateDialog.updateAvailableDetails + font.pixelSize: 14 + color: hifi.colors.text + anchors { + verticalCenter: parent.verticalCenter + left: updateAvailableText.right + leftMargin: 13 + } + } + } + + Flickable { + id: scrollArea + anchors { + top: dialogTitle.bottom + } + contentWidth: updateDialog.inputWidth + contentHeight: backgroundRectangle.height - (dialogTitle.height * 2) + width: updateDialog.inputWidth + height: backgroundRectangle.height - (dialogTitle.height * 2) + flickableDirection: Flickable.VerticalFlick + clip: true + + TextEdit { + id: releaseNotes + wrapMode: TextEdit.Wrap + width: parent.width + readOnly: true + text: updateDialog.releaseNotes + font.pixelSize: 14 + color: hifi.colors.text + anchors { + left: parent.left + leftMargin: updateDialog.borderWidth + } + } + + } + } } } - - Rectangle { - id: releaseNotes - color: "#CCE8E8E8" - anchors.top: backgroundImage.bottom - anchors.topMargin: 0 - width: backgroundImage.width - 90 - height: releaseNotesContent.height - x: 50 - radius: 10 - - - TextEdit { - id: releaseNotesContent - readOnly: true - font.pixelSize: 13 - width: parent.width - x: 10 - y: 10 - color: "#111111" - text: - "These are the release notes: \n" + - "And some more text about what this includes: \n" + - "These are the release notes: \n" + - "And some more text about what this includes: \n" + - "These are the release notes: \n" + - "And some more text about what this includes: \n"; - } - } - } \ No newline at end of file diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 45c9ea4151..81c7cd2770 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -52,13 +52,7 @@ void DialogsManager::showLoginDialog() { } void DialogsManager::showUpdateDialog() { - qDebug() << "[LEOTEST] We should be showing the update dialog"; - if (!_updateDialog) { - _updateDialog = new UpdateDialog(); - connect(_updateDialog, SIGNAL(closed()), _updateDialog, SLOT(deleteLater())); - _updateDialog->setUpdateAvailableDetails(""); - _updateDialog->show(); - } + UpdateDialog::show(); } void DialogsManager::octreeStatsDetails() { diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 14502f28fc..c5a6234f2c 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -13,30 +13,30 @@ HIFI_QML_DEF(UpdateDialog) UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { - + qDebug() << "[LEOTEST] We are creating the dialog"; + auto applicationUpdater = DependencyManager::get(); + int currentVersion = QCoreApplication::applicationVersion().toInt(); + int latestVersion = applicationUpdater.data()->getBuildData().lastKey(); + int versionsBehind = latestVersion - currentVersion; + _updateAvailableDetails = "v." + QString::number(latestVersion) + " released on " + applicationUpdater.data()->getBuildData()[latestVersion]["releaseTime"]; + _updateAvailableDetails += "\nYou are " + QString::number(versionsBehind) + " versions behind"; + _releaseNotes = applicationUpdater.data()->getBuildData()[latestVersion]["releaseNotes"]; + qDebug() << "[LEOTEST] Release time " << applicationUpdater.data()->getBuildData()[latestVersion]["releaseTime"]; + qDebug() << "[LEOTEST] Release notes: " << applicationUpdater.data()->getBuildData()[latestVersion]["releaseNotes"]; } UpdateDialog::~UpdateDialog() { -} -void UpdateDialog::displayDialog() { - setUpdateAvailableDetails(""); - show(); -} - -void UpdateDialog::setUpdateAvailableDetails(const QString& updateAvailableDetails) { - if (updateAvailableDetails == "") { - auto applicationUpdater = DependencyManager::get(); - _updateAvailableDetails = "This is just a test " + QString::number(applicationUpdater.data()->getBuildData().lastKey()); - qDebug() << "[LEOTEST] We are updating the text in the dialog"; - emit updateAvailableDetailsChanged(); - } } QString UpdateDialog::updateAvailableDetails() const { return _updateAvailableDetails; } +QString UpdateDialog::releaseNotes() const { + return _releaseNotes; +} + void UpdateDialog::hide() { ((QQuickItem*)parent())->setEnabled(false); } diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 23f2a0faf6..6ba8f0c46b 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -10,31 +10,29 @@ #ifndef __hifi__UpdateDialog__ #define __hifi__UpdateDialog__ + +#include #include class UpdateDialog : public OffscreenQmlDialog { Q_OBJECT HIFI_QML_DECL - Q_PROPERTY(QString updateAvailableDetails READ updateAvailableDetails WRITE setUpdateAvailableDetails NOTIFY updateAvailableDetailsChanged) + Q_PROPERTY(QString updateAvailableDetails READ updateAvailableDetails) + Q_PROPERTY(QString releaseNotes READ releaseNotes) public: UpdateDialog(QQuickItem* parent = nullptr); ~UpdateDialog(); - - void displayDialog(); - void setUpdateAvailableDetails(const QString& updateAvailableDetails); QString updateAvailableDetails() const; - -signals: - void updateAvailableDetailsChanged(); + QString releaseNotes() const; protected: void hide(); - private: QString _updateAvailableDetails; + QString _releaseNotes; protected: Q_INVOKABLE void triggerBuildDownload(const int& buildNumber); diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp index 093a7b5d86..be52b283c5 100644 --- a/libraries/auto-update/src/AutoUpdate.cpp +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -140,11 +140,17 @@ void AutoUpdate::downloadUpdateVersion(int version) { emit newVersionIsDownloaded(); } -void AutoUpdate::appendBuildData(int versionNumber, QString downloadURL, QString releaseTime, QString releaseNotes, QString pullRequestNumber) { +void AutoUpdate::appendBuildData(int versionNumber, + QString downloadURL, + QString releaseTime, + QString releaseNotes, + QString pullRequestNumber) { + QMap thisBuildDetails; thisBuildDetails.insert("downloadUrl", downloadURL); thisBuildDetails.insert("releaseTime", releaseTime); thisBuildDetails.insert("releaseNotes", releaseNotes); thisBuildDetails.insert("pullRequestNumber", pullRequestNumber); _builds->insert(versionNumber, thisBuildDetails); + } \ No newline at end of file From edce36f5a120f76a9453f4d805e9e74d2f44382f Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 8 Jun 2015 14:29:10 -0600 Subject: [PATCH 07/12] Checkpoint - buttons in place --- interface/resources/qml/UpdateDialog.qml | 101 ++++++++++++++++++++++- interface/src/ui/UpdateDialog.cpp | 13 +-- interface/src/ui/UpdateDialog.h | 7 +- 3 files changed, 110 insertions(+), 11 deletions(-) diff --git a/interface/resources/qml/UpdateDialog.qml b/interface/resources/qml/UpdateDialog.qml index a823bfff79..10b0839cca 100644 --- a/interface/resources/qml/UpdateDialog.qml +++ b/interface/resources/qml/UpdateDialog.qml @@ -1,6 +1,7 @@ import Hifi 1.0 import QtQuick 2.3 import QtQuick.Controls.Styles 1.3 +import QtGraphicalEffects 1.0 import "controls" import "styles" @@ -24,6 +25,12 @@ DialogContainer { readonly property int borderWidth: 30 readonly property int closeMargin: 16 readonly property int inputSpacing: 16 + readonly property int buttonWidth: 150 + readonly property int buttonHeight: 50 + readonly property int buttonRadius: 15 + + signal triggerBuildDownload + signal closeUpdateDialog Column { id: mainContent @@ -84,9 +91,9 @@ DialogContainer { top: dialogTitle.bottom } contentWidth: updateDialog.inputWidth - contentHeight: backgroundRectangle.height - (dialogTitle.height * 2) + contentHeight: backgroundRectangle.height - (dialogTitle.height * 2.5) width: updateDialog.inputWidth - height: backgroundRectangle.height - (dialogTitle.height * 2) + height: backgroundRectangle.height - (dialogTitle.height * 2.5) flickableDirection: Flickable.VerticalFlick clip: true @@ -105,6 +112,96 @@ DialogContainer { } } + + Rectangle { + id: downloadButton + width: updateDialog.buttonWidth + height: updateDialog.buttonHeight + radius: updateDialog.buttonRadius + color: "green" + anchors { + top: scrollArea.bottom + topMargin: 10 + right: backgroundRectangle.right + rightMargin: 15 + } + Accessible.name: "Upgrade" + Accessible.description: "Download and update to latest version" + Accessible.role: Accessible.Button + Accessible.onPressAction: { + updateDialog.triggerBuildDownload() + } + + + Text { + text: "Upgrade" + anchors { + verticalCenter: parent.verticalCenter + horizontalCenter: parent.horizontalCenter + } + + } + } + + DropShadow { + anchors.fill: downloadButton + horizontalOffset: 2 + verticalOffset: 2 + radius: updateDialog.buttonRadius + samples: 16 + color: "#80000000" + source: downloadButton + } + + MouseArea { + id: downloadButtonAction + anchors.fill: downloadButton + onClicked: updateDialog.triggerBuildDownload() + } + + Rectangle { + id: cancelButton + width: updateDialog.buttonWidth + height: updateDialog.buttonHeight + radius: updateDialog.buttonRadius + color: "red" + anchors { + top: scrollArea.bottom + topMargin: 10 + right: downloadButton.left + rightMargin: 15 + } + Accessible.name: "Cancel" + Accessible.description: "Do not upgrade your current version" + Accessible.role: Accessible.Button + Accessible.onPressAction: { + updateDialog.closeUpdateDialog() + } + + Text { + text: "Cancel" + anchors { + verticalCenter: parent.verticalCenter + horizontalCenter: parent.horizontalCenter + } + } + } + + DropShadow { + anchors.fill: cancelButton + horizontalOffset: 2 + verticalOffset: 2 + radius: updateDialog.buttonRadius + samples: 16 + color: "#80000000" + source: cancelButton + } + + MouseArea { + id: cancelButtonAction + anchors.fill: cancelButton + onClicked: updateDialog.closeUpdateDialog() + } } } } diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index c5a6234f2c..5cf5a4fbed 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -18,11 +18,9 @@ UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { int currentVersion = QCoreApplication::applicationVersion().toInt(); int latestVersion = applicationUpdater.data()->getBuildData().lastKey(); int versionsBehind = latestVersion - currentVersion; - _updateAvailableDetails = "v." + QString::number(latestVersion) + " released on " + applicationUpdater.data()->getBuildData()[latestVersion]["releaseTime"]; + _updateAvailableDetails = "v" + QString::number(latestVersion) + " released on " + applicationUpdater.data()->getBuildData()[latestVersion]["releaseTime"]; _updateAvailableDetails += "\nYou are " + QString::number(versionsBehind) + " versions behind"; _releaseNotes = applicationUpdater.data()->getBuildData()[latestVersion]["releaseNotes"]; - qDebug() << "[LEOTEST] Release time " << applicationUpdater.data()->getBuildData()[latestVersion]["releaseTime"]; - qDebug() << "[LEOTEST] Release notes: " << applicationUpdater.data()->getBuildData()[latestVersion]["releaseNotes"]; } UpdateDialog::~UpdateDialog() { @@ -37,10 +35,15 @@ QString UpdateDialog::releaseNotes() const { return _releaseNotes; } +void UpdateDialog::closeUpdateDialog() { + qDebug() << "[LEOTEST] Closing update dialog"; + hide(); +} + void UpdateDialog::hide() { ((QQuickItem*)parent())->setEnabled(false); } -void UpdateDialog::triggerBuildDownload(const int &buildNumber) { - qDebug() << "[LEOTEST] Triggering download of build number: " << QString::number(buildNumber); +void UpdateDialog::triggerUpgrade() { + qDebug() << "[LEOTEST] Triggering download of build number"; } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 6ba8f0c46b..eda7f8ceb2 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -27,15 +27,14 @@ public: QString updateAvailableDetails() const; QString releaseNotes() const; -protected: - void hide(); - private: QString _updateAvailableDetails; QString _releaseNotes; protected: - Q_INVOKABLE void triggerBuildDownload(const int& buildNumber); + void hide(); + Q_INVOKABLE void triggerUpgrade(); + Q_INVOKABLE void closeUpdateDialog(); }; From 7aee293df4e053c2bd21f0e82280750be186521a Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 8 Jun 2015 14:56:46 -0600 Subject: [PATCH 08/12] Buttons are connected and execting old functions --- interface/resources/qml/UpdateDialog.qml | 60 +++++------------------- interface/src/ui/UpdateDialog.cpp | 11 ++--- interface/src/ui/UpdateDialog.h | 3 +- libraries/auto-update/src/AutoUpdate.cpp | 22 +++------ libraries/auto-update/src/AutoUpdate.h | 5 +- 5 files changed, 24 insertions(+), 77 deletions(-) diff --git a/interface/resources/qml/UpdateDialog.qml b/interface/resources/qml/UpdateDialog.qml index 10b0839cca..e5216ff619 100644 --- a/interface/resources/qml/UpdateDialog.qml +++ b/interface/resources/qml/UpdateDialog.qml @@ -110,7 +110,6 @@ DialogContainer { leftMargin: updateDialog.borderWidth } } - } Rectangle { @@ -125,38 +124,19 @@ DialogContainer { right: backgroundRectangle.right rightMargin: 15 } - Accessible.name: "Upgrade" - Accessible.description: "Download and update to latest version" - Accessible.role: Accessible.Button - Accessible.onPressAction: { - updateDialog.triggerBuildDownload() - } - - Text { text: "Upgrade" anchors { verticalCenter: parent.verticalCenter horizontalCenter: parent.horizontalCenter } - } - } - - DropShadow { - anchors.fill: downloadButton - horizontalOffset: 2 - verticalOffset: 2 - radius: updateDialog.buttonRadius - samples: 16 - color: "#80000000" - source: downloadButton - } - - MouseArea { - id: downloadButtonAction - anchors.fill: downloadButton - onClicked: updateDialog.triggerBuildDownload() + MouseArea { + id: downloadButtonAction + anchors.fill: parent + onClicked: updateDialog.triggerUpgrade() + cursorShape: "PointingHandCursor" + } } Rectangle { @@ -171,12 +151,6 @@ DialogContainer { right: downloadButton.left rightMargin: 15 } - Accessible.name: "Cancel" - Accessible.description: "Do not upgrade your current version" - Accessible.role: Accessible.Button - Accessible.onPressAction: { - updateDialog.closeUpdateDialog() - } Text { text: "Cancel" @@ -185,22 +159,12 @@ DialogContainer { horizontalCenter: parent.horizontalCenter } } - } - - DropShadow { - anchors.fill: cancelButton - horizontalOffset: 2 - verticalOffset: 2 - radius: updateDialog.buttonRadius - samples: 16 - color: "#80000000" - source: cancelButton - } - - MouseArea { - id: cancelButtonAction - anchors.fill: cancelButton - onClicked: updateDialog.closeUpdateDialog() + MouseArea { + id: cancelButtonAction + anchors.fill: parent + onClicked: updateDialog.closeDialog() + cursorShape: "PointingHandCursor" + } } } } diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 5cf5a4fbed..9a6da9148e 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -13,7 +13,6 @@ HIFI_QML_DEF(UpdateDialog) UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { - qDebug() << "[LEOTEST] We are creating the dialog"; auto applicationUpdater = DependencyManager::get(); int currentVersion = QCoreApplication::applicationVersion().toInt(); int latestVersion = applicationUpdater.data()->getBuildData().lastKey(); @@ -23,10 +22,6 @@ UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { _releaseNotes = applicationUpdater.data()->getBuildData()[latestVersion]["releaseNotes"]; } -UpdateDialog::~UpdateDialog() { - -} - QString UpdateDialog::updateAvailableDetails() const { return _updateAvailableDetails; } @@ -35,8 +30,7 @@ QString UpdateDialog::releaseNotes() const { return _releaseNotes; } -void UpdateDialog::closeUpdateDialog() { - qDebug() << "[LEOTEST] Closing update dialog"; +void UpdateDialog::closeDialog() { hide(); } @@ -45,5 +39,6 @@ void UpdateDialog::hide() { } void UpdateDialog::triggerUpgrade() { - qDebug() << "[LEOTEST] Triggering download of build number"; + auto applicationUpdater = DependencyManager::get(); + applicationUpdater.data()->performAutoUpdate(applicationUpdater.data()->getBuildData().lastKey()); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index eda7f8ceb2..25ea42e7bc 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -23,7 +23,6 @@ class UpdateDialog : public OffscreenQmlDialog { public: UpdateDialog(QQuickItem* parent = nullptr); - ~UpdateDialog(); QString updateAvailableDetails() const; QString releaseNotes() const; @@ -34,7 +33,7 @@ private: protected: void hide(); Q_INVOKABLE void triggerUpgrade(); - Q_INVOKABLE void closeUpdateDialog(); + Q_INVOKABLE void closeDialog(); }; diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp index be52b283c5..3295016f81 100644 --- a/libraries/auto-update/src/AutoUpdate.cpp +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -29,10 +29,6 @@ AutoUpdate::AutoUpdate() { _builds = new QMap>; } -AutoUpdate::~AutoUpdate() { - qDebug() << "[LEOTEST] The object is now destroyed"; -} - void AutoUpdate::checkForUpdate() { this->getLatestVersionData(); @@ -113,18 +109,7 @@ void AutoUpdate::parseLatestVersionData() { emit latestVersionDataParsed(); } -void AutoUpdate::debugBuildData() { - qDebug() << "[LEOTEST] We finished parsing the xml build data"; - foreach (int key, _builds->keys()) { - qDebug() << "[LEOTEST] Build number: " << QString::number(key); - //foreach (QString detailsKey, _builds[key].keys()) { - // qDebug() << "[LEOTEST] Key: " << detailsKey << " Value: " << _builds[key][detailsKey]; - //} - } -} - void AutoUpdate::checkVersionAndNotify() { - qDebug() << "[LEOTEST] We are checking and notifying for updates"; int latestVersionAvailable = _builds->lastKey(); if (QCoreApplication::applicationVersion() != "dev" && QCoreApplication::applicationVersion().toInt() < latestVersionAvailable) { @@ -133,7 +118,12 @@ void AutoUpdate::checkVersionAndNotify() { } void AutoUpdate::performAutoUpdate(int version) { - + // NOTE: This is not yet auto updating - however this is a checkpoint towards that end + // Next PR will handle the automatic download, upgrading and application restart + QMap chosenVersion = _builds->value(version); + QUrl downloadUrl = chosenVersion.value("downloadUrl"); + QDesktopServices::openUrl(downloadUrl); + QCoreApplication::quit(); } void AutoUpdate::downloadUpdateVersion(int version) { diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h index 4b32d68c48..b060aca2b6 100644 --- a/libraries/auto-update/src/AutoUpdate.h +++ b/libraries/auto-update/src/AutoUpdate.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -40,10 +41,10 @@ class AutoUpdate : public QObject, public Dependency { public: // Methods AutoUpdate(); - ~AutoUpdate(); void checkForUpdate(); QMap> &getBuildData() { return *_builds; } + void performAutoUpdate(int version); public slots: @@ -63,9 +64,7 @@ private: private slots: void parseLatestVersionData(); - void debugBuildData(); void checkVersionAndNotify(); - void performAutoUpdate(int version); signals: void latestVersionDataParsed(); From 869461a01bfde937e7d6a11847aed5f8c6a36a4d Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 10 Jun 2015 14:14:00 -0600 Subject: [PATCH 09/12] Code Review changes --- interface/src/Application.cpp | 3 +- interface/src/ui/UpdateDialog.cpp | 17 +++++-- interface/src/ui/UpdateDialog.h | 17 ++++--- libraries/auto-update/src/AutoUpdate.cpp | 38 ++++++--------- libraries/auto-update/src/AutoUpdate.h | 62 +++++++++++------------- 5 files changed, 66 insertions(+), 71 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 64ad22d25f..88a8a274a3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -625,11 +625,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : #endif auto applicationUpdater = DependencyManager::get(); - connect(applicationUpdater.data(), SIGNAL(newVersionIsAvailable()), dialogsManager.data(), SLOT(showUpdateDialog())); + connect(applicationUpdater.data(), &AutoUpdate::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog); applicationUpdater->checkForUpdate(); } - void Application::aboutToQuit() { emit beforeAboutToQuit(); diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 9a6da9148e..61a7cb892c 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -1,18 +1,25 @@ // // UpdateDialog.cpp -// hifi +// interface/src/ui // // Created by Leonardo Murillo on 6/3/15. +// Copyright 2015 High Fidelity, Inc. // +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "UpdateDialog.h" -#include "DependencyManager.h" + #include +#include "DependencyManager.h" + HIFI_QML_DEF(UpdateDialog) -UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { +UpdateDialog::UpdateDialog(QQuickItem* parent) : + OffscreenQmlDialog(parent) +{ auto applicationUpdater = DependencyManager::get(); int currentVersion = QCoreApplication::applicationVersion().toInt(); int latestVersion = applicationUpdater.data()->getBuildData().lastKey(); @@ -22,11 +29,11 @@ UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { _releaseNotes = applicationUpdater.data()->getBuildData()[latestVersion]["releaseNotes"]; } -QString UpdateDialog::updateAvailableDetails() const { +const QString& UpdateDialog::updateAvailableDetails() const { return _updateAvailableDetails; } -QString UpdateDialog::releaseNotes() const { +const QString& UpdateDialog::releaseNotes() const { return _releaseNotes; } diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 25ea42e7bc..84d390c942 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -1,17 +1,20 @@ // // UpdateDialog.h -// hifi +// interface/src/ui // // Created by Leonardo Murillo on 6/3/15. +// Copyright 2015 High Fidelity, Inc. // +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #pragma once -#ifndef __hifi__UpdateDialog__ -#define __hifi__UpdateDialog__ - +#ifndef hifi_UpdateDialog_h +#define hifi_UpdateDialog_h #include + #include class UpdateDialog : public OffscreenQmlDialog { @@ -23,8 +26,8 @@ class UpdateDialog : public OffscreenQmlDialog { public: UpdateDialog(QQuickItem* parent = nullptr); - QString updateAvailableDetails() const; - QString releaseNotes() const; + const QString& updateAvailableDetails() const; + const QString& releaseNotes() const; private: QString _updateAvailableDetails; @@ -37,4 +40,4 @@ protected: }; -#endif /* defined(__hifi__UpdateDialog__) */ +#endif // hifi_UpdateDialog_h diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp index 3295016f81..04bb294fec 100644 --- a/libraries/auto-update/src/AutoUpdate.cpp +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -5,33 +5,29 @@ // Created by Leonardo Murillo on 6/1/2015. // Copyright 2015 High Fidelity, Inc. // -// -// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include -#include #include "AutoUpdate.h" +#include +#include + AutoUpdate::AutoUpdate() { -#ifdef Q_OS_WIN32 +#if defined Q_OS_WIN32 _operatingSystem = "windows"; -#endif -#ifdef Q_OS_MAC +#elif defined Q_OS_MAC _operatingSystem = "mac"; -#endif -#ifdef Q_OS_LINUX +#elif defined Q_OS_LINUX _operatingSystem = "ubuntu"; #endif + connect(this, SIGNAL(latestVersionDataParsed()), this, SLOT(checkVersionAndNotify())); - _builds = new QMap>; } void AutoUpdate::checkForUpdate() { this->getLatestVersionData(); - } void AutoUpdate::getLatestVersionData() { @@ -39,10 +35,9 @@ void AutoUpdate::getLatestVersionData() { QNetworkRequest latestVersionRequest(BUILDS_XML_URL); latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); QNetworkReply* reply = networkAccessManager.get(latestVersionRequest); - connect(reply, SIGNAL(finished()), this, SLOT(parseLatestVersionData())); + connect(reply, &QNetworkReply::finished, this, &AutoUpdate::parseLatestVersionData); } - void AutoUpdate::parseLatestVersionData() { QNetworkReply* sender = qobject_cast(QObject::sender()); @@ -55,7 +50,6 @@ void AutoUpdate::parseLatestVersionData() { QString commitSha; QString pullRequestNumber; - while (!xml.atEnd() && !xml.hasError()) { if (xml.name().toString() == "project" && xml.attributes().hasAttribute("name") && @@ -110,7 +104,7 @@ void AutoUpdate::parseLatestVersionData() { } void AutoUpdate::checkVersionAndNotify() { - int latestVersionAvailable = _builds->lastKey(); + int latestVersionAvailable = _builds.lastKey(); if (QCoreApplication::applicationVersion() != "dev" && QCoreApplication::applicationVersion().toInt() < latestVersionAvailable) { emit newVersionIsAvailable(); @@ -120,8 +114,8 @@ void AutoUpdate::checkVersionAndNotify() { void AutoUpdate::performAutoUpdate(int version) { // NOTE: This is not yet auto updating - however this is a checkpoint towards that end // Next PR will handle the automatic download, upgrading and application restart - QMap chosenVersion = _builds->value(version); - QUrl downloadUrl = chosenVersion.value("downloadUrl"); + const QMap& chosenVersion = _builds.value(version); + const QUrl& downloadUrl = chosenVersion.value("downloadUrl"); QDesktopServices::openUrl(downloadUrl); QCoreApplication::quit(); } @@ -131,16 +125,16 @@ void AutoUpdate::downloadUpdateVersion(int version) { } void AutoUpdate::appendBuildData(int versionNumber, - QString downloadURL, - QString releaseTime, - QString releaseNotes, - QString pullRequestNumber) { + const QString& downloadURL, + const QString& releaseTime, + const QString& releaseNotes, + const QString& pullRequestNumber) { QMap thisBuildDetails; thisBuildDetails.insert("downloadUrl", downloadURL); thisBuildDetails.insert("releaseTime", releaseTime); thisBuildDetails.insert("releaseNotes", releaseNotes); thisBuildDetails.insert("pullRequestNumber", pullRequestNumber); - _builds->insert(versionNumber, thisBuildDetails); + _builds.insert(versionNumber, thisBuildDetails); } \ No newline at end of file diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h index b060aca2b6..be8e479f63 100644 --- a/libraries/auto-update/src/AutoUpdate.h +++ b/libraries/auto-update/src/AutoUpdate.h @@ -5,33 +5,30 @@ // Created by Leonardo Murillo on 6/1/2015. // Copyright 2015 High Fidelity, Inc. // -// -// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef __hifi__AutoUpdate__ -#define __hifi__AutoUpdate__ +#ifndef hifi_AutoUpdate_h +#define hifi_AutoUpdate_h + -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include - const QUrl BUILDS_XML_URL("https://highfidelity.com/builds.xml"); class AutoUpdate : public QObject, public Dependency { @@ -39,38 +36,33 @@ class AutoUpdate : public QObject, public Dependency { SINGLETON_DEPENDENCY public: - // Methods AutoUpdate(); void checkForUpdate(); - QMap> &getBuildData() { return *_builds; } + const QMap> &getBuildData() { return _builds; } void performAutoUpdate(int version); -public slots: - private: - // Members - QMap> *_builds; + QMap> _builds; QString _operatingSystem; - // Methods void getLatestVersionData(); void downloadUpdateVersion(int version); void appendBuildData(int versionNumber, - QString downloadURL, - QString releaseTime, - QString releaseNotes, - QString pullRequestNumber); - -private slots: - void parseLatestVersionData(); - void checkVersionAndNotify(); + const QString& downloadURL, + const QString& releaseTime, + const QString& releaseNotes, + const QString& pullRequestNumber); signals: void latestVersionDataParsed(); void newVersionIsAvailable(); void newVersionIsDownloaded(); - + +private slots: + void parseLatestVersionData(); + void checkVersionAndNotify(); + }; -#endif /* defined(__hifi__AutoUpdate__) */ +#endif // _hifi_AutoUpdate_h From 3708f5ec96841d9b80fd3fab7a36bd48d343c526 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 10 Jun 2015 14:15:26 -0600 Subject: [PATCH 10/12] Code Review changes --- libraries/auto-update/src/AutoUpdate.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h index be8e479f63..71b55095ee 100644 --- a/libraries/auto-update/src/AutoUpdate.h +++ b/libraries/auto-update/src/AutoUpdate.h @@ -41,7 +41,12 @@ public: void checkForUpdate(); const QMap> &getBuildData() { return _builds; } void performAutoUpdate(int version); - + +signals: + void latestVersionDataParsed(); + void newVersionIsAvailable(); + void newVersionIsDownloaded(); + private: QMap> _builds; QString _operatingSystem; @@ -54,11 +59,6 @@ private: const QString& releaseNotes, const QString& pullRequestNumber); -signals: - void latestVersionDataParsed(); - void newVersionIsAvailable(); - void newVersionIsDownloaded(); - private slots: void parseLatestVersionData(); void checkVersionAndNotify(); From 3bd0c7bd87344da6a9f291f9f44cd4d4c66add73 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 10 Jun 2015 14:35:52 -0600 Subject: [PATCH 11/12] Code Review changes --- interface/CMakeLists.txt | 2 +- interface/src/Application.cpp | 8 +++---- interface/src/ui/UpdateDialog.cpp | 6 ++--- .../CMakeLists.txt | 2 +- .../src/AutoUpdater.cpp} | 22 +++++++++---------- .../src/AutoUpdater.h} | 12 +++++----- 6 files changed, 26 insertions(+), 26 deletions(-) rename libraries/{auto-update => auto-updater}/CMakeLists.txt (69%) rename libraries/{auto-update/src/AutoUpdate.cpp => auto-updater/src/AutoUpdater.cpp} (91%) rename libraries/{auto-update/src/AutoUpdate.h => auto-updater/src/AutoUpdater.h} (90%) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index b28c971298..00f6d4c3b2 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -140,7 +140,7 @@ target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) # link required hifi libraries link_hifi_libraries(shared octree environment gpu model render fbx networking entities avatars audio audio-client animation script-engine physics - render-utils entities-renderer ui auto-update) + render-utils entities-renderer ui auto-updater) add_dependency_external_projects(sdl2) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 88a8a274a3..560dccb238 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -59,7 +59,7 @@ #include #include #include -#include +#include #include #include #include @@ -295,7 +295,7 @@ bool setupEssentials(int& argc, char** argv) { auto discoverabilityManager = DependencyManager::set(); auto sceneScriptingInterface = DependencyManager::set(); auto offscreenUi = DependencyManager::set(); - auto autoUpdate = DependencyManager::set(); + auto autoUpdater = DependencyManager::set(); auto pathUtils = DependencyManager::set(); return true; @@ -624,8 +624,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); #endif - auto applicationUpdater = DependencyManager::get(); - connect(applicationUpdater.data(), &AutoUpdate::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog); + auto applicationUpdater = DependencyManager::get(); + connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog); applicationUpdater->checkForUpdate(); } diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 61a7cb892c..69dfc343d9 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -11,7 +11,7 @@ #include "UpdateDialog.h" -#include +#include #include "DependencyManager.h" @@ -20,7 +20,7 @@ HIFI_QML_DEF(UpdateDialog) UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) { - auto applicationUpdater = DependencyManager::get(); + auto applicationUpdater = DependencyManager::get(); int currentVersion = QCoreApplication::applicationVersion().toInt(); int latestVersion = applicationUpdater.data()->getBuildData().lastKey(); int versionsBehind = latestVersion - currentVersion; @@ -46,6 +46,6 @@ void UpdateDialog::hide() { } void UpdateDialog::triggerUpgrade() { - auto applicationUpdater = DependencyManager::get(); + auto applicationUpdater = DependencyManager::get(); applicationUpdater.data()->performAutoUpdate(applicationUpdater.data()->getBuildData().lastKey()); } \ No newline at end of file diff --git a/libraries/auto-update/CMakeLists.txt b/libraries/auto-updater/CMakeLists.txt similarity index 69% rename from libraries/auto-update/CMakeLists.txt rename to libraries/auto-updater/CMakeLists.txt index 0419048169..b3665af2cb 100644 --- a/libraries/auto-update/CMakeLists.txt +++ b/libraries/auto-updater/CMakeLists.txt @@ -1,3 +1,3 @@ -set(TARGET_NAME auto-update) +set(TARGET_NAME auto-updater) setup_hifi_library(Network) link_hifi_libraries(shared networking) diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-updater/src/AutoUpdater.cpp similarity index 91% rename from libraries/auto-update/src/AutoUpdate.cpp rename to libraries/auto-updater/src/AutoUpdater.cpp index 04bb294fec..445cdaec7b 100644 --- a/libraries/auto-update/src/AutoUpdate.cpp +++ b/libraries/auto-updater/src/AutoUpdater.cpp @@ -1,5 +1,5 @@ // -// AutoUpdate.cpp +// AutoUpdater.cpp // libraries/auto-update/src // // Created by Leonardo Murillo on 6/1/2015. @@ -9,12 +9,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "AutoUpdate.h" +#include "AutoUpdater.h" #include #include -AutoUpdate::AutoUpdate() { +AutoUpdater::AutoUpdater() { #if defined Q_OS_WIN32 _operatingSystem = "windows"; #elif defined Q_OS_MAC @@ -26,19 +26,19 @@ AutoUpdate::AutoUpdate() { connect(this, SIGNAL(latestVersionDataParsed()), this, SLOT(checkVersionAndNotify())); } -void AutoUpdate::checkForUpdate() { +void AutoUpdater::checkForUpdate() { this->getLatestVersionData(); } -void AutoUpdate::getLatestVersionData() { +void AutoUpdater::getLatestVersionData() { QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); QNetworkRequest latestVersionRequest(BUILDS_XML_URL); latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); QNetworkReply* reply = networkAccessManager.get(latestVersionRequest); - connect(reply, &QNetworkReply::finished, this, &AutoUpdate::parseLatestVersionData); + connect(reply, &QNetworkReply::finished, this, &AutoUpdater::parseLatestVersionData); } -void AutoUpdate::parseLatestVersionData() { +void AutoUpdater::parseLatestVersionData() { QNetworkReply* sender = qobject_cast(QObject::sender()); QXmlStreamReader xml(sender); @@ -103,7 +103,7 @@ void AutoUpdate::parseLatestVersionData() { emit latestVersionDataParsed(); } -void AutoUpdate::checkVersionAndNotify() { +void AutoUpdater::checkVersionAndNotify() { int latestVersionAvailable = _builds.lastKey(); if (QCoreApplication::applicationVersion() != "dev" && QCoreApplication::applicationVersion().toInt() < latestVersionAvailable) { @@ -111,7 +111,7 @@ void AutoUpdate::checkVersionAndNotify() { } } -void AutoUpdate::performAutoUpdate(int version) { +void AutoUpdater::performAutoUpdate(int version) { // NOTE: This is not yet auto updating - however this is a checkpoint towards that end // Next PR will handle the automatic download, upgrading and application restart const QMap& chosenVersion = _builds.value(version); @@ -120,11 +120,11 @@ void AutoUpdate::performAutoUpdate(int version) { QCoreApplication::quit(); } -void AutoUpdate::downloadUpdateVersion(int version) { +void AutoUpdater::downloadUpdateVersion(int version) { emit newVersionIsDownloaded(); } -void AutoUpdate::appendBuildData(int versionNumber, +void AutoUpdater::appendBuildData(int versionNumber, const QString& downloadURL, const QString& releaseTime, const QString& releaseNotes, diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-updater/src/AutoUpdater.h similarity index 90% rename from libraries/auto-update/src/AutoUpdate.h rename to libraries/auto-updater/src/AutoUpdater.h index 71b55095ee..a02ff11ca9 100644 --- a/libraries/auto-update/src/AutoUpdate.h +++ b/libraries/auto-updater/src/AutoUpdater.h @@ -1,5 +1,5 @@ // -// AutoUpdate.h +// AutoUpdater.h // libraries/auto-update/src // // Created by Leonardo Murillo on 6/1/2015. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_AutoUpdate_h -#define hifi_AutoUpdate_h +#ifndef hifi_AutoUpdater_h +#define hifi_AutoUpdater_h #include @@ -31,12 +31,12 @@ const QUrl BUILDS_XML_URL("https://highfidelity.com/builds.xml"); -class AutoUpdate : public QObject, public Dependency { +class AutoUpdater : public QObject, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY public: - AutoUpdate(); + AutoUpdater(); void checkForUpdate(); const QMap> &getBuildData() { return _builds; } @@ -65,4 +65,4 @@ private slots: }; -#endif // _hifi_AutoUpdate_h +#endif // _hifi_AutoUpdater_h From 917aa5db6d742ab064214889348965799bc85537 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 16 Jun 2015 13:21:40 -0600 Subject: [PATCH 12/12] Code review changes --- libraries/auto-updater/src/AutoUpdater.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/auto-updater/src/AutoUpdater.h b/libraries/auto-updater/src/AutoUpdater.h index a02ff11ca9..70867e5a44 100644 --- a/libraries/auto-updater/src/AutoUpdater.h +++ b/libraries/auto-updater/src/AutoUpdater.h @@ -27,6 +27,7 @@ #include #include #include + #include const QUrl BUILDS_XML_URL("https://highfidelity.com/builds.xml"); @@ -39,7 +40,7 @@ public: AutoUpdater(); void checkForUpdate(); - const QMap> &getBuildData() { return _builds; } + const QMap>& getBuildData() { return _builds; } void performAutoUpdate(int version); signals: @@ -62,7 +63,6 @@ private: private slots: void parseLatestVersionData(); void checkVersionAndNotify(); - }; #endif // _hifi_AutoUpdater_h