From 822d2a5eeec43346386a58707016ae0e0acf02fc Mon Sep 17 00:00:00 2001 From: borgmanJeremy <46930769+borgmanJeremy@users.noreply.github.com> Date: Sun, 3 Jul 2022 08:34:51 -0500 Subject: [PATCH] External all cli (#2752) * Properly constructs external app command line * DesktopFileParser only reads .desktop files * Replace % in AppLauncherWidget in array not string * applied clang-format Co-authored-by: Al Williams --- src/tools/launcher/applauncherwidget.cpp | 24 ++++++++++++++++++------ src/utils/desktopfileparse.cpp | 8 +++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/tools/launcher/applauncherwidget.cpp b/src/tools/launcher/applauncherwidget.cpp index 0e3a472a..d348b1c9 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 7e6fec8b..e095ded0 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) {