Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Network
Konqueror
Commits
02e59616
Commit
02e59616
authored
Jun 19, 2020
by
Stefano Crocco
Browse files
Add support for blob URLs
Currently only saving to a file is supported
parent
5c8e70cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
webenginepart/src/webenginepartdownloadmanager.cpp
View file @
02e59616
...
...
@@ -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
());
it
->
setDownloadDirectory
(
info
.
path
());
it
->
accept
();
}
#ifndef DOWNLOADITEM_KNOWS_PAGE
void
WebEnginePartDownloadManager
::
recordNavigationRequest
(
WebEnginePage
*
page
,
const
QUrl
&
url
)
...
...
webenginepart/src/webenginepartdownloadmanager.h
View file @
02e59616
...
...
@@ -39,6 +39,7 @@ public:
private:
WebEnginePartDownloadManager
();
void
downloadBlob
(
QWebEngineDownloadItem
*
it
);
public
Q_SLOTS
:
void
addPage
(
WebEnginePage
*
page
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment