Commit d38d7df3 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Replace QUrl::fromUserInput by lighter heuristic

I just found that QUrl::fromLocalFile() actually calls QFileInfo::exists on the URL which is not something you want to be doing
constantly and especially not for remote locations.

Differential Revision: https://phabricator.kde.org/D21164
parent 1e175254
......@@ -73,6 +73,15 @@ QSharedPointer<KFilePlacesModel> JobPrivate::createPlacesModel()
return s_instance.toStrongRef();
}
QUrl JobPrivate::localFileOrUrl(const QString &urlString)
{
QUrl url(urlString);
if (url.scheme().isEmpty()) {
url = QUrl::fromLocalFile(urlString);
}
return url;
}
// Tries to return a more user-friendly displayed destination
// - if it is a place, show the name, e.g. "Downloads"
// - if it is inside home, abbreviate that to tilde ~/foo
......@@ -82,7 +91,7 @@ QString JobPrivate::prettyDestUrl() const
QUrl url = m_destUrl;
// In case of a single file and no destUrl, try using the second label (most likely "Destination")...
if (!url.isValid() && m_totalFiles == 1) {
url = QUrl::fromUserInput(m_descriptionValue2, QString(), QUrl::AssumeLocalFile).adjusted(QUrl::RemoveFilename);
url = localFileOrUrl(m_descriptionValue2).adjusted(QUrl::RemoveFilename);
}
if (!url.isValid()) {
......@@ -193,9 +202,9 @@ QString JobPrivate::text() const
QUrl JobPrivate::descriptionUrl() const
{
QUrl url = QUrl::fromUserInput(m_descriptionValue2, QString(), QUrl::AssumeLocalFile);
QUrl url = localFileOrUrl(m_descriptionValue2);
if (!url.isValid()) {
url = QUrl::fromUserInput(m_descriptionValue1, QString(), QUrl::AssumeLocalFile);
url = localFileOrUrl(m_descriptionValue1);
}
return url;
}
......
......@@ -97,6 +97,8 @@ private:
static QSharedPointer<KFilePlacesModel> createPlacesModel();
static QUrl localFileOrUrl(const QString &stringUrl);
QString prettyDestUrl() const;
void updateHasDetails();
......
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