Commit 73621879 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

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
parent 323b94e4
......@@ -53,29 +53,23 @@ LocationsRunner::~LocationsRunner()
void LocationsRunner::match(Plasma::RunnerContext &context)
QString term = context.query();
QUrl url(term);
const bool isLocalFile = url.isLocalFile();
const QFileInfo fileInfo = QFileInfo(isLocalFile ? url.toLocalFile() : KShell::tildeExpand(term));
// We want to expand ENV variables like $HOME to get the actual path, BUG: 358221
KUriFilter::self()->filterUri(term, {QStringLiteral("kshorturifilter")});
const QUrl url(term);
// The uri filter takes care of the shell expansion
const QFileInfo fileInfo = QFileInfo(url.toLocalFile());
if (fileInfo.exists()) {
Plasma::QueryMatch match(this);
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.setData(isLocalFile ? url : QUrl::fromLocalFile(fileInfo.absoluteFilePath()));
} else if (!isLocalFile && !url.isEmpty()) {
if (!KUriFilter::self()->filterUri(term, {QStringLiteral("kshorturifilter")})) {
url = QUrl(term); // The KUriFilter changed the term
if (url.scheme().isEmpty() || url.isLocalFile()) { // We handled existend files above
} else if (!url.isLocalFile() && !url.isEmpty() && !url.scheme().isEmpty()) {
const QString protocol = url.scheme();
Plasma::QueryMatch match(this);
Supports Markdown
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