diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-03-15 17:30:45 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-03-15 17:30:45 +0100 |
commit | 1db5ea9fe9ca588852397a7d05d49267b0258e29 (patch) | |
tree | a3909d64319177e773c8f6a0057446669d1f145e | |
parent | Moved Configuration class into library (diff) | |
download | smolbote-1db5ea9fe9ca588852397a7d05d49267b0258e29.tar.xz |
Add pause/resume/cancel buttons to download
-rw-r--r-- | lib/downloads/downloadswidget.cpp | 7 | ||||
-rw-r--r-- | lib/downloads/downloadswidget.h | 8 | ||||
-rw-r--r-- | lib/downloads/widgets/downloaditemform.ui | 33 | ||||
-rw-r--r-- | lib/downloads/widgets/downloaditemwidget.cpp | 29 | ||||
-rw-r--r-- | lib/downloads/widgets/downloaditemwidget.h | 8 |
5 files changed, 65 insertions, 20 deletions
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 <QFileDialog> -#include <QListWidget> -#include <QWebEngineDownloadItem> 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 <QDialog> @@ -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 @@ <x>0</x> <y>0</y> <width>500</width> - <height>122</height> + <height>128</height> </rect> </property> <property name="sizePolicy"> @@ -41,11 +41,32 @@ <widget class="QWidget" name="detailsWidget" native="true"> <layout class="QVBoxLayout" name="detailsLayout"> <item> - <widget class="QLabel" name="status_label"> - <property name="text"> - <string>status_label</string> - </property> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QToolButton" name="pause_toolButton"> + <property name="text"> + <string>Pause</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="abort_toolButton"> + <property name="text"> + <string>Abort</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="status_label"> + <property name="text"> + <string>status_label</string> + </property> + </widget> + </item> + </layout> </item> <item> <widget class="QLabel" name="path_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 <QUrl> 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 <QWebEngineDownloadItem> #include <QWidget> @@ -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 |