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