summaryrefslogtreecommitdiffstats
path: root/src/common/nokde/nokde_kprocess.cpp
blob: ee3e35bb1d875d5b2208f63e091b28124eb13fee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "nokde_kprocess.h"

#if [[[TQT_VERSION IS DEPRECATED]]]<0x040000
#  include <tqprocess.h>
#  define Q3Process TQProcess
#else
#  include <TQt3Support/Q3Process>
#endif

#if defined(Q_OS_UNIX)
#  include <signal.h>
#endif

TDEProcess::TDEProcess(TQObject *parent, const char *name)
  : TQObject(parent, name)
{
  _process = new Q3Process(this);
  connect(_process, TQT_SIGNAL(processExited()), TQT_SLOT(processExitedSlot()));
  connect(_process, TQT_SIGNAL(readyReadStdout()), TQT_SLOT(readyReadStdoutSlot()));
  connect(_process, TQT_SIGNAL(readyReadStderr()), TQT_SLOT(readyReadStderrSlot()));
}

bool TDEProcess::start()
{
  _process->setArguments(_arguments);
  TQStringList env;
  if ( !_environment.isEmpty() ) {
    for (uint i=0; environ[i]; i++) env += environ[i];
    env += _environment;
  }
  return _process->start(env.isEmpty() ? 0 : &env);
}

void TDEProcess::processExitedSlot()
{
  readyReadStdoutSlot();
  readyReadStderrSlot();
  emit processExited(this);
}

void TDEProcess::readyReadStdoutSlot()
{
  TQByteArray a = _process->readStdout();
  emit receivedStdout(this, a.data(), a.count());
}

void TDEProcess::readyReadStderrSlot()
{
  TQByteArray a = _process->readStderr();
  emit receivedStderr(this, a.data(), a.count());
}

bool TDEProcess::writeStdin(const char *buffer, int len)
{
#if [[[TQT_VERSION IS DEPRECATED]]]<0x040000
  TQByteArray a;
  a.assign(buffer, len);
#else
  TQByteArray a(buffer, len);
#endif
  _process->writeToStdin(a);
  return true;
}

bool TDEProcess::kill()
{
  _process->kill();
  return true;
}

bool TDEProcess::kill(int n)
{
#if defined(Q_OS_UNIX)
  return ( ::kill(_process->processIdentifier(), n)!=-1 );
#elif defined(Q_OS_WIN)
  // #### impossible to do ??
  return false;
#endif
}

int TDEProcess::exitStatus() const
{
  return _process->exitStatus();
}

bool TDEProcess::isRunning() const
{
  return _process->isRunning();
}

void TDEProcess::setWorkingDirectory(const TQDir &dir)
{
  return _process->setWorkingDirectory(dir);
}

void TDEProcess::setUseShell(bool useShell)
{
  // ### TODO: just issue "/bin/sh" "-c" "command"
  Q_ASSERT(false);
}