23 #include <kprogress.h> 24 #include <tdelocale.h> 25 #include <tdemessagebox.h> 27 ExecCommand::ExecCommand(
const TQString& executable,
const TQStringList& args,
28 const TQString& workingDir,
const TQStringList& env,
29 TQObject* parent,
const char* name ):
30 TQObject( parent, name ), out(
"" )
35 proc =
new TDEProcess();
36 proc->setWorkingDirectory( workingDir );
37 for ( TQStringList::ConstIterator it = env.begin(); it != env.end(); ++it )
38 proc->setEnvironment( (*it).section(
'=', 0, 0 ), (*it).section(
'=', 1, 1 ) );
42 connect( proc, TQT_SIGNAL(processExited(TDEProcess*)),
43 this, TQT_SLOT(processExited()) );
44 connect( proc, TQT_SIGNAL(receivedStdout(TDEProcess*,
char*,
int)),
45 this, TQT_SLOT(receivedStdout(TDEProcess*,
char*,
int)) );
46 connect( proc, TQT_SIGNAL(receivedStderr(TDEProcess*,
char*,
int)),
47 this, TQT_SLOT(receivedStderr(TDEProcess*,
char*,
int)) );
49 bool ok = proc->start( TDEProcess::NotifyOnExit, TDEProcess::AllOutput );
52 KMessageBox::error( 0, i18n(
"Could not invoke \"%1\". Please make sure it is installed correctly").arg( executable ),
53 i18n(
"Error Invoking Command") );
55 emit finished( TQString(), TQString() );
59 progressDlg =
new KProgressDialog( 0, 0, i18n(
"Command running..."),
60 i18n(
"Please wait until the \"%1\" command finishes.").arg( executable ),
false );
61 connect( progressDlg, TQT_SIGNAL(cancelClicked()),
62 this, TQT_SLOT(cancelClicked()) );
66 void ExecCommand::receivedStdout (TDEProcess*,
char *buffer,
int buflen)
68 out += TQString::fromUtf8( buffer, buflen );
71 void ExecCommand::receivedStderr (TDEProcess*,
char *buffer,
int buflen)
73 err += TQString::fromUtf8( buffer, buflen );
76 void ExecCommand::processExited()
81 emit finished( out, err );
85 void ExecCommand::cancelClicked()
91 emit finished( TQString(), TQString() );
95 ExecCommand::~ExecCommand()
101 #include "execcommand.moc" Command execution facilities.