2 Copyright (c) 2008 Volker Krause <vkrause@kde.org>
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 <config-messageviewer.h>
21 #include "kleojobexecutor.h"
23 #include <kleo/decryptverifyjob.h>
24 #include <kleo/importjob.h>
25 #include <kleo/verifydetachedjob.h>
26 #include <kleo/verifyopaquejob.h>
36 using namespace GpgME
;
37 using namespace MessageViewer
;
38 using boost::shared_ptr
;
40 KleoJobExecutor::KleoJobExecutor( QObject
* parent
) : QObject( parent
)
42 setObjectName( "KleoJobExecutor" );
43 mEventLoop
= new QEventLoop( this );
47 GpgME::VerificationResult
KleoJobExecutor::exec(
48 Kleo::VerifyDetachedJob
* job
,
49 const QByteArray
& signature
,
50 const QByteArray
& signedData
)
52 kDebug() << "Starting detached verification job";
53 connect( job
, SIGNAL(result(GpgME::VerificationResult
)),
54 SLOT(verificationResult(GpgME::VerificationResult
)) );
55 GpgME::Error err
= job
->start( signature
, signedData
);
57 return VerificationResult( err
);
58 mEventLoop
->exec( QEventLoop::ExcludeUserInputEvents
);
59 return mVerificationResult
;
62 GpgME::VerificationResult
KleoJobExecutor::exec(
63 Kleo::VerifyOpaqueJob
* job
,
64 const QByteArray
& signedData
,
65 QByteArray
& plainText
)
67 kDebug() << "Starting opaque verification job";
68 connect( job
, SIGNAL(result(GpgME::VerificationResult
,QByteArray
)),
69 SLOT(verificationResult(GpgME::VerificationResult
,QByteArray
)) );
70 GpgME::Error err
= job
->start( signedData
);
73 return VerificationResult( err
);
75 mEventLoop
->exec( QEventLoop::ExcludeUserInputEvents
);
77 return mVerificationResult
;
80 std::pair
< GpgME::DecryptionResult
, GpgME::VerificationResult
> KleoJobExecutor::exec(
81 Kleo::DecryptVerifyJob
* job
,
82 const QByteArray
& cipherText
,
83 QByteArray
& plainText
)
85 kDebug() << "Starting decryption job";
86 connect( job
, SIGNAL(result(GpgME::DecryptionResult
,GpgME::VerificationResult
,QByteArray
)),
87 SLOT(decryptResult(GpgME::DecryptionResult
,GpgME::VerificationResult
,QByteArray
)) );
88 GpgME::Error err
= job
->start( cipherText
);
91 return std::make_pair( DecryptionResult( err
), VerificationResult( err
) );
93 mEventLoop
->exec( QEventLoop::ExcludeUserInputEvents
);
95 return std::make_pair( mDecryptResult
, mVerificationResult
);
98 GpgME::ImportResult
KleoJobExecutor::exec(Kleo::ImportJob
* job
, const QByteArray
& certData
)
100 connect( job
, SIGNAL(result(GpgME::ImportResult
)), SLOT(importResult(GpgME::ImportResult
)) );
101 GpgME::Error err
= job
->start( certData
);
103 return ImportResult( err
);
104 mEventLoop
->exec( QEventLoop::ExcludeUserInputEvents
);
105 return mImportResult
;
108 void KleoJobExecutor::verificationResult(const GpgME::VerificationResult
& result
)
110 kDebug() << "Detached verification job finished";
111 Kleo::Job
* job
= dynamic_cast<Kleo::Job
*>( sender() );
113 mVerificationResult
= result
;
114 mAuditLogError
= job
->auditLogError();
115 mAuditLog
= job
->auditLogAsHtml();
119 void KleoJobExecutor::verificationResult(const GpgME::VerificationResult
& result
, const QByteArray
& plainText
)
121 kDebug() << "Opaque verification job finished";
122 Kleo::Job
* job
= dynamic_cast<Kleo::Job
*>( sender() );
124 mVerificationResult
= result
;
126 mAuditLogError
= job
->auditLogError();
127 mAuditLog
= job
->auditLogAsHtml();
131 void KleoJobExecutor::decryptResult(
132 const GpgME::DecryptionResult
& decryptionresult
,
133 const GpgME::VerificationResult
& verificationresult
,
134 const QByteArray
& plainText
)
136 kDebug() << "Decryption job finished";
137 Kleo::Job
* job
= dynamic_cast<Kleo::Job
*>( sender() );
139 mVerificationResult
= verificationresult
;
140 mDecryptResult
= decryptionresult
;
142 mAuditLogError
= job
->auditLogError();
143 mAuditLog
= job
->auditLogAsHtml();
147 void KleoJobExecutor::importResult(const GpgME::ImportResult
& result
)
149 Kleo::Job
* job
= dynamic_cast<Kleo::Job
*>( sender() );
151 mImportResult
= result
;
152 mAuditLogError
= job
->auditLogError();
153 mAuditLog
= job
->auditLogAsHtml();
158 QString
KleoJobExecutor::auditLogAsHtml() const
163 #include "kleojobexecutor.moc"