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
wilder-5.19
Kai Uwe Broulik 7 years ago
parent 1e175254dd
commit d38d7df3e1
  1. 15
      libnotificationmanager/job_p.cpp
  2. 2
      libnotificationmanager/job_p.h

@ -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();

Loading…
Cancel
Save