Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Network
Konqueror
Commits
4f02e435
Commit
4f02e435
authored
Jul 17, 2020
by
Stefano Crocco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attempt to enable embedding/opening blob URL
parent
e66e1d6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
webenginepart/src/webenginepartdownloadmanager.cpp
webenginepart/src/webenginepartdownloadmanager.cpp
+64
-0
webenginepart/src/webenginepartdownloadmanager.h
webenginepart/src/webenginepartdownloadmanager.h
+5
-0
No files found.
webenginepart/src/webenginepartdownloadmanager.cpp
View file @
4f02e435
...
...
@@ -35,6 +35,8 @@
#include <KLocalizedString>
#include <KNotificationJobUiDelegate>
#include <KParts/BrowserOpenOrSaveQuestion>
#include <KIO/OpenUrlJob>
WebEnginePartDownloadManager
::
WebEnginePartDownloadManager
()
:
QObject
()
...
...
@@ -100,6 +102,28 @@ void WebEnginePartDownloadManager::performDownload(QWebEngineDownloadItem* it)
}
void
WebEnginePartDownloadManager
::
downloadBlob
(
QWebEngineDownloadItem
*
it
)
{
QWidget
*
w
=
it
->
page
()
?
it
->
page
()
->
view
()
:
nullptr
;
KParts
::
BrowserOpenOrSaveQuestion
askDlg
(
w
,
it
->
url
(),
it
->
mimeType
());
KParts
::
BrowserOpenOrSaveQuestion
::
Result
ans
=
askDlg
.
askEmbedOrSave
();
qDebug
()
<<
"ANSWER:"
<<
ans
;
switch
(
ans
)
{
case
KParts
::
BrowserOpenOrSaveQuestion
::
Cancel
:
qDebug
()
<<
"CANCEL"
;
it
->
cancel
();
return
;
case
KParts
::
BrowserOpenOrSaveQuestion
::
Save
:
qDebug
()
<<
"SAVE"
;
saveBlob
(
it
);
break
;
case
KParts
::
BrowserOpenOrSaveQuestion
::
Embed
:
case
KParts
::
BrowserOpenOrSaveQuestion
::
Open
:
openBlob
(
it
);
break
;
}
}
void
WebEnginePartDownloadManager
::
saveBlob
(
QWebEngineDownloadItem
*
it
)
{
QWidget
*
w
=
it
->
page
()
?
it
->
page
()
->
view
()
:
nullptr
;
QString
downloadDir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
DownloadLocation
);
...
...
@@ -131,6 +155,46 @@ void WebEnginePartDownloadManager::downloadBlob(QWebEngineDownloadItem* it)
j
->
start
();
}
void
WebEnginePartDownloadManager
::
embedBlob
(
QWebEngineDownloadItem
*
it
)
{
//TODO: implement me
}
void
WebEnginePartDownloadManager
::
openBlob
(
QWebEngineDownloadItem
*
it
)
{
qDebug
()
<<
"OPEN BLOB"
;
QMimeDatabase
db
;
QMimeType
type
=
db
.
mimeTypeForName
(
it
->
mimeType
());
int
i
=
0
;
QDir
tmpDir
(
QStandardPaths
::
writableLocation
(
QStandardPaths
::
TempLocation
));
QString
nameTemplate
=
"konqueror-%1-%2.%3"
;
QString
fileName
;
bool
validName
=
false
;
while
(
!
validName
)
{
++
i
;
fileName
=
nameTemplate
.
arg
(
QTime
::
currentTime
().
msecsSinceStartOfDay
()).
arg
(
i
).
arg
(
type
.
preferredSuffix
());
validName
=
!
tmpDir
.
exists
(
fileName
);
}
qDebug
()
<<
"TEMP FILE NAME"
<<
fileName
;
it
->
setDownloadDirectory
(
tmpDir
.
path
());
it
->
setDownloadFileName
(
fileName
);
connect
(
it
,
&
QWebEngineDownloadItem
::
finished
,
this
,
[
this
,
it
](){
blobDownloadedToFile
(
it
);});
qDebug
()
<<
"ACCEPTING DOWNLOAD"
;
it
->
accept
();
}
void
WebEnginePartDownloadManager
::
blobDownloadedToFile
(
QWebEngineDownloadItem
*
it
)
{
qDebug
()
<<
"DOWNLOAD FINISHED. ABOUT TO START JOB"
;
QString
file
=
QDir
(
it
->
downloadDirectory
()).
filePath
(
it
->
downloadFileName
());
KIO
::
OpenUrlJob
*
j
=
new
KIO
::
OpenUrlJob
(
QUrl
::
fromLocalFile
(
file
),
it
->
mimeType
(),
this
);
j
->
start
();
j
->
setDeleteTemporaryFile
(
true
);
qDebug
()
<<
"JOB STARTED"
;
}
#ifndef DOWNLOADITEM_KNOWS_PAGE
void
WebEnginePartDownloadManager
::
recordNavigationRequest
(
WebEnginePage
*
page
,
const
QUrl
&
url
)
...
...
webenginepart/src/webenginepartdownloadmanager.h
View file @
4f02e435
...
...
@@ -29,6 +29,7 @@
#include <KJob>
class
WebEnginePage
;
class
QFile
;
class
WebEnginePartDownloadManager
:
public
QObject
{
...
...
@@ -49,6 +50,10 @@ public Q_SLOTS:
private
Q_SLOTS
:
void
performDownload
(
QWebEngineDownloadItem
*
it
);
void
saveBlob
(
QWebEngineDownloadItem
*
it
);
void
embedBlob
(
QWebEngineDownloadItem
*
it
);
void
openBlob
(
QWebEngineDownloadItem
*
it
);
void
blobDownloadedToFile
(
QWebEngineDownloadItem
*
it
);
#ifndef DOWNLOADITEM_KNOWS_PAGE
private:
...
...
Write
Preview
Markdown
is supported
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