succesfully -> successfully
[kdepim.git] / korn / kio_read.cpp
blob1e86d9d004041df454bd39d6e397f051c68480a9
1 /*
2 * Copyright (C) 2004, Mart Kelder (mart.kde@hccnet.nl)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "kio_read.h"
21 #include "kio.h"
22 #include "kio_proto.h"
24 #include <kdebug.h>
25 #include <klocale.h>
26 #include <kurl.h>
27 #include <kio/global.h>
28 #include <kio/jobclasses.h>
29 #include <kio/scheduler.h>
31 #include <QString>
32 #include <QVariant>
34 KIO_Read::KIO_Read( QObject * parent )
35 : QObject( parent ),
36 _job( 0 ),
37 _message( 0 )
39 _message = new QString;
42 KIO_Read::~KIO_Read()
44 delete _message;
45 delete _job;
48 void KIO_Read::readMail( const QVariant mailid, KKioDrop* drop )
50 _kio = drop;
51 KUrl kurl = *_kio->_kurl;
52 KIO::MetaData metadata = *_kio->_metadata;
54 if( mailid.type() != QVariant::String )
56 kDebug() <<"Got wrong type of id in KIO_Read::readMail";
57 return;
59 kurl = mailid.toString();
61 _kio->_protocol->readMailKUrl( kurl, metadata );
63 _job = KIO::get( kurl, KIO::NoReload, KIO::HideProgressInfo );
64 _job->addMetaData( metadata );
66 connect( _job, SIGNAL( result( KJob* ) ), this, SLOT( slotResult( KJob* ) ) );
67 connect( _job, SIGNAL( data( KIO::Job*, const QByteArray& ) ), this, SLOT( slotData( KIO::Job*, const QByteArray & ) ) );
70 void KIO_Read::canceled( )
72 if( _job )
73 delete _job;
74 _job = 0;
77 void KIO_Read::slotResult( KJob* job )
79 if( job != _job )
80 kWarning() << i18n("Unknown job returned; I will try if this one will do..." );
82 if( job->error() )
83 kWarning() << i18n("An error occurred when fetching the requested email: %1.", job->errorString() );
85 _kio->emitReadMailReady( _message );
87 *_message = "";
88 _job = 0;
91 void KIO_Read::slotData( KIO::Job* job, const QByteArray & data )
93 if( job != _job )
94 kWarning() << i18n("Unknown job returned; I will try if this one will do..." );
96 if( !data.isEmpty() )
97 _message->append( data );
100 #include "kio_read.moc"