Expand ENV variables before displaying results

Before the variables would get expanded later and consequently
go through another code path than file locations. This leads to the
text being differently displayed and users getting confused.

Also this allows us to check if the file actually exists.

BUG: 358221
FIXED-IN: 5.21
wilder-5.22
Alexander Lohnau 5 years ago
parent 323b94e49e
commit 736218793a
  1. 22
      runners/locations/locationrunner.cpp

@ -53,29 +53,23 @@ LocationsRunner::~LocationsRunner()
void LocationsRunner::match(Plasma::RunnerContext &context) void LocationsRunner::match(Plasma::RunnerContext &context)
{ {
QString term = context.query(); QString term = context.query();
QUrl url(term); // We want to expand ENV variables like $HOME to get the actual path, BUG: 358221
const bool isLocalFile = url.isLocalFile(); KUriFilter::self()->filterUri(term, {QStringLiteral("kshorturifilter")});
const QFileInfo fileInfo = QFileInfo(isLocalFile ? url.toLocalFile() : KShell::tildeExpand(term)); const QUrl url(term);
// The uri filter takes care of the shell expansion
const QFileInfo fileInfo = QFileInfo(url.toLocalFile());
if (fileInfo.exists()) { if (fileInfo.exists()) {
Plasma::QueryMatch match(this); Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::ExactMatch); match.setType(Plasma::QueryMatch::ExactMatch);
match.setText(i18n("Open %1", term)); match.setText(i18n("Open %1", context.query()));
match.setIconName(fileInfo.isFile() ? KIO::iconNameForUrl(url) : QStringLiteral("system-file-manager")); match.setIconName(fileInfo.isFile() ? KIO::iconNameForUrl(url) : QStringLiteral("system-file-manager"));
match.setRelevance(1); match.setRelevance(1);
match.setData(isLocalFile ? url : QUrl::fromLocalFile(fileInfo.absoluteFilePath())); match.setData(url);
match.setType(Plasma::QueryMatch::ExactMatch); match.setType(Plasma::QueryMatch::ExactMatch);
context.addMatch(match); context.addMatch(match);
} else if (!isLocalFile && !url.isEmpty()) { } else if (!url.isLocalFile() && !url.isEmpty() && !url.scheme().isEmpty()) {
if (!KUriFilter::self()->filterUri(term, {QStringLiteral("kshorturifilter")})) {
return;
}
url = QUrl(term); // The KUriFilter changed the term
if (url.scheme().isEmpty() || url.isLocalFile()) { // We handled existend files above
return;
}
const QString protocol = url.scheme(); const QString protocol = url.scheme();
Plasma::QueryMatch match(this); Plasma::QueryMatch match(this);
match.setData(url); match.setData(url);

Loading…
Cancel
Save