| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef PROCESSCALLER_H |
| 6 | #define PROCESSCALLER_H |
| 7 | |
| 8 | #include <QString> |
| 9 | #include <QProcess> |
| 10 | #include <QByteArray> |
| 11 | |
| 12 | #include <functional> |
| 13 | |
| 14 | class ProcessUtil final |
| 15 | { |
| 16 | Q_DISABLE_COPY(ProcessUtil) |
| 17 | ProcessUtil() = delete; |
| 18 | public: |
| 19 | typedef std::function<void(int, QProcess::ExitStatus)> FinishedCallBack; |
| 20 | typedef std::function<void(const QByteArray &)> ReadCallBack; |
| 21 | static bool execute(const QString &program, |
| 22 | const QStringList &arguments, |
| 23 | ReadCallBack func = nullptr); |
| 24 | |
| 25 | static bool execute(const QString &program, |
| 26 | const QStringList &arguments, |
| 27 | const QString &workdir, |
| 28 | ReadCallBack func = nullptr); |
| 29 | |
| 30 | static bool execute(const QString &program, |
| 31 | const QStringList &arguments, |
| 32 | const QString &workdir, |
| 33 | const QProcessEnvironment &env, |
| 34 | ReadCallBack func = nullptr); |
| 35 | |
| 36 | static QString execute(const QStringList &commands, bool cascade); |
| 37 | |
| 38 | static bool exists(const QString &name); |
| 39 | static QString version(const QString &name); |
| 40 | |
| 41 | static bool hasGio(); |
| 42 | static bool moveToTrash(const QString &filePath); |
| 43 | static bool recoverFromTrash(const QString &filePath); |
| 44 | static bool portOverhead(unsigned int port); |
| 45 | static QString localPlatform(); |
| 46 | }; |
| 47 | #endif // PROCESSCALLER_H |
| 48 | |