FileScriptingInterface

Created new .cpp and .h for the download and unzipping of a model
This commit is contained in:
elisa-lj11 2016-06-28 17:56:28 -07:00
parent 4f33e1502f
commit f277a019bf
4 changed files with 87 additions and 0 deletions

View file

@ -58,6 +58,7 @@ public slots:
signals:
void domainChanged(const QString& domainHostname);
void svoImportRequested(const QString& url);
void zipImportRequested(const QString& url); // zip project
void domainConnectionRefused(const QString& reasonMessage, int reasonCode);
void snapshotTaken(const QString& path);

View 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 =(";
}
}

View 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

View file

@ -49,6 +49,7 @@
#include "BatchLoader.h"
#include "DataViewClass.h"
#include "EventTypes.h"
#include "FileScriptingInterface.h" // unzip project
#include "MenuItemProperties.h"
#include "ScriptAudioInjector.h"
#include "ScriptCache.h"
@ -501,6 +502,10 @@ void ScriptEngine::init() {
registerGlobalObject("Mat4", &_mat4Library);
registerGlobalObject("Uuid", &_uuidLibrary);
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
// unzip project
registerGlobalObject("File", new FileScriptingInterface(this));
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue);