mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:29:47 +02:00
Merge pull request #2642 from Atlante45/persistant_script_location
Persistant script location
This commit is contained in:
commit
e08dfeae2a
3 changed files with 83 additions and 48 deletions
|
@ -341,11 +341,15 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
// clear the scripts, and set out script to our default scripts
|
// clear the scripts, and set out script to our default scripts
|
||||||
clearScriptsBeforeRunning();
|
clearScriptsBeforeRunning();
|
||||||
loadScript("http://public.highfidelity.io/scripts/defaultScripts.js");
|
loadScript("http://public.highfidelity.io/scripts/defaultScripts.js");
|
||||||
|
|
||||||
|
QMutexLocker locker(&_settingsMutex);
|
||||||
_settings->setValue("firstRun",QVariant(false));
|
_settings->setValue("firstRun",QVariant(false));
|
||||||
} else {
|
} else {
|
||||||
// do this as late as possible so that all required subsystems are inialized
|
// do this as late as possible so that all required subsystems are inialized
|
||||||
loadScripts();
|
loadScripts();
|
||||||
|
|
||||||
|
QMutexLocker locker(&_settingsMutex);
|
||||||
|
_previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,16 +359,12 @@ Application::~Application() {
|
||||||
|
|
||||||
// make sure we don't call the idle timer any more
|
// make sure we don't call the idle timer any more
|
||||||
delete idleTimer;
|
delete idleTimer;
|
||||||
|
|
||||||
Menu::getInstance()->saveSettings();
|
|
||||||
_rearMirrorTools->saveSettings(_settings);
|
|
||||||
|
|
||||||
_sharedVoxelSystem.changeTree(new VoxelTree);
|
_sharedVoxelSystem.changeTree(new VoxelTree);
|
||||||
if (_voxelImporter) {
|
|
||||||
_voxelImporter->saveSettings(_settings);
|
saveSettings();
|
||||||
delete _voxelImporter;
|
|
||||||
}
|
delete _voxelImporter;
|
||||||
_settings->sync();
|
|
||||||
|
|
||||||
// let the avatar mixer know we're out
|
// let the avatar mixer know we're out
|
||||||
MyAvatar::sendKillAvatar();
|
MyAvatar::sendKillAvatar();
|
||||||
|
@ -398,35 +398,45 @@ Application::~Application() {
|
||||||
AccountManager::getInstance().destroy();
|
AccountManager::getInstance().destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::saveSettings() {
|
||||||
|
Menu::getInstance()->saveSettings();
|
||||||
|
_rearMirrorTools->saveSettings(_settings);
|
||||||
|
|
||||||
|
if (_voxelImporter) {
|
||||||
|
_voxelImporter->saveSettings(_settings);
|
||||||
|
}
|
||||||
|
_settings->sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Application::restoreSizeAndPosition() {
|
void Application::restoreSizeAndPosition() {
|
||||||
QSettings* settings = new QSettings(this);
|
|
||||||
QRect available = desktop()->availableGeometry();
|
QRect available = desktop()->availableGeometry();
|
||||||
|
|
||||||
settings->beginGroup("Window");
|
QMutexLocker locker(&_settingsMutex);
|
||||||
|
_settings->beginGroup("Window");
|
||||||
|
|
||||||
int x = (int)loadSetting(settings, "x", 0);
|
int x = (int)loadSetting(_settings, "x", 0);
|
||||||
int y = (int)loadSetting(settings, "y", 0);
|
int y = (int)loadSetting(_settings, "y", 0);
|
||||||
_window->move(x, y);
|
_window->move(x, y);
|
||||||
|
|
||||||
int width = (int)loadSetting(settings, "width", available.width());
|
int width = (int)loadSetting(_settings, "width", available.width());
|
||||||
int height = (int)loadSetting(settings, "height", available.height());
|
int height = (int)loadSetting(_settings, "height", available.height());
|
||||||
_window->resize(width, height);
|
_window->resize(width, height);
|
||||||
|
|
||||||
settings->endGroup();
|
_settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::storeSizeAndPosition() {
|
void Application::storeSizeAndPosition() {
|
||||||
QSettings* settings = new QSettings(this);
|
QMutexLocker locker(&_settingsMutex);
|
||||||
|
_settings->beginGroup("Window");
|
||||||
|
|
||||||
settings->beginGroup("Window");
|
_settings->setValue("width", _window->rect().width());
|
||||||
|
_settings->setValue("height", _window->rect().height());
|
||||||
|
|
||||||
settings->setValue("width", _window->rect().width());
|
_settings->setValue("x", _window->pos().x());
|
||||||
settings->setValue("height", _window->rect().height());
|
_settings->setValue("y", _window->pos().y());
|
||||||
|
|
||||||
settings->setValue("x", _window->pos().x());
|
_settings->endGroup();
|
||||||
settings->setValue("y", _window->pos().y());
|
|
||||||
|
|
||||||
settings->endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::initializeGL() {
|
void Application::initializeGL() {
|
||||||
|
@ -3167,35 +3177,36 @@ void Application::packetSent(quint64 length) {
|
||||||
|
|
||||||
void Application::loadScripts() {
|
void Application::loadScripts() {
|
||||||
// loads all saved scripts
|
// loads all saved scripts
|
||||||
QSettings* settings = new QSettings(this);
|
int size = lockSettings()->beginReadArray("Settings");
|
||||||
int size = settings->beginReadArray("Settings");
|
unlockSettings();
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i){
|
for (int i = 0; i < size; ++i){
|
||||||
settings->setArrayIndex(i);
|
lockSettings()->setArrayIndex(i);
|
||||||
QString string = settings->value("script").toString();
|
QString string = _settings->value("script").toString();
|
||||||
loadScript(string);
|
unlockSettings();
|
||||||
|
if (!string.isEmpty()) {
|
||||||
|
loadScript(string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings->endArray();
|
QMutexLocker locker(&_settingsMutex);
|
||||||
|
_settings->endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::clearScriptsBeforeRunning() {
|
void Application::clearScriptsBeforeRunning() {
|
||||||
// clears all scripts from the settings
|
// clears all scripts from the settings
|
||||||
QSettings* settings = new QSettings(this);
|
QMutexLocker locker(&_settingsMutex);
|
||||||
settings->beginWriteArray("Settings");
|
_settings->remove("Settings");
|
||||||
settings->endArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::saveScripts() {
|
void Application::saveScripts() {
|
||||||
// saves all current running scripts
|
// saves all current running scripts
|
||||||
QSettings* settings = new QSettings(this);
|
QMutexLocker locker(&_settingsMutex);
|
||||||
settings->beginWriteArray("Settings");
|
_settings->beginWriteArray("Settings");
|
||||||
for (int i = 0; i < getRunningScripts().size(); ++i){
|
for (int i = 0; i < getRunningScripts().size(); ++i){
|
||||||
settings->setArrayIndex(i);
|
_settings->setArrayIndex(i);
|
||||||
settings->setValue("script", getRunningScripts().at(i));
|
_settings->setValue("script", getRunningScripts().at(i));
|
||||||
}
|
}
|
||||||
|
_settings->endArray();
|
||||||
settings->endArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::stopAllScripts() {
|
void Application::stopAllScripts() {
|
||||||
|
@ -3336,7 +3347,10 @@ void Application::loadDialog() {
|
||||||
|
|
||||||
if (_previousScriptLocation.isEmpty()) {
|
if (_previousScriptLocation.isEmpty()) {
|
||||||
QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
|
// Temporary fix to Qt bug: http://stackoverflow.com/questions/16194475
|
||||||
|
#ifdef __APPLE__
|
||||||
suggestedName = desktopLocation.append("/script.js");
|
suggestedName = desktopLocation.append("/script.js");
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
suggestedName = _previousScriptLocation;
|
suggestedName = _previousScriptLocation;
|
||||||
}
|
}
|
||||||
|
@ -3345,9 +3359,11 @@ void Application::loadDialog() {
|
||||||
tr("JavaScript Files (*.js)"));
|
tr("JavaScript Files (*.js)"));
|
||||||
if (!fileNameString.isEmpty()) {
|
if (!fileNameString.isEmpty()) {
|
||||||
_previousScriptLocation = fileNameString;
|
_previousScriptLocation = fileNameString;
|
||||||
|
QMutexLocker locker(&_settingsMutex);
|
||||||
|
_settings->setValue("LastScriptLocation", _previousScriptLocation);
|
||||||
|
|
||||||
|
loadScript(fileNameString);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadScript(fileNameString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::loadScriptURLDialog() {
|
void Application::loadScriptURLDialog() {
|
||||||
|
|
|
@ -188,6 +188,8 @@ public:
|
||||||
/// if you need to access the application settings, use lockSettings()/unlockSettings()
|
/// if you need to access the application settings, use lockSettings()/unlockSettings()
|
||||||
QSettings* lockSettings() { _settingsMutex.lock(); return _settings; }
|
QSettings* lockSettings() { _settingsMutex.lock(); return _settings; }
|
||||||
void unlockSettings() { _settingsMutex.unlock(); }
|
void unlockSettings() { _settingsMutex.unlock(); }
|
||||||
|
|
||||||
|
void saveSettings();
|
||||||
|
|
||||||
QMainWindow* getWindow() { return _window; }
|
QMainWindow* getWindow() { return _window; }
|
||||||
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
|
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
|
|
||||||
#include <AccountManager.h>
|
#include <AccountManager.h>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
#include "renderer/FBXReader.h"
|
#include "renderer/FBXReader.h"
|
||||||
|
|
||||||
#include "ModelUploader.h"
|
#include "ModelUploader.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +36,8 @@ static const QString LOD_FIELD = "lod";
|
||||||
static const QString S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com";
|
static const QString S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com";
|
||||||
static const QString MODEL_URL = "/api/v1/models";
|
static const QString MODEL_URL = "/api/v1/models";
|
||||||
|
|
||||||
|
static const QString SETTING_NAME = "LastModelUploadLocation";
|
||||||
|
|
||||||
static const int MAX_SIZE = 10 * 1024 * 1024; // 10 MB
|
static const int MAX_SIZE = 10 * 1024 * 1024; // 10 MB
|
||||||
static const int TIMEOUT = 1000;
|
static const int TIMEOUT = 1000;
|
||||||
static const int MAX_CHECK = 30;
|
static const int MAX_CHECK = 30;
|
||||||
|
@ -59,14 +63,27 @@ ModelUploader::~ModelUploader() {
|
||||||
|
|
||||||
bool ModelUploader::zip() {
|
bool ModelUploader::zip() {
|
||||||
// File Dialog
|
// File Dialog
|
||||||
QString filename = QFileDialog::getOpenFileName(NULL,
|
QSettings* settings = Application::getInstance()->lockSettings();
|
||||||
"Select your .fst file ...",
|
QString lastLocation = settings->value(SETTING_NAME).toString();
|
||||||
QStandardPaths::writableLocation(QStandardPaths::HomeLocation),
|
|
||||||
"*.fst");
|
if (lastLocation.isEmpty()) {
|
||||||
|
lastLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||||
|
// Temporary fix to Qt bug: http://stackoverflow.com/questions/16194475
|
||||||
|
#ifdef __APPLE__
|
||||||
|
lastLocation.append("/model.fst");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString filename = QFileDialog::getOpenFileName(NULL, "Select your .fst file ...", lastLocation, "*.fst");
|
||||||
if (filename == "") {
|
if (filename == "") {
|
||||||
// If the user canceled we return.
|
// If the user canceled we return.
|
||||||
|
Application::getInstance()->unlockSettings();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
settings->setValue(SETTING_NAME, filename);
|
||||||
|
Application::getInstance()->unlockSettings();
|
||||||
|
|
||||||
bool _nameIsPresent = false;
|
bool _nameIsPresent = false;
|
||||||
QString texDir;
|
QString texDir;
|
||||||
QString fbxFile;
|
QString fbxFile;
|
||||||
|
|
Loading…
Reference in a new issue