forked from quickshell/quickshell
feat: add support for getting and setting workdir
This commit is contained in:
parent
b5f50cd68f
commit
bbe64f42f3
8 changed files with 109 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <csignal> // NOLINT
|
||||
#include <utility>
|
||||
|
||||
#include <qdir.h>
|
||||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qobject.h>
|
||||
|
@ -9,8 +10,18 @@
|
|||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "../core/qmlglobal.hpp"
|
||||
#include "datastream.hpp"
|
||||
|
||||
Process::Process(QObject* parent): QObject(parent) {
|
||||
QObject::connect(
|
||||
QuickshellGlobal::instance(),
|
||||
&QuickshellGlobal::workingDirectoryChanged,
|
||||
this,
|
||||
&Process::onGlobalWorkingDirectoryChanged
|
||||
);
|
||||
}
|
||||
|
||||
bool Process::isRunning() const { return this->process != nullptr; }
|
||||
|
||||
void Process::setRunning(bool running) {
|
||||
|
@ -24,6 +35,25 @@ QVariant Process::pid() const {
|
|||
return QVariant::fromValue(this->process->processId());
|
||||
}
|
||||
|
||||
QString Process::workingDirectory() const {
|
||||
if (this->mWorkingDirectory.isEmpty()) return QDir::current().absolutePath();
|
||||
else return this->mWorkingDirectory;
|
||||
}
|
||||
|
||||
void Process::setWorkingDirectory(const QString& workingDirectory) {
|
||||
auto absolute =
|
||||
workingDirectory.isEmpty() ? workingDirectory : QDir(workingDirectory).absolutePath();
|
||||
if (absolute == this->mWorkingDirectory) return;
|
||||
this->mWorkingDirectory = absolute;
|
||||
emit this->workingDirectoryChanged();
|
||||
}
|
||||
|
||||
void Process::onGlobalWorkingDirectoryChanged() {
|
||||
if (this->mWorkingDirectory.isEmpty()) {
|
||||
emit this->workingDirectoryChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QList<QString> Process::command() const { return this->mCommand; }
|
||||
|
||||
void Process::setCommand(QList<QString> command) {
|
||||
|
@ -137,6 +167,8 @@ void Process::startProcessIfReady() {
|
|||
if (this->mStderrParser == nullptr) this->process->closeReadChannel(QProcess::StandardError);
|
||||
if (!this->mStdinEnabled) this->process->closeWriteChannel();
|
||||
|
||||
if (!this->mWorkingDirectory.isEmpty())
|
||||
this->process->setWorkingDirectory(this->mWorkingDirectory);
|
||||
this->process->start(cmd, args);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue