aboutsummaryrefslogtreecommitdiff
path: root/lib/downloads
diff options
context:
space:
mode:
Diffstat (limited to 'lib/downloads')
-rw-r--r--lib/downloads/downloadswidget.cpp9
-rw-r--r--lib/downloads/widgets/downloaditemwidget.cpp23
2 files changed, 13 insertions, 19 deletions
diff --git a/lib/downloads/downloadswidget.cpp b/lib/downloads/downloadswidget.cpp
index 3ff7e69..02ed08a 100644
--- a/lib/downloads/downloadswidget.cpp
+++ b/lib/downloads/downloadswidget.cpp
@@ -30,7 +30,7 @@ DownloadsWidget::~DownloadsWidget()
void DownloadsWidget::addDownload(QWebEngineDownloadItem *item)
{
- const QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), m_downloadPath + "/" + QFileInfo(item->path()).fileName());
+ const QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), m_downloadPath + "/" + item->downloadFileName());
if(filepath.isEmpty()) {
// user cancelled the save dialog
@@ -38,7 +38,12 @@ void DownloadsWidget::addDownload(QWebEngineDownloadItem *item)
return;
}
- item->setPath(filepath);
+ QFileInfo info(filepath);
+
+ // you first have to set the download directory, then file name, otherwise the filename gets defaulted
+ item->setDownloadDirectory(info.absolutePath());
+ item->setDownloadFileName(info.fileName());
+
auto *listItem = new QListWidgetItem(ui->listWidget);
diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp
index 4096751..241b90b 100644
--- a/lib/downloads/widgets/downloaditemwidget.cpp
+++ b/lib/downloads/widgets/downloaditemwidget.cpp
@@ -48,7 +48,7 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa
}
ui->url_label->setText(item->url().toString());
- ui->path_label->setText(item->path());
+ ui->path_label->setText(QString("%1<br>%2").arg(item->downloadDirectory(), item->downloadFileName()));
this->updateState(item->state());
connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState);
@@ -64,7 +64,7 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa
}
});
connect(ui->open_toolButton, &QToolButton::clicked, item, [item]() {
- QDesktopServices::openUrl(QUrl::fromLocalFile(item->path()));
+ QDesktopServices::openUrl(QUrl::fromLocalFile(item->downloadDirectory()+'/'+item->downloadFileName()));
});
}
@@ -125,28 +125,17 @@ void DownloadItemWidget::updateFinished()
ui->abort_toolButton->hide();
ui->open_toolButton->show();
- // generate a useful tooltip
- QString tooltip = "<p><b>URL</b>: %1</p>"
- "<p><b>Path</b>: %2</p>"
- "<p><b>MIME Type</b>: %3</p>"
- "<p><b>Size</b>: %4</p>";
- tooltip = tooltip.arg(item->url().toString(), item->path(), item->mimeType(), sizeString(item->totalBytes()));
-
+ // generate a preview tooltip
if(item->mimeType().startsWith("image")) {
- const QPixmap pixmap(item->path());
+ const QPixmap pixmap(item->downloadDirectory()+'/'+item->downloadFileName());
const QPixmap thumbnail = pixmap.scaledToWidth(qMax(400, pixmap.width()), Qt::SmoothTransformation);
QByteArray imageData;
QBuffer buffer(&imageData);
thumbnail.save(&buffer, "PNG");
- tooltip = QString("<table>"
- "<tr><th>Preview</th><th>Information</th></tr>"
- "<tr><td>%1</td><td>%2</td></tr>"
- "</table>").arg(QString("<img src='data:image/png;base64," + imageData.toBase64() + "' width='400' alt='preview'>"),
- tooltip);
-
+ const auto tooltip = QString("<img src='data:image/png;base64," + imageData.toBase64() + "' width='400' alt='preview'>");
+ setToolTip(tooltip);
}
- setToolTip(tooltip);
}