diff --git a/apps/Launcher/infowidget.cpp b/apps/Launcher/infowidget.cpp index 7639f6bc1d..d15fc1d506 100644 --- a/apps/Launcher/infowidget.cpp +++ b/apps/Launcher/infowidget.cpp @@ -36,6 +36,8 @@ InfoWidget::InfoWidget(QString name, int totalBytes) , _messages(nullptr) , _totalBytes(totalBytes) { + setFixedHeight(100); + QGridLayout* layout = new QGridLayout; _name = new QLabel(name); @@ -68,7 +70,7 @@ void InfoWidget::update(int currentBytes) { void InfoWidget::update(float progress) { _bytes->setText(""); - _progress->setValue(progress); + _progress->setValue(static_cast(progress * 100)); } void InfoWidget::error(QString message) { diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index 4acff9cf59..668194ee51 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -95,7 +96,7 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) { QWidget* downloadBox = new QGroupBox; - downloadBox->setFixedSize(500, 500); + downloadBox->setMinimumSize(450, 1000); _downloadLayout = new QVBoxLayout; downloadBox->setLayout(_downloadLayout); @@ -157,80 +158,76 @@ void SyncWidget::clear() { } -void SyncWidget::handleDirectFiles(QString module, DirectFiles files) { +void SyncWidget::handleDirectFiles() { qDebug() << "Direct Files"; - for (const DirectFile& f : files) { + for (const DirectFile& f : _directFiles) { InfoWidget* w = new InfoWidget(f.destination); _downloadLayout->addWidget(w); //_stringInfoWidgetMap[f.destination] = w; qDebug() << f.url << " -> " << f.destination; - - auto finishedCallback = [w](const ghoul::filesystem::File& f) { qDebug() << QString::fromStdString(f.filename()) << "finished"; - //delete w; + delete w; + qApp->processEvents(); }; auto progressCallback = [w](const ghoul::filesystem::File& f, float progress) { qDebug() << QString::fromStdString(f.filename()) << ": " << progress; w->update(progress); + qApp->processEvents(); }; - std::string url = f.url.toStdString(); - std::string path = fullPath(module, f.destination).toStdString(); - - _threads.push_back( - std::thread([url, path, finishedCallback, progressCallback](){ - DlManager.downloadFile( - url, - path, - finishedCallback, - progressCallback - ); - }) + DlManager.downloadFile( + f.url.toStdString(), + fullPath(f.module, f.destination).toStdString(), + finishedCallback, + progressCallback ); } } -void SyncWidget::handleFileRequest(QString module, FileRequests files) { +void SyncWidget::handleFileRequest() { qDebug() << "File Requests"; - for (const FileRequest& f : files) { + for (const FileRequest& f : _fileRequests) { InfoWidget* w = new InfoWidget(f.identifier, -1); _downloadLayout->addWidget(w); - //_stringInfoWidgetMap[f.identifier] = w; + + auto finishedCallback = + [w](const ghoul::filesystem::File& f) { + qDebug() << QString::fromStdString(f.filename()) << "finished"; + delete w; + qApp->processEvents(); + }; auto progressCallback = [w](const ghoul::filesystem::File& f, float progress) { qDebug() << QString::fromStdString(f.filename()) << ": " << progress; w->update(progress); + qApp->processEvents(); }; qDebug() << f.identifier << " (" << f.version << ")" << " -> " << f.destination; std::string identifier = f.identifier.toStdString(); - std::string path = fullPath(module, f.destination).toStdString(); + std::string path = fullPath(f.module, f.destination).toStdString(); int version = f.version; - _threads.push_back( - std::thread([identifier, path, version, progressCallback](){ - DlManager.downloadRequestFiles( - identifier, - path, - version, - [](const ghoul::filesystem::File& f) { qDebug() << "finished"; }, - progressCallback - ); - }) + DlManager.downloadRequestFiles( + identifier, + path, + version, + finishedCallback, + progressCallback ); } } -void SyncWidget::handleTorrentFiles(QString module, TorrentFiles files) { +void SyncWidget::handleTorrentFiles() { qDebug() << "Torrent Files"; - for (const TorrentFile& f : files) { - QString file = QString::fromStdString(absPath(fullPath(module, f.file).toStdString())); + for (const TorrentFile& f : _torrentFiles) { + QString file = QString::fromStdString(absPath(fullPath(f.module, f.file).toStdString())); qDebug() << file; if (!QFileInfo(file).exists()) { @@ -240,7 +237,7 @@ void SyncWidget::handleTorrentFiles(QString module, TorrentFiles files) { libtorrent::error_code ec; libtorrent::add_torrent_params p; - p.save_path = absPath(fullPath(module, ".").toStdString()); + p.save_path = absPath(fullPath(f.module, ".").toStdString()); qDebug() << QString::fromStdString(p.save_path); p.ti = new libtorrent::torrent_info(file.toStdString(), ec); p.name = f.file.toStdString(); @@ -303,7 +300,6 @@ void SyncWidget::syncButtonPressed() { bool found = dataDictionary.getValue(FileDownloadKey, directDownloadFiles); if (found) { - DirectFiles files; for (int i = 1; i <= directDownloadFiles.size(); ++i) { if (!directDownloadFiles.hasKeyAndValue(std::to_string(i))) { qDebug() << QString::fromStdString(FileDownloadKey) << " is not a dictionary"; @@ -319,17 +315,16 @@ void SyncWidget::syncButtonPressed() { } std::string dest = d.value(DestinationKey); - files.append({ + _directFiles.append({ + module, QString::fromStdString(url), QString::fromStdString(dest) }); } - handleDirectFiles(module, files); } found = dataDictionary.getValue(FileRequestKey, fileRequests); if (found) { - FileRequests files; for (int i = 1; i <= fileRequests.size(); ++i) { ghoul::Dictionary d = fileRequests.value(std::to_string(i)); std::string url = d.value(IdentifierKey); @@ -337,28 +332,47 @@ void SyncWidget::syncButtonPressed() { int version = static_cast(d.value(VersionKey)); - files.append({ + _fileRequests.append({ + module, QString::fromStdString(url), QString::fromStdString(dest), version }); } - handleFileRequest(module, files); } found = dataDictionary.getValue(TorrentFilesKey, torrentFiles); if (found) { - TorrentFiles torrents; for (int i = 1; i <= torrentFiles.size(); ++i) { std::string f = torrentFiles.value(std::to_string(i)); - torrents.append({QString::fromStdString(f)}); + _torrentFiles.append({ + module, + QString::fromStdString(f) + }); } - handleTorrentFiles(module, torrents); } } } } + + //// Make the lists unique + //{ + // QSet s = _directFiles.toSet(); + // _directFiles = QList::fromSet(s); + //} + //{ + // QSet s = _fileRequests.toSet(); + // _fileRequests = QList::fromSet(s); + //} + //{ + // QSet s = _torrentFiles.toSet(); + // _torrentFiles = QList::fromSet(s); + //} + + handleDirectFiles(); + handleFileRequest(); + handleTorrentFiles(); } QStringList SyncWidget::selectedScenes() const { diff --git a/apps/Launcher/syncwidget.h b/apps/Launcher/syncwidget.h index 720a9d913a..c850586188 100644 --- a/apps/Launcher/syncwidget.h +++ b/apps/Launcher/syncwidget.h @@ -31,7 +31,7 @@ #include -#include +//#include class QBoxLayout; class QGridLayout; @@ -58,31 +58,31 @@ private slots: private: struct DirectFile { + QString module; QString url; QString destination; }; - typedef QList DirectFiles; struct FileRequest { + QString module; QString identifier; QString destination; int version; }; - typedef QList FileRequests; struct TorrentFile { + QString module; QString file; }; - typedef QList TorrentFiles; void clear(); QStringList selectedScenes() const; QString fullPath(QString module, QString destination) const; - void handleDirectFiles(QString module, DirectFiles files); - void handleFileRequest(QString module, FileRequests files); - void handleTorrentFiles(QString module, TorrentFiles files); + void handleDirectFiles(); + void handleFileRequest(); + void handleTorrentFiles(); QMap _sceneFiles; QString _modulesDirectory; @@ -91,9 +91,10 @@ private: libtorrent::session* _session; QMap _torrentInfoWidgetMap; - //QMap _stringInfoWidgetMap; - std::vector _threads; + QList _directFiles; + QList _fileRequests; + QList _torrentFiles; }; #endif // __SYNCWIDGET_H__ diff --git a/include/openspace/engine/downloadmanager.h b/include/openspace/engine/downloadmanager.h index 13f1f1f7e4..b000620b6e 100644 --- a/include/openspace/engine/downloadmanager.h +++ b/include/openspace/engine/downloadmanager.h @@ -42,6 +42,10 @@ public: void (const ghoul::filesystem::File&) > DownloadFinishedCallback; + //struct FileFuture { + + //}; + DownloadManager(std::string requestURL, int applicationVersion); bool downloadFile( diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index 9eae4bfe2d..b05bd42bcc 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -28,7 +28,7 @@ #include #include -#include +//#include #ifdef OPENSPACE_CURL_ENABLED #include @@ -161,12 +161,12 @@ bool DownloadManager::downloadRequestFiles( std::string requestFile = absPath("${TEMPORARY}/" + identifier); LDEBUG("Request File: " << requestFile); - std::vector threads; + //std::vector threads; bool success = downloadFile( fullRequest, requestFile, - [destination, &progressCallback, &threads](const ghoul::filesystem::File& f) { + [destination, &progressCallback](const ghoul::filesystem::File& f) { LDEBUG("Finished: " << f.path()); std::ifstream temporary(f.path()); std::string line; @@ -177,21 +177,22 @@ bool DownloadManager::downloadRequestFiles( std::string file = ghoul::filesystem::File(line).filename(); LDEBUG("\tLine: " << line << " ; Dest: " << destination.path() + "/" + file); - threads.push_back( - std::thread([&nFinished, line, destination, file, progressCallback](){ + //threads.push_back( + //std::thread([&nFinished, line, destination, file, progressCallback](){ DlManager.downloadFile( line, destination.path() + "/" + file, [&nFinished](const ghoul::filesystem::File& f) { ++nFinished; }, [&progressCallback](const ghoul::filesystem::File& f, float progress) { progressCallback(f, progress); } - );}) + //);} + //) ); } } ); - for (std::thread& t : threads) - t.join(); + //for (std::thread& t : threads) + //t.join();