diff options
author | Ken Moore <ken@ixsystems.com> | 2017-01-04 17:37:00 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-01-04 17:37:00 -0500 |
commit | 491b06d75e4ab3340429875b58e0149692384a03 (patch) | |
tree | dddae1dbfe59a82028a11cd436d7f286b72481b3 /src-qt5/core/libLumina/ExternalProcess.h | |
parent | Merge branch 'master' of github.com:trueos/lumina (diff) | |
download | lumina-491b06d75e4ab3340429875b58e0149692384a03.tar.gz lumina-491b06d75e4ab3340429875b58e0149692384a03.tar.bz2 lumina-491b06d75e4ab3340429875b58e0149692384a03.zip |
Create a new "ExternalProcess" class in the library directory which is specifically designed for launching external processes in an unattended manner and automatically cleaning up the object on the heap when finished. It will also hide any output from the process or forward it to a designated log file rather than polluting the current process output channel.
Diffstat (limited to 'src-qt5/core/libLumina/ExternalProcess.h')
-rw-r--r-- | src-qt5/core/libLumina/ExternalProcess.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src-qt5/core/libLumina/ExternalProcess.h b/src-qt5/core/libLumina/ExternalProcess.h new file mode 100644 index 00000000..2106f296 --- /dev/null +++ b/src-qt5/core/libLumina/ExternalProcess.h @@ -0,0 +1,45 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is a simple class for launching/managing an external process in a non-interactive manner +// This object will clean itself up when finished and log all output to a particular file if designated +// otherwise it will suppress all output from the process +//=========================================== +#ifndef _LUMINA_EXTERNAL_PROCESS_H +#define _LUMINA_EXTERNAL_PROCESS_H + +#include <QProcess> +#include <QString> + +class ExternalProcess : public QProcess{ + Q_OBJECT +private slots: + void processFinished(){ + //Clean up this object + this->deleteLater(); + } +public: + ExternalProcess(QString logfile = "") : QProcess(){ + this->setProcessChannelMode(QProcess::MergedChannels); + if(logfile.isEmpty()){ + this->setStandardOutputFile(QProcess::nullDevice()); + }else{ + this->setStandardOutputFile(logfile); + } + //Setup the connection for automatic cleanup + connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished()) ); + } + ~ExternalProcess(){ + } + + static void launch(QString program, QStringList args = QStringList()){ + //Quick launch of a process with logging disabled and automatic cleanup + ExternalProcess *tmp = new ExternalProcess(); + if(args.isEmpty()){ tmp->start(program); } + else{ tmp->start(program, args); } + } +}; +#endif |