aboutsummaryrefslogtreecommitdiff
path: root/lib/downloads/widgets
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-08-24 15:13:47 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-08-24 15:23:14 +0200
commiteca5159e12288e1b4ee7d2d52f0475ca6433a0eb (patch)
treee4f695d9ece39de9f45965b1d64a8d2cd610353b /lib/downloads/widgets
parentWebPage: add render process crash recovery page (diff)
downloadsmolbote-eca5159e12288e1b4ee7d2d52f0475ca6433a0eb.tar.xz
Downloads: prevent download widget width from exceeding download list width
Downloads: add open button
Diffstat (limited to 'lib/downloads/widgets')
-rw-r--r--lib/downloads/widgets/downloaditemform.ui10
-rw-r--r--lib/downloads/widgets/downloaditemwidget.cpp44
-rw-r--r--lib/downloads/widgets/downloaditemwidget.h2
-rw-r--r--lib/downloads/widgets/elidedlabel.cpp1
4 files changed, 35 insertions, 22 deletions
diff --git a/lib/downloads/widgets/downloaditemform.ui b/lib/downloads/widgets/downloaditemform.ui
index 9b4ba12..7944084 100644
--- a/lib/downloads/widgets/downloaditemform.ui
+++ b/lib/downloads/widgets/downloaditemform.ui
@@ -66,6 +66,13 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QToolButton" name="open_toolButton">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>
@@ -73,9 +80,6 @@
<property name="text">
<string>path_label</string>
</property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
</widget>
</item>
</layout>
diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp
index 3fe2ebd..927c58b 100644
--- a/lib/downloads/widgets/downloaditemwidget.cpp
+++ b/lib/downloads/widgets/downloaditemwidget.cpp
@@ -10,6 +10,24 @@
#include "ui_downloaditemform.h"
#include <QStyle>
#include <QUrl>
+#include <QDesktopServices>
+
+inline QString sizeString(int size)
+{
+ 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));
+}
DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent)
: QWidget(parent)
@@ -31,6 +49,7 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa
ui->url_label->setText(item->url().toString());
ui->path_label->setText(item->path());
+ this->updateState(item->state());
connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState);
connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress);
connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished);
@@ -43,6 +62,9 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa
item->resume();
}
});
+ connect(ui->open_toolButton, &QToolButton::clicked, item, [item]() {
+ QDesktopServices::openUrl(QUrl::fromLocalFile(item->path()));
+ });
}
DownloadItemWidget::~DownloadItemWidget()
@@ -50,23 +72,6 @@ DownloadItemWidget::~DownloadItemWidget()
delete ui;
}
-QString DownloadItemWidget::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 DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state)
{
switch(state) {
@@ -74,26 +79,31 @@ void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state
ui->status_label->setText(tr("Requested"));
ui->pause_toolButton->setEnabled(true);
ui->abort_toolButton->setEnabled(true);
+ ui->open_toolButton->setEnabled(false);
break;
case QWebEngineDownloadItem::DownloadInProgress:
ui->status_label->setText(tr("In progress"));
ui->pause_toolButton->setEnabled(true);
ui->abort_toolButton->setEnabled(true);
+ ui->open_toolButton->setEnabled(false);
break;
case QWebEngineDownloadItem::DownloadCompleted:
ui->status_label->setText(tr("Completed"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
+ ui->open_toolButton->setEnabled(true);
break;
case QWebEngineDownloadItem::DownloadCancelled:
ui->status_label->setText(tr("Cancelled"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
+ ui->open_toolButton->setEnabled(false);
break;
case QWebEngineDownloadItem::DownloadInterrupted:
ui->status_label->setText(tr("Interrupted"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
+ ui->open_toolButton->setEnabled(false);
break;
default:
break;
diff --git a/lib/downloads/widgets/downloaditemwidget.h b/lib/downloads/widgets/downloaditemwidget.h
index 29a02d6..db4dc8e 100644
--- a/lib/downloads/widgets/downloaditemwidget.h
+++ b/lib/downloads/widgets/downloaditemwidget.h
@@ -25,8 +25,6 @@ public:
explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0);
~DownloadItemWidget() override;
- QString sizeString(int size) const;
-
private slots:
void updateState(QWebEngineDownloadItem::DownloadState state);
void updateProgress(qint64 value, qint64 total);
diff --git a/lib/downloads/widgets/elidedlabel.cpp b/lib/downloads/widgets/elidedlabel.cpp
index da81407..b6761ab 100644
--- a/lib/downloads/widgets/elidedlabel.cpp
+++ b/lib/downloads/widgets/elidedlabel.cpp
@@ -14,6 +14,7 @@
ElidedLabel::ElidedLabel(QWidget *parent)
: QLabel(parent)
{
+ setWordWrap(true);
}
void ElidedLabel::setText(const QString &text)