File indexing completed on 2024-05-19 03:56:25

0001 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0002 // SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0003 
0004 #ifndef KSANDBOX_H
0005 #define KSANDBOX_H
0006 
0007 #include <QProcess>
0008 
0009 #include <kcoreaddons_export.h>
0010 
0011 /**
0012  * @brief Utility functions for use inside application sandboxes such as flatpak or snap.
0013  * @since 5.95
0014  */
0015 namespace KSandbox
0016 {
0017 
0018 /// @returns whether the application is inside one of the supported sandboxes
0019 KCOREADDONS_EXPORT bool isInside();
0020 
0021 /// @returns whether the application is inside a flatpak sandbox
0022 KCOREADDONS_EXPORT bool isFlatpak();
0023 
0024 /// @returns whether the application is inside a snap sandbox
0025 KCOREADDONS_EXPORT bool isSnap();
0026 
0027 /**
0028  * @brief Container for host process startup context
0029  * @since 5.97
0030  */
0031 struct ProcessContext {
0032     const QString program;
0033     const QStringList arguments;
0034 };
0035 
0036 /**
0037  * @returns the actual program and arguments for running the QProcess on the host (e.g. a flatpak-spawn-wrapped argument list)
0038  * @since 5.97
0039  */
0040 KCOREADDONS_EXPORT KSandbox::ProcessContext makeHostContext(const QProcess &process);
0041 
0042 /**
0043  * Starts the QProcess on the host (if the current context is inside a sandbox, otherwise it simply runs QProcess::start)
0044  * @since 5.97
0045  */
0046 KCOREADDONS_EXPORT void startHostProcess(QProcess &process, QProcess::OpenMode mode = QProcess::ReadWrite);
0047 
0048 } // namespace KSandbox
0049 
0050 #endif // KSANDBOX_H