diff --git a/src/tools/launcher/applauncherwidget.cpp b/src/tools/launcher/applauncherwidget.cpp index 0e3a472a67..d348b1c92c 100644 --- a/src/tools/launcher/applauncherwidget.cpp +++ b/src/tools/launcher/applauncherwidget.cpp @@ -96,11 +96,22 @@ void AppLauncherWidget::launch(const QModelIndex& index) return; } } - QString command = index.data(Qt::UserRole) - .toString() - .replace(QRegExp("(\\%.)"), '"' + m_tempFile + '"'); - - QString app_name = index.data(Qt::UserRole).toString().split(" ").at(0); + // Heuristically, if there is a % in the command we assume it is the file + // name slot + QString command = index.data(Qt::UserRole).toString(); + QStringList prog_args = command.split(" "); + // no quotes because it is going in an array! + if (command.contains("%")) { + // but that means we need to substitute IN the array not the string! + for (auto& i : prog_args) { + if (i.contains("%")) + i.replace(QRegExp("(\\%.)"), m_tempFile); + } + } else { + // we really should append the file name if there + prog_args.append(m_tempFile); // were no replacements + } + QString app_name = prog_args.at(0); bool inTerminal = index.data(Qt::UserRole + 1).toBool() || m_terminalCheckbox->isChecked(); if (inTerminal) { @@ -110,7 +121,8 @@ void AppLauncherWidget::launch(const QModelIndex& index) this, tr("Error"), tr("Unable to launch in terminal.")); } } else { - QProcess::startDetached(app_name, { m_tempFile }); + prog_args.removeAt(0); // strip program name out + QProcess::startDetached(app_name, prog_args); } if (!m_keepOpen) { close(); diff --git a/src/utils/desktopfileparse.cpp b/src/utils/desktopfileparse.cpp index 7e6fec8bd7..e095ded0f8 100644 --- a/src/utils/desktopfileparse.cpp +++ b/src/utils/desktopfileparse.cpp @@ -100,7 +100,13 @@ DesktopAppData DesktopFileParser::parseDesktopFile(const QString& fileName, int DesktopFileParser::processDirectory(const QDir& dir) { - QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files); + // Note that + // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html + // says files must end in .desktop or .directory + // So filtering by .desktop stops us reading things like editor backups + // .kdelnk is long deprecated + QStringList entries = + dir.entryList({ "*.desktop" }, QDir::NoDotAndDotDot | QDir::Files); bool ok; int length = m_appList.length(); for (QString file : entries) {