Skip to content

Commit

Permalink
External all cli (flameshot-org#2752)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
(cherry picked from commit 822d2a5)
  • Loading branch information
borgmanJeremy authored and Yuriy Puchkov committed Sep 9, 2022
1 parent ae7814a commit 270e2dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/tools/launcher/applauncherwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion src/utils/desktopfileparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 270e2dd

Please sign in to comment.