| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2013 David Faure <faure@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 | */ |
| 6 | |
| 7 | #ifndef KIO_DESKTOPEXECPARSER_H |
| 8 | #define KIO_DESKTOPEXECPARSER_H |
| 9 | |
| 10 | #include "kiocore_export.h" |
| 11 | |
| 12 | #include <QList> |
| 13 | #include <QScopedPointer> |
| 14 | #include <QStringList> |
| 15 | |
| 16 | class QUrl; |
| 17 | class KService; |
| 18 | |
| 19 | namespace KIO |
| 20 | { |
| 21 | class DesktopExecParserPrivate; |
| 22 | |
| 23 | /*! |
| 24 | * \class KIO::DesktopExecParser |
| 25 | * \inheaderfile KIO/DesktopExecParser |
| 26 | * \inmodule KIOCore |
| 27 | * |
| 28 | * \brief Parses the Exec= line from a .desktop file, |
| 29 | * and process all the '\%' placeholders, e.g.\ handling URLs vs local files. |
| 30 | * |
| 31 | * The processing actually happens when calling resultingArguments(), after |
| 32 | * setting everything up. |
| 33 | * |
| 34 | * \since 5.0 |
| 35 | */ |
| 36 | class KIOCORE_EXPORT DesktopExecParser |
| 37 | { |
| 38 | public: |
| 39 | /*! |
| 40 | * Creates a parser for a desktop file Exec line. |
| 41 | * |
| 42 | * \a service the service to extract information from. |
| 43 | * The KService instance must remain alive as long as the parser is alive. |
| 44 | * |
| 45 | * \a urls The urls the service should open. |
| 46 | */ |
| 47 | DesktopExecParser(const KService &service, const QList<QUrl> &urls); |
| 48 | |
| 49 | ~DesktopExecParser(); |
| 50 | |
| 51 | /*! |
| 52 | * If \a tempFiles is set to true and the urls given to the constructor are local files, |
| 53 | * they will be deleted when the application exits. |
| 54 | */ |
| 55 | void setUrlsAreTempFiles(bool tempFiles); |
| 56 | |
| 57 | /*! |
| 58 | * Sets the file name to use in the case of downloading the file to a tempfile |
| 59 | * in order to give to a non-url-aware application. Some apps rely on the extension |
| 60 | * to determine the MIME type of the file. Usually the file name comes from the URL, |
| 61 | * but in the case of the HTTP Content-Disposition header, we need to override the |
| 62 | * file name. |
| 63 | */ |
| 64 | void setSuggestedFileName(const QString &suggestedFileName); |
| 65 | |
| 66 | /*! |
| 67 | * Returns a list of arguments suitable for QProcess. |
| 68 | * Returns an empty list on error, check errorMessage() for details. |
| 69 | */ |
| 70 | QStringList resultingArguments() const; |
| 71 | |
| 72 | /*! |
| 73 | * Returns an error message for when resultingArguments() returns an empty list |
| 74 | * \since 5.71 |
| 75 | */ |
| 76 | QString errorMessage() const; |
| 77 | |
| 78 | /*! |
| 79 | * Returns the list of protocols which the application \a service supports. |
| 80 | * This can be a list of actual protocol names, or just "KIO" for KIO-based apps. |
| 81 | */ |
| 82 | static QStringList supportedProtocols(const KService &service); |
| 83 | |
| 84 | /*! |
| 85 | * Returns true if \a protocol is in the list of protocols returned by supportedProtocols(). |
| 86 | * The only reason for this method is the special handling of "KIO". |
| 87 | */ |
| 88 | static bool isProtocolInSupportedList(const QUrl &url, const QStringList &supportedProtocols); |
| 89 | |
| 90 | /*! |
| 91 | * Returns true if \a protocol should be opened by a "handler" application, i.e.\ an application |
| 92 | * associated to _all_ URLs using this protocol (a.k.a. scheme). |
| 93 | */ |
| 94 | static bool hasSchemeHandler(const QUrl &url); // KF6 TODO move to OpenUrlJob |
| 95 | |
| 96 | /*! |
| 97 | * Given a full command line (e.g.\ the Exec= line from a .desktop file), |
| 98 | * extract the name of the executable being run (removing the path, if specified). |
| 99 | * |
| 100 | * \a execLine the full command line |
| 101 | * |
| 102 | * Returns the name of the executable to run, example: "ls" |
| 103 | */ |
| 104 | static QString executableName(const QString &execLine); |
| 105 | |
| 106 | /*! |
| 107 | * Given a full command line (e.g.\ the Exec= line from a .desktop file), |
| 108 | * extract the name of the executable being run, including its full path, if specified. |
| 109 | * |
| 110 | * \a execLine the full command line |
| 111 | * |
| 112 | * Returns the name of the executable to run, example: "/bin/ls" |
| 113 | */ |
| 114 | static QString executablePath(const QString &execLine); |
| 115 | |
| 116 | private: |
| 117 | QScopedPointer<DesktopExecParserPrivate> d; |
| 118 | }; |
| 119 | |
| 120 | } // namespace KIO |
| 121 | |
| 122 | #endif |
| 123 | |