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
93edffa8
Commit
93edffa8
authored
Jul 18, 2020
by
Stefano Crocco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take into account suggested download file name
parent
a455e8ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
11 deletions
+29
-11
webenginepart/src/webenginepartdownloadmanager.cpp
webenginepart/src/webenginepartdownloadmanager.cpp
+28
-11
webenginepart/src/webenginepartdownloadmanager.h
webenginepart/src/webenginepartdownloadmanager.h
+1
-0
No files found.
webenginepart/src/webenginepartdownloadmanager.cpp
View file @
93edffa8
...
...
@@ -106,7 +106,6 @@ void WebEnginePartDownloadManager::downloadBlob(QWebEngineDownloadItem* it)
WebEnginePage
*
p
=
qobject_cast
<
WebEnginePage
*>
(
it
->
page
());
QWidget
*
w
=
p
?
p
->
view
()
:
nullptr
;
KParts
::
BrowserOpenOrSaveQuestion
askDlg
(
w
,
it
->
url
(),
it
->
mimeType
());
askDlg
.
setFeatures
(
KParts
::
BrowserOpenOrSaveQuestion
::
ServiceSelection
);
KParts
::
BrowserOpenOrSaveQuestion
::
Result
ans
=
askDlg
.
askEmbedOrSave
(
KParts
::
BrowserOpenOrSaveQuestion
::
AttachmentDisposition
);
switch
(
ans
)
{
case
KParts
::
BrowserOpenOrSaveQuestion
::
Cancel
:
...
...
@@ -158,22 +157,40 @@ void WebEnginePartDownloadManager::openBlob(QWebEngineDownloadItem* it, WebEngin
{
QMimeDatabase
db
;
QMimeType
type
=
db
.
mimeTypeForName
(
it
->
mimeType
());
int
i
=
0
;
QString
nameTemplate
=
"konqueror-%1-%2.%3"
;
QString
fileName
;
bool
validName
=
false
;
QDir
tempDir
(
m_tempDownloadDir
.
path
());
while
(
!
validName
)
{
++
i
;
fileName
=
nameTemplate
.
arg
(
QTime
::
currentTime
().
msecsSinceStartOfDay
()).
arg
(
i
).
arg
(
type
.
preferredSuffix
());
validName
=
!
tempDir
.
exists
(
fileName
);
}
QString
fileName
=
generateBlobTempFileName
(
it
->
suggestedFileName
(),
type
.
preferredSuffix
());
it
->
setDownloadDirectory
(
m_tempDownloadDir
.
path
());
it
->
setDownloadFileName
(
fileName
);
connect
(
it
,
&
QWebEngineDownloadItem
::
finished
,
this
,
[
this
,
it
,
page
](){
blobDownloadedToFile
(
it
,
page
);});
it
->
accept
();
}
QString
WebEnginePartDownloadManager
::
generateBlobTempFileName
(
const
QString
&
suggestedName
,
const
QString
&
ext
)
const
{
QDir
tmpDir
(
m_tempDownloadDir
.
path
());
QString
fileName
;
QString
actualExt
=
ext
;
if
(
!
suggestedName
.
isEmpty
())
{
fileName
=
tmpDir
.
filePath
(
suggestedName
);
QString
givenExt
=
QFileInfo
(
fileName
).
completeSuffix
();
if
(
!
givenExt
.
isEmpty
())
{
actualExt
=
givenExt
;
//Remove the extension from fileName. The -1 is needed to also remove the dot
fileName
=
fileName
.
left
(
fileName
.
length
()
-
givenExt
.
length
()
-
1
);
}
}
else
{
fileName
=
tmpDir
.
filePath
(
QString
::
number
(
QTime
::
currentTime
().
msecsSinceStartOfDay
()));
}
QString
completeName
=
fileName
+
"."
+
actualExt
;
QString
nameTemplate
=
"%1-%2.%3"
;
int
i
=
0
;
while
(
tmpDir
.
exists
(
completeName
))
{
++
i
;
completeName
=
nameTemplate
.
arg
(
fileName
).
arg
(
i
).
arg
(
actualExt
);
}
return
completeName
;
}
void
WebEnginePartDownloadManager
::
blobDownloadedToFile
(
QWebEngineDownloadItem
*
it
,
WebEnginePage
*
page
)
{
QString
file
=
QDir
(
it
->
downloadDirectory
()).
filePath
(
it
->
downloadFileName
());
...
...
webenginepart/src/webenginepartdownloadmanager.h
View file @
93edffa8
...
...
@@ -44,6 +44,7 @@ public:
private:
WebEnginePartDownloadManager
();
void
downloadBlob
(
QWebEngineDownloadItem
*
it
);
QString
generateBlobTempFileName
(
QString
const
&
suggestedName
,
const
QString
&
ext
)
const
;
public
Q_SLOTS
:
void
addPage
(
WebEnginePage
*
page
);
...
...
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