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 * @brief Utility functions for use inside application sandboxes such as flatpak or snap.
13 * @since 5.95
14 */
15namespace KSandbox
16{
17
18/// @returns whether the application is inside one of the supported sandboxes
19KCOREADDONS_EXPORT bool isInside();
20
21/// @returns whether the application is inside a flatpak sandbox
22KCOREADDONS_EXPORT bool isFlatpak();
23
24/// @returns whether the application is inside a snap sandbox
25KCOREADDONS_EXPORT bool isSnap();
26
27/**
28 * @brief Container for host process startup context
29 * @since 5.97
30 */
31struct ProcessContext {
32 const QString program;
33 const QStringList arguments;
34};
35
36/**
37 * @returns the actual program and arguments for running the QProcess on the host (e.g. a flatpak-spawn-wrapped argument list)
38 * @since 5.97
39 */
40KCOREADDONS_EXPORT KSandbox::ProcessContext makeHostContext(const QProcess &process);
41
42/**
43 * Starts the QProcess on the host (if the current context is inside a sandbox, otherwise it simply runs QProcess::start)
44 * @since 5.97
45 */
46KCOREADDONS_EXPORT void startHostProcess(QProcess &process, QProcess::OpenMode mode = QProcess::ReadWrite);
47
48} // namespace KSandbox
49
50#endif // KSANDBOX_H
51

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