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 <al.williams@awce.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user