~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/executable/executable.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2007, 2008 Petri Damsten <damu@iki.fi>
 
3
 *
 
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
 
7
 *
 
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
 
12
 *
 
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.
 
17
 */
 
18
 
 
19
#include "executable.h"
 
20
#include <KDebug>
 
21
#include <KProcess>
 
22
ExecutableContainer::ExecutableContainer(const QString& command, QObject* parent)
 
23
    : Plasma::DataContainer(parent), m_process(0)
 
24
{
 
25
    setObjectName(command);
 
26
    connect(this, SIGNAL(updateRequested(DataContainer*)), this, SLOT(exec()));
 
27
    exec();
 
28
}
 
29
 
 
30
ExecutableContainer::~ExecutableContainer()
 
31
{
 
32
    delete m_process;
 
33
}
 
34
 
 
35
void ExecutableContainer::finished(int exitCode, QProcess::ExitStatus exitStatus)
 
36
{
 
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();
 
43
}
 
44
 
 
45
void ExecutableContainer::exec()
 
46
{
 
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());
 
54
    }
 
55
 
 
56
    if (m_process->state() == QProcess::NotRunning) {
 
57
        m_process->start();
 
58
    } else {
 
59
        kDebug() << "Process" << objectName() << "already running. Pid:" << m_process->pid();
 
60
    }
 
61
}
 
62
 
 
63
 
 
64
ExecutableEngine::ExecutableEngine(QObject* parent, const QVariantList& args)
 
65
    : Plasma::DataEngine(parent, args)
 
66
{
 
67
    setMinimumPollingInterval(1000);
 
68
}
 
69
 
 
70
bool ExecutableEngine::sourceRequestEvent(const QString& source)
 
71
{
 
72
    //kDebug() << source;
 
73
    addSource(new ExecutableContainer(source, this));
 
74
    return true;
 
75
}
 
76
 
 
77
#include "executable.moc"