aboutsummaryrefslogtreecommitdiff
path: root/lib/downloads/widgets/downloaditemwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/downloads/widgets/downloaditemwidget.cpp')
-rw-r--r--lib/downloads/widgets/downloaditemwidget.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp
index e0c8a60..169ba6f 100644
--- a/lib/downloads/widgets/downloaditemwidget.cpp
+++ b/lib/downloads/widgets/downloaditemwidget.cpp
@@ -30,7 +30,7 @@ inline QString sizeString(qint64 size)
return QString("%1 GB").arg(size / (1024 * 1024 * 1024));
}
-DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *m_item, QWidget *parent)
+DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadRequest *m_item, QWidget *parent)
: QWidget(parent)
, ui(new Ui::DownloadItemForm)
{
@@ -51,11 +51,11 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *m_item, QWidget *
ui->path_label->setText(QString("%1<br>%2").arg(item->downloadDirectory(), item->downloadFileName()));
this->updateState(item->state());
- connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState);
- connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress);
- connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished);
+ connect(item, &QWebEngineDownloadRequest::stateChanged, this, &DownloadItemWidget::updateState);
+ connect(item, &QWebEngineDownloadRequest::receivedBytesChanged, this, &DownloadItemWidget::updateProgress);
+ connect(item, &QWebEngineDownloadRequest::isFinishedChanged, this, &DownloadItemWidget::updateFinished);
- connect(ui->abort_toolButton, &QToolButton::clicked, item, &QWebEngineDownloadItem::cancel);
+ connect(ui->abort_toolButton, &QToolButton::clicked, item, &QWebEngineDownloadRequest::cancel);
connect(ui->pause_toolButton, &QToolButton::clicked, item, [m_item](bool clicked) {
clicked ? m_item->pause() : m_item->resume();
});
@@ -69,34 +69,34 @@ DownloadItemWidget::~DownloadItemWidget()
delete ui;
}
-void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state)
+void DownloadItemWidget::updateState(QWebEngineDownloadRequest::DownloadState state)
{
switch(state) {
- case QWebEngineDownloadItem::DownloadRequested:
+ case QWebEngineDownloadRequest::DownloadRequested:
ui->status_label->setText(tr("Requested"));
ui->pause_toolButton->setEnabled(true);
ui->abort_toolButton->setEnabled(true);
ui->open_toolButton->setEnabled(false);
break;
- case QWebEngineDownloadItem::DownloadInProgress:
+ case QWebEngineDownloadRequest::DownloadInProgress:
ui->status_label->setText(tr("In progress"));
ui->pause_toolButton->setEnabled(true);
ui->abort_toolButton->setEnabled(true);
ui->open_toolButton->setEnabled(false);
break;
- case QWebEngineDownloadItem::DownloadCompleted:
+ case QWebEngineDownloadRequest::DownloadCompleted:
ui->status_label->setText(tr("Completed"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
ui->open_toolButton->setEnabled(true);
break;
- case QWebEngineDownloadItem::DownloadCancelled:
+ case QWebEngineDownloadRequest::DownloadCancelled:
ui->status_label->setText(tr("Cancelled"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
ui->open_toolButton->setEnabled(false);
break;
- case QWebEngineDownloadItem::DownloadInterrupted:
+ case QWebEngineDownloadRequest::DownloadInterrupted:
ui->status_label->setText(tr("Interrupted"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
@@ -107,8 +107,11 @@ void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state
}
}
-void DownloadItemWidget::updateProgress(qint64 value, qint64 total)
+void DownloadItemWidget::updateProgress()
{
+ const auto value = item->receivedBytes();
+ const auto total = item->totalBytes();
+
ui->progressBar->setValue(static_cast<int>((static_cast<long double>(value) / static_cast<long double>(total)) * 100));
ui->progressBar->setFormat(QString("%1 / %2").arg(sizeString(value), sizeString(total)));
}