Merge pull request #4460 from ZappoMan/runJSFiles

MVP task - Allow a script to be added to a users "running script" from the marketplace
This commit is contained in:
Brad Davis 2015-03-18 12:52:44 -07:00
commit 0c465ce2b5
4 changed files with 50 additions and 19 deletions

View file

@ -891,9 +891,10 @@ bool Application::event(QEvent* event) {
DependencyManager::get<AddressManager>()->handleLookupString(fileEvent->url().toString());
} else if (url.path().toLower().endsWith(SVO_EXTENSION)) {
emit svoImportRequested(url.url());
} else if (url.path().toLower().endsWith(JS_EXTENSION)) {
askToLoadScript(url.toString());
}
}
return false;
}
@ -1454,31 +1455,43 @@ void Application::wheelEvent(QWheelEvent* event) {
void Application::dropEvent(QDropEvent *event) {
QString snapshotPath;
const QMimeData *mimeData = event->mimeData();
bool atLeastOneFileAccepted = false;
foreach (QUrl url, mimeData->urls()) {
auto lower = url.path().toLower();
if (lower.endsWith(SNAPSHOT_EXTENSION)) {
snapshotPath = url.toLocalFile();
break;
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
if (snapshotData) {
if (!snapshotData->getDomain().isEmpty()) {
DependencyManager::get<NodeList>()->getDomainHandler().setHostnameAndPort(snapshotData->getDomain());
}
_myAvatar->setPosition(snapshotData->getLocation());
_myAvatar->setOrientation(snapshotData->getOrientation());
atLeastOneFileAccepted = true;
break; // don't process further files
} else {
QMessageBox msgBox;
msgBox.setText("No location details were found in the file "
+ snapshotPath + ", try dragging in an authentic Hifi snapshot.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
} else if (lower.endsWith(SVO_EXTENSION)) {
emit svoImportRequested(url.url());
event->acceptProposedAction();
return;
atLeastOneFileAccepted = true;
} else if (lower.endsWith(JS_EXTENSION)) {
askToLoadScript(url.url());
atLeastOneFileAccepted = true;
}
}
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
if (snapshotData) {
if (!snapshotData->getDomain().isEmpty()) {
DependencyManager::get<NodeList>()->getDomainHandler().setHostnameAndPort(snapshotData->getDomain());
}
_myAvatar->setPosition(snapshotData->getLocation());
_myAvatar->setOrientation(snapshotData->getOrientation());
} else {
QMessageBox msgBox;
msgBox.setText("No location details were found in this JPG, try dragging in an authentic Hifi snapshot.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
if (atLeastOneFileAccepted) {
event->acceptProposedAction();
}
}
@ -3583,6 +3596,19 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
workerThread->start();
}
void Application::askToLoadScript(const QString& scriptFilenameOrURL) {
QMessageBox::StandardButton reply;
QString message = "Would you like to run this script:\n" + scriptFilenameOrURL;
reply = QMessageBox::question(getWindow(), "Run Script", message, QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
qDebug() << "Chose to run the script: " << scriptFilenameOrURL;
loadScript(scriptFilenameOrURL);
} else {
qDebug() << "Declined to run the script: " << scriptFilenameOrURL;
}
}
ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
bool loadScriptFromEditor, bool activateMainWindow) {

View file

@ -95,6 +95,7 @@ static const float NODE_KILLED_BLUE = 0.0f;
static const QString SNAPSHOT_EXTENSION = ".jpg";
static const QString SVO_EXTENSION = ".svo";
static const QString JS_EXTENSION = ".js";
static const float BILLBOARD_FIELD_OF_VIEW = 30.0f; // degrees
static const float BILLBOARD_DISTANCE = 5.56f; // meters
@ -340,6 +341,7 @@ public slots:
void loadDialog();
void loadScriptURLDialog();
void toggleLogDialog();
void askToLoadScript(const QString& scriptFilenameOrURL);
ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true,
bool loadScriptFromEditor = false, bool activateMainWindow = false);
void scriptFinished(const QString& scriptName);

View file

@ -168,10 +168,10 @@ void GLCanvas::wheelEvent(QWheelEvent* event) {
}
void GLCanvas::dragEnterEvent(QDragEnterEvent* event) {
const QMimeData *mimeData = event->mimeData();
const QMimeData* mimeData = event->mimeData();
foreach (QUrl url, mimeData->urls()) {
auto lower = url.path().toLower();
if (lower.endsWith(SNAPSHOT_EXTENSION) || lower.endsWith(SVO_EXTENSION)) {
if (lower.endsWith(SNAPSHOT_EXTENSION) || lower.endsWith(SVO_EXTENSION) || lower.endsWith(JS_EXTENSION)) {
event->acceptProposedAction();
break;
}

View file

@ -37,6 +37,9 @@ bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkReques
if (request.url().path().toLower().endsWith(SVO_EXTENSION)) {
Application::getInstance()->importSVOFromURL(request.url());
return false;
} else if (request.url().path().toLower().endsWith(JS_EXTENSION)) {
Application::getInstance()->askToLoadScript(request.url().toString());
return false;
}
return true;
} else {