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
95d282ba
Commit
95d282ba
authored
Jul 25, 2020
by
Stefano Crocco
Browse files
Use KFileUtils::suggestName to have unique file name
parent
ed53dd42
Changes
1
Hide whitespace changes
Inline
Side-by-side
webenginepart/src/webenginepartdownloadmanager.cpp
View file @
95d282ba
...
...
@@ -39,6 +39,7 @@
#include <KJobTrackerInterface>
#include <KIO/JobTracker>
#include <KIO/OpenUrlJob>
#include <KFileUtils>
WebEnginePartDownloadManager
::
WebEnginePartDownloadManager
()
:
QObject
(),
m_tempDownloadDir
(
QDir
(
QDir
::
tempPath
()).
filePath
(
"WebEnginePartDownloadManager"
))
...
...
@@ -165,28 +166,16 @@ void WebEnginePartDownloadManager::openBlob(QWebEngineDownloadItem* it, WebEngin
QString
WebEnginePartDownloadManager
::
generateBlobTempFileName
(
const
QString
&
suggestedName
,
const
QString
&
ext
)
const
{
QDir
tmpDir
(
m_tempDownloadDir
.
path
());
QString
baseName
(
suggestedName
);
QString
actualExt
(
ext
);
if
(
!
baseName
.
isEmpty
())
{
QString
givenExt
=
QFileInfo
(
baseName
).
completeSuffix
();
if
(
!
givenExt
.
isEmpty
())
{
actualExt
=
givenExt
;
//The +1 is for the dot
int
extLength
=
givenExt
.
length
()
+
1
;
//Remove the extension from baseName
baseName
.
remove
(
baseName
.
length
()
-
extLength
,
extLength
);
}
}
else
{
if
(
baseName
.
isEmpty
())
{
baseName
=
QString
::
number
(
QTime
::
currentTime
().
msecsSinceStartOfDay
());
}
baseName
=
tmpDir
.
filePath
(
baseName
);
QString
completeName
=
QString
(
"%1.%2"
).
arg
(
baseName
,
actualExt
);
QString
nameTemplate
=
"%1-%2.%3"
;
int
i
=
0
;
while
(
QFileInfo
::
exists
(
completeName
))
{
++
i
;
completeName
=
nameTemplate
.
arg
(
baseName
).
arg
(
i
).
arg
(
actualExt
);
if
(
QFileInfo
(
baseName
).
completeSuffix
().
isEmpty
()
&&
!
ext
.
isEmpty
())
{
baseName
.
append
(
"."
+
ext
);
}
QString
completeName
=
QDir
(
m_tempDownloadDir
.
path
()).
filePath
(
baseName
);
if
(
QFileInfo
::
exists
(
completeName
))
{
completeName
=
KFileUtils
::
suggestName
(
QUrl
::
fromLocalFile
(
m_tempDownloadDir
.
path
()),
baseName
);
}
return
completeName
;
}
...
...
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