~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kmail/objecttreeparser_p.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- mode: C++; c-file-style: "gnu" -*-
2
 
    objecttreeparser_p.cpp
3
 
 
4
 
    This file is part of KMail, the KDE mail client.
5
 
    Copyright (c) 2009 Klarälvdalens Datakonsult AB
6
 
    Authors: Marc Mutz <marc@kdab.net>
7
 
 
8
 
    KMail is free software; you can redistribute it and/or modify it
9
 
    under the terms of the GNU General Public License, version 2, as
10
 
    published by the Free Software Foundation.
11
 
 
12
 
    KMail is distributed in the hope that it will be useful, but
13
 
    WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
    General Public License for more details.
16
 
 
17
 
    You should have received a copy of the GNU General Public License
18
 
    along with this program; if not, write to the Free Software
19
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
 
 
21
 
    In addition, as a special exception, the copyright holders give
22
 
    permission to link the code of this program with any edition of
23
 
    the Qt library by Trolltech AS, Norway (or with modified versions
24
 
    of Qt that use the same license as Qt), and distribute linked
25
 
    combinations including the two.  You must obey the GNU General
26
 
    Public License in all respects for all of the code used other than
27
 
    Qt.  If you modify this file, you may extend this exception to
28
 
    your version of the file, but you are not obligated to do so.  If
29
 
    you do not wish to do so, delete this exception statement from
30
 
    your version.
31
 
*/
32
 
 
33
 
#include "objecttreeparser_p.h"
34
 
 
35
 
#include <kleo/decryptverifyjob.h>
36
 
#include <kleo/verifydetachedjob.h>
37
 
#include <kleo/verifyopaquejob.h>
38
 
#include <kleo/keylistjob.h>
39
 
 
40
 
#include <gpgme++/keylistresult.h>
41
 
 
42
 
#include <qtimer.h>
43
 
#include <qstringlist.h>
44
 
 
45
 
#include <cassert>
46
 
 
47
 
using namespace KMail;
48
 
using namespace Kleo;
49
 
using namespace GpgME;
50
 
 
51
 
CryptoBodyPartMemento::CryptoBodyPartMemento()
52
 
  : QObject( 0 ),
53
 
    Interface::BodyPartMemento(),
54
 
    ISubject(),
55
 
    m_running( false )
56
 
{
57
 
 
58
 
}
59
 
 
60
 
CryptoBodyPartMemento::~CryptoBodyPartMemento() {}
61
 
 
62
 
void CryptoBodyPartMemento::setAuditLog( const Error & err, const QString & log ) {
63
 
  m_auditLogError = err;
64
 
  m_auditLog = log;
65
 
}
66
 
 
67
 
void CryptoBodyPartMemento::setRunning( bool running ) {
68
 
  m_running = running;
69
 
}
70
 
 
71
 
DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento( DecryptVerifyJob * job, const QByteArray & cipherText )
72
 
  : CryptoBodyPartMemento(),
73
 
    m_cipherText( cipherText ),
74
 
    m_job( job )
75
 
{
76
 
  assert( m_job );
77
 
}
78
 
 
79
 
DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() {
80
 
  if ( m_job )
81
 
    m_job->slotCancel();
82
 
}
83
 
 
84
 
bool DecryptVerifyBodyPartMemento::start() {
85
 
  assert( m_job );
86
 
  if ( const Error err = m_job->start( m_cipherText ) ) {
87
 
    m_dr = DecryptionResult( err );
88
 
    return false;
89
 
  }
90
 
  connect( m_job, SIGNAL(result(const GpgME::DecryptionResult&,const GpgME::VerificationResult&,const QByteArray&)),
91
 
           this, SLOT(slotResult(const GpgME::DecryptionResult&,const GpgME::VerificationResult&,const QByteArray&)) );
92
 
  setRunning( true );
93
 
  return true;
94
 
}
95
 
 
96
 
void DecryptVerifyBodyPartMemento::exec() {
97
 
  assert( m_job );
98
 
  QByteArray plainText;
99
 
  setRunning( true );
100
 
  const std::pair<DecryptionResult,VerificationResult> p = m_job->exec( m_cipherText, plainText );
101
 
  saveResult( p.first, p.second, plainText );
102
 
  m_job->deleteLater(); // exec'ed jobs don't delete themselves
103
 
  m_job = 0;
104
 
}
105
 
 
106
 
void DecryptVerifyBodyPartMemento::saveResult( const DecryptionResult & dr,
107
 
                                               const VerificationResult & vr,
108
 
                                               const QByteArray & plainText )
