History

Made code more QA; extra browser and download widget close upon download

elisa-lj11 committed 10 years ago

Commit b1b2ea41 parent a94a30413 files · +142 −194Browse files

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

Unified · Split

libraries/script-engine/src/FileScriptingInterface.cpp+56−53
@@ -28,94 +28,97 @@ · 27 unmodified lines
2828
2929
3030 FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent) {
31− // nothing for now
31+ // nothing for now
3232 }
3333
3434 void FileScriptingInterface::runUnzip(QString path, QUrl url) {
35− qDebug() << "Url that was downloaded: " + url.toString();
36− qDebug() << "Path where download is saved: " + path;
37− QString file = unzipFile(path);
38− if (file != "") {
39− qDebug() << "file to upload: " + file;
40− QUrl url = QUrl::fromLocalFile(file);
41− qDebug() << "url from local file: " + url.toString();
42− emit unzipSuccess(url.toString());
43− //Application::toggleAssetServerWidget(file);
44− } else {
45− qDebug() << "unzip failed";
46− }
35+ qDebug() << "Url that was downloaded: " + url.toString();
36+ qDebug() << "Path where download is saved: " + path;
37+ QString file = unzipFile(path);
38+ if (file != "") {
39+ qDebug() << "file to upload: " + file;
40+ QUrl url = QUrl::fromLocalFile(file);
41+ qDebug() << "url from local file: " + url.toString();
42+ emit unzipSuccess(url.toString());
43+ } else {
44+ qDebug() << "unzip failed";
45+ }
4746 }
4847
4948 bool FileScriptingInterface::testUrl(QUrl url) {
50− if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true;
51− qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model.";
52− return false;
49+ if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true;
50+ qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model.";
51+ return false;
5352 }
5453
54+// this function is not in use
5555 QString FileScriptingInterface::getTempDir() {
56− QTemporaryDir dir;
57− dir.setAutoRemove(false);
58− return dir.path();
59− // remember I must do something to delete this temp dir later
56+ QTemporaryDir dir;
57+ dir.setAutoRemove(false);
58+ return dir.path();
59+ // do something to delete this temp dir later
6060 }
6161
6262 QString FileScriptingInterface::convertUrlToPath(QUrl url) {
63− QString newUrl;
64− QString oldUrl = url.toString();
65− newUrl = oldUrl.section("filename=", 1, 1);
66− qDebug() << "Filename should be: " + newUrl;
67− return newUrl;
63+ QString newUrl;
64+ QString oldUrl = url.toString();
65+ newUrl = oldUrl.section("filename=", 1, 1);
66+ qDebug() << "Filename should be: " + newUrl;
67+ return newUrl;
6868 }
6969
70+// this function is not in use
7071 void FileScriptingInterface::downloadZip(QString path, const QString link) {
71− QUrl url = QUrl(link);
72− auto request = ResourceManager::createResourceRequest(nullptr, url);
73− connect(request, &ResourceRequest::finished, this, [this, path]{
74− unzipFile(path);
75− });
72+ QUrl url = QUrl(link);
73+ auto request = ResourceManager::createResourceRequest(nullptr, url);
74+ connect(request, &ResourceRequest::finished, this, [this, path]{
75+ unzipFile(path);
76+ });
7677 request->send();
7778 }
7879
79−// clement's help :D
80+
8081 QString FileScriptingInterface::unzipFile(QString path) {
8182
82− qDebug() << "Zip file was downloaded";
83− QDir dir(path);
83+ QDir dir(path);
8484 QString dirName = dir.path();
85− qDebug() << "Zip directory is stored at: " + dirName;
85+ qDebug() << "Zip directory is stored at: " + dirName;
86+ QString target = path.section("/", -1) + "/model_repo";
87+ qDebug() << "Target path: " + target;
8688 QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test");
8789
88− qDebug() << list;
90+ qDebug() << list;
8991
90− if (!list.isEmpty()) {
91− return list.front();
92− } else {
93− qDebug() << "Extraction failed";
94− return "";
95− }
92+ if (!list.isEmpty()) {
93+ return list.front();
94+ } else {
95+ qDebug() << "Extraction failed";
96+ return "";
97+ }
9698
9799 }
98100
101+// this function is not in use
99102 void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
100− /*if (!file.isDir()) {
101− qDebug() << "Regular file logged: " + file.fileName();
102− return;
103− }*/
103+ /*if (!file.isDir()) {
104+ qDebug() << "Regular file logged: " + file.fileName();
105+ return;
106+ }*/
104107 QFileInfoList files;
105108
106− if (file.fileName().contains(".zip")) {
107− qDebug() << "Extracting archive: " + file.fileName();
108− JlCompress::extractDir(file.fileName());
109+ if (file.fileName().contains(".zip")) {
110+ qDebug() << "Extracting archive: " + file.fileName();
111+ JlCompress::extractDir(file.fileName());
109112 }
110113 files = file.dir().entryInfoList();
111114
112− /*if (files.empty()) {
113− files = JlCompress::getFileList(file.fileName());
114− }*/
115+ /*if (files.empty()) {
116+ files = JlCompress::getFileList(file.fileName());
117+ }*/
115118
116− foreach (QFileInfo file, files) {
119+ foreach (QFileInfo file, files) {
117120 qDebug() << "Looking into file: " + file.fileName();
118121 recursiveFileScan(file, dirName);
119− }
122+ }
120123 return;
121124 }