From 1db5ea9fe9ca588852397a7d05d49267b0258e29 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 15 Mar 2018 17:30:45 +0100 Subject: Add pause/resume/cancel buttons to download --- lib/downloads/downloadswidget.cpp | 7 ++---- lib/downloads/downloadswidget.h | 8 +++---- lib/downloads/widgets/downloaditemform.ui | 33 +++++++++++++++++++++++----- lib/downloads/widgets/downloaditemwidget.cpp | 29 +++++++++++++++++++++++- lib/downloads/widgets/downloaditemwidget.h | 8 +++---- 5 files changed, 65 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/downloads/downloadswidget.cpp b/lib/downloads/downloadswidget.cpp index 3f1b9f7..c1ffb31 100644 --- a/lib/downloads/downloadswidget.cpp +++ b/lib/downloads/downloadswidget.cpp @@ -8,11 +8,8 @@ #include "downloadswidget.h" #include "ui_downloadsform.h" - #include "widgets/downloaditemwidget.h" #include -#include -#include DownloadsWidget::DownloadsWidget(const QString &downloadPath, QWidget *parent) : QDialog(parent) @@ -64,11 +61,11 @@ void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) item->setPath(filepath); - QListWidgetItem *listItem = new QListWidgetItem(); + auto *listItem = new QListWidgetItem(); int rowIndex = ui->listWidget->count(); ui->listWidget->insertItem(rowIndex, listItem); - DownloadItemWidget *form = new DownloadItemWidget(item, this); + auto *form = new DownloadItemWidget(item, this); ui->listWidget->setItemWidget(listItem, form); item->accept(); diff --git a/lib/downloads/downloadswidget.h b/lib/downloads/downloadswidget.h index 9ec95bb..3d5fcb8 100644 --- a/lib/downloads/downloadswidget.h +++ b/lib/downloads/downloadswidget.h @@ -6,8 +6,8 @@ * SPDX-License-Identifier: GPL-3.0 */ -#ifndef DOWNLOADDIALOG_H -#define DOWNLOADDIALOG_H +#ifndef SMOLBOTE_DOWNLOADDIALOG_H +#define SMOLBOTE_DOWNLOADDIALOG_H #include @@ -23,7 +23,7 @@ class DownloadsWidget : public QDialog public: explicit DownloadsWidget(const QString &downloadPath, QWidget *parent = nullptr); - ~DownloadsWidget(); + ~DownloadsWidget() override; public slots: void addDownload(QWebEngineDownloadItem *item); @@ -36,4 +36,4 @@ private: QString m_downloadPath; }; -#endif // DOWNLOADDIALOG_H +#endif // SMOLBOTE_DOWNLOADDIALOG_H diff --git a/lib/downloads/widgets/downloaditemform.ui b/lib/downloads/widgets/downloaditemform.ui index 17f1d6a..c8a4604 100644 --- a/lib/downloads/widgets/downloaditemform.ui +++ b/lib/downloads/widgets/downloaditemform.ui @@ -7,7 +7,7 @@ 0 0 500 - 122 + 128 @@ -41,11 +41,32 @@ - - - status_label - - + + + + + Pause + + + true + + + + + + + Abort + + + + + + + status_label + + + + diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp index 0de17c2..26a9a05 100644 --- a/lib/downloads/widgets/downloaditemwidget.cpp +++ b/lib/downloads/widgets/downloaditemwidget.cpp @@ -8,7 +8,6 @@ #include "downloaditemwidget.h" #include "ui_downloaditemform.h" - #include DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent) @@ -18,6 +17,15 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa m_item = item; ui->setupUi(this); + { + // pause/resume icons + QIcon pauseIcon; + pauseIcon.addPixmap(style()->standardPixmap(QStyle::SP_MediaPlay), QIcon::Normal, QIcon::Off); + pauseIcon.addPixmap(style()->standardPixmap(QStyle::SP_MediaPause), QIcon::Normal, QIcon::On); + ui->pause_toolButton->setIcon(pauseIcon); + + ui->abort_toolButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); + } ui->url_label->setContent(item->url().toString()); ui->detailsWidget->hide(); @@ -27,6 +35,15 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState); connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress); connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished); + + connect(ui->abort_toolButton, &QToolButton::clicked, item, &QWebEngineDownloadItem::cancel); + connect(ui->pause_toolButton, &QToolButton::clicked, item, [item](bool clicked) { + if(clicked) { + item->pause(); + } else { + item->resume(); + } + }); } DownloadItemWidget::~DownloadItemWidget() @@ -71,18 +88,28 @@ void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state switch(state) { case QWebEngineDownloadItem::DownloadRequested: ui->status_label->setText(tr("Requested")); + ui->pause_toolButton->setEnabled(true); + ui->abort_toolButton->setEnabled(true); break; case QWebEngineDownloadItem::DownloadInProgress: ui->status_label->setText(tr("In progress")); + ui->pause_toolButton->setEnabled(true); + ui->abort_toolButton->setEnabled(true); break; case QWebEngineDownloadItem::DownloadCompleted: ui->status_label->setText(tr("Completed")); + ui->pause_toolButton->setEnabled(false); + ui->abort_toolButton->setEnabled(false); break; case QWebEngineDownloadItem::DownloadCancelled: ui->status_label->setText(tr("Cancelled")); + ui->pause_toolButton->setEnabled(false); + ui->abort_toolButton->setEnabled(false); break; case QWebEngineDownloadItem::DownloadInterrupted: ui->status_label->setText(tr("Interrupted")); + ui->pause_toolButton->setEnabled(false); + ui->abort_toolButton->setEnabled(false); break; default: break; diff --git a/lib/downloads/widgets/downloaditemwidget.h b/lib/downloads/widgets/downloaditemwidget.h index 5013c36..a772769 100644 --- a/lib/downloads/widgets/downloaditemwidget.h +++ b/lib/downloads/widgets/downloaditemwidget.h @@ -6,8 +6,8 @@ * SPDX-License-Identifier: GPL-3.0 */ -#ifndef DOWNLOADITEMFORM_H -#define DOWNLOADITEMFORM_H +#ifndef SMOLBOTE_DOWNLOADITEMFORM_H +#define SMOLBOTE_DOWNLOADITEMFORM_H #include #include @@ -23,7 +23,7 @@ class DownloadItemWidget : public QWidget public: explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); - ~DownloadItemWidget(); + ~DownloadItemWidget() override; void showDetails(); void hideDetails(); @@ -41,4 +41,4 @@ private: QWebEngineDownloadItem *m_item; }; -#endif // DOWNLOADITEMFORM_H +#endif // SMOLBOTE_DOWNLOADITEMFORM_H -- cgit v1.2.1