Code Review changes

This commit is contained in:
Leonardo Murillo 2015-06-10 14:14:00 -06:00
parent 8f72763f17
commit 869461a01b
5 changed files with 66 additions and 71 deletions

View file

@ -625,11 +625,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
#endif
auto applicationUpdater = DependencyManager::get<AutoUpdate>();
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();

View file

@ -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 <AutoUpdate.h>
#include "DependencyManager.h"
HIFI_QML_DEF(UpdateDialog)
UpdateDialog::UpdateDialog(QQuickItem* parent) : OffscreenQmlDialog(parent) {
UpdateDialog::UpdateDialog(QQuickItem* parent) :
OffscreenQmlDialog(parent)
{
auto applicationUpdater = DependencyManager::get<AutoUpdate>();
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;
}

View file

@ -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 <QtCore/QCoreApplication>
#include <OffscreenQmlDialog.h>
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

View file

@ -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 <NetworkAccessManager.h>
#include <SharedUtil.h>
#include "AutoUpdate.h"
#include <NetworkAccessManager.h>
#include <SharedUtil.h>
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<int, QMap<QString, QString>>;
}
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<QNetworkReply*>(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<QString, QString> chosenVersion = _builds->value(version);
QUrl downloadUrl = chosenVersion.value("downloadUrl");
const QMap<QString, QString>& 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<QString, QString> 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);
}

View file

@ -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 <QtCore/QObject>
#include <QtCore/QSettings>
#include <QtCore/QCoreApplication>
#include <QDesktopServices>
#include <QDebug>
#include <QString>
#include <QUrl>
#include <QMap>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkConfiguration>
#include <QNetworkAccessManager>
#include <QXmlStreamReader>
#include <QXmlStreamAttributes>
#include <QtCore/QDebug>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QtCore/QXmlStreamAttributes>
#include <QtCore/QXmlStreamReader>
#include <QtGui/QDesktopServices>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkConfiguration>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <DependencyManager.h>
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<int, QMap<QString, QString>> &getBuildData() { return *_builds; }
const QMap<int, QMap<QString, QString>> &getBuildData() { return _builds; }
void performAutoUpdate(int version);
public slots:
private:
// Members
QMap<int, QMap<QString, QString>> *_builds;
QMap<int, QMap<QString, QString>> _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