diff --git a/apps/Launcher/infowidget.cpp b/apps/Launcher/infowidget.cpp index 9ddc547912..95a0e02700 100644 --- a/apps/Launcher/infowidget.cpp +++ b/apps/Launcher/infowidget.cpp @@ -31,7 +31,7 @@ #include InfoWidget::InfoWidget(QString name, int totalBytes) - : QWidget(nullptr) + : QGroupBox(nullptr) , _name(nullptr) , _bytes(nullptr) , _progress(nullptr) @@ -41,39 +41,40 @@ InfoWidget::InfoWidget(QString name, int totalBytes) setFixedHeight(100); QGridLayout* layout = new QGridLayout; + layout->setVerticalSpacing(0); + layout->setHorizontalSpacing(10); + layout->setContentsMargins(0, 0, 0, 0); _name = new QLabel(name); layout->addWidget(_name, 0, 0); _bytes = new QLabel(""); - layout->addWidget(_bytes, 0, 1); + layout->addWidget(_bytes, 1, 0); _progress = new QProgressBar; - layout->addWidget(_progress, 0, 2); + layout->addWidget(_progress, 1, 1); _messages = new QLabel(""); - layout->addWidget(_messages, 1, 0, 1, 3); + layout->addWidget(_messages, 2, 0, 1, 2); setLayout(layout); - - update(0); } -void InfoWidget::update(int currentBytes) { - _bytes->setText( - QString("%1 / %2") - .arg(currentBytes) - .arg(_totalBytes) - ); - - float progress = static_cast(currentBytes) / static_cast(_totalBytes); - _progress->setValue(static_cast(progress * 100)); -} - -void InfoWidget::update(float progress) { - _bytes->setText(""); - _progress->setValue(static_cast(progress * 100)); -} +//void InfoWidget::update(int currentBytes) { +// _bytes->setText( +// QString("%1 / %2") +// .arg(currentBytes) +// .arg(_totalBytes) +// ); +// +// float progress = static_cast(currentBytes) / static_cast(_totalBytes); +// _progress->setValue(static_cast(progress * 100)); +//} +// +//void InfoWidget::update(float progress) { +// _bytes->setText(""); +// _progress->setValue(static_cast(progress * 100)); +//} void InfoWidget::update(openspace::DownloadManager::FileFuture* f) { _bytes->setText( @@ -85,13 +86,44 @@ void InfoWidget::update(openspace::DownloadManager::FileFuture* f) { if (f->errorMessage.empty()) { QString t = "Time remaining %1 s"; - _messages->setText(t.arg(f->secondsRemaining)); + _messages->setText(t.arg(static_cast(f->secondsRemaining))); } else { _messages->setText(QString::fromStdString(f->errorMessage)); } } +void InfoWidget::update(libtorrent::torrent_status s) { + _bytes->setText( + QString("%1 / %2") + .arg(s.total_wanted_done) + .arg(s.total_wanted) + ); + float progress = static_cast(s.total_wanted_done) / s.total_wanted; + _progress->setValue(static_cast(progress * 100)); + + if (s.error.empty()) { + int bytesPerSecond = s.download_rate; + long long remainingBytes = s.total_wanted - s.total_wanted_done; + if (remainingBytes > 0) { + float seconds = static_cast(remainingBytes) / remainingBytes; + + //auto now = time(NULL); + //auto transferTime = now - s.added_time; + //auto estimatedTime = transferTime / progress; + //auto timeRemaining = estimatedTime - transferTime; + QString t = "Time remaining %1 s"; + _messages->setText(t.arg(static_cast(seconds))); + } + else + _messages->setText(""); + } + else { + _messages->setText(QString::fromStdString(s.error)); + } + +} + void InfoWidget::error(QString message) { _messages->setText(message); } diff --git a/apps/Launcher/infowidget.h b/apps/Launcher/infowidget.h index ea968194df..654408fc6d 100644 --- a/apps/Launcher/infowidget.h +++ b/apps/Launcher/infowidget.h @@ -25,22 +25,23 @@ #ifndef __INFOWIDGET_H__ #define __INFOWIDGET_H__ -#include +//#include +#include #include +#include + class QLabel; class QProgressBar; -class InfoWidget : public QWidget { +class InfoWidget : public QGroupBox { Q_OBJECT public: InfoWidget(QString name, int totalBytes = -1); - void update(int currentBytes); - void update(float progress); - void update(openspace::DownloadManager::FileFuture* f); + void update(libtorrent::torrent_status s); void error(QString message); diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index 32d126857c..9f23e35368 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -104,6 +104,8 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) area->setWidget(w); _downloadLayout = new QVBoxLayout(w); + _downloadLayout->setMargin(0); + _downloadLayout->setSpacing(0); _downloadLayout->addStretch(100); layout->addWidget(area); @@ -498,7 +500,7 @@ void SyncWidget::handleTimer() { InfoWidget* w = _torrentInfoWidgetMap[h]; if (w) - w->update(static_cast(s.total_wanted_done)); + w->update(s); if (CleanInfoWidgets && (s.state == torrent_status::finished || s.state == torrent_status::seeding)) { _torrentInfoWidgetMap.remove(h); @@ -574,12 +576,4 @@ void SyncWidget::handleFileFutureAddition( while (_mutex.test_and_set()) {} _futuresToAdd.insert(_futuresToAdd.end(), futures.begin(), futures.end()); _mutex.clear(); - //_futures.insert(_futures.end(), futures.begin(), futures.end()); - //for (openspace::DownloadManager::FileFuture* f : futures) { - // InfoWidget* w = new InfoWidget(QString::fromStdString(f->filePath), -1); - // _downloadLayout->addWidget(w); - - // _futureInfoWidgetMap[f] = w; - //} - } diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index 0b07b72116..ddbccd935d 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -44,7 +44,6 @@ namespace { const std::string RequestApplicationVersion = "application_version"; struct ProgressInformation { - CURL* curl; openspace::DownloadManager::FileFuture* future; std::chrono::system_clock::time_point startTime; const openspace::DownloadManager::DownloadProgressCallback* callback; @@ -67,7 +66,6 @@ namespace { ghoul_assert(p, "Passed progress information is nullptr"); ProgressInformation* i = static_cast(p); ghoul_assert(i, "Passed pointer is not a ProgressInformation"); - ghoul_assert(i->curl, "CURL pointer is nullptr"); ghoul_assert(i->future, "FileFuture is not initialized"); ghoul_assert(i->callback, "Callback pointer is nullptr"); @@ -152,7 +150,6 @@ DownloadManager::FileFuture* DownloadManager::downloadFile( curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); ProgressInformation p = { - curl, future, std::chrono::system_clock::now(), &progressCallback