24 #include "precommandjob.h"
27 #include <KLocalizedString>
31 using namespace MailTransport;
37 class PreCommandJobPrivate
46 void slotFinished(
int, QProcess::ExitStatus );
48 void slotError( QProcess::ProcessError error );
51 PreCommandJobPrivate::PreCommandJobPrivate(
PrecommandJob *parent )
52 : process( 0 ), q( parent )
57 : KJob( parent ), d( new PreCommandJobPrivate( this ) )
59 d->precommand = precommand;
61 connect( d->process, SIGNAL(started()), SLOT(slotStarted()) );
62 connect( d->process, SIGNAL(error(QProcess::ProcessError)),
63 SLOT(slotError(QProcess::ProcessError)) );
64 connect( d->process, SIGNAL(finished(
int,QProcess::ExitStatus)),
65 SLOT(slotFinished(
int,QProcess::ExitStatus)) );
75 d->process->start( d->precommand );
78 void PreCommandJobPrivate::slotStarted()
80 emit q->infoMessage( q, i18n(
"Executing precommand" ),
81 i18n(
"Executing precommand '%1'.", precommand ) );
84 void PreCommandJobPrivate::slotError( QProcess::ProcessError error )
86 q->setError( KJob::UserDefinedError );
87 if ( error == QProcess::FailedToStart ) {
88 q->setErrorText( i18n(
"Unable to start precommand '%1'.", precommand ) );
90 q->setErrorText( i18n(
"Error while executing precommand '%1'.", precommand ) );
102 void PreCommandJobPrivate::slotFinished(
int exitCode, QProcess::ExitStatus exitStatus )
104 if ( exitStatus == QProcess::CrashExit ) {
105 q->setError( KJob::UserDefinedError );
106 q->setErrorText( i18n(
"The precommand crashed." ) );
107 }
else if ( exitCode != 0 ) {
108 q->setError( KJob::UserDefinedError );
109 q->setErrorText( i18n(
"The precommand exited with code %1.",
110 process->exitStatus() ) );
115 #include "moc_precommandjob.cpp"
virtual bool doKill()
Reimplemented from KJob.
virtual void start()
Executes the precommand.
PrecommandJob(const QString &precommand, QObject *parent=0)
Creates a new precommand job.
Job to execute a command.
virtual ~PrecommandJob()
Destroys this job.