109
 
{
110
 
  assert( m_job );
111
 
  setRunning( false );
112
 
  m_dr = dr;
113
 
  m_vr = vr;
114
 
  m_plainText = plainText;
115
 
  setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
116
 
}
117
 
 
118
 
void DecryptVerifyBodyPartMemento::slotResult( const DecryptionResult & dr,
119
 
                                               const VerificationResult & vr,
120
 
                                               const QByteArray & plainText )
121
 
{
122
 
  saveResult( dr, vr, plainText );
123
 
  m_job = 0;
124
 
  notify();
125
 
}
126
 
 
127
 
 
128
 
 
129
 
 
130
 
VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob * job,
131
 
                                                              KeyListJob * klj,
132
 
                                                              const QByteArray & signature,
133
 
                                                              const QByteArray & plainText )
134
 
  : CryptoBodyPartMemento(),
135
 
    m_signature( signature ),
136
 
    m_plainText( plainText ),
137
 
    m_job( job ),
138
 
    m_keylistjob( klj )
139
 
{
140
 
  assert( m_job );
141
 
}
142
 
 
143
 
VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() {
144
 
  if ( m_job )
145
 
    m_job->slotCancel();
146
 
  if ( m_keylistjob )
147
 
    m_keylistjob->slotCancel();
148
 
}
149
 
 
150
 
bool VerifyDetachedBodyPartMemento::start() {
151
 
  assert( m_job );
152
 
  if ( const Error err = m_job->start( m_signature, m_plainText ) ) {
153
 
    m_vr = VerificationResult( err );
154
 
    return false;
155
 
  }
156
 
  connect( m_job, SIGNAL(result(const GpgME::VerificationResult&)),
157
 
           this, SLOT(slotResult(const GpgME::VerificationResult&)) );
158
 
  setRunning( true );
159
 
  return true;
160
 
}
161
 
 
162
 
void VerifyDetachedBodyPartMemento::exec() {
163
 
  assert( m_job );
164
 
  setRunning( true );
165
 
  saveResult( m_job->exec( m_signature, m_plainText ) );
166
 
  m_job->deleteLater(); // exec'ed jobs don't delete themselves
167
 
  m_job = 0;
168
 
  if ( canStartKeyListJob() ) {
169
 
    std::vector<GpgME::Key> keys;
170
 
    m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys );
171
 
    if ( !keys.empty() )
172
 
      m_key = keys.back();
173
 
  }
174
 
  if ( m_keylistjob )
175
 
    m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves
176
 
  m_keylistjob = 0;
177
 
  setRunning( false );
178
 
}
179
 
 
180
 
bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const
181
 
{
182
 
  if ( !m_keylistjob )
183
 
    return false;
184
 
  const char * const fpr = m_vr.signature( 0 ).fingerprint();
185
 
  return fpr && *fpr;
186
 
}
187
 
 
188
 
QStringList VerifyDetachedBodyPartMemento::keyListPattern() const
189
 
{
190
 
  assert( canStartKeyListJob() );
191
 
  return QStringList( QString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
192
 
}
193
 
 
194
 
void VerifyDetachedBodyPartMemento::saveResult( const VerificationResult & vr )
195
 
{
196
 
  assert( m_job );
197
 
  m_vr = vr;
198
 
  setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
199
 
}
200
 
 
201
 
void VerifyDetachedBodyPartMemento::slotResult( const VerificationResult & vr )
202
 
{
203
 
  saveResult( vr );
204
 
  m_job = 0;
205
 
  if ( canStartKeyListJob() && startKeyListJob() )
206
 
    return;
207
 
  if ( m_keylistjob )
208
 
    m_keylistjob->deleteLater();
209
 
  m_keylistjob = 0;
210
 
  setRunning( false );
211
 
  notify();
212
 
}
213
 
 
214
 
bool VerifyDetachedBodyPartMemento::startKeyListJob()
215
 
{
216
 
  assert( canStartKeyListJob() );
217
 
  if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) )
218
 
    return false;
219
 
  connect( m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
220
 
  connect( m_keylistjob, SIGNAL(nextKey(const GpgME::Key&)),
221
 
           this, SLOT(slotNextKey(const GpgME::Key&)) );
222
 
  return true;
223
 
}
224
 
 
225
 
void VerifyDetachedBodyPartMemento::slotNextKey( const GpgME::Key & key )
226
 
{
227
 
  m_key = key;
228
 
}
229
 
 
230
 
