Showing the changes to interface/src/Application.cpp (1 of 30 files). Show all
Unified · Split
| @@ -33,8 +33,10 @@ · 32 unmodified lines | ||
| 33 | 33 | #include <QMenuBar> |
| 34 | 34 | #include <QMouseEvent> |
| 35 | 35 | #include <QNetworkAccessManager> |
| 36 | +#include <QNetworkReply> | |
| 36 | 37 | #include <QNetworkDiskCache> |
| 37 | 38 | #include <QOpenGLFramebufferObject> |
| 39 | +#include <QObject> | |
| 38 | 40 | #include <QWheelEvent> |
| 39 | 41 | #include <QSettings> |
| 40 | 42 | #include <QShortcut> |
| @@ -43,6 +45,8 @@ · 2 unmodified lines | ||
| 43 | 45 | #include <QtDebug> |
| 44 | 46 | #include <QFileDialog> |
| 45 | 47 | #include <QDesktopServices> |
| 48 | +#include <QXmlStreamReader> | |
| 49 | +#include <QXmlStreamAttributes> | |
| 46 | 50 | |
| 47 | 51 | #include <AudioInjector.h> |
| 48 | 52 | #include <NodeTypes.h> |
| @@ -91,6 +95,9 @@ const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; · 42 unmodified lines | ||
| 91 | 95 | const float MIRROR_REARVIEW_DISTANCE = 0.65f; |
| 92 | 96 | const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f; |
| 93 | 97 | |
| 98 | +const QString CHECK_VERSION_URL = "http://highfidelity.io/latestVersion.xml"; | |
| 99 | +const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/hifi.skipversion"; | |
| 100 | + | |
| 94 | 101 | void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { |
| 95 | 102 | QString messageWithNewLine = message + "\n"; |
| 96 | 103 | fprintf(stdout, "%s", messageWithNewLine.toLocal8Bit().constData()); |
| @@ -160,8 +167,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 63 unmodified lines | ||
| 160 | 167 | // call Menu getInstance static method to set up the menu |
| 161 | 168 | _window->setMenuBar(Menu::getInstance()); |
| 162 | 169 | |
| 163 | − qDebug("[VERSION] Build sequence: %i", BUILD_VERSION); | |
| 164 | − | |
| 165 | 170 | unsigned int listenPort = 0; // bind to an ephemeral port by default |
| 166 | 171 | const char** constArgv = const_cast<const char**>(argv); |
| 167 | 172 | const char* portStr = getCmdOption(argc, constArgv, "--listenPort"); |
| @@ -195,9 +200,11 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 27 unmodified lines | ||
| 195 | 200 | applicationInfo.beginGroup("INFO"); |
| 196 | 201 | |
| 197 | 202 | setApplicationName(applicationInfo.value("name").toString()); |
| 198 | − setApplicationVersion(applicationInfo.value("version").toString()); | |
| 203 | + setApplicationVersion(BUILD_VERSION); | |
| 199 | 204 | setOrganizationName(applicationInfo.value("organizationName").toString()); |
| 200 | 205 | setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); |
| 206 | + | |
| 207 | + qDebug() << "[VERSION] Build sequence: " << qPrintable(applicationVersion()); | |
| 201 | 208 | |
| 202 | 209 | _settings = new QSettings(this); |
| 203 | 210 | |
| @@ -232,6 +239,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 28 unmodified lines | ||
| 232 | 239 | _window->setCentralWidget(_glWidget); |
| 233 | 240 | |
| 234 | 241 | restoreSizeAndPosition(); |
| 242 | + loadScripts(); | |
| 235 | 243 | _window->setVisible(true); |
| 236 | 244 | _glWidget->setFocusPolicy(Qt::StrongFocus); |
| 237 | 245 | _glWidget->setFocus(); |
| @@ -255,7 +263,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 17 unmodified lines | ||
| 255 | 263 | |
| 256 | 264 | // Set the sixense filtering |
| 257 | 265 | _sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense)); |
| 258 | − | |
| 266 | + | |
| 267 | + checkVersion(); | |
| 259 | 268 | } |
| 260 | 269 | |
| 261 | 270 | Application::~Application() { |
| @@ -270,7 +279,7 @@ Application::~Application() { · 8 unmodified lines | ||
| 270 | 279 | _audio.thread()->wait(); |
| 271 | 280 | |
| 272 | 281 | storeSizeAndPosition(); |
| 273 | − | |
| 282 | + saveScripts(); | |
| 274 | 283 | _sharedVoxelSystem.changeTree(new VoxelTree); |
| 275 | 284 | |
| 276 | 285 | VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown |
| @@ -1384,6 +1393,7 @@ void Application::idle() { · 1107 unmodified lines | ||
| 1384 | 1393 | } |
| 1385 | 1394 | } |
| 1386 | 1395 | } |
| 1396 | + | |
| 1387 | 1397 | void Application::terminate() { |
| 1388 | 1398 | // Close serial port |
| 1389 | 1399 | // close(serial_fd); |
| @@ -3955,8 +3965,9 @@ void Application::attachNewHeadToNode(Node* newNode) { · 2565 unmodified lines | ||
| 3955 | 3965 | |
| 3956 | 3966 | void Application::updateWindowTitle(){ |
| 3957 | 3967 | QString title = ""; |
| 3958 | − QString buildVersion = " (build " + QString::number(BUILD_VERSION) + ")"; | |
| 3959 | − | |
| 3968 | + | |
| 3969 | + QString buildVersion = " (build " + applicationVersion() + ")"; | |
| 3970 | + | |
| 3960 | 3971 | QString username = _profile.getUsername(); |
| 3961 | 3972 | if(!username.isEmpty()){ |
| 3962 | 3973 | title += username; |
| @@ -4235,13 +4246,38 @@ void Application::packetSentNotification(ssize_t length) { · 272 unmodified lines | ||
| 4235 | 4246 | _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length); |
| 4236 | 4247 | } |
| 4237 | 4248 | |
| 4238 | −void Application::loadScript() { | |
| 4239 | − // shut down and stop any existing script | |
| 4240 | − QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | |
| 4241 | − QString suggestedName = desktopLocation.append("/script.js"); | |
| 4249 | +void Application::loadScripts(){ | |
| 4250 | + // loads all saved scripts | |
| 4251 | + QSettings* settings = new QSettings(this); | |
| 4252 | + int size = settings->beginReadArray("Settings"); | |
| 4253 | + for(int i=0; i<size; ++i){ | |
| 4254 | + settings->setArrayIndex(i); | |
| 4255 | + QString string = settings->value("script").toString(); | |
| 4256 | + loadScript(string); | |
| 4257 | + } | |
| 4258 | + settings->endArray(); | |
| 4242 | 4259 | |
| 4243 | − QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName, | |
| 4244 | − tr("JavaScript Files (*.js)")); | |
| 4260 | +} | |
| 4261 | + | |
| 4262 | +void Application::saveScripts(){ | |
| 4263 | + // saves all current running scripts | |
| 4264 | + QSettings* settings = new QSettings(this); | |
| 4265 | + settings->beginWriteArray("Settings"); | |
| 4266 | + for(int i=0; i<_activeScripts.size(); ++i){ | |
| 4267 | + settings->setArrayIndex(i); | |
| 4268 | + settings->setValue("script", _activeScripts.at(i)); | |
| 4269 | + } | |
| 4270 | + settings->endArray(); | |
| 4271 | + | |
| 4272 | +} | |
| 4273 | + | |
| 4274 | +void Application::removeScriptName(const QString& fileNameString) | |
| 4275 | +{ | |
| 4276 | + _activeScripts.removeOne(fileNameString); | |
| 4277 | +} | |
| 4278 | + | |
| 4279 | +void Application::loadScript(const QString& fileNameString){ | |
| 4280 | + _activeScripts.append(fileNameString); | |
| 4245 | 4281 | QByteArray fileNameAscii = fileNameString.toLocal8Bit(); |
| 4246 | 4282 | const char* fileName = fileNameAscii.data(); |
| 4247 | 4283 | |
| @@ -4268,9 +4304,7 @@ void Application::loadScript() { · 20 unmodified lines | ||
| 4268 | 4304 | // start the script on a new thread... |
| 4269 | 4305 | bool wantMenuItems = true; // tells the ScriptEngine object to add menu items for itself |
| 4270 | 4306 | |
| 4271 | − | |
| 4272 | − ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(), | |
| 4273 | − &_controllerScriptingInterface); | |
| 4307 | + ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(), &_controllerScriptingInterface); | |
| 4274 | 4308 | scriptEngine->setupMenuItems(); |
| 4275 | 4309 | |
| 4276 | 4310 | // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so |
| @@ -4284,8 +4318,9 @@ void Application::loadScript() { · 7 unmodified lines | ||
| 4284 | 4318 | connect(workerThread, SIGNAL(started()), scriptEngine, SLOT(run())); |
| 4285 | 4319 | |
| 4286 | 4320 | // when the thread is terminated, add both scriptEngine and thread to the deleteLater queue |
| 4287 | − connect(scriptEngine, SIGNAL(finished()), scriptEngine, SLOT(deleteLater())); | |
| 4321 | + connect(scriptEngine, SIGNAL(finished(const QString&)), scriptEngine, SLOT(deleteLater())); | |
| 4288 | 4322 | connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); |
| 4323 | + connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(removeScriptName(const QString&))); | |
| 4289 | 4324 | |
| 4290 | 4325 | // when the application is about to quit, stop our script engine so it unwinds properly |
| 4291 | 4326 | connect(this, SIGNAL(aboutToQuit()), scriptEngine, SLOT(stop())); |
| @@ -4299,6 +4334,17 @@ void Application::loadScript() { · 7 unmodified lines | ||
| 4299 | 4334 | _window->activateWindow(); |
| 4300 | 4335 | } |
| 4301 | 4336 | |
| 4337 | +void Application::loadDialog() { | |
| 4338 | + // shut down and stop any existing script | |
| 4339 | + QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | |
| 4340 | + QString suggestedName = desktopLocation.append("/script.js"); | |
| 4341 | + | |
| 4342 | + QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName, | |
| 4343 | + tr("JavaScript Files (*.js)")); | |
| 4344 | + | |
| 4345 | + loadScript(fileNameString); | |
| 4346 | +} | |
| 4347 | + | |
| 4302 | 4348 | void Application::toggleLogDialog() { |
| 4303 | 4349 | if (! _logDialog) { |
| 4304 | 4350 | _logDialog = new LogDialog(_glWidget, getLogger()); |
| @@ -4308,7 +4354,6 @@ void Application::toggleLogDialog() { · 3 unmodified lines | ||
| 4308 | 4354 | } |
| 4309 | 4355 | } |
| 4310 | 4356 | |
| 4311 | − | |
| 4312 | 4357 | void Application::initAvatarAndViewFrustum() { |
| 4313 | 4358 | updateAvatar(0.f); |
| 4314 | 4359 | } |
| @@ -4355,3 +4400,72 @@ void Application::updateLocalOctreeCache(bool firstTime) { · 40 unmodified lines | ||
| 4355 | 4400 | } |
| 4356 | 4401 | } |
| 4357 | 4402 | } |
| 4403 | + | |
| 4404 | +void Application::checkVersion() { | |
| 4405 | + QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); | |
| 4406 | + latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); | |
| 4407 | + connect(Application::getInstance()->getNetworkAccessManager()->get(latestVersionRequest), SIGNAL(finished()), SLOT(parseVersionXml())); | |
| 4408 | +} | |
| 4409 | + | |
| 4410 | +void Application::parseVersionXml() { | |
| 4411 | + | |
| 4412 | + #ifdef Q_OS_WIN32 | |
| 4413 | + QString operatingSystem("win"); | |
| 4414 | + #endif | |
| 4415 | + | |
| 4416 | + #ifdef Q_OS_MAC | |
| 4417 | + QString operatingSystem("mac"); | |
| 4418 | + #endif | |
| 4419 | + | |
| 4420 | + #ifdef Q_OS_LINUX | |
| 4421 | + QString operatingSystem("ubuntu"); | |
| 4422 | + #endif | |
| 4423 | + | |
| 4424 | + QString releaseDate; | |
| 4425 | + QString releaseNotes; | |
| 4426 | + QString latestVersion; | |
| 4427 | + QUrl downloadUrl; | |
| 4428 | + QObject* sender = QObject::sender(); | |
| 4429 | + | |
| 4430 | + QXmlStreamReader xml(qobject_cast<QNetworkReply*>(sender)); | |
| 4431 | + while (!xml.atEnd() && !xml.hasError()) { | |
| 4432 | + QXmlStreamReader::TokenType token = xml.readNext(); | |
| 4433 | + | |
| 4434 | + if (token == QXmlStreamReader::StartElement) { | |
| 4435 | + if (xml.name() == "ReleaseDate") { | |
| 4436 | + xml.readNext(); | |
| 4437 | + releaseDate = xml.text().toString(); | |
| 4438 | + } | |
| 4439 | + if (xml.name() == "ReleaseNotes") { | |
| 4440 | + xml.readNext(); | |
| 4441 | + releaseNotes = xml.text().toString(); | |
| 4442 | + } | |
| 4443 | + if (xml.name() == "Version") { | |
| 4444 | + xml.readNext(); | |
| 4445 | + latestVersion = xml.text().toString(); | |
| 4446 | + } | |
| 4447 | + if (xml.name() == operatingSystem) { | |
| 4448 | + xml.readNext(); | |
| 4449 | + downloadUrl = QUrl(xml.text().toString()); | |
| 4450 | + } | |
| 4451 | + } | |
| 4452 | + } | |
| 4453 | + if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { | |
| 4454 | + new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); | |
| 4455 | + } | |
| 4456 | + sender->deleteLater(); | |
| 4457 | +} | |
| 4458 | + | |
| 4459 | +bool Application::shouldSkipVersion(QString latestVersion) { | |
| 4460 | + QFile skipFile(SKIP_FILENAME); | |
| 4461 | + skipFile.open(QIODevice::ReadWrite); | |
| 4462 | + QString skipVersion(skipFile.readAll()); | |
| 4463 | + return (skipVersion == latestVersion || applicationVersion() == "dev"); | |
| 4464 | +} | |
| 4465 | + | |
| 4466 | +void Application::skipVersion(QString latestVersion) { | |
| 4467 | + QFile skipFile(SKIP_FILENAME); | |
| 4468 | + skipFile.open(QIODevice::WriteOnly | QIODevice::Truncate); | |
| 4469 | + skipFile.seek(0); | |
| 4470 | + skipFile.write(latestVersion.toStdString().c_str()); | |
| 4471 | +} | |