QtPass 1.7.0
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
executor.h
1// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
3#ifndef SRC_EXECUTOR_H_
4#define SRC_EXECUTOR_H_
5
6#include <QObject>
7#include <QProcess>
8#include <QQueue>
9
19
20class Executor : public QObject {
21 Q_OBJECT
22
27 struct execQueueItem {
31 int id;
35 QString app;
39 QStringList args;
43 QString input;
47 bool readStdout;
53 bool readStderr;
58 QString workingDir;
59 };
60
61 QQueue<execQueueItem> m_execQueue;
62 QProcess m_process;
63 bool running;
64 void executeNext();
65 void startProcess(const QString &app, const QStringList &args);
66 static void startProcessBlocking(QProcess &internal, const QString &app,
67 const QStringList &args);
68
69public:
74 explicit Executor(QObject *parent = nullptr);
75
84 void execute(int id, const QString &app, const QStringList &args,
85 bool readStdout, bool readStderr = true);
86
96 void execute(int id, const QString &workDir, const QString &app,
97 const QStringList &args, bool readStdout,
98 bool readStderr = true);
99
109 void execute(int id, const QString &app, const QStringList &args,
110 QString input = QString(), bool readStdout = false,
111 bool readStderr = true);
112
123 void execute(int id, const QString &workDir, const QString &app,
124 const QStringList &args, QString input = QString(),
125 bool readStdout = false, bool readStderr = true);
126
136 static auto executeBlocking(const QString &app, const QStringList &args,
137 const QString &input = QString(),
138 QString *process_out = nullptr,
139 QString *process_err = nullptr) -> int;
140
149 static auto executeBlocking(const QString &app, const QStringList &args,
150 QString *process_out,
151 QString *process_err = nullptr) -> int;
152
162 static auto executeBlocking(const QStringList &env, const QString &app,
163 const QStringList &args,
164 QString *process_out = nullptr,
165 QString *process_err = nullptr) -> int;
166
171 void setEnvironment(const QStringList &env);
176 auto environment() const -> QStringList;
177
182 auto cancelNext() -> int;
183private slots:
184 void finished(int exitCode, QProcess::ExitStatus exitStatus);
185signals:
194 void finished(int id, int exitCode, const QString &output,
195 const QString &errout);
199 void starting();
209 void error(int id, int exitCode, const QString &output,
210 const QString &errout);
211};
212
213#endif // SRC_EXECUTOR_H_
static auto executeBlocking(const QStringList &env, const QString &app, const QStringList &args, QString *process_out=nullptr, QString *process_err=nullptr) -> int
Run a command synchronously with a custom environment.
void execute(int id, const QString &workDir, const QString &app, const QStringList &args, bool readStdout, bool readStderr=true)
Queue a command with an explicit working directory.
auto environment() const -> QStringList
Return the environment passed to child processes.
void execute(int id, const QString &app, const QStringList &args, bool readStdout, bool readStderr=true)
Queue a command without stdin input.
void error(int id, int exitCode, const QString &output, const QString &errout)
error signal that is emited when process finishes with an error
Executor(QObject *parent=nullptr)
Construct an Executor with an optional parent QObject.
void setEnvironment(const QStringList &env)
Set the environment passed to all child processes.
static auto executeBlocking(const QString &app, const QStringList &args, const QString &input=QString(), QString *process_out=nullptr, QString *process_err=nullptr) -> int
Run a command synchronously and return its exit code.
void starting()
starting signal that is emited when process starts
static auto executeBlocking(const QString &app, const QStringList &args, QString *process_out, QString *process_err=nullptr) -> int
Run a command synchronously capturing stdout and stderr.
void execute(int id, const QString &app, const QStringList &args, QString input=QString(), bool readStdout=false, bool readStderr=true)
Queue a command with optional stdin input.
auto cancelNext() -> int
Cancel the next queued command without executing it.
void execute(int id, const QString &workDir, const QString &app, const QStringList &args, QString input=QString(), bool readStdout=false, bool readStderr=true)
Queue a command with working directory and optional stdin input.