From b60597aa90189ffaac26270644cfffdc4d857dc0 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 3 Jun 2015 19:38:54 -0600 Subject: [PATCH] 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(); };