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