mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-08 04:47:44 +02:00
FileScriptingInterface
Created new .cpp and .h for the download and unzipping of a model
This commit is contained in:
parent
4f33e1502f
commit
f277a019bf
4 changed files with 87 additions and 0 deletions
|
@ -58,6 +58,7 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void svoImportRequested(const QString& url);
|
void svoImportRequested(const QString& url);
|
||||||
|
void zipImportRequested(const QString& url); // zip project
|
||||||
void domainConnectionRefused(const QString& reasonMessage, int reasonCode);
|
void domainConnectionRefused(const QString& reasonMessage, int reasonCode);
|
||||||
void snapshotTaken(const QString& path);
|
void snapshotTaken(const QString& path);
|
||||||
|
|
||||||
|
|
51
libraries/script-engine/src/FileScriptingInterface.cpp
Normal file
51
libraries/script-engine/src/FileScriptingInterface.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
//
|
||||||
|
// FileScriptingInterface.cpp
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Elisa Lupin-Jimenez on 6/28/16.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QUrl>
|
||||||
|
#include "ResourceManager.h"
|
||||||
|
|
||||||
|
#include "FileScriptingInterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
FileScriptingInterface::FileScriptingInterface(QObject* parent) {
|
||||||
|
// nothing for now
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileScriptingInterface::downloadZip() {
|
||||||
|
QUrl url(*parent);
|
||||||
|
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
||||||
|
connect(request, &ResourceRequest::finished, this, &FileScriptingInterface::unzipFile);
|
||||||
|
request->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
// clement's help :D
|
||||||
|
bool FileScriptingInterface::unzipFile() {
|
||||||
|
ResourceRequest* request = qobject_cast<ResourceRequest*>(sender());
|
||||||
|
|
||||||
|
// Get the file URL
|
||||||
|
QUrl url = request->getUrl();
|
||||||
|
|
||||||
|
if (request->getResult() == ResourceRequest::Success) {
|
||||||
|
qDebug() << "Success =)";
|
||||||
|
|
||||||
|
QByteArray fileContent = request->getData(); // <-- Downloaded file is in here
|
||||||
|
// Do stuff
|
||||||
|
//
|
||||||
|
// unzipFile(fileContent);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
qDebug() << "Could not download the file =(";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
30
libraries/script-engine/src/FileScriptingInterface.h
Normal file
30
libraries/script-engine/src/FileScriptingInterface.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
//
|
||||||
|
// FileScriptingInterface.h
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Elisa Lupin-Jimenez on 6/28/16.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_FileScriptingInterface_h
|
||||||
|
#define hifi_FileScriptingInterface_h
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
class FileScriptingInterface : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FileScriptingInterface(QObject* parent);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QScriptValue hasFocus();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // hifi_FileScriptingInterface_h
|
|
@ -49,6 +49,7 @@
|
||||||
#include "BatchLoader.h"
|
#include "BatchLoader.h"
|
||||||
#include "DataViewClass.h"
|
#include "DataViewClass.h"
|
||||||
#include "EventTypes.h"
|
#include "EventTypes.h"
|
||||||
|
#include "FileScriptingInterface.h" // unzip project
|
||||||
#include "MenuItemProperties.h"
|
#include "MenuItemProperties.h"
|
||||||
#include "ScriptAudioInjector.h"
|
#include "ScriptAudioInjector.h"
|
||||||
#include "ScriptCache.h"
|
#include "ScriptCache.h"
|
||||||
|
@ -501,6 +502,10 @@ void ScriptEngine::init() {
|
||||||
registerGlobalObject("Mat4", &_mat4Library);
|
registerGlobalObject("Mat4", &_mat4Library);
|
||||||
registerGlobalObject("Uuid", &_uuidLibrary);
|
registerGlobalObject("Uuid", &_uuidLibrary);
|
||||||
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
||||||
|
|
||||||
|
// unzip project
|
||||||
|
registerGlobalObject("File", new FileScriptingInterface(this));
|
||||||
|
|
||||||
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
|
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
|
||||||
qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue);
|
qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue