diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-02-23 20:40:47 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-02-23 20:40:47 +0100 |
commit | 8c37e1ade4ab4a32e97711f037bbf0fd396ec40c (patch) | |
tree | 1da35ba85a71fb6db2ff7573c7f40dfbc89072e2 /src/webengine/downloaditemform.cpp | |
parent | Download manager improvements (diff) | |
download | smolbote-8c37e1ade4ab4a32e97711f037bbf0fd396ec40c.tar.xz |
Download manager
Added total size to widget
Added default file name
Diffstat (limited to 'src/webengine/downloaditemform.cpp')
-rw-r--r-- | src/webengine/downloaditemform.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/webengine/downloaditemform.cpp b/src/webengine/downloaditemform.cpp index 599ea08..61d954d 100644 --- a/src/webengine/downloaditemform.cpp +++ b/src/webengine/downloaditemform.cpp @@ -31,7 +31,7 @@ DownloadItemForm::DownloadItemForm(QWebEngineDownloadItem *item, QWidget *parent m_item = item; ui->setupUi(this); - ui->url_lineEdit->setText(item->url().toString()); + ui->url_label->setText(item->url().toString()); connect(item, SIGNAL(stateChanged(QWebEngineDownloadItem::DownloadState)), this, SLOT(updateState(QWebEngineDownloadItem::DownloadState))); connect(item, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64))); @@ -48,6 +48,23 @@ QWebEngineDownloadItem *DownloadItemForm::item() const return m_item; } +QString DownloadItemForm::sizeString(int size) const +{ + if(size < 1024) { + return QString("%1 bytes").arg(size); + } + // KiB + if(size < 1024 * 1024) { + return QString("%1 kB").arg(size / 1024); + } + // MiB + if(size < 1024 * 1024 * 1024) { + return QString("%1 MB").arg(size / (1024 * 1024)); + } + // GiB + return QString("%1 GB").arg(size / (1024 * 1024 * 1024)); +} + void DownloadItemForm::updateState(QWebEngineDownloadItem::DownloadState state) { switch (state) { @@ -75,6 +92,7 @@ void DownloadItemForm::updateProgress(qint64 value, qint64 total) { ui->progressBar->setMaximum(total); ui->progressBar->setValue(value); + ui->filesize_label->setText(QString("%1 / %2").arg(sizeString(value)).arg(sizeString(total))); } void DownloadItemForm::updateFinished() |