forked from quickshell/quickshell
io/process: add Process.exec()
This commit is contained in:
parent
8fc3e1cb6e
commit
98d09b5a36
6 changed files with 128 additions and 64 deletions
|
|
@ -1,11 +1,60 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qhash.h>
|
||||
#include <qlist.h>
|
||||
#include <qprocess.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
namespace qs::core::process {
|
||||
namespace qs::io::process {
|
||||
|
||||
class ProcessContext {
|
||||
Q_PROPERTY(QList<QString> command MEMBER command WRITE setCommand);
|
||||
Q_PROPERTY(QHash<QString, QVariant> environment MEMBER environment WRITE setEnvironment);
|
||||
Q_PROPERTY(bool clearEnvironment MEMBER clearEnvironment WRITE setClearEnvironment);
|
||||
Q_PROPERTY(QString workingDirectory MEMBER workingDirectory WRITE setWorkingDirectory);
|
||||
Q_GADGET;
|
||||
QML_STRUCTURED_VALUE;
|
||||
QML_VALUE_TYPE(processContext);
|
||||
|
||||
public:
|
||||
ProcessContext() = default;
|
||||
// Making this a Q_INVOKABLE does not work with QML_STRUCTURED_VALUe in Qt 6.9.
|
||||
explicit ProcessContext(QList<QString> command): command(std::move(command)), commandSet(true) {}
|
||||
|
||||
void setCommand(QList<QString> command) {
|
||||
this->command = std::move(command);
|
||||
this->commandSet = true;
|
||||
}
|
||||
|
||||
void setEnvironment(QHash<QString, QVariant> environment) {
|
||||
this->environment = std::move(environment);
|
||||
this->environmentSet = true;
|
||||
}
|
||||
|
||||
void setClearEnvironment(bool clearEnvironment) {
|
||||
this->clearEnvironment = clearEnvironment;
|
||||
this->clearEnvironmentSet = true;
|
||||
}
|
||||
|
||||
void setWorkingDirectory(QString workingDirectory) {
|
||||
this->workingDirectory = std::move(workingDirectory);
|
||||
this->workingDirectorySet = true;
|
||||
}
|
||||
|
||||
QList<QString> command;
|
||||
QHash<QString, QVariant> environment;
|
||||
bool clearEnvironment = false;
|
||||
QString workingDirectory;
|
||||
|
||||
bool commandSet : 1 = false;
|
||||
bool environmentSet : 1 = false;
|
||||
bool clearEnvironmentSet : 1 = false;
|
||||
bool workingDirectorySet : 1 = false;
|
||||
};
|
||||
|
||||
void setupProcessEnvironment(
|
||||
QProcess* process,
|
||||
|
|
@ -13,4 +62,4 @@ void setupProcessEnvironment(
|
|||
const QHash<QString, QVariant>& envChanges
|
||||
);
|
||||
|
||||
}
|
||||
} // namespace qs::io::process
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue