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 | |
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')
-rw-r--r-- | src/webengine/downloaditemform.cpp | 20 | ||||
-rw-r--r-- | src/webengine/downloaditemform.h | 1 | ||||
-rw-r--r-- | src/webengine/downloaditemform.ui | 30 |
3 files changed, 33 insertions, 18 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() diff --git a/src/webengine/downloaditemform.h b/src/webengine/downloaditemform.h index 0b987b9..b4cb0e5 100644 --- a/src/webengine/downloaditemform.h +++ b/src/webengine/downloaditemform.h @@ -37,6 +37,7 @@ public: ~DownloadItemForm(); QWebEngineDownloadItem *item() const; + QString sizeString(int size) const; private slots: void updateState(QWebEngineDownloadItem::DownloadState state); diff --git a/src/webengine/downloaditemform.ui b/src/webengine/downloaditemform.ui index d06dcf4..8a8d148 100644 --- a/src/webengine/downloaditemform.ui +++ b/src/webengine/downloaditemform.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>500</width> - <height>80</height> + <height>70</height> </rect> </property> <property name="windowTitle"> @@ -15,22 +15,11 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <layout class="QFormLayout" name="formLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>URL</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="url_lineEdit"> - <property name="enabled"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> + <widget class="QLabel" name="url_label"> + <property name="text"> + <string>[url]</string> + </property> + </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout"> @@ -42,6 +31,13 @@ </widget> </item> <item> + <widget class="QLabel" name="filesize_label"> + <property name="text"> + <string>x MiB / y MiB</string> + </property> + </widget> + </item> + <item> <widget class="QProgressBar" name="progressBar"> <property name="value"> <number>24</number> |