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
16class QUrl;
17class KService;
18
19namespace KIO
20{
21class DesktopExecParserPrivate;
22
23/**
24 * @class KIO::DesktopExecParser desktopexecparser.h <KIO/DesktopExecParser>
25 *
26 * Parses the Exec= line from a .desktop file,
27 * and process all the '\%' placeholders, e.g.\ handling URLs vs local files.
28 *
29 * The processing actually happens when calling resultingArguments(), after
30 * setting everything up.
31 *
32 * @since 5.0
33 */
34class KIOCORE_EXPORT DesktopExecParser
35{
36public:
37 /**
38 * Creates a parser for a desktop file Exec line.
39 *
40 * @param service the service to extract information from.
41 * The KService instance must remain alive as long as the parser is alive.
42 * @param urls The urls the service should open.
43 */
44 DesktopExecParser(const KService &service, const QList<QUrl> &urls);
45
46 /**
47 * Destructor
48 */
49 ~DesktopExecParser();
50
51 /**
52 * If @p 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 * @return 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 * @return 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 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 @p 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 @p 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 * @param execLine the full command line
100 * @return the name of the executable to run, example: "ls"
101 */
102 static QString executableName(const QString &execLine);
103
104 /**
105 * Given a full command line (e.g.\ the Exec= line from a .desktop file),
106 * extract the name of the executable being run, including its full path, if specified.
107 * @param execLine the full command line
108 * @return the name of the executable to run, example: "/bin/ls"
109 */
110 static QString executablePath(const QString &execLine);
111
112private:
113 QScopedPointer<DesktopExecParserPrivate> d;
114};
115
116} // namespace KIO
117
118#endif
119

source code of kio/src/core/desktopexecparser.h