aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-02-23 20:40:47 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-02-23 20:40:47 +0100
commit8c37e1ade4ab4a32e97711f037bbf0fd396ec40c (patch)
tree1da35ba85a71fb6db2ff7573c7f40dfbc89072e2
parentDownload manager improvements (diff)
downloadsmolbote-8c37e1ade4ab4a32e97711f037bbf0fd396ec40c.tar.xz
Download manager
Added total size to widget Added default file name
-rw-r--r--src/forms/downloaddialog.cpp9
-rw-r--r--src/forms/downloaddialog.ui30
-rw-r--r--src/webengine/downloaditemform.cpp20
-rw-r--r--src/webengine/downloaditemform.h1
-rw-r--r--src/webengine/downloaditemform.ui30
5 files changed, 62 insertions, 28 deletions
diff --git a/src/forms/downloaddialog.cpp b/src/forms/downloaddialog.cpp
index 7d26c4b..950fa96 100644
--- a/src/forms/downloaddialog.cpp
+++ b/src/forms/downloaddialog.cpp
@@ -34,6 +34,7 @@ DownloadDialog::DownloadDialog(QWidget *parent) :
ui(new Ui::DownloadDialog)
{
ui->setupUi(this);
+ ui->filePath->setWordWrap(true);
connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int)));
}
@@ -47,10 +48,7 @@ void DownloadDialog::addDownload(QWebEngineDownloadItem *item)
{
Settings settings;
- qDebug("download item: %s", qUtf8Printable(item->url().toString()));
- qDebug("download path: %s", qUtf8Printable(settings.value("downloads/path").toString()));
-
- QString filepath = QFileDialog::getSaveFileName(this, tr("Save"), settings.value("downloads/path").toString());
+ QString filepath = QFileDialog::getSaveFileName(this, tr("Save"), settings.value("downloads/path").toString() + "/" + QFileInfo(item->path()).fileName());
if(filepath.isEmpty()) {
// user cancelled the save dialog
@@ -76,5 +74,6 @@ void DownloadDialog::showItemDetails(int index)
{
DownloadItemForm *form = qobject_cast<DownloadItemForm *>(ui->listWidget->itemWidget(ui->listWidget->item(index)));
ui->mimeType_label->setText(form->item()->mimeType());
- ui->path_label->setText(form->item()->path());
+ ui->filePath_label->setText(form->item()->path());
+ ui->fileSize_label->setText(QString("%1 bytes").arg(form->item()->totalBytes()));
}
diff --git a/src/forms/downloaddialog.ui b/src/forms/downloaddialog.ui
index f9bc307..2e21106 100644
--- a/src/forms/downloaddialog.ui
+++ b/src/forms/downloaddialog.ui
@@ -27,14 +27,20 @@
<height>0</height>
</size>
</property>
+ <property name="maximumSize">
+ <size>
+ <width>250</width>
+ <height>16777215</height>
+ </size>
+ </property>
<property name="title">
<string>Details</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
- <widget class="QLabel" name="label">
+ <widget class="QLabel" name="mimeType">
<property name="text">
- <string>mime</string>
+ <string>Type</string>
</property>
</widget>
</item>
@@ -46,14 +52,28 @@
</widget>
</item>
<item row="1" column="0">
- <widget class="QLabel" name="label_2">
+ <widget class="QLabel" name="filePath">
<property name="text">
- <string>path</string>
+ <string>Path</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="fileSize">
+ <property name="text">
+ <string>Size</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="fileSize_label">
+ <property name="text">
+ <string/>
</property>
</widget>
</item>
<item row="1" column="1">
- <widget class="QLabel" name="path_label">
+ <widget class="QLabel" name="filePath_label">
<property name="text">
<string/>
</property>
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>