Persistant script location
Showing the changes to interface/src/Application.cpp (1 of 3 files). Show all
Unified · Split
| @@ -341,11 +341,15 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 340 unmodified lines | ||
| 341 | 341 | // clear the scripts, and set out script to our default scripts |
| 342 | 342 | clearScriptsBeforeRunning(); |
| 343 | 343 | loadScript("http://public.highfidelity.io/scripts/defaultScripts.js"); |
| 344 | − | |
| 344 | + | |
| 345 | + QMutexLocker locker(&_settingsMutex); | |
| 345 | 346 | _settings->setValue("firstRun",QVariant(false)); |
| 346 | 347 | } else { |
| 347 | 348 | // do this as late as possible so that all required subsystems are inialized |
| 348 | 349 | loadScripts(); |
| 350 | + | |
| 351 | + QMutexLocker locker(&_settingsMutex); | |
| 352 | + _previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString(); | |
| 349 | 353 | } |
| 350 | 354 | } |
| 351 | 355 | |
| @@ -355,16 +359,12 @@ Application::~Application() { · 3 unmodified lines | ||
| 355 | 359 | |
| 356 | 360 | // make sure we don't call the idle timer any more |
| 357 | 361 | delete idleTimer; |
| 358 | − | |
| 359 | − Menu::getInstance()->saveSettings(); | |
| 360 | − _rearMirrorTools->saveSettings(_settings); | |
| 361 | − | |
| 362 | + | |
| 362 | 363 | _sharedVoxelSystem.changeTree(new VoxelTree); |
| 363 | − if (_voxelImporter) { | |
| 364 | − _voxelImporter->saveSettings(_settings); | |
| 365 | − delete _voxelImporter; | |
| 366 | − } | |
| 367 | − _settings->sync(); | |
| 364 | + | |
| 365 | + saveSettings(); | |
| 366 | + | |
| 367 | + delete _voxelImporter; | |
| 368 | 368 | |
| 369 | 369 | // let the avatar mixer know we're out |
| 370 | 370 | MyAvatar::sendKillAvatar(); |
| @@ -398,35 +398,45 @@ Application::~Application() { · 27 unmodified lines | ||
| 398 | 398 | AccountManager::getInstance().destroy(); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | +void Application::saveSettings() { | |
| 402 | + Menu::getInstance()->saveSettings(); | |
| 403 | + _rearMirrorTools->saveSettings(_settings); | |
| 404 | + | |
| 405 | + if (_voxelImporter) { | |
| 406 | + _voxelImporter->saveSettings(_settings); | |
| 407 | + } | |
| 408 | + _settings->sync(); | |
| 409 | +} | |
| 410 | + | |
| 411 | + | |
| 401 | 412 | void Application::restoreSizeAndPosition() { |
| 402 | − QSettings* settings = new QSettings(this); | |
| 403 | 413 | QRect available = desktop()->availableGeometry(); |
| 404 | 414 | |
| 405 | − settings->beginGroup("Window"); | |
| 415 | + QMutexLocker locker(&_settingsMutex); | |
| 416 | + _settings->beginGroup("Window"); | |
| 406 | 417 | |
| 407 | − int x = (int)loadSetting(settings, "x", 0); | |
| 408 | − int y = (int)loadSetting(settings, "y", 0); | |
| 418 | + int x = (int)loadSetting(_settings, "x", 0); | |
| 419 | + int y = (int)loadSetting(_settings, "y", 0); | |
| 409 | 420 | _window->move(x, y); |
| 410 | 421 | |
| 411 | − int width = (int)loadSetting(settings, "width", available.width()); | |
| 412 | − int height = (int)loadSetting(settings, "height", available.height()); | |
| 422 | + int width = (int)loadSetting(_settings, "width", available.width()); | |
| 423 | + int height = (int)loadSetting(_settings, "height", available.height()); | |
| 413 | 424 | _window->resize(width, height); |
| 414 | 425 | |
| 415 | − settings->endGroup(); | |
| 426 | + _settings->endGroup(); | |
| 416 | 427 | } |
| 417 | 428 | |
| 418 | 429 | void Application::storeSizeAndPosition() { |
| 419 | − QSettings* settings = new QSettings(this); | |
| 420 | − | |
| 421 | − settings->beginGroup("Window"); | |
| 430 | + QMutexLocker locker(&_settingsMutex); | |
| 431 | + _settings->beginGroup("Window"); | |
| 422 | 432 | |
| 423 | − settings->setValue("width", _window->rect().width()); | |
| 424 | − settings->setValue("height", _window->rect().height()); | |
| 433 | + _settings->setValue("width", _window->rect().width()); | |
| 434 | + _settings->setValue("height", _window->rect().height()); | |
| 425 | 435 | |
| 426 | − settings->setValue("x", _window->pos().x()); | |
| 427 | − settings->setValue("y", _window->pos().y()); | |
| 436 | + _settings->setValue("x", _window->pos().x()); | |
| 437 | + _settings->setValue("y", _window->pos().y()); | |
| 428 | 438 | |
| 429 | − settings->endGroup(); | |
| 439 | + _settings->endGroup(); | |
| 430 | 440 | } |
| 431 | 441 | |
| 432 | 442 | void Application::initializeGL() { |
| @@ -3167,35 +3177,36 @@ void Application::packetSent(quint64 length) { · 2734 unmodified lines | ||
| 3167 | 3177 | |
| 3168 | 3178 | void Application::loadScripts() { |
| 3169 | 3179 | // loads all saved scripts |
| 3170 | − QSettings* settings = new QSettings(this); | |
| 3171 | − int size = settings->beginReadArray("Settings"); | |
| 3172 | − | |
| 3180 | + int size = lockSettings()->beginReadArray("Settings"); | |
| 3181 | + unlockSettings(); | |
| 3173 | 3182 | for (int i = 0; i < size; ++i){ |
| 3174 | − settings->setArrayIndex(i); | |
| 3175 | − QString string = settings->value("script").toString(); | |
| 3176 | − loadScript(string); | |
| 3183 | + lockSettings()->setArrayIndex(i); | |
| 3184 | + QString string = _settings->value("script").toString(); | |
| 3185 | + unlockSettings(); | |
| 3186 | + if (!string.isEmpty()) { | |
| 3187 | + loadScript(string); | |
| 3188 | + } | |
| 3177 | 3189 | } |
| 3178 | − | |
| 3179 | − settings->endArray(); | |
| 3190 | + | |
| 3191 | + QMutexLocker locker(&_settingsMutex); | |
| 3192 | + _settings->endArray(); | |
| 3180 | 3193 | } |
| 3181 | 3194 | |
| 3182 | 3195 | void Application::clearScriptsBeforeRunning() { |
| 3183 | 3196 | // clears all scripts from the settings |
| 3184 | − QSettings* settings = new QSettings(this); | |
| 3185 | − settings->beginWriteArray("Settings"); | |
| 3186 | − settings->endArray(); | |
| 3197 | + QMutexLocker locker(&_settingsMutex); | |
| 3198 | + _settings->remove("Settings"); | |
| 3187 | 3199 | } |
| 3188 | 3200 | |
| 3189 | 3201 | void Application::saveScripts() { |
| 3190 | 3202 | // saves all current running scripts |
| 3191 | − QSettings* settings = new QSettings(this); | |
| 3192 | − settings->beginWriteArray("Settings"); | |
| 3203 | + QMutexLocker locker(&_settingsMutex); | |
| 3204 | + _settings->beginWriteArray("Settings"); | |
| 3193 | 3205 | for (int i = 0; i < getRunningScripts().size(); ++i){ |
| 3194 | − settings->setArrayIndex(i); | |
| 3195 | − settings->setValue("script", getRunningScripts().at(i)); | |
| 3206 | + _settings->setArrayIndex(i); | |
| 3207 | + _settings->setValue("script", getRunningScripts().at(i)); | |
| 3196 | 3208 | } |
| 3197 | − | |
| 3198 | − settings->endArray(); | |
| 3209 | + _settings->endArray(); | |
| 3199 | 3210 | } |
| 3200 | 3211 | |
| 3201 | 3212 | void Application::stopAllScripts() { |
| @@ -3336,7 +3347,10 @@ void Application::loadDialog() { · 134 unmodified lines | ||
| 3336 | 3347 | |
| 3337 | 3348 | if (_previousScriptLocation.isEmpty()) { |
| 3338 | 3349 | QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| 3350 | +// Temporary fix to Qt bug: http://stackoverflow.com/questions/16194475 | |
| 3351 | +#ifdef __APPLE__ | |
| 3339 | 3352 | suggestedName = desktopLocation.append("/script.js"); |
| 3353 | +#endif | |
| 3340 | 3354 | } else { |
| 3341 | 3355 | suggestedName = _previousScriptLocation; |
| 3342 | 3356 | } |
| @@ -3345,9 +3359,11 @@ void Application::loadDialog() { · 2 unmodified lines | ||
| 3345 | 3359 | tr("JavaScript Files (*.js)")); |
| 3346 | 3360 | if (!fileNameString.isEmpty()) { |
| 3347 | 3361 | _previousScriptLocation = fileNameString; |
| 3362 | + QMutexLocker locker(&_settingsMutex); | |
| 3363 | + _settings->setValue("LastScriptLocation", _previousScriptLocation); | |
| 3364 | + | |
| 3365 | + loadScript(fileNameString); | |
| 3348 | 3366 | } |
| 3349 | − | |
| 3350 | − loadScript(fileNameString); | |
| 3351 | 3367 | } |
| 3352 | 3368 | |
| 3353 | 3369 | void Application::loadScriptURLDialog() { |