From ba79b1b329bbe7378cc709b95021dc1baff303c2 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 6 Jan 2014 09:18:10 -0600 Subject: [PATCH 01/50] Using BUILD_VERSION to setApplicationVersion --- interface/resources/info/ApplicationInfo.ini | 3 +-- interface/src/Application.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/interface/resources/info/ApplicationInfo.ini b/interface/resources/info/ApplicationInfo.ini index a1d1603172..35a6c71eb8 100644 --- a/interface/resources/info/ApplicationInfo.ini +++ b/interface/resources/info/ApplicationInfo.ini @@ -1,5 +1,4 @@ [INFO] name=Interface -version=0.0.1 organizationName=High Fidelity -organizationDomain=highfidelity.io \ No newline at end of file +organizationDomain=highfidelity.io diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 64a50a5b99..93af683240 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -190,7 +190,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : applicationInfo.beginGroup("INFO"); setApplicationName(applicationInfo.value("name").toString()); - setApplicationVersion(applicationInfo.value("version").toString()); + setApplicationVersion(BUILD_VERSION); setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); From 314c4ffcfa3c79a12c584f1480f20279bfd17dad Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 6 Jan 2014 09:24:29 -0600 Subject: [PATCH 02/50] Using applicationVersion() instead of const wherever version is specified --- interface/src/Application.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 93af683240..6df74a47d5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -156,8 +156,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : // call Menu getInstance static method to set up the menu _window->setMenuBar(Menu::getInstance()); - qDebug("[VERSION] Build sequence: %i\n", BUILD_VERSION); - unsigned int listenPort = 0; // bind to an ephemeral port by default const char** constArgv = const_cast(argv); const char* portStr = getCmdOption(argc, constArgv, "--listenPort"); @@ -193,6 +191,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setApplicationVersion(BUILD_VERSION); setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + + qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); _settings = new QSettings(this); @@ -4175,7 +4175,7 @@ void Application::attachNewHeadToNode(Node* newNode) { void Application::updateWindowTitle(){ QString title = ""; - QString buildVersion = " (build " + QString::number(BUILD_VERSION) + ")"; + QString buildVersion = " (build " + applicationVersion() + ")"; QString username = _profile.getUsername(); if(!username.isEmpty()){ title += _profile.getUsername(); From d44126ac33c65bafb270b15c8f29724e23141e40 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 8 Jan 2014 08:30:50 -0600 Subject: [PATCH 03/50] Get version XML and store latest version as application property --- interface/CMakeLists.txt | 3 ++- interface/src/Application.cpp | 41 +++++++++++++++++++++++++++++++++++ interface/src/Application.h | 9 ++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index ecc6ff79cb..ccc26b630a 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -60,6 +60,7 @@ find_package(Qt5OpenGL REQUIRED) find_package(Qt5Svg REQUIRED) find_package(Qt5WebKit REQUIRED) find_package(Qt5WebKitWidgets REQUIRED) +find_package(Qt5Xml REQUIRED) if (APPLE) set(MACOSX_BUNDLE_BUNDLE_NAME Interface) @@ -136,7 +137,7 @@ if (LIBOVR_FOUND AND NOT DISABLE_LIBOVR) target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES}) endif (LIBOVR_FOUND AND NOT DISABLE_LIBOVR) -qt5_use_modules(${TARGET_NAME} Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets) +qt5_use_modules(${TARGET_NAME} Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml) # include headers for interface and InterfaceConfig. include_directories( diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6df74a47d5..1cdef9f0fe 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,8 @@ #include #include #include +#include +#include #include #include @@ -192,6 +195,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + checkVersion(); + qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); _settings = new QSettings(this); @@ -4536,3 +4541,39 @@ void Application::toggleLogDialog() { _logDialog->close(); } } + +void Application::loadLatestVersionDetails() { + QUrl url("https://a-tower.below92.com/version.xml"); + QNetworkAccessManager *downloadXML = new QNetworkAccessManager(this); + QNetworkRequest request(url); + connect(downloadXML, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseVersionXml(QNetworkReply*))); + downloadXML->get(request); + +} + +void Application::parseVersionXml(QNetworkReply *reply) { + QXmlStreamReader xml(reply); + while (!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + + if (token == QXmlStreamReader::StartElement) { + if (xml.name() == "Version") { + xml.readNext(); + _latestVersion = xml.text().toString(); + qDebug("################ Version found %s\n", _latestVersion.toStdString().c_str()); + } + } + + } +} + +void Application::checkVersion() { + loadLatestVersionDetails(); + + // This is a very rudimentary check, if this version is not equal to latest then you need to get it + // unless you're coming from the future. + + //if (applicationVersion() != 0 && applicationVersion() != this->_latestVersion) { + + //} +} diff --git a/interface/src/Application.h b/interface/src/Application.h index 6f0463bc88..a02f136d3d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -212,6 +212,11 @@ public: /// set a voxel which is to be rendered with a highlight void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; } void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } + + // Get XML with version information and parse it + // Display dialog when version is not the latest and allow for new version download from link + void loadLatestVersionDetails(); + void checkVersion(); public slots: void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data); @@ -255,6 +260,8 @@ private slots: void restoreMirrorView(); void shrinkMirrorView(); void resetSensors(); + + void parseVersionXml(QNetworkReply *reply); private: void resetCamerasOnResizeGL(Camera& camera, int width, int height); @@ -512,6 +519,8 @@ private: QPointer _logDialog; FileLogger* _logger; + + QString _latestVersion; }; #endif /* defined(__interface__Application__) */ From efb173e1d4d9b4d29815cb0e7b45b6686cc92169 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 8 Jan 2014 21:20:43 -0600 Subject: [PATCH 04/50] Preliminary update dialog work --- interface/resources/styles/update_dialog.qss | 0 interface/src/Application.cpp | 58 +++++++++++++++++--- interface/src/Application.h | 4 +- interface/src/ui/UpdateDialog.cpp | 40 ++++++++++++++ interface/src/ui/UpdateDialog.h | 38 +++++++++++++ 5 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 interface/resources/styles/update_dialog.qss create mode 100644 interface/src/ui/UpdateDialog.cpp create mode 100644 interface/src/ui/UpdateDialog.h diff --git a/interface/resources/styles/update_dialog.qss b/interface/resources/styles/update_dialog.qss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1cdef9f0fe..4a762e4fc3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -195,6 +196,18 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + #ifdef Q_WS_X11 + _operatingSystem = "ubuntu"; + #endif + + #ifdef Q_WS_WIN + _operatingSystem = "win"; + #endif + + #ifdef Q_WS_MACX + _operatingSystem = "mac"; + #endif + checkVersion(); qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); @@ -1419,6 +1432,7 @@ void Application::idle() { } } } + void Application::terminate() { // Close serial port // close(serial_fd); @@ -4542,7 +4556,7 @@ void Application::toggleLogDialog() { } } -void Application::loadLatestVersionDetails() { +void Application::checkVersion() { QUrl url("https://a-tower.below92.com/version.xml"); QNetworkAccessManager *downloadXML = new QNetworkAccessManager(this); QNetworkRequest request(url); @@ -4552,28 +4566,56 @@ void Application::loadLatestVersionDetails() { } void Application::parseVersionXml(QNetworkReply *reply) { + QString _releaseDate; + QString _releaseNotes; + QString _downloadLink; + QXmlStreamReader xml(reply); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); if (token == QXmlStreamReader::StartElement) { + + if (xml.name() == "ReleaseDate") { + xml.readNext(); + _releaseDate = xml.text().toString(); + } + + if (xml.name() == "ReleaseNotes") { + xml.readNext(); + _releaseNotes = xml.text().toString(); + } + if (xml.name() == "Version") { xml.readNext(); _latestVersion = xml.text().toString(); - qDebug("################ Version found %s\n", _latestVersion.toStdString().c_str()); } } } + + if (applicationVersion() != _latestVersion) { + + } + + displayUpdateDialog(); } -void Application::checkVersion() { - loadLatestVersionDetails(); +void Application::displayUpdateDialog() { + int _windowWidth = 500; + int _windowHeigth = 300; + QString _windowTitle = "Newer build available"; - // This is a very rudimentary check, if this version is not equal to latest then you need to get it - // unless you're coming from the future. + QPushButton *download = new QPushButton("Download"); + QPushButton *ignore = new QPushButton("Ignore this version"); + QPushButton *close = new QPushButton("Close"); + + QWidget *updateDialog = new QWidget; + updateDialog->setFixedWidth(_windowWidth); + updateDialog->setFixedHeight(_windowHeigth); + updateDialog->setWindowTitle(_windowTitle); + + updateDialog->show(); - //if (applicationVersion() != 0 && applicationVersion() != this->_latestVersion) { - //} } diff --git a/interface/src/Application.h b/interface/src/Application.h index a02f136d3d..99873d4b57 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -69,6 +69,7 @@ #include "ui/RearMirrorTools.h" #include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" +#include "ui/UpdateDialog.h" #include "FileLogger.h" #include "ParticleTreeRenderer.h" #include "ParticleEditHandle.h" @@ -215,8 +216,8 @@ public: // Get XML with version information and parse it // Display dialog when version is not the latest and allow for new version download from link - void loadLatestVersionDetails(); void checkVersion(); + void displayUpdateDialog(); public slots: void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data); @@ -521,6 +522,7 @@ private: FileLogger* _logger; QString _latestVersion; + QString _operatingSystem; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp new file mode 100644 index 0000000000..c76cad7701 --- /dev/null +++ b/interface/src/ui/UpdateDialog.cpp @@ -0,0 +1,40 @@ +// +// UpdateDialog.cpp +// interface +// +// Created by Leonardo Murillo on 1/8/14. +// Copyright (c) 2013, 2014 High Fidelity, Inc. All rights reserved. +// + +#include +#include +#include + +#include "SharedUtil.h" +#include "UpdateDialog.h" + +const int buttonWidth = 120; +const int buttonHeight = 40; + +const QString dialogTitle = "Update Required"; +const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ + Please download and install the most recent release to access the latest \ + features and bug fixes.").arg("1", "2"); + +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString downloadURL) : QDialog(parent, Qt::Dialog) { + setWindowTitle(dialogTitle); + _releaseNotes = new QLabel(this); + _releaseNotes->setText(releaseNotes); + + _updateRequired = new QLabel(this); + _updateRequired->setText(updateRequired); + + _downloadButton = new QPushButton("Download", this); + _downloadButton->setObjectName("downloadButton"); + _skipButton = new QPushButton("Skip Version", this); + _skipButton->setObjectName("skipButton"); + _closeButton = new QPushButton("Close", this); + _closeButton->setObjectName("closeButton"); + + +} \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h new file mode 100644 index 0000000000..9a1bfff1c4 --- /dev/null +++ b/interface/src/ui/UpdateDialog.h @@ -0,0 +1,38 @@ +// +// UpdateDialog.h +// interface +// +// Created by Leonardo Murillo on 1/8/14. +// Copyright (c) 2013, 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__UpdateDialog__ +#define __hifi__UpdateDialog__ + +#include +#include +#include + +#include + +class UpdateDialog : public QDialog { + Q_OBJECT + +public: + UpdateDialog(QWidget*, QString releaseNotes, QString downloadURL); + ~UpdateDialog(); + +private: + QLabel *_updateRequired; + QLabel *_releaseNotes; + QPushButton *_downloadButton; + QPushButton *_skipButton; + QPushButton *_closeButton; + +private slots: + void handleDownload(); + void handleIgnore(); + void handleClose(); +}; + +#endif /* defined(__hifi__UpdateDialog__) */ From 9dd37344b8a7a65067013e8065cc58db37f1cca2 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 9 Jan 2014 16:14:51 -0600 Subject: [PATCH 05/50] checkpoint --- interface/src/Application.cpp | 23 ++++----------------- interface/src/ui/UpdateDialog.cpp | 33 +++++++++++++++++++++++++++---- interface/src/ui/UpdateDialog.h | 7 ++++--- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4a762e4fc3..0727c8658f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4568,7 +4568,7 @@ void Application::checkVersion() { void Application::parseVersionXml(QNetworkReply *reply) { QString _releaseDate; QString _releaseNotes; - QString _downloadLink; + QUrl *_downloadLink; QXmlStreamReader xml(reply); while (!xml.atEnd() && !xml.hasError()) { @@ -4598,24 +4598,9 @@ void Application::parseVersionXml(QNetworkReply *reply) { } - displayUpdateDialog(); -} - -void Application::displayUpdateDialog() { - int _windowWidth = 500; - int _windowHeigth = 300; - QString _windowTitle = "Newer build available"; - - QPushButton *download = new QPushButton("Download"); - QPushButton *ignore = new QPushButton("Ignore this version"); - QPushButton *close = new QPushButton("Close"); - - QWidget *updateDialog = new QWidget; - updateDialog->setFixedWidth(_windowWidth); - updateDialog->setFixedHeight(_windowHeigth); - updateDialog->setWindowTitle(_windowTitle); - - updateDialog->show(); + _downloadLink = new QUrl("http://www.google.com"); + UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes, _downloadLink, _latestVersion, applicationVersion()); + _updateDialog->show(); } diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index c76cad7701..d9543f318b 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -15,14 +15,23 @@ const int buttonWidth = 120; const int buttonHeight = 40; +const int dialogWidth = 500; +const int dialogHeigth = 300; const QString dialogTitle = "Update Required"; -const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ - Please download and install the most recent release to access the latest \ - features and bug fixes.").arg("1", "2"); -UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString downloadURL) : QDialog(parent, Qt::Dialog) { +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *downloadURL, QString latestVersion, QString currentVersion) : QDialog(parent, Qt::Dialog) { + + const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ + Please download and install the most recent release to access the latest \ + features and bug fixes.").arg(currentVersion, latestVersion); + setWindowTitle(dialogTitle); + setModal(true); + QFile styleSheet("resources/styles/update_dialog.qss"); + if (styleSheet.open(QIODevice::ReadOnly)) { + setStyleSheet(styleSheet.readAll()); + } _releaseNotes = new QLabel(this); _releaseNotes->setText(releaseNotes); @@ -36,5 +45,21 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString downlo _closeButton = new QPushButton("Close", this); _closeButton->setObjectName("closeButton"); + _titleBackground = new QFrame(); + connect(_downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); + connect(_skipButton, SIGNAL(released()), this, SLOT(handleDownload())); + connect(_closeButton, SIGNAL(released()), this, SLOT(handleClose())); +} + +void UpdateDialog::handleDownload() { + qDebug("download clicked"); +} + +void UpdateDialog::handleSkip() { + qDebug("skip clicked"); +} + +void UpdateDialog::handleClose() { + qDebug("close clicked"); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 9a1bfff1c4..bd374afb5b 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -19,8 +20,7 @@ class UpdateDialog : public QDialog { Q_OBJECT public: - UpdateDialog(QWidget*, QString releaseNotes, QString downloadURL); - ~UpdateDialog(); + UpdateDialog(QWidget*, QString releaseNotes, QUrl *downloadURL, QString latestVersion, QString currentVersion); private: QLabel *_updateRequired; @@ -28,10 +28,11 @@ private: QPushButton *_downloadButton; QPushButton *_skipButton; QPushButton *_closeButton; + QFrame *_titleBackground; private slots: void handleDownload(); - void handleIgnore(); + void handleSkip(); void handleClose(); }; From 664a1a7677eb1402f415eea5e9606d2fdc15636b Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 9 Jan 2014 20:12:39 -0600 Subject: [PATCH 06/50] Checkpoint --- interface/src/Application.cpp | 4 ++-- interface/src/Application.h | 2 +- interface/src/ui/UpdateDialog.cpp | 31 ++++++++++++++++++++++++------- interface/src/ui/UpdateDialog.h | 4 +++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0727c8658f..b0b26be540 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4588,7 +4588,7 @@ void Application::parseVersionXml(QNetworkReply *reply) { if (xml.name() == "Version") { xml.readNext(); - _latestVersion = xml.text().toString(); + *_latestVersion = xml.text().toString(); } } @@ -4601,6 +4601,6 @@ void Application::parseVersionXml(QNetworkReply *reply) { _downloadLink = new QUrl("http://www.google.com"); UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes, _downloadLink, _latestVersion, applicationVersion()); - _updateDialog->show(); + _updateDialog->exec(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 99873d4b57..6461bf3925 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -521,7 +521,7 @@ private: FileLogger* _logger; - QString _latestVersion; + QString *_latestVersion; QString _operatingSystem; }; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index d9543f318b..710c4e7166 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -15,19 +15,27 @@ const int buttonWidth = 120; const int buttonHeight = 40; -const int dialogWidth = 500; +const int buttonMargin = 15; +const int leftStartingPosition = 345; +const int dialogWidth = 750; const int dialogHeigth = 300; const QString dialogTitle = "Update Required"; -UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *downloadURL, QString latestVersion, QString currentVersion) : QDialog(parent, Qt::Dialog) { +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *downloadURL, QString *latestVersion, QString currentVersion) : QDialog(parent, Qt::Dialog) { + + _downloadURL = downloadURL; + _latestVersion = latestVersion; const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ Please download and install the most recent release to access the latest \ - features and bug fixes.").arg(currentVersion, latestVersion); + features and bug fixes.").arg(currentVersion, *latestVersion); + int leftPosition = leftStartingPosition; setWindowTitle(dialogTitle); + //setWindowFlags(Qt::WindowTitleHint); setModal(true); + resize(dialogWidth, dialogHeigth); QFile styleSheet("resources/styles/update_dialog.qss"); if (styleSheet.open(QIODevice::ReadOnly)) { setStyleSheet(styleSheet.readAll()); @@ -40,26 +48,35 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *download _downloadButton = new QPushButton("Download", this); _downloadButton->setObjectName("downloadButton"); + _downloadButton->setGeometry(leftPosition, buttonMargin, buttonWidth, buttonHeight); + leftPosition += buttonWidth; + _skipButton = new QPushButton("Skip Version", this); _skipButton->setObjectName("skipButton"); + _skipButton->setGeometry(leftPosition, buttonMargin, buttonWidth, buttonHeight); + leftPosition += buttonWidth; + _closeButton = new QPushButton("Close", this); _closeButton->setObjectName("closeButton"); + _closeButton->setGeometry(leftPosition, buttonMargin, buttonWidth, buttonHeight); _titleBackground = new QFrame(); connect(_downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); - connect(_skipButton, SIGNAL(released()), this, SLOT(handleDownload())); + connect(_skipButton, SIGNAL(released()), this, SLOT(handleSkip())); connect(_closeButton, SIGNAL(released()), this, SLOT(handleClose())); } void UpdateDialog::handleDownload() { - qDebug("download clicked"); + QDesktopServices::openUrl((*_downloadURL)); + close(); } void UpdateDialog::handleSkip() { - qDebug("skip clicked"); + QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + fileName.append(QString("/hifi.skipversion")); } void UpdateDialog::handleClose() { - qDebug("close clicked"); + close(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index bd374afb5b..b50b38bf72 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -20,7 +20,7 @@ class UpdateDialog : public QDialog { Q_OBJECT public: - UpdateDialog(QWidget*, QString releaseNotes, QUrl *downloadURL, QString latestVersion, QString currentVersion); + UpdateDialog(QWidget*, QString releaseNotes, QUrl *downloadURL, QString *latestVersion, QString currentVersion); private: QLabel *_updateRequired; @@ -29,6 +29,8 @@ private: QPushButton *_skipButton; QPushButton *_closeButton; QFrame *_titleBackground; + QUrl *_downloadURL; + QString *_latestVersion; private slots: void handleDownload(); From eb52ded4ad4c4a818fb204fa1de66f883dd2efa3 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 9 Jan 2014 20:34:02 -0600 Subject: [PATCH 07/50] Styling + others --- interface/resources/styles/update_dialog.qss | 6 ++++++ interface/src/Application.cpp | 3 ++- interface/src/ui/UpdateDialog.cpp | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/interface/resources/styles/update_dialog.qss b/interface/resources/styles/update_dialog.qss index e69de29bb2..dbcc2fcbb2 100644 --- a/interface/resources/styles/update_dialog.qss +++ b/interface/resources/styles/update_dialog.qss @@ -0,0 +1,6 @@ +QPushButton { + background-color: #333333; + border-width: 0; + border-top-left-radius: 9px; + border-bottom-left-radius: 9px; +} diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b0b26be540..207a068232 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4588,7 +4588,8 @@ void Application::parseVersionXml(QNetworkReply *reply) { if (xml.name() == "Version") { xml.readNext(); - *_latestVersion = xml.text().toString(); + QString latestVersion = xml.text().toString(); + _latestVersion = &latestVersion; } } diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 710c4e7166..8185b96e95 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -42,9 +42,11 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *download } _releaseNotes = new QLabel(this); _releaseNotes->setText(releaseNotes); + _releaseNotes->setObjectName("releaseNotes"); _updateRequired = new QLabel(this); _updateRequired->setText(updateRequired); + _updateRequired->setObjectName("updateRequired"); _downloadButton = new QPushButton("Download", this); _downloadButton->setObjectName("downloadButton"); From ede32cfadc08d7c9a2d12b7d9bf4f3a5470b3b2d Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 10 Jan 2014 14:08:10 -0600 Subject: [PATCH 08/50] Checkpoint --- interface/resources/styles/update_dialog.qss | 12 +++++-- interface/src/Application.cpp | 34 +++++++++++++++++--- interface/src/Application.h | 9 ++++-- interface/src/ui/UpdateDialog.cpp | 22 +++++++------ interface/src/ui/UpdateDialog.h | 3 +- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/interface/resources/styles/update_dialog.qss b/interface/resources/styles/update_dialog.qss index dbcc2fcbb2..005ab72b47 100644 --- a/interface/resources/styles/update_dialog.qss +++ b/interface/resources/styles/update_dialog.qss @@ -1,6 +1,12 @@ QPushButton { background-color: #333333; border-width: 0; - border-top-left-radius: 9px; - border-bottom-left-radius: 9px; -} + border-radius: 9px; + border-radius: 9px; + font-family: Arial; + font-size: 18px; + font-weight: 100; + color: #b7b7b7; + width: 120px; + height: 40px; +} \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 207a068232..fe37de1c4f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4588,20 +4588,44 @@ void Application::parseVersionXml(QNetworkReply *reply) { if (xml.name() == "Version") { xml.readNext(); - QString latestVersion = xml.text().toString(); - _latestVersion = &latestVersion; + _latestVersion = new QString(xml.text().toString()); } } } - - if (applicationVersion() != _latestVersion) { + if (!shouldSkipVersion() && applicationVersion() != _latestVersion) { } _downloadLink = new QUrl("http://www.google.com"); - UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes, _downloadLink, _latestVersion, applicationVersion()); + UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes, _downloadLink); _updateDialog->exec(); } + +QFile *Application::loadSkipFile() { + QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + fileName.append(QString("/hifi.skipversion")); + QFile *file = new QFile(fileName); + file->open(QIODevice::ReadWrite); + return file; +} + +bool Application::shouldSkipVersion() { + QFile *skipFile = loadSkipFile(); + QByteArray skipFileContents = skipFile->readAll(); + QString *skipVersion = new QString(skipFileContents); + skipFile->close(); + if (*skipVersion == *_latestVersion ) { + return true; + } + return false; +} + +void Application::skipVersion() { + QFile *skipFile = loadSkipFile(); + skipFile->seek(0); + skipFile->write(_latestVersion->toStdString().c_str()); + skipFile->close(); +} diff --git a/interface/src/Application.h b/interface/src/Application.h index 6461bf3925..88b38ddbbb 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -216,8 +216,14 @@ public: // Get XML with version information and parse it // Display dialog when version is not the latest and allow for new version download from link + QFile *loadSkipFile(); void checkVersion(); void displayUpdateDialog(); + bool shouldSkipVersion(); + void skipVersion(); + + QString *_latestVersion; + QString *_operatingSystem; public slots: void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data); @@ -520,9 +526,6 @@ private: QPointer _logDialog; FileLogger* _logger; - - QString *_latestVersion; - QString _operatingSystem; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 8185b96e95..d8bf6bd742 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -6,30 +6,32 @@ // Copyright (c) 2013, 2014 High Fidelity, Inc. All rights reserved. // +#include #include #include #include +#include "Application.h" #include "SharedUtil.h" #include "UpdateDialog.h" -const int buttonWidth = 120; +const int buttonWidth = 125; const int buttonHeight = 40; -const int buttonMargin = 15; -const int leftStartingPosition = 345; +const int buttonMargin = 100; +const int leftStartingPosition = 275; const int dialogWidth = 750; const int dialogHeigth = 300; const QString dialogTitle = "Update Required"; -UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *downloadURL, QString *latestVersion, QString currentVersion) : QDialog(parent, Qt::Dialog) { +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *downloadURL) : QDialog(parent, Qt::Dialog) { + Application* application = Application::getInstance(); _downloadURL = downloadURL; - _latestVersion = latestVersion; const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ Please download and install the most recent release to access the latest \ - features and bug fixes.").arg(currentVersion, *latestVersion); + features and bug fixes.").arg(application->applicationVersion(), *application->_latestVersion); int leftPosition = leftStartingPosition; setWindowTitle(dialogTitle); @@ -70,13 +72,15 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *download } void UpdateDialog::handleDownload() { + Application* application = Application::getInstance(); QDesktopServices::openUrl((*_downloadURL)); - close(); + application->quit(); } void UpdateDialog::handleSkip() { - QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - fileName.append(QString("/hifi.skipversion")); + Application* application = Application::getInstance(); + application->skipVersion(); + close(); } void UpdateDialog::handleClose() { diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index b50b38bf72..54ce812471 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -20,7 +20,7 @@ class UpdateDialog : public QDialog { Q_OBJECT public: - UpdateDialog(QWidget*, QString releaseNotes, QUrl *downloadURL, QString *latestVersion, QString currentVersion); + UpdateDialog(QWidget*, QString releaseNotes, QUrl *downloadURL); private: QLabel *_updateRequired; @@ -30,7 +30,6 @@ private: QPushButton *_closeButton; QFrame *_titleBackground; QUrl *_downloadURL; - QString *_latestVersion; private slots: void handleDownload(); From 1c2b27f0f40ed3a71c0fdf9387584b299653a459 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 10 Jan 2014 15:18:24 -0600 Subject: [PATCH 09/50] Checkpoint --- interface/CMakeLists.txt | 2 +- interface/src/Application.cpp | 26 +++++++++++--------------- interface/src/Application.h | 1 + interface/src/ui/UpdateDialog.cpp | 5 ++--- interface/src/ui/UpdateDialog.h | 2 +- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 3cf3463f83..ee9188a7d7 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -19,7 +19,7 @@ set(UVCCAMERACONTROL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/UVCCameraCont if (DEFINED ENV{JOB_ID}) set(BUILD_SEQ $ENV{JOB_ID}) else () - set(BUILD_SEQ "0") + set(BUILD_SEQ "0.1") endif () set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} $ENV{QT_CMAKE_PREFIX_PATH}) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 79a32addb2..4e9705b49c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -89,6 +89,8 @@ const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; const float MIRROR_REARVIEW_DISTANCE = 0.65f; const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f; +const QString CHECK_VERSION_URL = "http://www.google.com"; + void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { fprintf(stdout, "%s", message.toLocal8Bit().constData()); @@ -196,20 +198,21 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); #ifdef Q_WS_X11 - _operatingSystem = "ubuntu"; + _operatingSystem = new QString("ubuntu"); #endif #ifdef Q_WS_WIN - _operatingSystem = "win"; + _operatingSystem = new QString("win"); #endif #ifdef Q_WS_MACX - _operatingSystem = "mac"; + _operatingSystem = new QString("mac"); #endif checkVersion(); qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); + qDebug("[OS] %s", _operatingSystem->toStdString().c_str()); _settings = new QSettings(this); @@ -4555,40 +4558,33 @@ void Application::checkVersion() { void Application::parseVersionXml(QNetworkReply *reply) { QString _releaseDate; QString _releaseNotes; - QUrl *_downloadLink; QXmlStreamReader xml(reply); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); if (token == QXmlStreamReader::StartElement) { - if (xml.name() == "ReleaseDate") { xml.readNext(); _releaseDate = xml.text().toString(); } - if (xml.name() == "ReleaseNotes") { xml.readNext(); _releaseNotes = xml.text().toString(); } - if (xml.name() == "Version") { xml.readNext(); _latestVersion = new QString(xml.text().toString()); } } - } + + _downloadURL = new QUrl(CHECK_VERSION_URL); + if (!shouldSkipVersion() && applicationVersion() != _latestVersion) { - + UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes); + _updateDialog->exec(); } - - _downloadLink = new QUrl("http://www.google.com"); - - UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes, _downloadLink); - _updateDialog->exec(); - } QFile *Application::loadSkipFile() { diff --git a/interface/src/Application.h b/interface/src/Application.h index 88b38ddbbb..8d45b9257f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -224,6 +224,7 @@ public: QString *_latestVersion; QString *_operatingSystem; + QUrl *_downloadURL; public slots: void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data); diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index d8bf6bd742..c218d9ddbd 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -24,10 +24,9 @@ const int dialogHeigth = 300; const QString dialogTitle = "Update Required"; -UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *downloadURL) : QDialog(parent, Qt::Dialog) { +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(parent, Qt::Dialog) { Application* application = Application::getInstance(); - _downloadURL = downloadURL; const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ Please download and install the most recent release to access the latest \ @@ -73,7 +72,7 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QUrl *download void UpdateDialog::handleDownload() { Application* application = Application::getInstance(); - QDesktopServices::openUrl((*_downloadURL)); + QDesktopServices::openUrl(*application->_downloadURL); application->quit(); } diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 54ce812471..4f5969f3bd 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -20,7 +20,7 @@ class UpdateDialog : public QDialog { Q_OBJECT public: - UpdateDialog(QWidget*, QString releaseNotes, QUrl *downloadURL); + UpdateDialog(QWidget*, QString releaseNotes); private: QLabel *_updateRequired; From ca16acef6be5d01dd045566be9c0ac6c0d69f96a Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 13 Jan 2014 07:37:47 -0600 Subject: [PATCH 10/50] Checkpoint --- interface/InterfaceVersion.h.in | 2 +- interface/src/Application.cpp | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/interface/InterfaceVersion.h.in b/interface/InterfaceVersion.h.in index 26b2260965..60e51b4ab6 100644 --- a/interface/InterfaceVersion.h.in +++ b/interface/InterfaceVersion.h.in @@ -6,4 +6,4 @@ // Copyright (c) 2013 High Fidelity, Inc.. All rights reserved. // -const int BUILD_VERSION = @BUILD_SEQ@; +const QString BUILD_VERSION = "@BUILD_SEQ@"; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4e9705b49c..1f433868a0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -197,22 +197,17 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); - #ifdef Q_WS_X11 - _operatingSystem = new QString("ubuntu"); - #endif - - #ifdef Q_WS_WIN + #ifdef Q_OS_WIN32 _operatingSystem = new QString("win"); #endif - #ifdef Q_WS_MACX + #ifdef Q_OS_MAC _operatingSystem = new QString("mac"); #endif checkVersion(); qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); - qDebug("[OS] %s", _operatingSystem->toStdString().c_str()); _settings = new QSettings(this); From 4373cc17189b90c35993a1e8306b1fd96d2f8ad5 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 13 Jan 2014 11:05:58 -0600 Subject: [PATCH 11/50] Trivial commit - triggering github merge for testing --- interface/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index ee9188a7d7..7d71cd11fe 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -228,3 +228,4 @@ INSTALL(TARGETS ${TARGET_NAME} BUNDLE DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime ) + From 4a4b4835321f7c710e23da9486e0627f9c1ba257 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 14 Jan 2014 10:31:47 -0600 Subject: [PATCH 12/50] Resolving conflicts --- interface/src/Application.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6bb54e7d95..d50b8962a9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -89,12 +89,8 @@ const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; const float MIRROR_REARVIEW_DISTANCE = 0.65f; const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f; -<<<<<<< HEAD const QString CHECK_VERSION_URL = "http://www.google.com"; - -======= ->>>>>>> a8bbe41642f5ce3152f7e7ca8b9b001c78c2fcdc void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { fprintf(stdout, "%s", message.toLocal8Bit().constData()); Application::getInstance()->getLogger()->addMessage(message.toLocal8Bit().constData()); From f9bb98680deacec117d7f2a85029b87a5d142336 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 14 Jan 2014 21:57:28 -0600 Subject: [PATCH 13/50] Using Qt Designer .ui file instead of manually coding dialog --- interface/CMakeLists.txt | 3 +- interface/resources/ui/updateDialog.ui | 182 +++++++++++++++++++++++++ interface/src/Application.cpp | 13 +- interface/src/ui/UpdateDialog.cpp | 54 +++----- interface/src/ui/UpdateDialog.h | 9 -- 5 files changed, 210 insertions(+), 51 deletions(-) create mode 100644 interface/resources/ui/updateDialog.ui diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 7d71cd11fe..ab68326765 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -60,6 +60,7 @@ find_package(Qt5Svg REQUIRED) find_package(Qt5WebKit REQUIRED) find_package(Qt5WebKitWidgets REQUIRED) find_package(Qt5Xml REQUIRED) +find_package(Qt5UiTools REQUIRED) if (APPLE) set(MACOSX_BUNDLE_BUNDLE_NAME Interface) @@ -135,7 +136,7 @@ if (LIBOVR_FOUND AND NOT DISABLE_LIBOVR) target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES}) endif (LIBOVR_FOUND AND NOT DISABLE_LIBOVR) -qt5_use_modules(${TARGET_NAME} Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml) +qt5_use_modules(${TARGET_NAME} Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml UiTools) # include headers for interface and InterfaceConfig. include_directories( diff --git a/interface/resources/ui/updateDialog.ui b/interface/resources/ui/updateDialog.ui new file mode 100644 index 0000000000..de3358ea80 --- /dev/null +++ b/interface/resources/ui/updateDialog.ui @@ -0,0 +1,182 @@ + + + Dialog + + + Qt::NonModal + + + + 0 + 0 + 750 + 300 + + + + PointingHandCursor + + + Update Required + + + background-color: rgb(255, 255, 255); + + + + + 0 + 0 + 751 + 71 + + + + Qt::LeftToRight + + + false + + + background-color: rgb(236, 236, 236); + + + QFrame::StyledPanel + + + QFrame::Plain + + + 0 + + + + + 240 + 10 + 271 + 41 + + + + + Arial + 36 + PreferAntialias + false + + + + color: rgb(51, 51, 51); + + + Update Required + + + + + + + 100 + 110 + 561 + 61 + + + + + Arial + 18 + 50 + false + + + + You are currently running build 312, the latest build available is 375. Please download and install the most recent release to access the latest features and bug fixes. + + + true + + + + + + 360 + 240 + 364 + 40 + + + + + + + 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/interface/src/Application.cpp b/interface/src/Application.cpp index d50b8962a9..6cab83a44b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -89,7 +89,7 @@ const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; const float MIRROR_REARVIEW_DISTANCE = 0.65f; const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f; -const QString CHECK_VERSION_URL = "http://www.google.com"; +const QString CHECK_VERSION_URL = "http://highfidelity.io/latestVersion.xml"; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { fprintf(stdout, "%s", message.toLocal8Bit().constData()); @@ -4602,7 +4602,7 @@ void Application::updateLocalOctreeCache(bool firstTime) { } void Application::checkVersion() { - QUrl url("https://a-tower.below92.com/version.xml"); + QUrl url(CHECK_VERSION_URL); QNetworkAccessManager *downloadXML = new QNetworkAccessManager(this); QNetworkRequest request(url); connect(downloadXML, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseVersionXml(QNetworkReply*))); @@ -4631,14 +4631,15 @@ void Application::parseVersionXml(QNetworkReply *reply) { xml.readNext(); _latestVersion = new QString(xml.text().toString()); } + if (xml.name() == _operatingSystem) { + xml.readNext(); + _downloadURL = new QUrl(xml.text().toString()); + } } } - _downloadURL = new QUrl(CHECK_VERSION_URL); - if (!shouldSkipVersion() && applicationVersion() != _latestVersion) { UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes); - _updateDialog->exec(); } } @@ -4655,7 +4656,7 @@ bool Application::shouldSkipVersion() { QByteArray skipFileContents = skipFile->readAll(); QString *skipVersion = new QString(skipFileContents); skipFile->close(); - if (*skipVersion == *_latestVersion ) { + if (*skipVersion == *_latestVersion /*|| applicationVersion() == "0.1"*/) { return true; } return false; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index c218d9ddbd..5e924221ea 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "Application.h" #include "SharedUtil.h" @@ -26,44 +27,26 @@ const QString dialogTitle = "Update Required"; UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(parent, Qt::Dialog) { + QUiLoader updateDialogLoader; + + QFile updateDialogUi("resources/ui/updateDialog.ui"); + updateDialogUi.open(QFile::ReadOnly); + QWidget *updateDialog = updateDialogLoader.load(&updateDialogUi, this); + updateDialogUi.close(); + + updateDialog->show(); + Application* application = Application::getInstance(); - const QString updateRequired = QString("You are currently running build %1, the latest build released is %2.\n \ - Please download and install the most recent release to access the latest \ - features and bug fixes.").arg(application->applicationVersion(), *application->_latestVersion); + const QString updateRequired = QString("You are currently running build %1, the latest build released is %2. Please download and install the most recent release to access the latest features and bug fixes.").arg(application->applicationVersion(), *application->_latestVersion); - int leftPosition = leftStartingPosition; - setWindowTitle(dialogTitle); - //setWindowFlags(Qt::WindowTitleHint); - setModal(true); - resize(dialogWidth, dialogHeigth); - QFile styleSheet("resources/styles/update_dialog.qss"); - if (styleSheet.open(QIODevice::ReadOnly)) { - setStyleSheet(styleSheet.readAll()); - } - _releaseNotes = new QLabel(this); - _releaseNotes->setText(releaseNotes); - _releaseNotes->setObjectName("releaseNotes"); - _updateRequired = new QLabel(this); - _updateRequired->setText(updateRequired); - _updateRequired->setObjectName("updateRequired"); + QPushButton *_downloadButton = updateDialog->findChild("downloadButton"); + QPushButton *_skipButton = updateDialog->findChild("skipButton"); + QPushButton *_closeButton = updateDialog->findChild("closeButton"); + QLabel *_updateContent = updateDialog->findChild("updateContent"); - _downloadButton = new QPushButton("Download", this); - _downloadButton->setObjectName("downloadButton"); - _downloadButton->setGeometry(leftPosition, buttonMargin, buttonWidth, buttonHeight); - leftPosition += buttonWidth; - - _skipButton = new QPushButton("Skip Version", this); - _skipButton->setObjectName("skipButton"); - _skipButton->setGeometry(leftPosition, buttonMargin, buttonWidth, buttonHeight); - leftPosition += buttonWidth; - - _closeButton = new QPushButton("Close", this); - _closeButton->setObjectName("closeButton"); - _closeButton->setGeometry(leftPosition, buttonMargin, buttonWidth, buttonHeight); - - _titleBackground = new QFrame(); + _updateContent->setText(updateRequired); connect(_downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); connect(_skipButton, SIGNAL(released()), this, SLOT(handleSkip())); @@ -79,9 +62,10 @@ void UpdateDialog::handleDownload() { void UpdateDialog::handleSkip() { Application* application = Application::getInstance(); application->skipVersion(); - close(); + this->QDialog::close(); } void UpdateDialog::handleClose() { - close(); + qDebug("###### HANDLECLOSE\n"); + this->QDialog::close(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 4f5969f3bd..425a4e5dc7 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -22,15 +22,6 @@ class UpdateDialog : public QDialog { public: UpdateDialog(QWidget*, QString releaseNotes); -private: - QLabel *_updateRequired; - QLabel *_releaseNotes; - QPushButton *_downloadButton; - QPushButton *_skipButton; - QPushButton *_closeButton; - QFrame *_titleBackground; - QUrl *_downloadURL; - private slots: void handleDownload(); void handleSkip(); From b20334de1d63fb7c1d82dcdeb8b5a7600197a72a Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 14 Jan 2014 22:13:49 -0600 Subject: [PATCH 14/50] Dont need qss --- interface/resources/styles/update_dialog.qss | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 interface/resources/styles/update_dialog.qss diff --git a/interface/resources/styles/update_dialog.qss b/interface/resources/styles/update_dialog.qss deleted file mode 100644 index 005ab72b47..0000000000 --- a/interface/resources/styles/update_dialog.qss +++ /dev/null @@ -1,12 +0,0 @@ -QPushButton { - 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; -} \ No newline at end of file From 40492a1713fd55d6b17e6761d4e4392b71baacd1 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 14 Jan 2014 22:16:06 -0600 Subject: [PATCH 15/50] Removing text from .ui --- interface/resources/ui/updateDialog.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/ui/updateDialog.ui b/interface/resources/ui/updateDialog.ui index de3358ea80..b0f1e63cb9 100644 --- a/interface/resources/ui/updateDialog.ui +++ b/interface/resources/ui/updateDialog.ui @@ -92,13 +92,13 @@ - You are currently running build 312, the latest build available is 375. Please download and install the most recent release to access the latest features and bug fixes. + true - + 360 From 049be6a56953d656755b58a72333b5cff376d8c2 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 15 Jan 2014 12:40:40 -0600 Subject: [PATCH 16/50] Finishing changes --- interface/src/Application.cpp | 4 +++- interface/src/Application.h | 1 + interface/src/ui/UpdateDialog.cpp | 34 +++++++++++++++++++++---------- interface/src/ui/UpdateDialog.h | 6 ++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bbc61234de..609214df5a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include @@ -4456,7 +4458,7 @@ void Application::parseVersionXml(QNetworkReply *reply) { } if (!shouldSkipVersion() && applicationVersion() != _latestVersion) { - UpdateDialog *_updateDialog = new UpdateDialog(_glWidget, _releaseNotes); + _updateDialog = new UpdateDialog(_glWidget, _releaseNotes); } } diff --git a/interface/src/Application.h b/interface/src/Application.h index 5f705b22f3..5a06c69808 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -220,6 +220,7 @@ public: QString *_latestVersion; QString *_operatingSystem; QUrl *_downloadURL; + QWidget *_updateDialog; public slots: void domainChanged(const QString& domainHostname); diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 326957638d..d3aefebc97 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -26,33 +26,45 @@ const int dialogHeigth = 300; const QString dialogTitle = "Update Required"; UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(parent, Qt::Dialog) { + Application* application = Application::getInstance(); QUiLoader updateDialogLoader; QFile updateDialogUi("resources/ui/updateDialog.ui"); updateDialogUi.open(QFile::ReadOnly); - QWidget *updateDialog = updateDialogLoader.load(&updateDialogUi, this); + dialogWidget = updateDialogLoader.load(&updateDialogUi, parent); updateDialogUi.close(); - updateDialog->show(); - - Application* application = Application::getInstance(); - const QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ Please download and install the most recent release to access the latest features and bug fixes.") .arg(application->applicationVersion(), *application->_latestVersion); - QPushButton *_downloadButton = updateDialog->findChild("downloadButton"); - QPushButton *_skipButton = updateDialog->findChild("skipButton"); - QPushButton *_closeButton = updateDialog->findChild("closeButton"); - QLabel *_updateContent = updateDialog->findChild("updateContent"); + setAttribute(Qt::WA_DeleteOnClose); + + QPushButton *_downloadButton = dialogWidget->findChild("downloadButton"); + QPushButton *_skipButton = dialogWidget->findChild("skipButton"); + QPushButton *_closeButton = dialogWidget->findChild("closeButton"); + QLabel *_updateContent = dialogWidget->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(handleClose())); + dialogWidget->show(); +} + +UpdateDialog::~UpdateDialog() { + deleteLater(); +} + +void UpdateDialog::toggleUpdateDialog() { + if (this->dialogWidget->isVisible()) { + this->dialogWidget->hide(); + } else { + this->dialogWidget->show(); + } } void UpdateDialog::handleDownload() { @@ -64,9 +76,9 @@ void UpdateDialog::handleDownload() { void UpdateDialog::handleSkip() { Application* application = Application::getInstance(); application->skipVersion(); - this->reject(); + this->toggleUpdateDialog(); } void UpdateDialog::handleClose() { - this->reject(); + this->toggleUpdateDialog(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 425a4e5dc7..50ab7dacbe 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -21,6 +22,11 @@ class UpdateDialog : public QDialog { public: UpdateDialog(QWidget*, QString releaseNotes); + ~UpdateDialog(); + void toggleUpdateDialog(); + +private: + QWidget *dialogWidget; private slots: void handleDownload(); From dd2392f74bbc00d2c5adcb3044b841b377296e08 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 15 Jan 2014 12:40:56 -0600 Subject: [PATCH 17/50] Finishing changes --- interface/src/Application.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 609214df5a..49e6837d15 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -41,8 +41,6 @@ #include #include #include -#include -#include #include #include From f187ac0f98dd1aa61caed834fecaa6ad97b1781e Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 15 Jan 2014 12:44:22 -0600 Subject: [PATCH 18/50] Removing comment --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 49e6837d15..bf70430d24 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4473,7 +4473,7 @@ bool Application::shouldSkipVersion() { QByteArray skipFileContents = skipFile->readAll(); QString *skipVersion = new QString(skipFileContents); skipFile->close(); - if (*skipVersion == *_latestVersion /*|| applicationVersion() == "0.1"*/) { + if (*skipVersion == *_latestVersion || applicationVersion() == "0.1") { return true; } return false; From f975c8ff6948044b1e95d07e45fecc33c72e06eb Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 15 Jan 2014 12:45:26 -0600 Subject: [PATCH 19/50] Removing unneeded vars --- interface/src/ui/UpdateDialog.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index d3aefebc97..5096c462d3 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -16,15 +16,6 @@ #include "SharedUtil.h" #include "UpdateDialog.h" -const int buttonWidth = 125; -const int buttonHeight = 40; -const int buttonMargin = 100; -const int leftStartingPosition = 275; -const int dialogWidth = 750; -const int dialogHeigth = 300; - -const QString dialogTitle = "Update Required"; - UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(parent, Qt::Dialog) { Application* application = Application::getInstance(); From 1b687848d1a3d43441db640b1424f1bcea504289 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 15 Jan 2014 12:47:19 -0600 Subject: [PATCH 20/50] Unneeded include --- interface/src/Application.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bf70430d24..82fe11d174 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include From 746b45d9391e34cacc1c684839e98ee31a0b3d86 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 15 Jan 2014 15:08:47 -0600 Subject: [PATCH 21/50] Moving ifdef to xml --- interface/src/Application.cpp | 18 ++++++++++-------- interface/src/Application.h | 1 - 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f264b9ba9b..e1e0446ef4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -197,14 +197,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); - #ifdef Q_OS_WIN32 - _operatingSystem = new QString("win"); - #endif - - #ifdef Q_OS_MAC - _operatingSystem = new QString("mac"); - #endif - checkVersion(); qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); @@ -4430,6 +4422,16 @@ void Application::checkVersion() { } void Application::parseVersionXml(QNetworkReply *reply) { + QString *_operatingSystem; + + #ifdef Q_OS_WIN32 + _operatingSystem = new QString("win"); + #endif + + #ifdef Q_OS_MAC + _operatingSystem = new QString("mac"); + #endif + QString _releaseDate; QString _releaseNotes; diff --git a/interface/src/Application.h b/interface/src/Application.h index 5a06c69808..d9ea3c8ae3 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -218,7 +218,6 @@ public: void skipVersion(); QString *_latestVersion; - QString *_operatingSystem; QUrl *_downloadURL; QWidget *_updateDialog; From b8aaf4e813d1e77622e15cbaadbfa6f78518b5a6 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 13:06:54 -0600 Subject: [PATCH 22/50] CR fixes --- interface/src/Application.cpp | 36 ++++++++++++++------------ interface/src/Application.h | 22 ++++++---------- interface/src/ui/UpdateDialog.cpp | 42 +++++++++++-------------------- interface/src/ui/UpdateDialog.h | 5 ++-- 4 files changed, 44 insertions(+), 61 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e1e0446ef4..f8621f03c6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4422,18 +4422,22 @@ void Application::checkVersion() { } void Application::parseVersionXml(QNetworkReply *reply) { - QString *_operatingSystem; + QString *operatingSystem; #ifdef Q_OS_WIN32 - _operatingSystem = new QString("win"); + operatingSystem = new QString("win"); #endif #ifdef Q_OS_MAC - _operatingSystem = new QString("mac"); + operatingSystem = new QString("mac"); #endif - QString _releaseDate; - QString _releaseNotes; + QString releaseDate; + QString releaseNotes; + QString latestVersion; + QUrl downloadURL; + + QWidget *updateDialog; QXmlStreamReader xml(reply); while (!xml.atEnd() && !xml.hasError()) { @@ -4442,25 +4446,25 @@ void Application::parseVersionXml(QNetworkReply *reply) { if (token == QXmlStreamReader::StartElement) { if (xml.name() == "ReleaseDate") { xml.readNext(); - _releaseDate = xml.text().toString(); + releaseDate = xml.text().toString(); } if (xml.name() == "ReleaseNotes") { xml.readNext(); - _releaseNotes = xml.text().toString(); + releaseNotes = xml.text().toString(); } if (xml.name() == "Version") { xml.readNext(); - _latestVersion = new QString(xml.text().toString()); + latestVersion = xml.text().toString(); } - if (xml.name() == _operatingSystem) { + if (xml.name() == operatingSystem) { xml.readNext(); - _downloadURL = new QUrl(xml.text().toString()); + downloadURL = QUrl(xml.text().toString()); } } } - if (!shouldSkipVersion() && applicationVersion() != _latestVersion) { - _updateDialog = new UpdateDialog(_glWidget, _releaseNotes); + if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { + updateDialog = new UpdateDialog(_glWidget, releaseNotes); } } @@ -4472,20 +4476,20 @@ QFile *Application::loadSkipFile() { return file; } -bool Application::shouldSkipVersion() { +bool Application::shouldSkipVersion(QString latestVersion) { QFile *skipFile = loadSkipFile(); QByteArray skipFileContents = skipFile->readAll(); QString *skipVersion = new QString(skipFileContents); skipFile->close(); - if (*skipVersion == *_latestVersion || applicationVersion() == "0.1") { + if (*skipVersion == latestVersion || applicationVersion() == "0.1") { return true; } return false; } -void Application::skipVersion() { +void Application::skipVersion(QString latestVersion) { QFile *skipFile = loadSkipFile(); skipFile->seek(0); - skipFile->write(_latestVersion->toStdString().c_str()); + skipFile->write(latestVersion.toStdString().c_str()); skipFile->close(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index d9ea3c8ae3..3b5276f891 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -208,18 +208,6 @@ public: /// set a voxel which is to be rendered with a highlight void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; } void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } - - // Get XML with version information and parse it - // Display dialog when version is not the latest and allow for new version download from link - QFile *loadSkipFile(); - void checkVersion(); - void displayUpdateDialog(); - bool shouldSkipVersion(); - void skipVersion(); - - QString *_latestVersion; - QUrl *_downloadURL; - QWidget *_updateDialog; public slots: void domainChanged(const QString& domainHostname); @@ -267,8 +255,6 @@ private slots: void restoreMirrorView(); void shrinkMirrorView(); void resetSensors(); - - void parseVersionXml(QNetworkReply *reply); private: void resetCamerasOnResizeGL(Camera& camera, int width, int height); @@ -522,6 +508,14 @@ private: QString getLocalVoxelCacheFileName(); void updateLocalOctreeCache(bool firstTime = false); + + QFile *loadSkipFile(); + void checkVersion(); + void displayUpdateDialog(); + bool shouldSkipVersion(QString latestVersion); + void skipVersion(QString latestVersion); + + void parseVersionXml(QNetworkReply *reply); }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 5096c462d3..256183682b 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -16,7 +16,7 @@ #include "SharedUtil.h" #include "UpdateDialog.h" -UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(parent, Qt::Dialog) { +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latestVersion, QUrl downloadURL) : QDialog(parent, Qt::Dialog) { Application* application = Application::getInstance(); QUiLoader updateDialogLoader; @@ -28,48 +28,34 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes) : QDialog(pare const QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ Please download and install the most recent release to access the latest features and bug fixes.") - .arg(application->applicationVersion(), *application->_latestVersion); + .arg(application->applicationVersion(), latestVersion); setAttribute(Qt::WA_DeleteOnClose); - QPushButton *_downloadButton = dialogWidget->findChild("downloadButton"); - QPushButton *_skipButton = dialogWidget->findChild("skipButton"); - QPushButton *_closeButton = dialogWidget->findChild("closeButton"); - QLabel *_updateContent = dialogWidget->findChild("updateContent"); + QPushButton *downloadButton = dialogWidget->findChild("downloadButton"); + QPushButton *skipButton = dialogWidget->findChild("skipButton"); + QPushButton *closeButton = dialogWidget->findChild("closeButton"); + QLabel *updateContent = dialogWidget->findChild("updateContent"); - _updateContent->setText(updateRequired); + updateContent->setText(updateRequired); - connect(_downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); - connect(_skipButton, SIGNAL(released()), this, SLOT(handleSkip())); - connect(_closeButton, SIGNAL(released()), this, SLOT(handleClose())); + connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload(QUrl downloadURL))); + connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip())); + connect(closeButton, SIGNAL(released()), this, SLOT(handleClose())); dialogWidget->show(); } -UpdateDialog::~UpdateDialog() { - deleteLater(); -} - -void UpdateDialog::toggleUpdateDialog() { - if (this->dialogWidget->isVisible()) { - this->dialogWidget->hide(); - } else { - this->dialogWidget->show(); - } -} - -void UpdateDialog::handleDownload() { +void UpdateDialog::handleDownload(QUrl downloadURL) { Application* application = Application::getInstance(); - QDesktopServices::openUrl(*application->_downloadURL); + QDesktopServices::openUrl(downloadURL); application->quit(); } void UpdateDialog::handleSkip() { - Application* application = Application::getInstance(); - application->skipVersion(); - this->toggleUpdateDialog(); + this->close(); } void UpdateDialog::handleClose() { - this->toggleUpdateDialog(); + this->close(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 50ab7dacbe..f91424c656 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -21,15 +21,14 @@ class UpdateDialog : public QDialog { Q_OBJECT public: - UpdateDialog(QWidget*, QString releaseNotes); + UpdateDialog(QWidget*, QString releaseNotes, QString latestVersion, QUrl downloadURL); ~UpdateDialog(); - void toggleUpdateDialog(); private: QWidget *dialogWidget; private slots: - void handleDownload(); + void handleDownload(QUrl downloadURL); void handleSkip(); void handleClose(); }; From 93e4dc7d5aa90993568b09193994400a740f2880 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 13:35:49 -0600 Subject: [PATCH 23/50] PR Changes --- interface/src/Application.cpp | 5 +++-- interface/src/Application.h | 6 +++--- interface/src/ui/UpdateDialog.cpp | 13 +++++++------ interface/src/ui/UpdateDialog.h | 3 +-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3cbd590914..8377514d8f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4418,13 +4418,14 @@ void Application::parseVersionXml(QNetworkReply *reply) { } if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - updateDialog = new UpdateDialog(_glWidget, releaseNotes); + updateDialog = new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadURL); } } QFile *Application::loadSkipFile() { QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); fileName.append(QString("/hifi.skipversion")); + qDebug("###### FILENAME %s \n", fileName.toStdString().c_str()); QFile *file = new QFile(fileName); file->open(QIODevice::ReadWrite); return file; @@ -4435,7 +4436,7 @@ bool Application::shouldSkipVersion(QString latestVersion) { QByteArray skipFileContents = skipFile->readAll(); QString *skipVersion = new QString(skipFileContents); skipFile->close(); - if (*skipVersion == latestVersion || applicationVersion() == "0.1") { + if (*skipVersion == latestVersion /*|| applicationVersion() == "0.1"*/) { return true; } return false; diff --git a/interface/src/Application.h b/interface/src/Application.h index b992748224..ce9f2bbaae 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -250,6 +250,8 @@ private slots: void restoreMirrorView(); void shrinkMirrorView(); void resetSensors(); + + void parseVersionXml(QNetworkReply *reply); private: void resetCamerasOnResizeGL(Camera& camera, int width, int height); @@ -497,13 +499,11 @@ private: QString getLocalVoxelCacheFileName(); void updateLocalOctreeCache(bool firstTime = false); - QFile *loadSkipFile(); + QFile* loadSkipFile(); void checkVersion(); void displayUpdateDialog(); bool shouldSkipVersion(QString latestVersion); void skipVersion(QString latestVersion); - - void parseVersionXml(QNetworkReply *reply); }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 256183682b..5c4ac2c8fc 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -23,7 +23,7 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latest QFile updateDialogUi("resources/ui/updateDialog.ui"); updateDialogUi.open(QFile::ReadOnly); - dialogWidget = updateDialogLoader.load(&updateDialogUi, parent); + _dialogWidget = updateDialogLoader.load(&updateDialogUi, parent); updateDialogUi.close(); const QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ @@ -33,17 +33,17 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latest setAttribute(Qt::WA_DeleteOnClose); - QPushButton *downloadButton = dialogWidget->findChild("downloadButton"); - QPushButton *skipButton = dialogWidget->findChild("skipButton"); - QPushButton *closeButton = dialogWidget->findChild("closeButton"); - QLabel *updateContent = dialogWidget->findChild("updateContent"); + QPushButton* downloadButton = _dialogWidget->findChild("downloadButton"); + QPushButton* skipButton = _dialogWidget->findChild("skipButton"); + QPushButton* closeButton = _dialogWidget->findChild("closeButton"); + QLabel* updateContent = _dialogWidget->findChild("updateContent"); updateContent->setText(updateRequired); connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload(QUrl downloadURL))); connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip())); connect(closeButton, SIGNAL(released()), this, SLOT(handleClose())); - dialogWidget->show(); + _dialogWidget->show(); } void UpdateDialog::handleDownload(QUrl downloadURL) { @@ -53,6 +53,7 @@ void UpdateDialog::handleDownload(QUrl downloadURL) { } void UpdateDialog::handleSkip() { + this->close(); } diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index f91424c656..dd15cd7efb 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -22,10 +22,9 @@ class UpdateDialog : public QDialog { public: UpdateDialog(QWidget*, QString releaseNotes, QString latestVersion, QUrl downloadURL); - ~UpdateDialog(); private: - QWidget *dialogWidget; + QWidget* _dialogWidget; private slots: void handleDownload(QUrl downloadURL); From 9582fadef4115ac08e0403f548eeec9cfe7aa8ff Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 13:44:03 -0600 Subject: [PATCH 24/50] Last changes --- interface/src/ui/UpdateDialog.cpp | 8 +++++--- interface/src/ui/UpdateDialog.h | 3 --- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 5c4ac2c8fc..2fd03a48f2 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include #include "Application.h" #include "SharedUtil.h" @@ -53,10 +56,9 @@ void UpdateDialog::handleDownload(QUrl downloadURL) { } void UpdateDialog::handleSkip() { - - this->close(); + this->_dialogWidget->close(); } void UpdateDialog::handleClose() { - this->close(); + this->_dialogWidget->close(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index dd15cd7efb..04973620e6 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -10,9 +10,6 @@ #define __hifi__UpdateDialog__ #include -#include -#include -#include #include #include From a4efe55bbf37479daa0aea85fb4c0d9ab10e8214 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 14:02:57 -0600 Subject: [PATCH 25/50] changing dev version --- interface/CMakeLists.txt | 2 +- interface/src/Application.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index c855cef906..d05ea7a7c0 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -15,7 +15,7 @@ set(SIXENSE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/Sixense) if (DEFINED ENV{JOB_ID}) set(BUILD_SEQ $ENV{JOB_ID}) else () - set(BUILD_SEQ "0.1") + set(BUILD_SEQ "dev") endif () if (APPLE) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8377514d8f..2284e9fbbf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4436,7 +4436,7 @@ bool Application::shouldSkipVersion(QString latestVersion) { QByteArray skipFileContents = skipFile->readAll(); QString *skipVersion = new QString(skipFileContents); skipFile->close(); - if (*skipVersion == latestVersion /*|| applicationVersion() == "0.1"*/) { + if (*skipVersion == latestVersion || applicationVersion() == "dev") { return true; } return false; From ff6a9b2052c7c74b8f2ea94e9b6b73f065850e0b Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 14:05:38 -0600 Subject: [PATCH 26/50] PR fix --- interface/src/Application.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2284e9fbbf..4bb40af623 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4372,7 +4372,6 @@ void Application::checkVersion() { QNetworkRequest request(url); connect(downloadXML, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseVersionXml(QNetworkReply*))); downloadXML->get(request); - } void Application::parseVersionXml(QNetworkReply *reply) { @@ -4425,7 +4424,6 @@ void Application::parseVersionXml(QNetworkReply *reply) { QFile *Application::loadSkipFile() { QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); fileName.append(QString("/hifi.skipversion")); - qDebug("###### FILENAME %s \n", fileName.toStdString().c_str()); QFile *file = new QFile(fileName); file->open(QIODevice::ReadWrite); return file; From 99275dadd4e99bfc1ab3506b520137ed033b74b2 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 14:39:34 -0600 Subject: [PATCH 27/50] PR Changes --- interface/src/Application.cpp | 30 ++++++++++++++---------------- interface/src/Application.h | 1 - 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4bb40af623..ae82d44e90 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4421,28 +4421,26 @@ void Application::parseVersionXml(QNetworkReply *reply) { } } -QFile *Application::loadSkipFile() { +bool Application::shouldSkipVersion(QString latestVersion) { QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); fileName.append(QString("/hifi.skipversion")); - QFile *file = new QFile(fileName); - file->open(QIODevice::ReadWrite); - return file; -} - -bool Application::shouldSkipVersion(QString latestVersion) { - QFile *skipFile = loadSkipFile(); - QByteArray skipFileContents = skipFile->readAll(); - QString *skipVersion = new QString(skipFileContents); - skipFile->close(); - if (*skipVersion == latestVersion || applicationVersion() == "dev") { + QFile skipFile(fileName); + skipFile.open(QIODevice::ReadWrite); + QByteArray skipFileContents = skipFile.readAll(); + QString skipVersion(skipFileContents); + skipFile.close(); + if (skipVersion == latestVersion /*|| applicationVersion() == "dev"*/) { return true; } return false; } void Application::skipVersion(QString latestVersion) { - QFile *skipFile = loadSkipFile(); - skipFile->seek(0); - skipFile->write(latestVersion.toStdString().c_str()); - skipFile->close(); + QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + fileName.append(QString("/hifi.skipversion")); + QFile skipFile(fileName); + skipFile.open(QIODevice::WriteOnly|QIODevice::Truncate); + skipFile.seek(0); + skipFile.write(latestVersion.toStdString().c_str()); + skipFile.close(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index ce9f2bbaae..acb2901452 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -499,7 +499,6 @@ private: QString getLocalVoxelCacheFileName(); void updateLocalOctreeCache(bool firstTime = false); - QFile* loadSkipFile(); void checkVersion(); void displayUpdateDialog(); bool shouldSkipVersion(QString latestVersion); From a13d7b084fcf363450cd78fa7b3f3dbcdd9ac9b7 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Fri, 17 Jan 2014 14:39:48 -0600 Subject: [PATCH 28/50] Removing comment --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ae82d44e90..68f850d01b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4429,7 +4429,7 @@ bool Application::shouldSkipVersion(QString latestVersion) { QByteArray skipFileContents = skipFile.readAll(); QString skipVersion(skipFileContents); skipFile.close(); - if (skipVersion == latestVersion /*|| applicationVersion() == "dev"*/) { + if (skipVersion == latestVersion || applicationVersion() == "dev") { return true; } return false; From d0a53f817a42eb01774612c75be68e5e56d27454 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 17 Jan 2014 17:14:57 -0800 Subject: [PATCH 29/50] applyHardCollision() now takes a CollisionInfo rather than two vectors ("penetration" and "addedVelocity") --- .../particles/src/ParticleCollisionSystem.cpp | 64 +++++++++---------- .../particles/src/ParticleCollisionSystem.h | 4 +- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 8544932181..5e0a6d4e39 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -74,16 +73,16 @@ void ParticleCollisionSystem::updateCollisionWithVoxels(Particle* particle) { const float ELASTICITY = 0.4f; const float DAMPING = 0.0f; const float COLLISION_FREQUENCY = 0.5f; - glm::vec3 penetration; + CollisionInfo collisionInfo; VoxelDetail* voxelDetails = NULL; - if (_voxels->findSpherePenetration(center, radius, penetration, (void**)&voxelDetails)) { + if (_voxels->findSpherePenetration(center, radius, collisionInfo._penetration, (void**)&voxelDetails)) { // let the particles run their collision scripts if they have them particle->collisionWithVoxel(voxelDetails); - penetration /= (float)(TREE_SCALE); - updateCollisionSound(particle, penetration, COLLISION_FREQUENCY); - applyHardCollision(particle, penetration, ELASTICITY, DAMPING); + collisionInfo._penetration /= (float)(TREE_SCALE); + updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY); + applyHardCollision(particle, ELASTICITY, DAMPING, collisionInfo); delete voxelDetails; // cleanup returned details } @@ -153,11 +152,11 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { // first check the selfAvatar if set... if (_selfAvatar) { AvatarData* avatar = (AvatarData*)_selfAvatar; - CollisionInfo collision; - if (avatar->findSphereCollision(center, radius, collision)) { - collision._addedVelocity /= (float)(TREE_SCALE); - glm::vec3 relativeVelocity = collision._addedVelocity - particle->getVelocity(); - if (glm::dot(relativeVelocity, collision._penetration) < 0.f) { + CollisionInfo collisionInfo; + if (avatar->findSphereCollision(center, radius, collisionInfo)) { + collisionInfo._addedVelocity /= (float)(TREE_SCALE); + glm::vec3 relativeVelocity = collisionInfo._addedVelocity - particle->getVelocity(); + if (glm::dot(relativeVelocity, collisionInfo._penetration) < 0.f) { // only collide when particle and collision point are moving toward each other // (doing this prevents some "collision snagging" when particle penetrates the object) @@ -166,16 +165,16 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { // TODO: make this less hacky when we have more per-collision details float elasticity = ELASTICITY; float SLOW_PADDLE_SPEED = 5.0e-5f; - float attenuationFactor = glm::length(collision._addedVelocity) / SLOW_PADDLE_SPEED; + float attenuationFactor = glm::length(collisionInfo._addedVelocity) / SLOW_PADDLE_SPEED; if (attenuationFactor < 1.f) { - collision._addedVelocity *= attenuationFactor; + collisionInfo._addedVelocity *= attenuationFactor; elasticity *= attenuationFactor; } // HACK END - collision._penetration /= (float)(TREE_SCALE); - updateCollisionSound(particle, collision._penetration, COLLISION_FREQUENCY); - applyHardCollision(particle, collision._penetration, elasticity, DAMPING, collision._addedVelocity); + collisionInfo._penetration /= (float)(TREE_SCALE); + updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY); + applyHardCollision(particle, elasticity, DAMPING, collisionInfo); } } } @@ -185,26 +184,26 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { //qDebug() << "updateCollisionWithAvatars()... node:" << *node << "\n"; if (node->getLinkedData() && node->getType() == NODE_TYPE_AGENT) { AvatarData* avatar = static_cast(node->getLinkedData()); - CollisionInfo collision; - if (avatar->findSphereCollision(center, radius, collision)) { - collision._addedVelocity /= (float)(TREE_SCALE); - glm::vec3 relativeVelocity = collision._addedVelocity - particle->getVelocity(); - if (glm::dot(relativeVelocity, collision._penetration) < 0.f) { + CollisionInfo collisionInfo; + if (avatar->findSphereCollision(center, radius, collisionInfo)) { + collisionInfo._addedVelocity /= (float)(TREE_SCALE); + glm::vec3 relativeVelocity = collisionInfo._addedVelocity - particle->getVelocity(); + if (glm::dot(relativeVelocity, collisionInfo._penetration) < 0.f) { // HACK BEGIN: to allow paddle hands to "hold" particles we attenuate soft collisions against the avatar. // NOTE: the physics are wrong (particles cannot roll) but it IS possible to catch a slow moving particle. // TODO: make this less hacky when we have more per-collision details float elasticity = ELASTICITY; float SLOW_PADDLE_SPEED = 5.0e-5f; - float attenuationFactor = glm::length(collision._addedVelocity) / SLOW_PADDLE_SPEED; + float attenuationFactor = glm::length(collisionInfo._addedVelocity) / SLOW_PADDLE_SPEED; if (attenuationFactor < 1.f) { - collision._addedVelocity *= attenuationFactor; + collisionInfo._addedVelocity *= attenuationFactor; elasticity *= attenuationFactor; } // HACK END - collision._penetration /= (float)(TREE_SCALE); - updateCollisionSound(particle, collision._penetration, COLLISION_FREQUENCY); - applyHardCollision(particle, collision._penetration, ELASTICITY, DAMPING, collision._addedVelocity); + collisionInfo._penetration /= (float)(TREE_SCALE); + updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY); + applyHardCollision(particle, ELASTICITY, DAMPING, collisionInfo); } } } @@ -213,8 +212,7 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { // TODO: convert applyHardCollision() to take a CollisionInfo& instead of penetration + addedVelocity -void ParticleCollisionSystem::applyHardCollision(Particle* particle, const glm::vec3& penetration, - float elasticity, float damping, const glm::vec3& addedVelocity) { +void ParticleCollisionSystem::applyHardCollision(Particle* particle, float elasticity, float damping, const CollisionInfo& collisionInfo) { // // Update the particle in response to a hard collision. Position will be reset exactly // to outside the colliding surface. Velocity will be modified according to elasticity. @@ -226,16 +224,14 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, const glm:: glm::vec3 velocity = particle->getVelocity(); const float EPSILON = 0.0f; - float velocityDotPenetration = glm::dot(velocity, penetration); + float velocityDotPenetration = glm::dot(velocity, collisionInfo._penetration); if (velocityDotPenetration > EPSILON) { - position -= penetration; + position -= collisionInfo._penetration; static float HALTING_VELOCITY = 0.2f / (float)(TREE_SCALE); // cancel out the velocity component in the direction of penetration - float penetrationLength = glm::length(penetration); - glm::vec3 direction = penetration / penetrationLength; - velocity -= (glm::dot(velocity, direction) * (1.0f + elasticity)) * direction; - velocity += addedVelocity; + glm::vec3 direction = glm::normalize(collisionInfo._penetration); + velocity += collisionInfo._addedVelocity - (glm::dot(velocity, direction) * (1.0f + elasticity)) * direction; velocity *= glm::clamp(1.f - damping, 0.0f, 1.0f); if (glm::length(velocity) < HALTING_VELOCITY) { // If moving really slowly after a collision, and not applying forces, stop altogether diff --git a/libraries/particles/src/ParticleCollisionSystem.h b/libraries/particles/src/ParticleCollisionSystem.h index 13766a0264..cf52d01a7a 100644 --- a/libraries/particles/src/ParticleCollisionSystem.h +++ b/libraries/particles/src/ParticleCollisionSystem.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -46,8 +47,7 @@ public: void updateCollisionWithVoxels(Particle* particle); void updateCollisionWithParticles(Particle* particle); void updateCollisionWithAvatars(Particle* particle); - void applyHardCollision(Particle* particle, const glm::vec3& penetration, float elasticity, float damping, - const glm::vec3& addedVelocity = NO_ADDED_VELOCITY); + void applyHardCollision(Particle* particle, float elasticity, float damping, const CollisionInfo& collisionInfo); void updateCollisionSound(Particle* particle, const glm::vec3 &penetration, float frequency); private: From cd9f2fd240f2e8864322dc303ff6591c7a8b0a5d Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Sat, 18 Jan 2014 20:17:47 -0600 Subject: [PATCH 30/50] Pull Request fixes --- interface/src/Application.cpp | 51 ++++++++++++------------------- interface/src/Application.h | 5 ++- interface/src/ui/UpdateDialog.cpp | 19 ++++++------ interface/src/ui/UpdateDialog.h | 4 +-- 4 files changed, 36 insertions(+), 43 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 23113dfd71..d8a906e06a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -95,6 +95,7 @@ const float MIRROR_REARVIEW_DISTANCE = 0.65f; const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f; const QString CHECK_VERSION_URL = "http://highfidelity.io/latestVersion.xml"; +const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/hifi.skipversion"; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { QString messageWithNewLine = message + "\n"; @@ -202,8 +203,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); - checkVersion(); - qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); _settings = new QSettings(this); @@ -262,7 +261,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : // Set the sixense filtering _sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense)); - + + checkVersion(); } Application::~Application() { @@ -4367,31 +4367,28 @@ void Application::updateLocalOctreeCache(bool firstTime) { void Application::checkVersion() { QUrl url(CHECK_VERSION_URL); - QNetworkAccessManager *downloadXML = new QNetworkAccessManager(this); - QNetworkRequest request(url); - connect(downloadXML, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseVersionXml(QNetworkReply*))); - downloadXML->get(request); + QNetworkRequest latestVersionRequest(url); + latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + _latestVersionReply = getNetworkAccessManager()->get(latestVersionRequest); + + connect(_latestVersionReply, SIGNAL(readyRead()), SLOT(parseVersionXml())); } -void Application::parseVersionXml(QNetworkReply *reply) { - QString *operatingSystem; +void Application::parseVersionXml() { #ifdef Q_OS_WIN32 - operatingSystem = new QString("win"); + QString operatingSystem("win"); #endif #ifdef Q_OS_MAC - operatingSystem = new QString("mac"); + QString operatingSystem("mac"); #endif QString releaseDate; QString releaseNotes; QString latestVersion; - QUrl downloadURL; - QWidget *updateDialog; - - QXmlStreamReader xml(reply); + QXmlStreamReader xml(_latestVersionReply); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); @@ -4410,36 +4407,28 @@ void Application::parseVersionXml(QNetworkReply *reply) { } if (xml.name() == operatingSystem) { xml.readNext(); - downloadURL = QUrl(xml.text().toString()); + _downloadUrl = QUrl(xml.text().toString()); } } } if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - updateDialog = new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadURL); + new UpdateDialog(_glWidget, releaseNotes, latestVersion, _downloadUrl); } + + delete _latestVersionReply; } bool Application::shouldSkipVersion(QString latestVersion) { - QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - fileName.append(QString("/hifi.skipversion")); - QFile skipFile(fileName); + QFile skipFile(SKIP_FILENAME); skipFile.open(QIODevice::ReadWrite); - QByteArray skipFileContents = skipFile.readAll(); - QString skipVersion(skipFileContents); - skipFile.close(); - if (skipVersion == latestVersion || applicationVersion() == "dev") { - return true; - } - return false; + QString skipVersion(skipFile.readAll()); + return (skipVersion == latestVersion /*|| applicationVersion() == "dev"*/); } void Application::skipVersion(QString latestVersion) { - QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - fileName.append(QString("/hifi.skipversion")); - QFile skipFile(fileName); + QFile skipFile(SKIP_FILENAME); skipFile.open(QIODevice::WriteOnly|QIODevice::Truncate); skipFile.seek(0); skipFile.write(latestVersion.toStdString().c_str()); - skipFile.close(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index acb2901452..86a162e835 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -203,6 +203,8 @@ public: /// set a voxel which is to be rendered with a highlight void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; } void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } + + QUrl _downloadUrl; public slots: void domainChanged(const QString& domainHostname); @@ -251,7 +253,7 @@ private slots: void shrinkMirrorView(); void resetSensors(); - void parseVersionXml(QNetworkReply *reply); + void parseVersionXml(); private: void resetCamerasOnResizeGL(Camera& camera, int width, int height); @@ -503,6 +505,7 @@ private: void displayUpdateDialog(); bool shouldSkipVersion(QString latestVersion); void skipVersion(QString latestVersion); + QNetworkReply* _latestVersionReply; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 2fd03a48f2..5ee6cd6812 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -19,17 +19,18 @@ #include "SharedUtil.h" #include "UpdateDialog.h" -UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latestVersion, QUrl downloadURL) : QDialog(parent, Qt::Dialog) { +UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latestVersion, QUrl downloadURL) : + QDialog(parent, Qt::Dialog) { + Application* application = Application::getInstance(); QUiLoader updateDialogLoader; QFile updateDialogUi("resources/ui/updateDialog.ui"); updateDialogUi.open(QFile::ReadOnly); - _dialogWidget = updateDialogLoader.load(&updateDialogUi, parent); - updateDialogUi.close(); + _dialogWidget = updateDialogLoader.load(&updateDialogUi, this); - const QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ + QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ Please download and install the most recent release to access the latest features and bug fixes.") .arg(application->applicationVersion(), latestVersion); @@ -43,22 +44,22 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latest updateContent->setText(updateRequired); - connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload(QUrl downloadURL))); + connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip())); connect(closeButton, SIGNAL(released()), this, SLOT(handleClose())); _dialogWidget->show(); } -void UpdateDialog::handleDownload(QUrl downloadURL) { +void UpdateDialog::handleDownload() { Application* application = Application::getInstance(); - QDesktopServices::openUrl(downloadURL); + QDesktopServices::openUrl(application->_downloadUrl); application->quit(); } void UpdateDialog::handleSkip() { - this->_dialogWidget->close(); + this->close(); } void UpdateDialog::handleClose() { - this->_dialogWidget->close(); + this->close(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 04973620e6..690d0a9f0d 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -18,13 +18,13 @@ class UpdateDialog : public QDialog { Q_OBJECT public: - UpdateDialog(QWidget*, QString releaseNotes, QString latestVersion, QUrl downloadURL); + UpdateDialog(QWidget* parent, QString releaseNotes, QString latestVersion, QUrl downloadURL); private: QWidget* _dialogWidget; private slots: - void handleDownload(QUrl downloadURL); + void handleDownload(); void handleSkip(); void handleClose(); }; From 7748002db7ad433431761e4771bb4e90b26545bb Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Sat, 18 Jan 2014 20:27:56 -0600 Subject: [PATCH 31/50] More PR related changes --- interface/src/Application.cpp | 4 ++++ interface/src/Application.h | 2 +- interface/src/ui/UpdateDialog.cpp | 6 +++++- interface/src/ui/UpdateDialog.h | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d8a906e06a..18202ee1b6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4384,6 +4384,10 @@ void Application::parseVersionXml() { QString operatingSystem("mac"); #endif + #ifdef Q_OS_LINUX + QString operatingSystem("ubuntu"); + #endif + QString releaseDate; QString releaseNotes; QString latestVersion; diff --git a/interface/src/Application.h b/interface/src/Application.h index 86a162e835..d66042149d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -205,6 +205,7 @@ public: void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } QUrl _downloadUrl; + void skipVersion(QString latestVersion); public slots: void domainChanged(const QString& domainHostname); @@ -504,7 +505,6 @@ private: void checkVersion(); void displayUpdateDialog(); bool shouldSkipVersion(QString latestVersion); - void skipVersion(QString latestVersion); QNetworkReply* _latestVersionReply; }; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 5ee6cd6812..adc2139634 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -20,10 +20,12 @@ #include "UpdateDialog.h" UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latestVersion, QUrl downloadURL) : - QDialog(parent, Qt::Dialog) { + QWidget(parent, Qt::Widget) { Application* application = Application::getInstance(); + QString _latestVersion(latestVersion); + QUiLoader updateDialogLoader; QFile updateDialogUi("resources/ui/updateDialog.ui"); @@ -57,6 +59,8 @@ void UpdateDialog::handleDownload() { } void UpdateDialog::handleSkip() { + Application* application = Application::getInstance(); + application->skipVersion(_latestVersion); this->close(); } diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 690d0a9f0d..6faca45974 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -14,7 +14,7 @@ #include -class UpdateDialog : public QDialog { +class UpdateDialog : public QWidget { Q_OBJECT public: @@ -22,6 +22,7 @@ public: private: QWidget* _dialogWidget; + QString _latestVersion; private slots: void handleDownload(); From 3d5d02d5b0c4e4b0f0f02101f4230ec382b8a412 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Sat, 18 Jan 2014 20:33:29 -0600 Subject: [PATCH 32/50] Some more changes --- interface/src/ui/UpdateDialog.cpp | 8 ++++---- interface/src/ui/UpdateDialog.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index adc2139634..8a06d69b3f 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -24,7 +24,7 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latest Application* application = Application::getInstance(); - QString _latestVersion(latestVersion); + _latestVersion = new QString(latestVersion); QUiLoader updateDialogLoader; @@ -33,8 +33,8 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latest _dialogWidget = updateDialogLoader.load(&updateDialogUi, this); QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ - Please download and install the most recent release to access the latest features and bug fixes.") - .arg(application->applicationVersion(), latestVersion); + Please download and install the most recent release to access the latest features and bug fixes.") + .arg(application->applicationVersion(), latestVersion); setAttribute(Qt::WA_DeleteOnClose); @@ -60,7 +60,7 @@ void UpdateDialog::handleDownload() { void UpdateDialog::handleSkip() { Application* application = Application::getInstance(); - application->skipVersion(_latestVersion); + application->skipVersion(*_latestVersion); this->close(); } diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 6faca45974..e7ea79a9d9 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -22,7 +22,7 @@ public: private: QWidget* _dialogWidget; - QString _latestVersion; + QString* _latestVersion; private slots: void handleDownload(); From 825c64e1d0141353b0b7e0898e4cec76511ae445 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 20 Jan 2014 10:57:10 -0600 Subject: [PATCH 33/50] Anything obviously wrong? --- interface/src/Application.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 18202ee1b6..96687a55c3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4366,10 +4366,10 @@ void Application::updateLocalOctreeCache(bool firstTime) { } void Application::checkVersion() { - QUrl url(CHECK_VERSION_URL); - QNetworkRequest latestVersionRequest(url); + qDebug("############# in check version"); + QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - _latestVersionReply = getNetworkAccessManager()->get(latestVersionRequest); + _latestVersionReply = Application::getInstance()->getNetworkAccessManager()->get(latestVersionRequest); connect(_latestVersionReply, SIGNAL(readyRead()), SLOT(parseVersionXml())); } @@ -4432,6 +4432,7 @@ bool Application::shouldSkipVersion(QString latestVersion) { void Application::skipVersion(QString latestVersion) { QFile skipFile(SKIP_FILENAME); + qDebug("##### Storing %s in file %s", latestVersion.toStdString().c_str(), SKIP_FILENAME.toStdString().c_str()); skipFile.open(QIODevice::WriteOnly|QIODevice::Truncate); skipFile.seek(0); skipFile.write(latestVersion.toStdString().c_str()); From f6bc7a2c4bf9254a50ac0c591a474b454c3a2408 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 20 Jan 2014 11:51:17 -0600 Subject: [PATCH 34/50] I think last fixes --- interface/src/ui/UpdateDialog.cpp | 18 ++++++++---------- interface/src/ui/UpdateDialog.h | 1 - 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 8a06d69b3f..ae3a52932f 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -22,34 +22,32 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latestVersion, QUrl downloadURL) : QWidget(parent, Qt::Widget) { - Application* application = Application::getInstance(); - _latestVersion = new QString(latestVersion); QUiLoader updateDialogLoader; - + QWidget* updateDialog; QFile updateDialogUi("resources/ui/updateDialog.ui"); updateDialogUi.open(QFile::ReadOnly); - _dialogWidget = updateDialogLoader.load(&updateDialogUi, this); + updateDialog = updateDialogLoader.load(&updateDialogUi, this); QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ Please download and install the most recent release to access the latest features and bug fixes.") - .arg(application->applicationVersion(), latestVersion); + .arg(Application::getInstance()->applicationVersion(), latestVersion); setAttribute(Qt::WA_DeleteOnClose); - QPushButton* downloadButton = _dialogWidget->findChild("downloadButton"); - QPushButton* skipButton = _dialogWidget->findChild("skipButton"); - QPushButton* closeButton = _dialogWidget->findChild("closeButton"); - QLabel* updateContent = _dialogWidget->findChild("updateContent"); + QPushButton* downloadButton = updateDialog->findChild("downloadButton"); + QPushButton* skipButton = updateDialog->findChild("skipButton"); + QPushButton* closeButton = updateDialog->findChild("closeButton"); + QLabel* updateContent = updateDialog->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(handleClose())); - _dialogWidget->show(); + updateDialog->show(); } void UpdateDialog::handleDownload() { diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index e7ea79a9d9..aa0b800528 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -21,7 +21,6 @@ public: UpdateDialog(QWidget* parent, QString releaseNotes, QString latestVersion, QUrl downloadURL); private: - QWidget* _dialogWidget; QString* _latestVersion; private slots: From 04970be8a21c5b8193b942cc873a3abf03616723 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 20 Jan 2014 11:52:26 -0600 Subject: [PATCH 35/50] Removing comments --- interface/src/Application.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 96687a55c3..0d1435d5df 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4427,12 +4427,11 @@ bool Application::shouldSkipVersion(QString latestVersion) { QFile skipFile(SKIP_FILENAME); skipFile.open(QIODevice::ReadWrite); QString skipVersion(skipFile.readAll()); - return (skipVersion == latestVersion /*|| applicationVersion() == "dev"*/); + return (skipVersion == latestVersion || applicationVersion() == "dev"); } void Application::skipVersion(QString latestVersion) { QFile skipFile(SKIP_FILENAME); - qDebug("##### Storing %s in file %s", latestVersion.toStdString().c_str(), SKIP_FILENAME.toStdString().c_str()); skipFile.open(QIODevice::WriteOnly|QIODevice::Truncate); skipFile.seek(0); skipFile.write(latestVersion.toStdString().c_str()); From 3036142a389eaab3443a8f26ac3d6f71623f1fa9 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Mon, 20 Jan 2014 11:55:10 -0600 Subject: [PATCH 36/50] Removing comments --- interface/src/Application.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0d1435d5df..6c9dcae410 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4366,7 +4366,6 @@ void Application::updateLocalOctreeCache(bool firstTime) { } void Application::checkVersion() { - qDebug("############# in check version"); QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); _latestVersionReply = Application::getInstance()->getNetworkAccessManager()->get(latestVersionRequest); @@ -4432,7 +4431,7 @@ bool Application::shouldSkipVersion(QString latestVersion) { void Application::skipVersion(QString latestVersion) { QFile skipFile(SKIP_FILENAME); - skipFile.open(QIODevice::WriteOnly|QIODevice::Truncate); + skipFile.open(QIODevice::WriteOnly | QIODevice::Truncate); skipFile.seek(0); skipFile.write(latestVersion.toStdString().c_str()); } From 61e1b25e70c7dd7015036d76d9c6da3ed01221f6 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 20 Jan 2014 12:43:27 -0800 Subject: [PATCH 37/50] ParticleTreeElement::_particles is now a QList<> instead of std::vector<> for faster erase() --- interface/src/ParticleTreeRenderer.cpp | 2 +- .../particles/src/ParticleCollisionSystem.cpp | 9 +- .../particles/src/ParticleTreeElement.cpp | 92 +++++++++++-------- libraries/particles/src/ParticleTreeElement.h | 16 ++-- 4 files changed, 71 insertions(+), 48 deletions(-) diff --git a/interface/src/ParticleTreeRenderer.cpp b/interface/src/ParticleTreeRenderer.cpp index c6ed1488e4..81ef7f1221 100644 --- a/interface/src/ParticleTreeRenderer.cpp +++ b/interface/src/ParticleTreeRenderer.cpp @@ -32,7 +32,7 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg // we need to iterate the actual particles of the element ParticleTreeElement* particleTreeElement = (ParticleTreeElement*)element; - const std::vector& particles = particleTreeElement->getParticles(); + const QList& particles = particleTreeElement->getParticles(); uint16_t numberOfParticles = particles.size(); diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 5e0a6d4e39..dc8f2f5269 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -42,7 +42,7 @@ bool ParticleCollisionSystem::updateOperation(OctreeElement* element, void* extr ParticleTreeElement* particleTreeElement = static_cast(element); // iterate the particles... - std::vector& particles = particleTreeElement->getParticles(); + QList& particles = particleTreeElement->getParticles(); uint16_t numberOfParticles = particles.size(); for (uint16_t i = 0; i < numberOfParticles; i++) { Particle* particle = &particles[i]; @@ -227,13 +227,14 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, float elast float velocityDotPenetration = glm::dot(velocity, collisionInfo._penetration); if (velocityDotPenetration > EPSILON) { position -= collisionInfo._penetration; - static float HALTING_VELOCITY = 0.2f / (float)(TREE_SCALE); // cancel out the velocity component in the direction of penetration - glm::vec3 direction = glm::normalize(collisionInfo._penetration); velocity += collisionInfo._addedVelocity - (glm::dot(velocity, direction) * (1.0f + elasticity)) * direction; velocity *= glm::clamp(1.f - damping, 0.0f, 1.0f); - if (glm::length(velocity) < HALTING_VELOCITY) { + + // TODO: move this halt logic into Particle::update() method + static float HALTING_SPEED = 0.2f / (float)(TREE_SCALE); + if (glm::length(velocity) < HALTING_SPEED) { // If moving really slowly after a collision, and not applying forces, stop altogether velocity *= 0.f; } diff --git a/libraries/particles/src/ParticleTreeElement.cpp b/libraries/particles/src/ParticleTreeElement.cpp index 44cb8db008..525f567ed4 100644 --- a/libraries/particles/src/ParticleTreeElement.cpp +++ b/libraries/particles/src/ParticleTreeElement.cpp @@ -11,12 +11,14 @@ #include "ParticleTree.h" #include "ParticleTreeElement.h" -ParticleTreeElement::ParticleTreeElement(unsigned char* octalCode) : OctreeElement() { +ParticleTreeElement::ParticleTreeElement(unsigned char* octalCode) : OctreeElement(), _particles(NULL) { init(octalCode); }; ParticleTreeElement::~ParticleTreeElement() { _voxelMemoryUsage -= sizeof(ParticleTreeElement); + delete _particles; + _particles = NULL; } // This will be called primarily on addChildAt(), which means we're adding a child of our @@ -31,6 +33,7 @@ OctreeElement* ParticleTreeElement::createNewElement(unsigned char* octalCode) c void ParticleTreeElement::init(unsigned char* octalCode) { OctreeElement::init(octalCode); + _particles = new QList; _voxelMemoryUsage += sizeof(ParticleTreeElement); } @@ -45,12 +48,12 @@ bool ParticleTreeElement::appendElementData(OctreePacketData* packetData) const bool success = true; // assume the best... // write our particles out... - uint16_t numberOfParticles = _particles.size(); + uint16_t numberOfParticles = _particles->size(); success = packetData->appendValue(numberOfParticles); if (success) { for (uint16_t i = 0; i < numberOfParticles; i++) { - const Particle& particle = _particles[i]; + const Particle& particle = (*_particles)[i]; success = particle.appendParticleData(packetData); if (!success) { break; @@ -62,35 +65,42 @@ bool ParticleTreeElement::appendElementData(OctreePacketData* packetData) const void ParticleTreeElement::update(ParticleTreeUpdateArgs& args) { markWithChangedTime(); + // TODO: early exit when _particles is empty // update our contained particles - uint16_t numberOfParticles = _particles.size(); - - for (uint16_t i = 0; i < numberOfParticles; i++) { - _particles[i].update(); + QList::iterator particleItr = _particles->begin(); + while(particleItr != _particles->end()) { + Particle& particle = (*particleItr); + particle.update(); // If the particle wants to die, or if it's left our bounding box, then move it // into the arguments moving particles. These will be added back or deleted completely - if (_particles[i].getShouldDie() || !_box.contains(_particles[i].getPosition())) { - args._movingParticles.push_back(_particles[i]); + if (particle.getShouldDie() || !_box.contains(particle.getPosition())) { + args._movingParticles.push_back(particle); // erase this particle - _particles.erase(_particles.begin()+i); - - // reduce our index since we just removed this item - i--; - numberOfParticles--; + particleItr = _particles->erase(particleItr); + } + else + { + ++particleItr; } } + // TODO: if _particles is empty after while loop consider freeing memory in _particles if + // internal array is too big (QList internal array does not decrease size except in dtor and + // assignment operator). Otherwise _particles could become a "resource leak" for large + // roaming piles of particles. } bool ParticleTreeElement::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const { - uint16_t numberOfParticles = _particles.size(); - for (uint16_t i = 0; i < numberOfParticles; i++) { - glm::vec3 particleCenter = _particles[i].getPosition(); - float particleRadius = _particles[i].getRadius(); + QList::iterator particleItr = _particles->begin(); + QList::const_iterator particleEnd = _particles->end(); + while(particleItr != particleEnd) { + Particle& particle = (*particleItr); + glm::vec3 particleCenter = particle.getPosition(); + float particleRadius = particle.getRadius(); // don't penetrate yourself if (particleCenter == center && particleRadius == radius) { @@ -102,23 +112,28 @@ bool ParticleTreeElement::findSpherePenetration(const glm::vec3& center, float r const bool IN_HAND_PARTICLES_DONT_COLLIDE = false; if (IN_HAND_PARTICLES_DONT_COLLIDE) { // don't penetrate if the particle is "inHand" -- they don't collide - if (_particles[i].getInHand()) { - return false; + if (particle.getInHand()) { + ++particleItr; + continue; } } if (findSphereSpherePenetration(center, radius, particleCenter, particleRadius, penetration)) { - *penetratedObject = (void*)&_particles[i]; + // return true on first valid particle penetration + *penetratedObject = (void*)(&particle); return true; } + ++particleItr; } return false; } bool ParticleTreeElement::containsParticle(const Particle& particle) const { - uint16_t numberOfParticles = _particles.size(); + // TODO: remove this method and force callers to use getParticleWithID() instead + uint16_t numberOfParticles = _particles->size(); + uint32_t particleID = particle.getID(); for (uint16_t i = 0; i < numberOfParticles; i++) { - if (_particles[i].getID() == particle.getID()) { + if ((*_particles)[i].getID() == particleID) { return true; } } @@ -126,13 +141,17 @@ bool ParticleTreeElement::containsParticle(const Particle& particle) const { } bool ParticleTreeElement::updateParticle(const Particle& particle) { + // NOTE: this method must first lookup the particle by ID, hence it is O(N) + // and "particle is not found" is worst-case (full N) but maybe we don't care? + // (guaranteed that num particles per elemen is small?) const bool wantDebug = false; - uint16_t numberOfParticles = _particles.size(); + uint16_t numberOfParticles = _particles->size(); for (uint16_t i = 0; i < numberOfParticles; i++) { - if (_particles[i].getID() == particle.getID()) { - int difference = _particles[i].getLastUpdated() - particle.getLastUpdated(); - bool changedOnServer = _particles[i].getLastEdited() < particle.getLastEdited(); - bool localOlder = _particles[i].getLastUpdated() < particle.getLastUpdated(); + Particle& thisParticle = (*_particles)[i]; + if (thisParticle.getID() == particle.getID()) { + int difference = thisParticle.getLastUpdated() - particle.getLastUpdated(); + bool changedOnServer = thisParticle.getLastEdited() < particle.getLastEdited(); + bool localOlder = thisParticle.getLastUpdated() < particle.getLastUpdated(); if (changedOnServer || localOlder) { if (wantDebug) { printf("local particle [id:%d] %s and %s than server particle by %d, particle.isNewlyCreated()=%s\n", @@ -140,7 +159,7 @@ bool ParticleTreeElement::updateParticle(const Particle& particle) { (localOlder ? "OLDER" : "NEWER"), difference, debug::valueOf(particle.isNewlyCreated()) ); } - _particles[i].copyChangedProperties(particle); + thisParticle.copyChangedProperties(particle); } else { if (wantDebug) { printf(">>> IGNORING SERVER!!! Would've caused jutter! <<< " @@ -159,22 +178,23 @@ bool ParticleTreeElement::updateParticle(const Particle& particle) { const Particle* ParticleTreeElement::getClosestParticle(glm::vec3 position) const { const Particle* closestParticle = NULL; float closestParticleDistance = FLT_MAX; - uint16_t numberOfParticles = _particles.size(); + uint16_t numberOfParticles = _particles->size(); for (uint16_t i = 0; i < numberOfParticles; i++) { - float distanceToParticle = glm::distance(position, _particles[i].getPosition()); + float distanceToParticle = glm::distance(position, (*_particles)[i].getPosition()); if (distanceToParticle < closestParticleDistance) { - closestParticle = &_particles[i]; + closestParticle = &(*_particles)[i]; } } return closestParticle; } const Particle* ParticleTreeElement::getParticleWithID(uint32_t id) const { + // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num particles per elemen is small?) const Particle* foundParticle = NULL; - uint16_t numberOfParticles = _particles.size(); + uint16_t numberOfParticles = _particles->size(); for (uint16_t i = 0; i < numberOfParticles; i++) { - if (_particles[i].getID() == id) { - foundParticle = &_particles[i]; + if ((*_particles)[i].getID() == id) { + foundParticle = &(*_particles)[i]; break; } } @@ -229,7 +249,7 @@ bool ParticleTreeElement::collapseChildren() { void ParticleTreeElement::storeParticle(const Particle& particle, Node* senderNode) { - _particles.push_back(particle); + _particles->push_back(particle); markWithChangedTime(); } diff --git a/libraries/particles/src/ParticleTreeElement.h b/libraries/particles/src/ParticleTreeElement.h index 971f5f5481..ab697aed1b 100644 --- a/libraries/particles/src/ParticleTreeElement.h +++ b/libraries/particles/src/ParticleTreeElement.h @@ -10,9 +10,10 @@ #ifndef __hifi__ParticleTreeElement__ #define __hifi__ParticleTreeElement__ -#include +//#include #include +#include #include "Particle.h" #include "ParticleTree.h" @@ -22,7 +23,7 @@ class ParticleTreeElement; class ParticleTreeUpdateArgs { public: - std::vector _movingParticles; + QList _movingParticles; }; class ParticleTreeElement : public OctreeElement { @@ -34,7 +35,6 @@ class ParticleTreeElement : public OctreeElement { public: virtual ~ParticleTreeElement(); - virtual void init(unsigned char * octalCode); // type safe versions of OctreeElement methods ParticleTreeElement* getChildAtIndex(int index) { return (ParticleTreeElement*)OctreeElement::getChildAtIndex(index); } @@ -79,9 +79,9 @@ public: virtual bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const; - const std::vector& getParticles() const { return _particles; } - std::vector& getParticles() { return _particles; } - bool hasParticles() const { return _particles.size() > 0; } + const QList& getParticles() const { return *_particles; } + QList& getParticles() { return *_particles; } + bool hasParticles() const { return _particles->size() > 0; } void update(ParticleTreeUpdateArgs& args); void setTree(ParticleTree* tree) { _myTree = tree; } @@ -93,10 +93,12 @@ public: protected: + virtual void init(unsigned char * octalCode); + void storeParticle(const Particle& particle, Node* senderNode = NULL); ParticleTree* _myTree; - std::vector _particles; + QList* _particles; }; #endif /* defined(__hifi__ParticleTreeElement__) */ From 79e4b6d69166ec939ee5529396258b0a614ef601 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 20 Jan 2014 13:27:19 -0800 Subject: [PATCH 38/50] Removing per-particle calls to usecTimestampNow() which can add up when simulating a lot of particles. --- libraries/particles/src/Particle.cpp | 8 +++----- libraries/particles/src/Particle.h | 2 +- libraries/particles/src/ParticleTreeElement.cpp | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index dcb344f164..a6d0a0ded7 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -475,15 +475,13 @@ void Particle::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssiz } -void Particle::update() { - uint64_t now = usecTimestampNow(); - float elapsed = static_cast(now - _lastUpdated); +void Particle::update(const uint64_t& now) { + float timeElapsed = (float)(now - _lastUpdated) / (float)(USECS_PER_SECOND); _lastUpdated = now; - float timeElapsed = elapsed / static_cast(USECS_PER_SECOND); // calculate our default shouldDie state... then allow script to change it if it wants... float velocityScalar = glm::length(getVelocity()); - const float STILL_MOVING = 0.05f / static_cast(TREE_SCALE); + const float STILL_MOVING = 0.05f / (float)(TREE_SCALE); bool isStillMoving = (velocityScalar > STILL_MOVING); const float REALLY_OLD = 30.0f; // 30 seconds bool isReallyOld = (getLifetime() > REALLY_OLD); diff --git a/libraries/particles/src/Particle.h b/libraries/particles/src/Particle.h index 2c112daeeb..d53c7b9c40 100644 --- a/libraries/particles/src/Particle.h +++ b/libraries/particles/src/Particle.h @@ -117,7 +117,7 @@ public: static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew); - void update(); + void update(const uint64_t& now); void collisionWithParticle(Particle* other); void collisionWithVoxel(VoxelDetail* voxel); diff --git a/libraries/particles/src/ParticleTreeElement.cpp b/libraries/particles/src/ParticleTreeElement.cpp index 525f567ed4..101c6f6c47 100644 --- a/libraries/particles/src/ParticleTreeElement.cpp +++ b/libraries/particles/src/ParticleTreeElement.cpp @@ -71,7 +71,7 @@ void ParticleTreeElement::update(ParticleTreeUpdateArgs& args) { QList::iterator particleItr = _particles->begin(); while(particleItr != _particles->end()) { Particle& particle = (*particleItr); - particle.update(); + particle.update(_lastChanged); // If the particle wants to die, or if it's left our bounding box, then move it // into the arguments moving particles. These will be added back or deleted completely From 1eb2f19320406cf30af08965fe04e93eba6beaa8 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 20 Jan 2014 13:34:08 -0800 Subject: [PATCH 39/50] Removing one more usecTimestampNow() call in Particle::update() --- libraries/particles/src/Particle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index a6d0a0ded7..5ab9f1c470 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -484,7 +484,7 @@ void Particle::update(const uint64_t& now) { const float STILL_MOVING = 0.05f / (float)(TREE_SCALE); bool isStillMoving = (velocityScalar > STILL_MOVING); const float REALLY_OLD = 30.0f; // 30 seconds - bool isReallyOld = (getLifetime() > REALLY_OLD); + bool isReallyOld = ((float)(now - _created) > REALLY_OLD); bool isInHand = getInHand(); bool shouldDie = getShouldDie() || (!isInHand && !isStillMoving && isReallyOld); setShouldDie(shouldDie); From 1ed57e044a16e21401c62e6e63d0cf1353ac6687 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 20 Jan 2014 13:40:15 -0800 Subject: [PATCH 40/50] Fixing measure of "old" particles while simplifying the math (faster!). --- libraries/particles/src/Particle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index 5ab9f1c470..0c677c4058 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -483,8 +483,8 @@ void Particle::update(const uint64_t& now) { float velocityScalar = glm::length(getVelocity()); const float STILL_MOVING = 0.05f / (float)(TREE_SCALE); bool isStillMoving = (velocityScalar > STILL_MOVING); - const float REALLY_OLD = 30.0f; // 30 seconds - bool isReallyOld = ((float)(now - _created) > REALLY_OLD); + const uint64_t REALLY_OLD = 30 * USECS_PER_SECOND; // 30 seconds + bool isReallyOld = ((now - _created) > REALLY_OLD); bool isInHand = getInHand(); bool shouldDie = getShouldDie() || (!isInHand && !isStillMoving && isReallyOld); setShouldDie(shouldDie); From 516a590e4fcb28426696d2df8da8ae8d4620917f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 20 Jan 2014 17:33:09 -0800 Subject: [PATCH 41/50] Modifying how the "particle is stopped" logic reads with minimal modification to how it works. --- libraries/particles/src/Particle.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index 0c677c4058..e395996c45 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -474,19 +474,21 @@ void Particle::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssiz } } +// MIN_VALID_SPEED is obtained by computing speed gained at one gravity during the shortest expected frame period +const float MIN_EXPECTED_FRAME_PERIOD = 0.005f; // 1/200th of a second +const float MIN_VALID_SPEED = 9.8 * MIN_EXPECTED_FRAME_PERIOD / (float)(TREE_SCALE); void Particle::update(const uint64_t& now) { float timeElapsed = (float)(now - _lastUpdated) / (float)(USECS_PER_SECOND); _lastUpdated = now; // calculate our default shouldDie state... then allow script to change it if it wants... - float velocityScalar = glm::length(getVelocity()); - const float STILL_MOVING = 0.05f / (float)(TREE_SCALE); - bool isStillMoving = (velocityScalar > STILL_MOVING); + float speed = glm::length(_velocity); + bool isStopped = (speed < MIN_VALID_SPEED); const uint64_t REALLY_OLD = 30 * USECS_PER_SECOND; // 30 seconds bool isReallyOld = ((now - _created) > REALLY_OLD); bool isInHand = getInHand(); - bool shouldDie = getShouldDie() || (!isInHand && !isStillMoving && isReallyOld); + bool shouldDie = getShouldDie() || (!isInHand && isStopped && isReallyOld); setShouldDie(shouldDie); runUpdateScript(); // allow the javascript to alter our state From 966cd76e2c5d05816a38cc527ce62073c9ab842c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 20 Jan 2014 17:34:24 -0800 Subject: [PATCH 42/50] Adding static friction for easier "catching" of particles on paddle hands. --- .../particles/src/ParticleCollisionSystem.cpp | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index dc8f2f5269..dee0259eb7 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -71,7 +71,7 @@ void ParticleCollisionSystem::updateCollisionWithVoxels(Particle* particle) { glm::vec3 center = particle->getPosition() * (float)(TREE_SCALE); float radius = particle->getRadius() * (float)(TREE_SCALE); const float ELASTICITY = 0.4f; - const float DAMPING = 0.0f; + const float DAMPING = 0.05f; const float COLLISION_FREQUENCY = 0.5f; CollisionInfo collisionInfo; VoxelDetail* voxelDetails = NULL; @@ -135,6 +135,10 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA) } } +// MIN_VALID_SPEED is obtained by computing speed gained at one gravity after the shortest expected frame +const float MIN_EXPECTED_FRAME_PERIOD = 0.0167f; // 1/60th of a second +const float HALTING_SPEED = 9.8 * MIN_EXPECTED_FRAME_PERIOD / (float)(TREE_SCALE); + void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { // particles that are in hand, don't collide with avatars @@ -145,7 +149,7 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { glm::vec3 center = particle->getPosition() * (float)(TREE_SCALE); float radius = particle->getRadius() * (float)(TREE_SCALE); const float ELASTICITY = 0.9f; - const float DAMPING = 0.0f; + const float DAMPING = 0.1f; const float COLLISION_FREQUENCY = 0.5f; glm::vec3 penetration; @@ -164,17 +168,20 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { // NOTE: the physics are wrong (particles cannot roll) but it IS possible to catch a slow moving particle. // TODO: make this less hacky when we have more per-collision details float elasticity = ELASTICITY; - float SLOW_PADDLE_SPEED = 5.0e-5f; - float attenuationFactor = glm::length(collisionInfo._addedVelocity) / SLOW_PADDLE_SPEED; + float attenuationFactor = glm::length(collisionInfo._addedVelocity) / HALTING_SPEED; + float damping = DAMPING; if (attenuationFactor < 1.f) { collisionInfo._addedVelocity *= attenuationFactor; elasticity *= attenuationFactor; + // NOTE: the math below keeps the damping piecewise continuous, + // while ramping it up to 1.0 when attenuationFactor = 0 + damping = DAMPING + (1.f - attenuationFactor) * (1.f - DAMPING); } // HACK END collisionInfo._penetration /= (float)(TREE_SCALE); updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY); - applyHardCollision(particle, elasticity, DAMPING, collisionInfo); + applyHardCollision(particle, elasticity, damping, collisionInfo); } } } @@ -193,24 +200,26 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { // NOTE: the physics are wrong (particles cannot roll) but it IS possible to catch a slow moving particle. // TODO: make this less hacky when we have more per-collision details float elasticity = ELASTICITY; - float SLOW_PADDLE_SPEED = 5.0e-5f; - float attenuationFactor = glm::length(collisionInfo._addedVelocity) / SLOW_PADDLE_SPEED; + float attenuationFactor = glm::length(collisionInfo._addedVelocity) / HALTING_SPEED; + float damping = DAMPING; if (attenuationFactor < 1.f) { collisionInfo._addedVelocity *= attenuationFactor; elasticity *= attenuationFactor; + // NOTE: the math below keeps the damping piecewise continuous, + // while ramping it up to 1.0 when attenuationFactor = 0 + damping = DAMPING + (1.f - attenuationFactor) * (1.f - DAMPING); } // HACK END collisionInfo._penetration /= (float)(TREE_SCALE); updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY); - applyHardCollision(particle, ELASTICITY, DAMPING, collisionInfo); + applyHardCollision(particle, ELASTICITY, damping, collisionInfo); } } } } } - // TODO: convert applyHardCollision() to take a CollisionInfo& instead of penetration + addedVelocity void ParticleCollisionSystem::applyHardCollision(Particle* particle, float elasticity, float damping, const CollisionInfo& collisionInfo) { // @@ -224,19 +233,19 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, float elast glm::vec3 velocity = particle->getVelocity(); const float EPSILON = 0.0f; - float velocityDotPenetration = glm::dot(velocity, collisionInfo._penetration); - if (velocityDotPenetration > EPSILON) { + glm::vec3 relativeVelocity = collisionInfo._addedVelocity - velocity; + float velocityDotPenetration = glm::dot(relativeVelocity, collisionInfo._penetration); + if (velocityDotPenetration < EPSILON) { + // particle is moving into collision surface position -= collisionInfo._penetration; - // cancel out the velocity component in the direction of penetration - glm::vec3 direction = glm::normalize(collisionInfo._penetration); - velocity += collisionInfo._addedVelocity - (glm::dot(velocity, direction) * (1.0f + elasticity)) * direction; - velocity *= glm::clamp(1.f - damping, 0.0f, 1.0f); - // TODO: move this halt logic into Particle::update() method - static float HALTING_SPEED = 0.2f / (float)(TREE_SCALE); - if (glm::length(velocity) < HALTING_SPEED) { - // If moving really slowly after a collision, and not applying forces, stop altogether - velocity *= 0.f; + if (glm::length(relativeVelocity) < HALTING_SPEED) { + // static friction kicks in and particle moves with colliding object + velocity = collisionInfo._addedVelocity; + } else { + glm::vec3 direction = glm::normalize(collisionInfo._penetration); + velocity += glm::dot(relativeVelocity, direction) * (1.0f + elasticity) * direction; // dynamic reflection + velocity += glm::clamp(damping, 0.0f, 1.0f) * (relativeVelocity - glm::dot(relativeVelocity, direction) * direction); // dynamic friction } } const bool wantDebug = false; From 0eed041deb70a71f0ba509b22c18d90db56d450f Mon Sep 17 00:00:00 2001 From: aw Date: Mon, 20 Jan 2014 22:58:01 -0800 Subject: [PATCH 43/50] scripts save on exit and load on entry --- interface/src/Application.cpp | 58 ++++++++++++++++---- interface/src/Application.h | 9 ++- interface/src/ControllerScriptingInterface.h | 1 + interface/src/Menu.cpp | 2 +- libraries/script-engine/src/ScriptEngine.cpp | 13 +++-- libraries/script-engine/src/ScriptEngine.h | 5 +- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 229cedf55c..0bbaa38362 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -232,6 +232,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _window->setCentralWidget(_glWidget); restoreSizeAndPosition(); + loadScripts(); _window->setVisible(true); _glWidget->setFocusPolicy(Qt::StrongFocus); _glWidget->setFocus(); @@ -270,7 +271,7 @@ Application::~Application() { _audio.thread()->wait(); storeSizeAndPosition(); - + saveScripts(); _sharedVoxelSystem.changeTree(new VoxelTree); VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown @@ -4237,13 +4238,38 @@ void Application::packetSentNotification(ssize_t length) { _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length); } -void Application::loadScript() { - // shut down and stop any existing script - QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); - QString suggestedName = desktopLocation.append("/script.js"); +void Application::loadScripts(){ + // loads all saved scripts + QSettings* settings = new QSettings(this); + int size = settings->beginReadArray("Settings"); + for(int i=0; isetArrayIndex(i); + QString string = settings->value("script").toString(); + loadScript(string); + } + settings->endArray(); - QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName, - tr("JavaScript Files (*.js)")); +} + +void Application::saveScripts(){ + // saves all current running scripts + QSettings* settings = new QSettings(this); + settings->beginWriteArray("Settings"); + for(int i=0; i<_activeScripts.size(); ++i){ + settings->setArrayIndex(i); + settings->setValue("script", _activeScripts.at(i)); + } + settings->endArray(); + +} + +void Application::removeScriptName(const QString& fileNameString) +{ + _activeScripts.removeOne(fileNameString); +} + +void Application::loadScript(const QString& fileNameString){ + _activeScripts.append(fileNameString); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); const char* fileName = fileNameAscii.data(); @@ -4270,9 +4296,7 @@ void Application::loadScript() { // start the script on a new thread... bool wantMenuItems = true; // tells the ScriptEngine object to add menu items for itself - - ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(), - &_controllerScriptingInterface); + ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(), &_controllerScriptingInterface); scriptEngine->setupMenuItems(); // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so @@ -4286,8 +4310,9 @@ void Application::loadScript() { connect(workerThread, SIGNAL(started()), scriptEngine, SLOT(run())); // when the thread is terminated, add both scriptEngine and thread to the deleteLater queue - connect(scriptEngine, SIGNAL(finished()), scriptEngine, SLOT(deleteLater())); + connect(scriptEngine, SIGNAL(finished(const QString&)), scriptEngine, SLOT(deleteLater())); connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); + connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(removeScriptName(const QString&))); // when the application is about to quit, stop our script engine so it unwinds properly connect(this, SIGNAL(aboutToQuit()), scriptEngine, SLOT(stop())); @@ -4301,6 +4326,17 @@ void Application::loadScript() { _window->activateWindow(); } +void Application::loadDialog() { + // shut down and stop any existing script + QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + QString suggestedName = desktopLocation.append("/script.js"); + + QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName, + tr("JavaScript Files (*.js)")); + + loadScript(fileNameString); +} + void Application::toggleLogDialog() { if (! _logDialog) { _logDialog = new LogDialog(_glWidget, getLogger()); diff --git a/interface/src/Application.h b/interface/src/Application.h index 7e78cced4c..be4c687043 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -103,7 +104,10 @@ public: ~Application(); void restoreSizeAndPosition(); + void loadScript(const QString& fileNameString); + void loadScripts(); void storeSizeAndPosition(); + void saveScripts(); void initializeGL(); void paintGL(); void resizeGL(int width, int height); @@ -221,7 +225,7 @@ public slots: void doKillLocalVoxels(); void decreaseVoxelSize(); void increaseVoxelSize(); - void loadScript(); + void loadDialog(); void toggleLogDialog(); void initAvatarAndViewFrustum(); @@ -250,6 +254,8 @@ private slots: void shrinkMirrorView(); void resetSensors(); + void removeScriptName(const QString& fileNameString); + private: void resetCamerasOnResizeGL(Camera& camera, int width, int height); void updateProjectionMatrix(); @@ -373,6 +379,7 @@ private: Faceshift _faceshift; SixenseManager _sixenseManager; + QStringList _activeScripts; Camera _myCamera; // My view onto the world Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode diff --git a/interface/src/ControllerScriptingInterface.h b/interface/src/ControllerScriptingInterface.h index d0e032d52f..69daefa3fb 100644 --- a/interface/src/ControllerScriptingInterface.h +++ b/interface/src/ControllerScriptingInterface.h @@ -12,6 +12,7 @@ #include #include +class PalmData; /// handles scripting of input controller commands from JS class ControllerScriptingInterface : public AbstractControllerScriptingInterface { diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7299615ecc..87edfa82a2 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -91,7 +91,7 @@ Menu::Menu() : SLOT(login()))); addDisabledActionAndSeparator(fileMenu, "Scripts"); - addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadScript())); + addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog())); _activeScriptsMenu = fileMenu->addMenu("Running Scripts"); addDisabledActionAndSeparator(fileMenu, "Voxels"); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 6b85cf33ad..e3f694f7cc 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -38,17 +38,20 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng return soundScriptValue; } -ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, - const char* scriptMenuName, AbstractMenuInterface* menu, +ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, const QString& fileNameString, AbstractMenuInterface* menu, AbstractControllerScriptingInterface* controllerScriptingInterface) { _scriptContents = scriptContents; _isFinished = false; _isRunning = false; _isInitialized = false; + _fileNameString = fileNameString; + + QByteArray fileNameAscii = fileNameString.toLocal8Bit(); + const char* scriptMenuName = fileNameAscii.data(); // some clients will use these menu features _wantMenuItems = wantMenuItems; - if (scriptMenuName) { + if (!fileNameString.isEmpty()) { _scriptMenuName = "Stop "; _scriptMenuName.append(scriptMenuName); _scriptMenuName.append(QString(" [%1]").arg(_scriptNumber)); @@ -233,9 +236,11 @@ void ScriptEngine::run() { thread()->quit(); } - emit finished(); + emit finished(_fileNameString); + _isRunning = false; } + void ScriptEngine::stop() { _isFinished = true; } diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 06597f82a8..d1a4d6cf51 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -29,7 +29,7 @@ class ScriptEngine : public QObject { Q_OBJECT public: ScriptEngine(const QString& scriptContents = NO_SCRIPT, bool wantMenuItems = false, - const char* scriptMenuName = NULL, AbstractMenuInterface* menu = NULL, + const QString& scriptMenuName = QString(""), AbstractMenuInterface* menu = NULL, AbstractControllerScriptingInterface* controllerScriptingInterface = NULL); ~ScriptEngine(); @@ -58,7 +58,7 @@ signals: void willSendAudioDataCallback(); void willSendVisualDataCallback(); void scriptEnding(); - void finished(); + void finished(const QString& fileNameString); protected: QString _scriptContents; @@ -74,6 +74,7 @@ private: AudioScriptingInterface _audioScriptingInterface; bool _wantMenuItems; QString _scriptMenuName; + QString _fileNameString; AbstractMenuInterface* _menu; static int _scriptNumber; }; From b972d4260cd38e2b7dff7c804e84229fa7c6e0fd Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 21 Jan 2014 10:31:16 -0600 Subject: [PATCH 44/50] PR Fixes --- interface/src/Application.cpp | 7 ++++--- interface/src/ui/UpdateDialog.cpp | 19 +++++++------------ interface/src/ui/UpdateDialog.h | 9 +++------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5b87fd470d..52c54c8b3d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -203,7 +203,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : setOrganizationName(applicationInfo.value("organizationName").toString()); setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); - qDebug("[VERSION] Build sequence: %s\n", applicationVersion().toStdString().c_str()); + qDebug() << "[VERSION] Build sequence: " << qPrintable(applicationVersion()); _settings = new QSettings(this); @@ -4426,6 +4426,7 @@ void Application::parseVersionXml() { QString releaseDate; QString releaseNotes; QString latestVersion; + QUrl downloadUrl; QXmlStreamReader xml(_latestVersionReply); while (!xml.atEnd() && !xml.hasError()) { @@ -4446,13 +4447,13 @@ void Application::parseVersionXml() { } if (xml.name() == operatingSystem) { xml.readNext(); - _downloadUrl = QUrl(xml.text().toString()); + downloadUrl = QUrl(xml.text().toString()); } } } if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - new UpdateDialog(_glWidget, releaseNotes, latestVersion, _downloadUrl); + new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); } delete _latestVersionReply; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index ae3a52932f..9bf86dd015 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -19,10 +19,11 @@ #include "SharedUtil.h" #include "UpdateDialog.h" -UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latestVersion, QUrl downloadURL) : +UpdateDialog::UpdateDialog(QWidget *parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL) : QWidget(parent, Qt::Widget) { - _latestVersion = new QString(latestVersion); + _latestVersion = latestVersion; + _downloadUrl = downloadURL; QUiLoader updateDialogLoader; QWidget* updateDialog; @@ -46,22 +47,16 @@ UpdateDialog::UpdateDialog(QWidget *parent, QString releaseNotes, QString latest connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip())); - connect(closeButton, SIGNAL(released()), this, SLOT(handleClose())); + connect(closeButton, SIGNAL(released()), this, SLOT(close())); updateDialog->show(); } void UpdateDialog::handleDownload() { - Application* application = Application::getInstance(); - QDesktopServices::openUrl(application->_downloadUrl); - application->quit(); + QDesktopServices::openUrl(_downloadUrl); + Application::getInstance()->quit(); } void UpdateDialog::handleSkip() { - Application* application = Application::getInstance(); - application->skipVersion(*_latestVersion); - this->close(); -} - -void UpdateDialog::handleClose() { + Application::getInstance()->skipVersion(_latestVersion); this->close(); } \ No newline at end of file diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index aa0b800528..1c4f5de9d0 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -9,24 +9,21 @@ #ifndef __hifi__UpdateDialog__ #define __hifi__UpdateDialog__ -#include #include -#include - class UpdateDialog : public QWidget { Q_OBJECT public: - UpdateDialog(QWidget* parent, QString releaseNotes, QString latestVersion, QUrl downloadURL); + UpdateDialog(QWidget* parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL); private: - QString* _latestVersion; + QString _latestVersion; + QUrl _downloadUrl; private slots: void handleDownload(); void handleSkip(); - void handleClose(); }; #endif /* defined(__hifi__UpdateDialog__) */ From cc147bc8bfbde559eadb8677b28dc2b0a5450310 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 21 Jan 2014 10:39:29 -0600 Subject: [PATCH 45/50] PR fixes --- interface/src/Application.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 52c54c8b3d..1a12bdd85b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4402,14 +4402,16 @@ void Application::updateLocalOctreeCache(bool firstTime) { } void Application::checkVersion() { + qDebug() << "################### in check version"; QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); _latestVersionReply = Application::getInstance()->getNetworkAccessManager()->get(latestVersionRequest); - connect(_latestVersionReply, SIGNAL(readyRead()), SLOT(parseVersionXml())); + connect(_latestVersionReply, SIGNAL(finished()), SLOT(parseVersionXml())); } void Application::parseVersionXml() { + qDebug() << "################### in parse version xml"; #ifdef Q_OS_WIN32 QString operatingSystem("win"); @@ -4463,7 +4465,7 @@ bool Application::shouldSkipVersion(QString latestVersion) { QFile skipFile(SKIP_FILENAME); skipFile.open(QIODevice::ReadWrite); QString skipVersion(skipFile.readAll()); - return (skipVersion == latestVersion || applicationVersion() == "dev"); + return (skipVersion == latestVersion /*|| applicationVersion() == "dev"*/); } void Application::skipVersion(QString latestVersion) { From b2ef07f4856a0c8571ecce76303a060d5f9768aa Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 21 Jan 2014 11:17:43 -0600 Subject: [PATCH 46/50] PR Fixes --- interface/src/Application.cpp | 12 +++--------- interface/src/Application.h | 2 -- interface/src/ui/UpdateDialog.cpp | 9 ++++----- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1a12bdd85b..8c48dfd378 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -4402,16 +4403,12 @@ void Application::updateLocalOctreeCache(bool firstTime) { } void Application::checkVersion() { - qDebug() << "################### in check version"; QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - _latestVersionReply = Application::getInstance()->getNetworkAccessManager()->get(latestVersionRequest); - - connect(_latestVersionReply, SIGNAL(finished()), SLOT(parseVersionXml())); + connect(Application::getInstance()->getNetworkAccessManager()->get(latestVersionRequest), SIGNAL(finished()), SLOT(parseVersionXml())); } void Application::parseVersionXml() { - qDebug() << "################### in parse version xml"; #ifdef Q_OS_WIN32 QString operatingSystem("win"); @@ -4430,7 +4427,7 @@ void Application::parseVersionXml() { QString latestVersion; QUrl downloadUrl; - QXmlStreamReader xml(_latestVersionReply); + QXmlStreamReader xml(qobject_cast(QObject::sender())); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); @@ -4453,12 +4450,9 @@ void Application::parseVersionXml() { } } } - if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); } - - delete _latestVersionReply; } bool Application::shouldSkipVersion(QString latestVersion) { diff --git a/interface/src/Application.h b/interface/src/Application.h index d1d5047db2..ae2638c230 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -208,7 +208,6 @@ public: void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; } void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } - QUrl _downloadUrl; void skipVersion(QString latestVersion); public slots: @@ -512,7 +511,6 @@ private: void checkVersion(); void displayUpdateDialog(); bool shouldSkipVersion(QString latestVersion); - QNetworkReply* _latestVersionReply; }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 9bf86dd015..12c5cd83e0 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -20,10 +20,9 @@ #include "UpdateDialog.h" UpdateDialog::UpdateDialog(QWidget *parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL) : - QWidget(parent, Qt::Widget) { - - _latestVersion = latestVersion; - _downloadUrl = downloadURL; + QWidget(parent, Qt::Widget), + _latestVersion(latestVersion), + _downloadUrl(downloadURL) { QUiLoader updateDialogLoader; QWidget* updateDialog; @@ -36,7 +35,7 @@ UpdateDialog::UpdateDialog(QWidget *parent, const QString& releaseNotes, const Q .arg(Application::getInstance()->applicationVersion(), latestVersion); - setAttribute(Qt::WA_DeleteOnClose); + updateDialog->setAttribute(Qt::WA_DeleteOnClose); QPushButton* downloadButton = updateDialog->findChild("downloadButton"); QPushButton* skipButton = updateDialog->findChild("skipButton"); From 18a6d7416534c478e1ed917bb1e37c6180f40d65 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 21 Jan 2014 11:24:23 -0600 Subject: [PATCH 47/50] removing comment --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8c48dfd378..044dfdbb74 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4459,7 +4459,7 @@ bool Application::shouldSkipVersion(QString latestVersion) { QFile skipFile(SKIP_FILENAME); skipFile.open(QIODevice::ReadWrite); QString skipVersion(skipFile.readAll()); - return (skipVersion == latestVersion /*|| applicationVersion() == "dev"*/); + return (skipVersion == latestVersion || applicationVersion() == "dev"); } void Application::skipVersion(QString latestVersion) { From 141c20f4ef64a98599f83f54b1b8d3154d56db6f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 21 Jan 2014 09:26:23 -0800 Subject: [PATCH 48/50] Fix formatting to abide by compressed K&R style. --- libraries/particles/src/ParticleTreeElement.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/particles/src/ParticleTreeElement.cpp b/libraries/particles/src/ParticleTreeElement.cpp index 101c6f6c47..2be0c330d2 100644 --- a/libraries/particles/src/ParticleTreeElement.cpp +++ b/libraries/particles/src/ParticleTreeElement.cpp @@ -80,9 +80,7 @@ void ParticleTreeElement::update(ParticleTreeUpdateArgs& args) { // erase this particle particleItr = _particles->erase(particleItr); - } - else - { + } else { ++particleItr; } } From a4c057b01fe0487c0623073a110b0855971129cc Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Tue, 21 Jan 2014 11:27:03 -0600 Subject: [PATCH 49/50] PR fix --- interface/src/Application.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 044dfdbb74..2b75763875 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4426,8 +4426,9 @@ void Application::parseVersionXml() { QString releaseNotes; QString latestVersion; QUrl downloadUrl; + QObject* sender = QObject::sender(); - QXmlStreamReader xml(qobject_cast(QObject::sender())); + QXmlStreamReader xml(qobject_cast(sender)); while (!xml.atEnd() && !xml.hasError()) { QXmlStreamReader::TokenType token = xml.readNext(); @@ -4453,6 +4454,7 @@ void Application::parseVersionXml() { if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); } + sender->deleteLater(); } bool Application::shouldSkipVersion(QString latestVersion) { From 1423f91717394720364d3c89b0e0e808e3c9e50e Mon Sep 17 00:00:00 2001 From: Lucas Crisman Date: Tue, 21 Jan 2014 15:48:44 -0300 Subject: [PATCH 50/50] Allow domain-server to read configuration from file --- domain-server/src/DomainServer.cpp | 92 +++++++++++++++++++++++++++--- domain-server/src/DomainServer.h | 3 + 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 28edf6b6a1..3e60d1509c 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -22,6 +23,10 @@ const int RESTART_HOLD_TIME_MSECS = 5 * 1000; +const char* VOXEL_SERVER_CONFIG = "voxelServerConfig"; +const char* PARTICLE_SERVER_CONFIG = "particleServerConfig"; +const char* METAVOXEL_SERVER_CONFIG = "metavoxelServerConfig"; + void signalhandler(int sig){ if (sig == SIGINT) { qApp->quit(); @@ -47,17 +52,22 @@ DomainServer::DomainServer(int argc, char* argv[]) : const char* customPortString = getCmdOption(argc, (const char**) argv, CUSTOM_PORT_OPTION); unsigned short domainServerPort = customPortString ? atoi(customPortString) : DEFAULT_DOMAIN_SERVER_PORT; + const char CONFIG_FILE_OPTION[] = "-c"; + const char* configFilePath = getCmdOption(argc, (const char**) argv, CONFIG_FILE_OPTION); + + if (!readConfigFile(configFilePath)) { + QByteArray voxelConfigOption = QString("--%1").arg(VOXEL_SERVER_CONFIG).toLocal8Bit(); + _voxelServerConfig = getCmdOption(argc, (const char**) argv, voxelConfigOption.constData()); + + QByteArray particleConfigOption = QString("--%1").arg(PARTICLE_SERVER_CONFIG).toLocal8Bit(); + _particleServerConfig = getCmdOption(argc, (const char**) argv, particleConfigOption.constData()); + + QByteArray metavoxelConfigOption = QString("--%1").arg(METAVOXEL_SERVER_CONFIG).toLocal8Bit(); + _metavoxelServerConfig = getCmdOption(argc, (const char**) argv, metavoxelConfigOption.constData()); + } + NodeList* nodeList = NodeList::createInstance(NODE_TYPE_DOMAIN, domainServerPort); - const char VOXEL_CONFIG_OPTION[] = "--voxelServerConfig"; - _voxelServerConfig = getCmdOption(argc, (const char**) argv, VOXEL_CONFIG_OPTION); - - const char PARTICLE_CONFIG_OPTION[] = "--particleServerConfig"; - _particleServerConfig = getCmdOption(argc, (const char**) argv, PARTICLE_CONFIG_OPTION); - - const char METAVOXEL_CONFIG_OPTION[] = "--metavoxelServerConfig"; - _metavoxelServerConfig = getCmdOption(argc, (const char**)argv, METAVOXEL_CONFIG_OPTION); - connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), this, SLOT(nodeKilled(SharedNodePointer))); if (!_staticAssignmentFile.exists() || _voxelServerConfig) { @@ -275,6 +285,70 @@ QJsonObject jsonObjectForNode(Node* node) { return nodeJson; } +// Attempts to read configuration from specified path +// returns true on success, false otherwise +bool DomainServer::readConfigFile(const char* path) { + if (!path) { + // config file not specified + return false; + } + + if (!QFile::exists(path)) { + qWarning("Specified configuration file does not exist!\n"); + return false; + } + + QFile configFile(path); + if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning("Can't open specified configuration file!\n"); + return false; + } else { + qDebug("Reading configuration from %s\n", path); + } + QTextStream configStream(&configFile); + QByteArray configStringByteArray = configStream.readAll().toUtf8(); + QJsonObject configDocObject = QJsonDocument::fromJson(configStringByteArray).object(); + configFile.close(); + + QString voxelServerConfig = readServerAssignmentConfig(configDocObject, VOXEL_SERVER_CONFIG); + _voxelServerConfig = new char[strlen(voxelServerConfig.toLocal8Bit().constData()) +1]; + _voxelServerConfig = strcpy((char *) _voxelServerConfig, voxelServerConfig.toLocal8Bit().constData() + '\0'); + + QString particleServerConfig = readServerAssignmentConfig(configDocObject, PARTICLE_SERVER_CONFIG); + _particleServerConfig = new char[strlen(particleServerConfig.toLocal8Bit().constData()) +1]; + _particleServerConfig = strcpy((char *) _particleServerConfig, particleServerConfig.toLocal8Bit().constData() + '\0'); + + QString metavoxelServerConfig = readServerAssignmentConfig(configDocObject, METAVOXEL_SERVER_CONFIG); + _metavoxelServerConfig = new char[strlen(metavoxelServerConfig.toLocal8Bit().constData()) +1]; + _metavoxelServerConfig = strcpy((char *) _metavoxelServerConfig, metavoxelServerConfig.toLocal8Bit().constData() + '\0'); + + return true; +} + +// find assignment configurations on the specified node name and json object +// returns a string in the form of its equivalent cmd line params +QString DomainServer::readServerAssignmentConfig(QJsonObject jsonObject, const char* nodeName) { + QJsonArray nodeArray = jsonObject[nodeName].toArray(); + + QStringList serverConfig; + foreach (const QJsonValue & childValue, nodeArray) { + QString cmdParams; + QJsonObject childObject = childValue.toObject(); + QStringList keys = childObject.keys(); + for (int i = 0; i < keys.size(); i++) { + QString key = keys[i]; + QString value = childObject[key].toString(); + // both cmd line params and json keys are the same + cmdParams += QString("--%1 %2 ").arg(key, value); + } + serverConfig << cmdParams; + } + + // according to split() calls from DomainServer::prepopulateStaticAssignmentFile + // we shold simply join them with semicolons + return serverConfig.join(';'); +} + bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString& path) { const QString JSON_MIME_TYPE = "application/json"; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index c9c4f0e2d7..fed5aaaa43 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -35,6 +35,9 @@ public slots: void nodeKilled(SharedNodePointer node); private: + bool readConfigFile(const char* path); + QString readServerAssignmentConfig(QJsonObject jsonObj, const char* nodeName); + void prepopulateStaticAssignmentFile(); Assignment* matchingStaticAssignmentForCheckIn(const QUuid& checkInUUID, NODE_TYPE nodeType); Assignment* deployableAssignmentForRequest(Assignment& requestAssignment);