| 63 | #include "share/WizMisc.h" |
| 64 | |
| 65 | DownloadWidget::DownloadWidget(QWebEngineDownloadItem *download, QWidget *parent) |
| 66 | : QFrame(parent) |
| 67 | , m_download(download) |
| 68 | , m_timeAdded() |
| 69 | { |
| 70 | m_timeAdded.start(); |
| 71 | setupUi(this); |
| 72 | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) |
| 73 | m_dstName->setText(m_download->downloadFileName()); |
| 74 | #else |
| 75 | m_dstName->setText(QFileInfo(m_download->path()).fileName()); |
| 76 | #endif |
| 77 | m_srcUrl->setText(m_download->url().toDisplayString()); |
| 78 | QIcon removeIcon(WizLoadSkinIcon(Utils::WizStyleHelper::themeName(), "trash")); |
| 79 | m_cancelButton->setIcon(removeIcon); |
| 80 | |
| 81 | connect(m_cancelButton, &QPushButton::clicked, |
| 82 | [this](bool) { |
| 83 | if (m_download->state() == QWebEngineDownloadItem::DownloadInProgress) |
| 84 | m_download->cancel(); |
| 85 | else |
| 86 | emit removeClicked(this); |
| 87 | }); |
| 88 | |
| 89 | connect(m_download, &QWebEngineDownloadItem::downloadProgress, |
| 90 | this, &DownloadWidget::updateWidget); |
| 91 | |
| 92 | connect(m_download, &QWebEngineDownloadItem::stateChanged, |
| 93 | this, &DownloadWidget::updateWidget); |
| 94 | |
| 95 | updateWidget(); |
| 96 | } |
| 97 | |
| 98 | inline QString DownloadWidget::withUnit(qreal bytes) |
| 99 | { |