37 #include "qgpgmesignencryptjob.h"
39 #include "ui/messagebox.h"
41 #include <qgpgme/eventloopinteractor.h>
42 #include <qgpgme/dataprovider.h>
44 #include <gpgmepp/context.h>
45 #include <gpgmepp/data.h>
46 #include <gpgmepp/key.h>
48 #include <tdelocale.h>
52 Kleo::QGpgMESignEncryptJob::QGpgMESignEncryptJob( GpgME::Context * context )
53 : SignEncryptJob( QGpgME::EventLoopInteractor::instance(),
"Kleo::QGpgMESignEncryptJob" ),
54 QGpgMEJob( this, context )
59 Kleo::QGpgMESignEncryptJob::~QGpgMESignEncryptJob() {
62 GpgME::Error Kleo::QGpgMESignEncryptJob::setup(
const std::vector<GpgME::Key> & signers,
63 const TQByteArray & plainText ) {
67 createInData( plainText );
70 return setSigningKeys( signers );
73 GpgME::Error Kleo::QGpgMESignEncryptJob::start(
const std::vector<GpgME::Key> & signers,
74 const std::vector<GpgME::Key> & recipients,
75 const TQByteArray & plainText,
bool alwaysTrust ) {
76 if (
const GpgME::Error error = setup( signers, plainText ) ) {
81 hookupContextToEventLoopInteractor();
83 const GpgME::Context::EncryptionFlags flags =
84 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ;
85 const GpgME::Error err = mCtx->startCombinedSigningAndEncryption( recipients, *mInData, *mOutData, flags );
89 mResult.first = GpgME::SigningResult( err );
90 mResult.second = GpgME::EncryptionResult( err );
94 std::pair<GpgME::SigningResult,GpgME::EncryptionResult>
95 Kleo::QGpgMESignEncryptJob::exec(
const std::vector<GpgME::Key> & signers,
96 const std::vector<GpgME::Key> & recipients,
97 const TQByteArray & plainText,
bool alwaysTrust,
98 TQByteArray & cipherText ) {
99 if ( GpgME::Error err = setup( signers, plainText ) )
100 return std::make_pair( GpgME::SigningResult( 0, err ), GpgME::EncryptionResult() );
101 const GpgME::Context::EncryptionFlags flags =
102 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ;
103 mResult = mCtx->signAndEncrypt( recipients, *mInData, *mOutData, flags );
104 cipherText = mOutDataDataProvider->data();
109 void Kleo::QGpgMESignEncryptJob::doOperationDoneEvent(
const GpgME::Error & ) {
110 mResult.first = mCtx->signingResult();
111 mResult.second = mCtx->encryptionResult();
112 const TQByteArray cipherText = mOutDataDataProvider->data();
114 emit result( mResult.first, mResult.second, cipherText );
117 void Kleo::QGpgMESignEncryptJob::showErrorDialog( TQWidget * parent,
const TQString & caption )
const {
118 if ( (mResult.first.error() && !mResult.first.error().isCanceled()) ||
119 (mResult.second.error() && !mResult.second.error().isCanceled()) )
120 Kleo::MessageBox::error( parent, mResult.first, mResult.second,
this, caption );
123 #include "qgpgmesignencryptjob.moc"