[PATCH] Fix selecting binaries from component chooser KCM
authorDavid Edmundson <kde@davidedmundson.co.uk>
Wed, 14 Jul 2021 16:06:59 +0000 (17:06 +0100)
committerNorbert Preining <norbert@preining.info>
Thu, 15 Jul 2021 01:20:01 +0000 (02:20 +0100)
In the kcmshell for a component chooser we use the open with dialog to
select services for various scheme handlers.

If you select a binary instead of a .desktop file a temporary .desktop
file is created in ~/.local/share/applications

This is in the format
Exec=someBinary
MimeType=x-scheme-handler/http

When we then use this application for launching KIO::DesktopExecParser
then (sort of correctly) determines that that the chosen service cannot
handle the http scheme because even though it is a scheme handler it
does not have a "%u" in the exec line.

This leads to us potentially loading websites via kioclient or kio-fuse.

Testing done:
 - kcmshell5 component chooser
 - web browser -> other -> type "/usr/bin/firefox"
 - kde-open5 http://kde.org
 - Previously this gave a local URL, now it is correct

Gbp-Pq: Name upstream-8ad69215-fix-selecting-binaries-from-components.patch

src/widgets/kopenwithdialog.cpp

index 8d82f0a2eb36082957f282fbc0e83ee569350308..bfc65359571e35b10a08d607db47112cde537e67 100644 (file)
@@ -1070,6 +1070,14 @@ bool KOpenWithDialogPrivate::checkAccept()
             KConfigGroup cg = desktopFile.desktopGroup();
             cg.writeEntry("Type", "Application");
             cg.writeEntry("Name", initialServiceName);
+
+            // if we select a binary for a scheme handler, then it's safe to assume it can handle URLs
+            if (qMimeType.startsWith(QLatin1String("x-scheme-handler/"))) {
+                if (!typedExec.contains(QLatin1String("%u"), Qt::CaseInsensitive) && !typedExec.contains(QLatin1String("%f"), Qt::CaseInsensitive)) {
+                    fullExec += QStringLiteral(" %u");
+                }
+            }
+
             cg.writeEntry("Exec", fullExec);
             cg.writeEntry("NoDisplay", true); // don't make it appear in the K menu
             if (terminal->isChecked()) {