From 9883f381e688c73b1aff179fd60e28fa63eb7fa3 Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Thu, 3 Nov 2022 11:55:50 -0500 Subject: [PATCH 01/11] Add environment variables support to kpropertiesdialog --- .gitignore | 1 + src/widgets/kpropertiesdesktopbase.ui | 23 ++++++++++++++++++----- src/widgets/kpropertiesdialog.cpp | 13 ++++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d84c8172d..2396b4157 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ CMakeLists.txt.user* .idea /cmake-build* .cache +.vscode diff --git a/src/widgets/kpropertiesdesktopbase.ui b/src/widgets/kpropertiesdesktopbase.ui index a87a4ca0d..461563dc4 100644 --- a/src/widgets/kpropertiesdesktopbase.ui +++ b/src/widgets/kpropertiesdesktopbase.ui @@ -77,6 +77,19 @@ + + + Environment Variables: + + + envarsEdit + + + + + + + Type the command to start this application here. @@ -99,7 +112,7 @@ Following the command, you can have several placeholders which will be replaced - + @@ -130,7 +143,7 @@ Following the command, you can have several placeholders which will be replaced - + Sets the working directory for your application. @@ -143,21 +156,21 @@ Following the command, you can have several placeholders which will be replaced - + Sets the working directory for your application. - + Arguments: - + diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index abd79163c..c2315eb0e 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3305,6 +3305,7 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) connect(d->w->nameEdit, &QLineEdit::textChanged, this, &KPropertiesDialogPlugin::changed); connect(d->w->genNameEdit, &QLineEdit::textChanged, this, &KPropertiesDialogPlugin::changed); connect(d->w->commentEdit, &QLineEdit::textChanged, this, &KPropertiesDialogPlugin::changed); + connect(d->w->envarsEdit, &QLineEdit::textChanged, this, &KPropertiesDialogPlugin::changed); connect(d->w->programEdit, &QLineEdit::textChanged, this, &KPropertiesDialogPlugin::changed); connect(d->w->argumentsEdit, &QLineEdit::textChanged, this, &KPropertiesDialogPlugin::changed); connect(d->w->pathEdit, &KUrlRequester::textChanged, this, &KPropertiesDialogPlugin::changed); @@ -3397,13 +3398,23 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) d->w->commentEdit->setText(commentStr); QStringList execLine = KShell::splitArgs(commandStr); + QStringList envars = {}; if (!execLine.isEmpty()) { + foreach (const QString &env, execLine) { + if (env.contains(QLatin1String("="))) { + enVars += env; + execLine.pop_front(); + } else { + break; + } + } d->w->programEdit->setText(execLine.takeFirst()); } else { d->w->programEdit->clear(); } d->w->argumentsEdit->setText(KShell::joinArgs(execLine)); + d->w->envarsEdit->setText(KShell::joinArgs(envars)); d->w->pathEdit->lineEdit()->setText(pathStr); @@ -3742,7 +3753,7 @@ bool KDesktopPropsPlugin::supports(const KFileItemList &_items) QString KDesktopPropsPlugin::KDesktopPropsPluginPrivate::command() const { - QStringList execSplit = QStringList(w->programEdit->text()) + KShell::splitArgs(w->argumentsEdit->text()); + QStringList execSplit = KShell::splitArgs(w->envarsEdit->text()) + QStringList(w->programEdit->text()) + KShell::splitArgs(w->argumentsEdit->text()); return KShell::joinArgs(execSplit); } -- GitLab From 6405b1a1492355fa9dba7883ccfda75e0fab6e7e Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Fri, 4 Nov 2022 10:22:35 -0500 Subject: [PATCH 02/11] Remove unrelated change --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2396b4157..d84c8172d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,3 @@ CMakeLists.txt.user* .idea /cmake-build* .cache -.vscode -- GitLab From c7dcc7991c872df550dbe62827ed7ba3da5d222b Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Fri, 4 Nov 2022 11:32:45 -0500 Subject: [PATCH 03/11] Use c++ style ranged loop instead of deprecated Qt foreach statement --- .vscode/c_cpp_properties.json | 17 +++++++++++++++++ src/widgets/kpropertiesdialog.cpp | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 000000000..a268581e3 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/usr/include/**" + ], + "defines": [], + "compilerPath": "/usr/bin/g++", + "cStandard": "c17", + "cppStandard": "c++14", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index c2315eb0e..0d8b22558 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3401,7 +3401,7 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) QStringList envars = {}; if (!execLine.isEmpty()) { - foreach (const QString &env, execLine) { + for (auto env : execLine) { if (env.contains(QLatin1String("="))) { enVars += env; execLine.pop_front(); -- GitLab From 7665c3d9dc71a570f4996d8f981e38614a745332 Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Fri, 4 Nov 2022 12:31:28 -0500 Subject: [PATCH 04/11] Add an additional check for the env executable. Also need to consider if there are other ways of setting environment variables. --- src/widgets/kpropertiesdialog.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index 0d8b22558..3de74423a 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3398,9 +3398,15 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) d->w->commentEdit->setText(commentStr); QStringList execLine = KShell::splitArgs(commandStr); - QStringList envars = {}; + QStringList enVars = {}; if (!execLine.isEmpty()) { + // check for apps that use the env executable + // to set the environment + if (execLine[0] == QLatin1String("env")) { + enVars += execLine[0]; + execLine.pop_front(); + } for (auto env : execLine) { if (env.contains(QLatin1String("="))) { enVars += env; @@ -3414,7 +3420,7 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) d->w->programEdit->clear(); } d->w->argumentsEdit->setText(KShell::joinArgs(execLine)); - d->w->envarsEdit->setText(KShell::joinArgs(envars)); + d->w->envarsEdit->setText(KShell::joinArgs(enVars)); d->w->pathEdit->lineEdit()->setText(pathStr); -- GitLab From 0c9d82208963e296d9a51e172e5ef072dfac99c7 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Mon, 7 Nov 2022 16:28:56 +0000 Subject: [PATCH 05/11] Apply early break to reduce level of nesting. --- src/widgets/kpropertiesdialog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index 3de74423a..62899ce21 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3408,12 +3408,12 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) execLine.pop_front(); } for (auto env : execLine) { - if (env.contains(QLatin1String("="))) { - enVars += env; - execLine.pop_front(); - } else { + if (!env.contains(QLatin1String("="))) { break; } + + enVars += env; + execLine.pop_front(); } d->w->programEdit->setText(execLine.takeFirst()); } else { -- GitLab From 31bc89ca8b6c53c16af200029a41202450d3c032 Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Mon, 7 Nov 2022 10:39:28 -0600 Subject: [PATCH 06/11] Remove accidentally added file --- .vscode/c_cpp_properties.json | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index a268581e3..000000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**", - "/usr/include/**" - ], - "defines": [], - "compilerPath": "/usr/bin/g++", - "cStandard": "c17", - "cppStandard": "c++14", - "intelliSenseMode": "linux-gcc-x64" - } - ], - "version": 4 -} \ No newline at end of file -- GitLab From 5734d59b3cf99ec3ce5838bf086df2ba6527c5b7 Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Mon, 7 Nov 2022 11:16:17 -0600 Subject: [PATCH 07/11] Revert "Apply early break to reduce level of nesting." This reverts commit 6c130e03746af82e7df4a9e64360528f71f46e3e. Reverting this because it is redundant and causes us to exit the application. --- src/widgets/kpropertiesdialog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index 62899ce21..3de74423a 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3408,12 +3408,12 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) execLine.pop_front(); } for (auto env : execLine) { - if (!env.contains(QLatin1String("="))) { + if (env.contains(QLatin1String("="))) { + enVars += env; + execLine.pop_front(); + } else { break; } - - enVars += env; - execLine.pop_front(); } d->w->programEdit->setText(execLine.takeFirst()); } else { -- GitLab From b78978b53ed82db7fb6d7cfa30f5c37fa275ae7d Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Mon, 7 Nov 2022 12:13:33 -0600 Subject: [PATCH 08/11] Reapply Nate's suggestion without the additonal execLine.pop_front() call. --- src/widgets/kpropertiesdialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index 3de74423a..d4fa0c453 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3414,6 +3414,9 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) } else { break; } + if (!env.contains(QLatin1String("="))) { + break; + } } d->w->programEdit->setText(execLine.takeFirst()); } else { -- GitLab From 9a919dcf8b2f430c854403646da8fa9d1a3c0d7f Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Tue, 8 Nov 2022 10:36:09 -0600 Subject: [PATCH 09/11] Remove redundant code --- src/widgets/kpropertiesdialog.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index d4fa0c453..e35f9c293 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3408,16 +3408,13 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) execLine.pop_front(); } for (auto env : execLine) { - if (env.contains(QLatin1String("="))) { - enVars += env; - execLine.pop_front(); - } else { - break; - } if (!env.contains(QLatin1String("="))) { break; } + enVars += env; + execLine.pop_front(); } + d->w->programEdit->setText(execLine.takeFirst()); } else { d->w->programEdit->clear(); -- GitLab From 903e8b3a7cb21c3c03dd91c9590665581c087772 Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Tue, 8 Nov 2022 13:11:51 -0600 Subject: [PATCH 10/11] Hide 'env' program name and add it only when writing to a file --- src/widgets/kpropertiesdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index e35f9c293..fd81c047e 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3404,7 +3404,6 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *_props) // check for apps that use the env executable // to set the environment if (execLine[0] == QLatin1String("env")) { - enVars += execLine[0]; execLine.pop_front(); } for (auto env : execLine) { @@ -3760,6 +3759,7 @@ bool KDesktopPropsPlugin::supports(const KFileItemList &_items) QString KDesktopPropsPlugin::KDesktopPropsPluginPrivate::command() const { QStringList execSplit = KShell::splitArgs(w->envarsEdit->text()) + QStringList(w->programEdit->text()) + KShell::splitArgs(w->argumentsEdit->text()); + execSplit.push_front(QLatin1String("env")); return KShell::joinArgs(execSplit); } -- GitLab From 638fbd70d97fe79894ac0d18300f45b8e1502bb4 Mon Sep 17 00:00:00 2001 From: Dashon Wells Date: Wed, 9 Nov 2022 11:07:06 -0600 Subject: [PATCH 11/11] Make sure we are handleing the case of removing environment variables. --- src/widgets/kpropertiesdialog.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/widgets/kpropertiesdialog.cpp b/src/widgets/kpropertiesdialog.cpp index fd81c047e..88ecf0de4 100644 --- a/src/widgets/kpropertiesdialog.cpp +++ b/src/widgets/kpropertiesdialog.cpp @@ -3759,7 +3759,11 @@ bool KDesktopPropsPlugin::supports(const KFileItemList &_items) QString KDesktopPropsPlugin::KDesktopPropsPluginPrivate::command() const { QStringList execSplit = KShell::splitArgs(w->envarsEdit->text()) + QStringList(w->programEdit->text()) + KShell::splitArgs(w->argumentsEdit->text()); - execSplit.push_front(QLatin1String("env")); + + if (KShell::splitArgs(w->envarsEdit->text()).length()) { + execSplit.push_front(QLatin1String("env")); + } + return KShell::joinArgs(execSplit); } -- GitLab