• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

mailtransport

  • mailtransport
precommandjob.cpp
1/*
2 Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3
4 Based on KMail code by:
5 Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
6 Copyright (c) 2000-2002 Michael Haeckel <haeckel@kde.org>
7
8 This library is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Library General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
12
13 This library is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16 License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
22*/
23
24#include "precommandjob.h"
25
26#include <KDebug>
27#include <KLocalizedString>
28
29#include <QProcess>
30
31using namespace MailTransport;
32
37class PreCommandJobPrivate
38{
39 public:
40 PreCommandJobPrivate( PrecommandJob *parent );
41 QProcess *process;
42 QString precommand;
43 PrecommandJob *q;
44
45 // Slots
46 void slotFinished( int, QProcess::ExitStatus );
47 void slotStarted();
48 void slotError( QProcess::ProcessError error );
49};
50
51PreCommandJobPrivate::PreCommandJobPrivate( PrecommandJob *parent )
52 : process( 0 ), q( parent )
53{
54}
55
56PrecommandJob::PrecommandJob( const QString &precommand, QObject *parent )
57 : KJob( parent ), d( new PreCommandJobPrivate( this ) )
58{
59 d->precommand = precommand;
60 d->process = new QProcess( this );
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)) );
66}
67
68PrecommandJob::~ PrecommandJob()
69{
70 delete d;
71}
72
73void PrecommandJob::start()
74{
75 d->process->start( d->precommand );
76}
77
78void PreCommandJobPrivate::slotStarted()
79{
80 emit q->infoMessage( q, i18n( "Executing precommand" ),
81 i18n( "Executing precommand '%1'.", precommand ) );
82}
83
84void PreCommandJobPrivate::slotError( QProcess::ProcessError error )
85{
86 q->setError( KJob::UserDefinedError );
87 if ( error == QProcess::FailedToStart ) {
88 q->setErrorText( i18n( "Unable to start precommand '%1'.", precommand ) );
89 } else {
90 q->setErrorText( i18n( "Error while executing precommand '%1'.", precommand ) );
91 }
92 q->emitResult();
93}
94
95bool PrecommandJob::doKill()
96{
97 delete d->process;
98 d->process = 0;
99 return true;
100}
101
102void PreCommandJobPrivate::slotFinished( int exitCode, QProcess::ExitStatus exitStatus )
103{
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() ) );
111 }
112 q->emitResult();
113}
114
115#include "moc_precommandjob.cpp"
MailTransport::PrecommandJob
Job to execute a command.
Definition: precommandjob.h:44
MailTransport::PrecommandJob::start
virtual void start()
Executes the precommand.
Definition: precommandjob.cpp:73
MailTransport::PrecommandJob::PrecommandJob
PrecommandJob(const QString &precommand, QObject *parent=0)
Creates a new precommand job.
Definition: precommandjob.cpp:56
MailTransport::PrecommandJob::doKill
virtual bool doKill()
Reimplemented from KJob.
Definition: precommandjob.cpp:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailtransport

Skip menu "mailtransport"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal