1// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
2// SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
3
4#ifndef KSANDBOX_H
5#define KSANDBOX_H
6
7#include <QProcess>
8
9#include <kcoreaddons_export.h>
10
11/*!
12 * \namespace KSandbox
13 * \inmodule KCoreAddons
14 * \brief Utility functions for use inside application sandboxes such as flatpak or snap.
15 * \since 5.95
16 */
17namespace KSandbox
18{
19
20/*!
21 * Returns whether the application is inside one of the supported sandboxes
22 */
23KCOREADDONS_EXPORT bool isInside();
24
25/*!
26 * Returns whether the application is inside a flatpak sandbox
27 */
28KCOREADDONS_EXPORT bool isFlatpak();
29
30/*!
31 * Returns whether the application is inside a snap sandbox
32 */
33KCOREADDONS_EXPORT bool isSnap();
34
35/*!
36 * \struct KSandbox::ProcessContext
37 * \brief Container for host process startup context.
38 * \since 5.97
39 */
40struct ProcessContext {
41 /*!
42 * \variable KSandbox::ProcessContext::program
43 * the program
44 */
45 const QString program;
46
47 /*!
48 * \variable KSandbox::ProcessContext::arguments
49 * the arguments
50 */
51 const QStringList arguments;
52};
53
54/*!
55 * Returns the actual program and arguments for running the QProcess on the host (e.g. a flatpak-spawn-wrapped argument list)
56 * \since 5.97
57 */
58KCOREADDONS_EXPORT KSandbox::ProcessContext makeHostContext(const QProcess &process);
59
60/*!
61 * Starts the QProcess on the host (if the current context is inside a sandbox, otherwise it simply runs QProcess::start)
62 * \since 5.97
63 */
64KCOREADDONS_EXPORT void startHostProcess(QProcess &process, QProcess::OpenMode mode = QProcess::ReadWrite);
65
66} // namespace KSandbox
67
68#endif // KSANDBOX_H
69

source code of kcoreaddons/src/lib/util/ksandbox.h