mailtransport
precommandjob.cpp
00001 /* 00002 Copyright (c) 2007 Volker Krause <vkrause@kde.org> 00003 00004 Based on KMail code by: 00005 Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org> 00006 Copyright (c) 2000-2002 Michael Haeckel <haeckel@kde.org> 00007 00008 This library is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU Library General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or (at your 00011 option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00016 License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to the 00020 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00021 02110-1301, USA. 00022 */ 00023 00024 #include "precommandjob.h" 00025 00026 #include <KDebug> 00027 #include <KLocalizedString> 00028 00029 #include <QProcess> 00030 00031 using namespace MailTransport; 00032 00037 class PreCommandJobPrivate 00038 { 00039 public: 00040 PreCommandJobPrivate( PrecommandJob *parent ); 00041 QProcess *process; 00042 QString precommand; 00043 PrecommandJob *q; 00044 00045 // Slots 00046 void slotFinished( int, QProcess::ExitStatus ); 00047 void slotStarted(); 00048 void slotError( QProcess::ProcessError error ); 00049 }; 00050 00051 PreCommandJobPrivate::PreCommandJobPrivate( PrecommandJob *parent ) 00052 : q( parent ) 00053 { 00054 } 00055 00056 PrecommandJob::PrecommandJob( const QString &precommand, QObject *parent ) 00057 : KJob( parent ), d( new PreCommandJobPrivate( this ) ) 00058 { 00059 d->precommand = precommand; 00060 d->process = new QProcess( this ); 00061 connect( d->process, SIGNAL(started()), SLOT(slotStarted()) ); 00062 connect( d->process, SIGNAL(error(QProcess::ProcessError)), 00063 SLOT(slotError(QProcess::ProcessError)) ); 00064 connect( d->process, SIGNAL(finished(int,QProcess::ExitStatus)), 00065 SLOT(slotFinished(int,QProcess::ExitStatus)) ); 00066 } 00067 00068 PrecommandJob::~ PrecommandJob() 00069 { 00070 delete d; 00071 } 00072 00073 void PrecommandJob::start() 00074 { 00075 d->process->start( d->precommand ); 00076 } 00077 00078 void PreCommandJobPrivate::slotStarted() 00079 { 00080 emit q->infoMessage( q, i18n( "Executing precommand" ), 00081 i18n( "Executing precommand '%1'.", precommand ) ); 00082 } 00083 00084 void PreCommandJobPrivate::slotError( QProcess::ProcessError error ) 00085 { 00086 q->setError( KJob::UserDefinedError ); 00087 if ( error == QProcess::FailedToStart ) { 00088 q->setErrorText( i18n( "Unable to start precommand '%1'.", precommand ) ); 00089 } else { 00090 q->setErrorText( i18n( "Error while executing precommand '%1'.", precommand ) ); 00091 } 00092 q->emitResult(); 00093 } 00094 00095 bool PrecommandJob::doKill() 00096 { 00097 delete d->process; 00098 d->process = 0; 00099 return true; 00100 } 00101 00102 void PreCommandJobPrivate::slotFinished( int exitCode, QProcess::ExitStatus exitStatus ) 00103 { 00104 if ( exitStatus == QProcess::CrashExit ) { 00105 q->setError( KJob::UserDefinedError ); 00106 q->setErrorText( i18n( "The precommand crashed." ) ); 00107 } else if ( exitCode != 0 ) { 00108 q->setError( KJob::UserDefinedError ); 00109 q->setErrorText( i18n( "The precommand exited with code %1.", 00110 process->exitStatus() ) ); 00111 } 00112 q->emitResult(); 00113 } 00114 00115 #include "precommandjob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:49:32 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:49:32 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.