Showing the changes to libraries/script-engine/src/FileScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -31,9 +31,15 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent · 30 unmodified lines | ||
| 31 | 31 | // nothing for now |
| 32 | 32 | } |
| 33 | 33 | |
| 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(); | |
| 36 | 36 | 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; | |
| 37 | 43 | } |
| 38 | 44 | |
| 39 | 45 | QString FileScriptingInterface::getTempDir() { |
| @@ -43,6 +49,14 @@ QString FileScriptingInterface::getTempDir() { · 3 unmodified lines | ||
| 43 | 49 | // remember I must do something to delete this temp dir later |
| 44 | 50 | } |
| 45 | 51 | |
| 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 | + | |
| 46 | 60 | void FileScriptingInterface::downloadZip(QString path, const QString link) { |
| 47 | 61 | QUrl url = QUrl(link); |
| 48 | 62 | auto request = ResourceManager::createResourceRequest(nullptr, url); |
| @@ -54,15 +68,15 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 5 unmodified lines | ||
| 54 | 68 | |
| 55 | 69 | // clement's help :D |
| 56 | 70 | 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(); | |
| 59 | 73 | |
| 60 | − if (request->getResult() == ResourceRequest::Success) { | |
| 74 | + //if (request->getResult() == ResourceRequest::Success) { | |
| 61 | 75 | qDebug() << "Zip file was downloaded"; |
| 62 | 76 | 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); | |
| 66 | 80 | |
| 67 | 81 | //QString zipFileName = QFile::decodeName(compressedFileContent); |
| 68 | 82 | QString dirName = dir.path(); |
| @@ -104,10 +118,10 @@ void FileScriptingInterface::unzipFile(QString path) { · 35 unmodified lines | ||
| 104 | 118 | }*/ |
| 105 | 119 | |
| 106 | 120 | |
| 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 | + //} | |
| 111 | 125 | |
| 112 | 126 | } |
| 113 | 127 | |