1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
31 #include <sys/types.h>
33 #include <QtCore/QTime>
34 #include <QtDeclarative/qdeclarative.h>
35 #include <QtCore/QDebug>
37 #include "ProcessObject.h"
39 ProcessObject::ProcessObject(QObject *parent):
41 m_suspend(false), m_started(false)
43 m_process = new QProcess(this);
44 connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
46 SLOT(processFinished(int, QProcess::ExitStatus)));
47 connect(m_process, SIGNAL(error(QProcess::ProcessError)),this,
48 SLOT(processErrored(QProcess::ProcessError)));
51 ProcessObject::~ProcessObject()
60 void ProcessObject::processErrored(QProcess::ProcessError error) {
61 QString err(m_process->readAllStandardError());
62 qDebug() << "failed with exitCode" << m_process->exitCode();
63 emit failed(m_process->exitCode(), err, error);
67 void ProcessObject::processFinished(int exitCode,
68 QProcess::ExitStatus exitStatus)
70 if (exitStatus == QProcess::NormalExit)
74 QString out(m_process->readAllStandardOutput());
80 QString err(m_process->readAllStandardError());
82 emit failed(exitCode, err, m_process->error());
87 QString err(m_process->readAllStandardError());
89 emit failed(exitCode, err, m_process->error());
94 QString ProcessObject::command() const
99 void ProcessObject::setCommand(const QString &command)
101 if (m_command != command) {
106 void ProcessObject::run()
111 qDebug() << "already started";
113 qDebug() << m_command;
114 m_process->start(m_command);
115 qDebug() << "started";
119 bool ProcessObject::isSuspended() const
124 void ProcessObject::setSuspend(bool suspend)
126 if (!m_started || m_process->pid() == 0)
128 qDebug() << "No process running";
131 if (m_suspend != suspend)
135 ::kill(m_process->pid(), SIGCONT);
136 qDebug() << "Process resumed";
139 ::kill(m_process->pid(), SIGSTOP);
140 qDebug() << "Process suspended";
143 emit suspendChanged(suspend);
148 void ProcessObject::terminate()
150 if (m_started && m_process->pid() != 0)
157 QML_DECLARE_TYPE(ProcessObject);