|
|
@@ -0,0 +1,116 @@ |
|
|
/*************************************************************************** |
|
|
* Copyright (C) 2015 Leslie Zhai <xiang.zhai@i-soft.com.cn> |
|
|
* |
|
|
* This program is free software; you can redistribute it and/or modify |
|
|
* it under the terms of the GNU General Public License as published by |
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
|
* (at your option) any later version. |
|
|
* |
|
|
* This program is distributed in the hope that it will be useful, |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
* GNU General Public License for more details. |
|
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with this program; if not, write to the |
|
|
* Free Software Foundation, Inc., |
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
|
***************************************************************************/ |
|
|
|
|
|
#include "Process.h" |
|
|
|
|
|
#include <QtCore/QProcess> |
|
|
|
|
|
class Process::Private : public QProcess |
|
|
{ |
|
|
Q_OBJECT |
|
|
public: |
|
|
Private(Process *parent); |
|
|
|
|
|
QString program; |
|
|
QStringList arguments; |
|
|
QString dir; |
|
|
private: |
|
|
Process *q; |
|
|
}; |
|
|
|
|
|
Process::Private::Private(Process *parent) |
|
|
: QProcess(parent) |
|
|
, q(parent) |
|
|
{ |
|
|
connect(this, SIGNAL(started()), q, SIGNAL(started())); |
|
|
connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), q, SIGNAL(finished(int))); |
|
|
connect(this, SIGNAL(readyReadStandardOutput()), q, SIGNAL(readyReadStandardOutput())); |
|
|
connect(this, SIGNAL(readyReadStandardError()), q, SIGNAL(readyReadStandardError())); |
|
|
} |
|
|
|
|
|
Process::Process(QObject *parent) |
|
|
: QObject(parent) |
|
|
, d(new Private(this)) |
|
|
{ |
|
|
} |
|
|
|
|
|
Process::~Process() |
|
|
{ |
|
|
} |
|
|
|
|
|
const QString &Process::program() const |
|
|
{ |
|
|
return d->program; |
|
|
} |
|
|
|
|
|
void Process::setProgram(const QString &program) |
|
|
{ |
|
|
if (program == d->program) return; |
|
|
d->program = program; |
|
|
emit programChanged(d->program); |
|
|
} |
|
|
|
|
|
const QStringList &Process::arguments() const |
|
|
{ |
|
|
return d->arguments; |
|
|
} |
|
|
|
|
|
void Process::setArguments(const QStringList &arguments) |
|
|
{ |
|
|
if (arguments == d->arguments) return; |
|
|
d->arguments = arguments; |
|
|
emit argumentsChanged(d->arguments); |
|
|
} |
|
|
|
|
|
const QString &Process::dir() const { return d->dir; } |
|
|
|
|
|
void Process::setDir(const QString &dir) |
|
|
{ |
|
|
if (dir == d->dir) return; |
|
|
d->dir = dir; |
|
|
d->setWorkingDirectory(d->dir); |
|
|
emit dirChanged(); |
|
|
} |
|
|
|
|
|
void Process::start() |
|
|
{ |
|
|
d->start(d->program, d->arguments); |
|
|
} |
|
|
|
|
|
void Process::terminate() |
|
|
{ |
|
|
d->terminate(); |
|
|
} |
|
|
|
|
|
void Process::kill() |
|
|
{ |
|
|
d->kill(); |
|
|
} |
|
|
|
|
|
QByteArray Process::readAllStandardError() |
|
|
{ |
|
|
return d->readAllStandardError(); |
|
|
} |
|
|
|
|
|
QByteArray Process::readAllStandardOutput() |
|
|
{ |
|
|
return d->readAllStandardOutput(); |
|
|
} |
|
|
|
|
|
#include "Process.moc" |