History

Zip download works

elisa-lj11 committed 10 years ago

Commit c36fc291 parent ab02d165 files · +82 −37Browse files

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

Unified · Split

libraries/script-engine/src/FileScriptingInterface.cpp+26−12
@@ -31,9 +31,15 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent · 30 unmodified lines
3131 // nothing for now
3232 }
3333
34−void FileScriptingInterface::runUnzip(QString path) {
35− //downloadZip(path, importURL);
34+void FileScriptingInterface::runUnzip(QString path, QUrl url) {
35+ qDebug() << "Url that was downloaded: " + url.toString();
3636 qDebug() << "Path where download is saved: " + path;
37+ unzipFile(path);
38+}
39+
40+bool FileScriptingInterface::testUrl(QUrl url) {
41+ if (url.toString().contains(".zip")) return true;
42+ return false;
3743 }
3844
3945 QString FileScriptingInterface::getTempDir() {
@@ -43,6 +49,14 @@ QString FileScriptingInterface::getTempDir() { · 3 unmodified lines
4349 // remember I must do something to delete this temp dir later
4450 }
4551
52+QString FileScriptingInterface::convertUrlToPath(QUrl url) {
53+ QString newUrl;
54+ QString oldUrl = url.toString();
55+ newUrl = oldUrl.section("filename=", 1, 1);
56+ qDebug() << "Filename should be: " + newUrl;
57+ return newUrl;
58+}
59+
4660 void FileScriptingInterface::downloadZip(QString path, const QString link) {
4761 QUrl url = QUrl(link);
4862 auto request = ResourceManager::createResourceRequest(nullptr, url);
@@ -54,15 +68,15 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 5 unmodified lines
5468
5569 // clement's help :D
5670 void FileScriptingInterface::unzipFile(QString path) {
57− ResourceRequest* request = qobject_cast<ResourceRequest*>(sender());
58− QUrl url = request->getUrl();
71+ //ResourceRequest* request = qobject_cast<ResourceRequest*>(sender());
72+ //QUrl url = request->getUrl();
5973
60− if (request->getResult() == ResourceRequest::Success) {
74+ //if (request->getResult() == ResourceRequest::Success) {
6175 qDebug() << "Zip file was downloaded";
6276 QDir dir(path);
63− QByteArray compressedFileContent = request->getData(); // <-- Downloaded file is in here
64− QBuffer buffer(&compressedFileContent);
65− buffer.open(QIODevice::ReadOnly);
77+ //QByteArray compressedFileContent = request->getData(); // <-- Downloaded file is in here
78+ //QBuffer buffer(&compressedFileContent);
79+ //buffer.open(QIODevice::ReadOnly);
6680
6781 //QString zipFileName = QFile::decodeName(compressedFileContent);
6882 QString dirName = dir.path();
@@ -104,10 +118,10 @@ void FileScriptingInterface::unzipFile(QString path) { · 35 unmodified lines
104118 }*/
105119
106120
107− buffer.close();
108− } else {
109− qDebug() << "Could not download the zip file";
110− }
121+ //buffer.close();
122+ //} else {
123+ // qDebug() << "Could not download the zip file";
124+ //}
111125
112126 }
113127