1 | /* |
2 | Copyright (c) 2007 Volker Krause <vkrause@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "transportjob.h" |
21 | #include "transport.h" |
22 | |
23 | #include <QBuffer> |
24 | |
25 | #include <KLocalizedString> |
26 | |
27 | using namespace MailTransport; |
28 | |
29 | class MailTransport::TransportJob::Private |
30 | { |
31 | public: |
32 | Transport *transport; |
33 | QString sender; |
34 | QStringList to; |
35 | QStringList cc; |
36 | QStringList bcc; |
37 | QByteArray data; |
38 | QBuffer *buffer; |
39 | }; |
40 | |
41 | TransportJob::TransportJob( Transport *transport, QObject *parent ) |
42 | : KCompositeJob( parent ), d( new Private ) |
43 | { |
44 | d->transport = transport; |
45 | d->buffer = 0; |
46 | } |
47 | |
48 | TransportJob::~ TransportJob() |
49 | { |
50 | delete d->transport; |
51 | delete d; |
52 | } |
53 | |
54 | void TransportJob::setSender( const QString &sender ) |
55 | { |
56 | d->sender = sender; |
57 | } |
58 | |
59 | void TransportJob::setTo( const QStringList &to ) |
60 | { |
61 | d->to = to; |
62 | } |
63 | |
64 | void TransportJob::setCc( const QStringList &cc ) |
65 | { |
66 | d->cc = cc; |
67 | } |
68 | |
69 | void TransportJob::setBcc( const QStringList &bcc ) |
70 | { |
71 | d->bcc = bcc; |
72 | } |
73 | |
74 | void TransportJob::setData( const QByteArray &data ) |
75 | { |
76 | d->data = data; |
77 | } |
78 | |
79 | Transport *TransportJob::transport() const |
80 | { |
81 | return d->transport; |
82 | } |
83 | |
84 | QString TransportJob::sender() const |
85 | { |
86 | return d->sender; |
87 | } |
88 | |
89 | QStringList TransportJob::to() const |
90 | { |
91 | return d->to; |
92 | } |
93 | |
94 | QStringList TransportJob::cc() const |
95 | { |
96 | return d->cc; |
97 | } |
98 | |
99 | QStringList TransportJob::bcc() const |
100 | { |
101 | return d->bcc; |
102 | } |
103 | |
104 | QByteArray TransportJob::data() const |
105 | { |
106 | return d->data; |
107 | } |
108 | |
109 | QBuffer *TransportJob::buffer() |
110 | { |
111 | if ( !d->buffer ) { |
112 | d->buffer = new QBuffer( this ); |
113 | d->buffer->setData( d->data ); |
114 | d->buffer->open( QIODevice::ReadOnly ); |
115 | Q_ASSERT( d->buffer->isOpen() ); |
116 | } |
117 | return d->buffer; |
118 | } |
119 | |
120 | void TransportJob::start() |
121 | { |
122 | if ( !transport()->isValid() ) { |
123 | setError( UserDefinedError ); |
124 | setErrorText( i18n( "The outgoing account \"%1\" is not correctly configured." , |
125 | transport()->name() ) ); |
126 | emitResult(); |
127 | return; |
128 | } |
129 | doStart(); |
130 | } |
131 | |