From 3150def9fc2be4677921c14ffca79e565f4280f7 Mon Sep 17 00:00:00 2001 From: Anmol Gautam Date: Sun, 31 Mar 2019 18:01:23 +0530 Subject: [PATCH] added pause/resume for downloads Summary: Added button to pause/resume download from the download manager Reviewers: drosca Reviewed By: drosca Subscribers: falkon Tags: #falkon Differential Revision: https://phabricator.kde.org/D20037 --- src/lib/downloads/downloaditem.cpp | 35 +++++++++++++++++++++--- src/lib/downloads/downloaditem.h | 1 + src/lib/downloads/downloaditem.ui | 44 ++++++++++++++++++++---------- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/lib/downloads/downloaditem.cpp b/src/lib/downloads/downloaditem.cpp index 5d00cd4c6..f77fe47c9 100644 --- a/src/lib/downloads/downloaditem.cpp +++ b/src/lib/downloads/downloaditem.cpp @@ -66,13 +66,15 @@ DownloadItem::DownloadItem(QListWidgetItem *item, QWebEngineDownloadItem* downlo ui->setupUi(this); setMaximumWidth(525); - ui->button->setPixmap(QIcon::fromTheme(QSL("process-stop")).pixmap(20, 20)); + ui->cancelButton->setPixmap(QIcon::fromTheme(QSL("process-stop")).pixmap(20, 20)); + ui->pauseResumeButton->setPixmap(QIcon::fromTheme(QSL("media-playback-pause")).pixmap(20, 20)); ui->fileName->setText(m_fileName); ui->downloadInfo->setText(tr("Remaining time unavailable")); setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint))); - connect(ui->button, &ClickableLabel::clicked, this, &DownloadItem::stop); + connect(ui->cancelButton, &ClickableLabel::clicked, this, &DownloadItem::stop); + connect(ui->pauseResumeButton, &ClickableLabel::clicked, this, &DownloadItem::pauseResume); connect(manager, &DownloadManager::resized, this, &DownloadItem::parentResized); } @@ -138,7 +140,8 @@ void DownloadItem::finished() } ui->progressBar->hide(); - ui->button->hide(); + ui->cancelButton->hide(); + ui->pauseResumeButton->hide(); ui->frame->hide(); m_item->setSizeHint(sizeHint()); @@ -231,6 +234,10 @@ void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 // | m_remTime | |m_currSize| |m_fileSize| |m_speed| // Remaining 26 minutes - 339MB of 693 MB (350kB/s) + if (m_download->isPaused()) { + return; + } + int estimatedTime = ((total - received) / 1024) / (currSpeed / 1024); QString speed = currentSpeedToString(currSpeed); // We have QString speed now @@ -261,7 +268,8 @@ void DownloadItem::stop() } m_downloadStopped = true; ui->progressBar->hide(); - ui->button->hide(); + ui->cancelButton->hide(); + ui->pauseResumeButton->hide(); m_item->setSizeHint(sizeHint()); ui->downloadInfo->setText(tr("Cancelled - %1").arg(m_download->url().host())); m_download->cancel(); @@ -270,6 +278,18 @@ void DownloadItem::stop() emit downloadFinished(false); } +void DownloadItem::pauseResume() +{ + if (m_download->isPaused()) { + m_download->resume(); + ui->pauseResumeButton->setPixmap(QIcon::fromTheme(QSL("media-playback-pause")).pixmap(20, 20)); + } else { + m_download->pause(); + ui->pauseResumeButton->setPixmap(QIcon::fromTheme(QSL("media-playback-start")).pixmap(20, 20)); + ui->downloadInfo->setText(tr("Paused - %1").arg(m_download->url().host())); + } +} + void DownloadItem::mouseDoubleClickEvent(QMouseEvent* e) { openFile(); @@ -286,6 +306,13 @@ void DownloadItem::customContextMenuRequested(const QPoint &pos) menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy Download Link"), this, &DownloadItem::copyDownloadLink); menu.addSeparator(); menu.addAction(QIcon::fromTheme("process-stop"), tr("Cancel downloading"), this, &DownloadItem::stop)->setEnabled(m_downloading); + + if (m_download->isPaused()) { + menu.addAction(QIcon::fromTheme("media-playback-start"), tr("Resume downloading"), this, &DownloadItem::pauseResume)->setEnabled(m_downloading); + } else { + menu.addAction(QIcon::fromTheme("media-playback-pause"), tr("Pause downloading"), this, &DownloadItem::pauseResume)->setEnabled(m_downloading); + } + menu.addAction(QIcon::fromTheme("list-remove"), tr("Remove From List"), this, &DownloadItem::clear)->setEnabled(!m_downloading); if (m_downloading || ui->downloadInfo->text().startsWith(tr("Cancelled")) || ui->downloadInfo->text().startsWith(tr("Error"))) { diff --git a/src/lib/downloads/downloaditem.h b/src/lib/downloads/downloaditem.h index 7e38d3094..fac639571 100644 --- a/src/lib/downloads/downloaditem.h +++ b/src/lib/downloads/downloaditem.h @@ -65,6 +65,7 @@ private Q_SLOTS: void finished(); void downloadProgress(qint64 received, qint64 total); void stop(); + void pauseResume(); void openFile(); void openFolder(); void customContextMenuRequested(const QPoint &pos); diff --git a/src/lib/downloads/downloaditem.ui b/src/lib/downloads/downloaditem.ui index a0a32b7e1..b382c0351 100644 --- a/src/lib/downloads/downloaditem.ui +++ b/src/lib/downloads/downloaditem.ui @@ -33,13 +33,6 @@ - - - - A Clockwork Orange.avi - - - @@ -47,6 +40,13 @@ + + + + A Clockwork Orange.avi + + + @@ -56,7 +56,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -73,7 +82,14 @@ - + + + + + + + + @@ -85,16 +101,16 @@ - - ClickableLabel - QLabel -
clickablelabel.h
-
SqueezeLabelV2 QLabel
squeezelabelv2.h
+ + ClickableLabel + QLabel +
clickablelabel.h
+