History

FileScriptingInterface

Created new .cpp and .h for the download and unzipping of a model

elisa-lj11 committed 10 years ago

Commit f277a011 parent 4f33e154 files · +87 −0Browse files

Showing the changes to libraries/script-engine/src/FileScriptingInterface.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/FileScriptingInterface.cpp+51−0
@@ -0,0 +1,51 @@
1//
2// FileScriptingInterface.cpp
3// interface/src/scripting
4//
5// Created by Elisa Lupin-Jimenez on 6/28/16.
6// Copyright 2014 High Fidelity, Inc.
7//
8// Distributed under the Apache License, Version 2.0.
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10//
11
12#include <QTemporaryDir>
13#include <QFile>
14#include <QUrl>
15#include "ResourceManager.h"
16
17#include "FileScriptingInterface.h"
18
19
20FileScriptingInterface::FileScriptingInterface(QObject* parent) {
21 // nothing for now
22}
23
24void FileScriptingInterface::downloadZip() {
25 QUrl url(*parent);
26 auto request = ResourceManager::createResourceRequest(nullptr, url);
27 connect(request, &ResourceRequest::finished, this, &FileScriptingInterface::unzipFile);
28 request->send();
29}
30
31// clement's help :D
32bool FileScriptingInterface::unzipFile() {
33 ResourceRequest* request = qobject_cast<ResourceRequest*>(sender());
34
35 // Get the file URL
36 QUrl url = request->getUrl();
37
38 if (request->getResult() == ResourceRequest::Success) {
39 qDebug() << "Success =)";
40
41 QByteArray fileContent = request->getData(); // <-- Downloaded file is in here
42 // Do stuff
43 //
44 // unzipFile(fileContent);
45
46 } else {
47 qDebug() << "Could not download the file =(";
48 }
49
50}
51