Commit 2b9c62b7 authored by Stefano Crocco's avatar Stefano Crocco
Browse files

Add support for blob URLs

Currently only saving to a file is supported
parent 5c8e70cc
......@@ -26,6 +26,13 @@
#include <QWebEngineDownloadItem>
#include <QWebEngineView>
#include <QWebEngineProfile>
#include <QFileDialog>
#include <QStandardPaths>
#include <QFileInfo>
#include <QMimeDatabase>
#include <QMimeType>
#include <KLocalizedString>
WebEnginePartDownloadManager::WebEnginePartDownloadManager()
: QObject()
......@@ -83,9 +90,32 @@ void WebEnginePartDownloadManager::performDownload(QWebEngineDownloadItem* it)
qCDebug(WEBENGINEPART_LOG) << "Couldn't find a part wanting to download" << it->url();
return;
}
page->download(it->url(), forceNew);
if (it->url().scheme() != "blob") {
page->download(it->url(), forceNew);
} else {
downloadBlob(it);
}
}
void WebEnginePartDownloadManager::downloadBlob(QWebEngineDownloadItem* it)
{
QWidget *w =it->page() ? it->page()->view() : nullptr;
QString downloadDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
QMimeDatabase db;
QMimeType type = db.mimeTypeForName(it->mimeType());
QString filters = i18nc("Filter in file dialog", "%1 (*.%2);;All files", type.comment(), type.preferredSuffix());
QString file = QFileDialog::getSaveFileName(w, QString(), downloadDir, filters);
if (file.isEmpty()) {
it->cancel();
return;
}
QFileInfo info(file);
it->setDownloadFileName(info.fileName());
  • These lines require Qt 5.14. That means konqueror fails to compile in a standard install of Fedora 31, where the highest Qt version available in updates is 5.13.

    Qt 5.14 is the version where QWebEngineDownloadItem introduced: suggestedFileName setDownloadDirectory setDownloadFileName downloadDirectory downloadFileName

    make reports the lines with these errors as 131, 147, 148, 149, 173, 246, 258 and I also commented on settings/konqhtml/appearance.cpp which has the same problem at around line 210.

Please register or sign in to reply
it->setDownloadDirectory(info.path());
it->accept();
}
#ifndef DOWNLOADITEM_KNOWS_PAGE
void WebEnginePartDownloadManager::recordNavigationRequest(WebEnginePage *page, const QUrl& url)
......
......@@ -39,6 +39,7 @@ public:
private:
WebEnginePartDownloadManager();
void downloadBlob(QWebEngineDownloadItem *it);
public Q_SLOTS:
void addPage(WebEnginePage *page);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment