add more spacing
[personal-kdebase.git] / workspace / plasma / dataengines / executable / executable.cpp
blob8ad3fb8ca435f70c73808c108e92ba08a6bb5edf
1 /*
2 * Copyright (C) 2007, 2008 Petri Damsten <damu@iki.fi>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "executable.h"
20 #include <KDebug>
22 ExecutableContainer::ExecutableContainer(const QString& command, QObject* parent)
23 : Plasma::DataContainer(parent), m_process(0)
25 setObjectName(command);
26 connect(this, SIGNAL(updateRequested(DataContainer*)), this, SLOT(exec()));
27 exec();
30 ExecutableContainer::~ExecutableContainer()
32 delete m_process;
35 void ExecutableContainer::finished(int exitCode, QProcess::ExitStatus exitStatus)
37 //kDebug() << objectName();
38 setData("exit code", exitCode);
39 setData("exit status", exitStatus);
40 setData("stdout", QString::fromLocal8Bit(m_process->readAllStandardOutput()));
41 setData("stderr", QString::fromLocal8Bit(m_process->readAllStandardError()));
42 checkForUpdate();
45 void ExecutableContainer::exec()
47 //kDebug() << objectName();
48 if (!m_process) {
49 m_process = new KProcess();
50 connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
51 this, SLOT(finished(int, QProcess::ExitStatus)));
52 m_process->setOutputChannelMode(KProcess::SeparateChannels);
53 m_process->setShellCommand(objectName());
56 if (m_process->state() == QProcess::NotRunning) {
57 m_process->start();
58 } else {
59 kDebug() << "Process" << objectName() << "already running. Pid:" << m_process->pid();
64 ExecutableEngine::ExecutableEngine(QObject* parent, const QVariantList& args)
65 : Plasma::DataEngine(parent, args)
67 setMinimumPollingInterval(1000);
70 bool ExecutableEngine::sourceRequestEvent(const QString& source)
72 //kDebug() << source;
73 addSource(new ExecutableContainer(source, this));
74 return true;
77 #include "executable.moc"