void VerifyDetachedBodyPartMemento::slotKeyListJobDone()
231
 
{
232
 
  m_keylistjob = 0;
233
 
  setRunning( false );
234
 
  notify();
235
 
}
236
 
 
237
 
 
238
 
VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob * job,
239
 
                                                          KeyListJob *  klj,
240
 
                                                          const QByteArray & signature )
241
 
  : CryptoBodyPartMemento(),
242
 
    m_signature( signature ),
243
 
    m_job( job ),
244
 
    m_keylistjob( klj )
245
 
{
246
 
  assert( m_job );
247
 
}
248
 
 
249
 
VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() {
250
 
  if ( m_job )
251
 
    m_job->slotCancel();
252
 
  if ( m_keylistjob )
253
 
    m_keylistjob->slotCancel();
254
 
}
255
 
 
256
 
bool VerifyOpaqueBodyPartMemento::start() {
257
 
  assert( m_job );
258
 
  if ( const Error err = m_job->start( m_signature ) ) {
259
 
    m_vr = VerificationResult( err );
260
 
    return false;
261
 
  }
262
 
  connect( m_job, SIGNAL(result(const GpgME::VerificationResult&,const QByteArray&)),
263
 
           this, SLOT(slotResult(const GpgME::VerificationResult&,const QByteArray&)) );
264
 
  setRunning( true );
265
 
  return true;
266
 
}
267
 
 
268
 
void VerifyOpaqueBodyPartMemento::exec() {
269
 
  assert( m_job );
270
 
  setRunning( true );
271
 
  QByteArray plainText;
272
 
  saveResult( m_job->exec( m_signature, plainText ), plainText );
273
 
  m_job->deleteLater(); // exec'ed jobs don't delete themselves
274
 
  m_job = 0;
275
 
  if ( canStartKeyListJob() ) {
276
 
    std::vector<GpgME::Key> keys;
277
 
    m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys );
278
 
    if ( !keys.empty() )
279
 
      m_key = keys.back();
280
 
  }
281
 
  if ( m_keylistjob )
282
 
    m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves
283
 
  m_keylistjob = 0;
284
 
  setRunning( false );
285
 
}
286
 
 
287
 
bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const
288
 
{
289
 
  if ( !m_keylistjob )
290
 
    return false;
291
 
  const char * const fpr = m_vr.signature( 0 ).fingerprint();
292
 
  return fpr && *fpr;
293
 
}
294
 
 
295
 
QStringList VerifyOpaqueBodyPartMemento::keyListPattern() const
296
 
{
297
 
  assert( canStartKeyListJob() );
298
 
  return QStringList( QString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
299
 
}
300
 
 
301
 
void VerifyOpaqueBodyPartMemento::saveResult( const VerificationResult & vr,
302
 
                                              const QByteArray & plainText )
303
 
{
304
 
  assert( m_job );
305
 
  m_vr = vr;
306
 
  m_plainText = plainText;
307
 
  setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
308
 
}
309
 
 
310
 
void VerifyOpaqueBodyPartMemento::slotResult( const VerificationResult & vr,
311
 
                                              const QByteArray & plainText )
312
 
{
313
 
  saveResult( vr, plainText );
314
 
  m_job = 0;
315
 
  if ( canStartKeyListJob() && startKeyListJob() )
316
 
    return;
317
 
  if ( m_keylistjob )
318
 
    m_keylistjob->deleteLater();
319
 
  m_keylistjob = 0;
320
 
  setRunning( false );
321
 
  notify();
322
 
}
323
 
 
324
 
bool VerifyOpaqueBodyPartMemento::startKeyListJob()
325
 
{
326
 
  assert( canStartKeyListJob() );
327
 
  if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) )
328
 
    return false;
329
 
  connect( m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
330
 
  connect( m_keylistjob, SIGNAL(nextKey(const GpgME::Key&)),
331
 
           this, SLOT(slotNextKey(const GpgME::Key&)) );
332
 
  return true;
333
 
}
334
 
 
335
 
void VerifyOpaqueBodyPartMemento::slotNextKey( const GpgME::Key & key )
336
 
{
337
 
  m_key = key;
338
 
}
339
 
 
340
 
void VerifyOpaqueBodyPartMemento::slotKeyListJobDone()
341
 
{
342
 
  m_keylistjob = 0;
343
 
  setRunning( false );
344
 
  notify();
345
 
}
346
 
 
347
 
 
348
 
#include "objecttreeparser_p.moc"