certmanager/lib
qgpgmesignencryptjob.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036
00037 #include "qgpgmesignencryptjob.h"
00038
00039 #include <klocale.h>
00040 #include <kmessagebox.h>
00041
00042 #include <qgpgme/eventloopinteractor.h>
00043 #include <qgpgme/dataprovider.h>
00044
00045 #include <gpgmepp/context.h>
00046 #include <gpgmepp/data.h>
00047 #include <gpgmepp/key.h>
00048
00049 #include <assert.h>
00050
00051 Kleo::QGpgMESignEncryptJob::QGpgMESignEncryptJob( GpgME::Context * context )
00052 : SignEncryptJob( QGpgME::EventLoopInteractor::instance(), "Kleo::QGpgMESignEncryptJob" ),
00053 QGpgMEJob( this, context )
00054 {
00055 assert( context );
00056 }
00057
00058 Kleo::QGpgMESignEncryptJob::~QGpgMESignEncryptJob() {
00059 }
00060
00061 GpgME::Error Kleo::QGpgMESignEncryptJob::setup( const std::vector<GpgME::Key> & signers,
00062 const QByteArray & plainText ) {
00063 assert( !mInData );
00064 assert( !mOutData );
00065
00066 createInData( plainText );
00067 createOutData();
00068
00069 return setSigningKeys( signers );
00070 }
00071
00072 GpgME::Error Kleo::QGpgMESignEncryptJob::start( const std::vector<GpgME::Key> & signers,
00073 const std::vector<GpgME::Key> & recipients,
00074 const QByteArray & plainText, bool alwaysTrust ) {
00075 if ( const GpgME::Error error = setup( signers, plainText ) ) {
00076 deleteLater();
00077 return error;
00078 }
00079
00080 hookupContextToEventLoopInteractor();
00081
00082 const GpgME::Context::EncryptionFlags flags =
00083 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ;
00084 const GpgME::Error err = mCtx->startCombinedSigningAndEncryption( recipients, *mInData, *mOutData, flags );
00085
00086 if ( err )
00087 deleteLater();
00088 mResult.first = GpgME::SigningResult( err );
00089 mResult.second = GpgME::EncryptionResult( err );
00090 return err;
00091 }
00092
00093 std::pair<GpgME::SigningResult,GpgME::EncryptionResult>
00094 Kleo::QGpgMESignEncryptJob::exec( const std::vector<GpgME::Key> & signers,
00095 const std::vector<GpgME::Key> & recipients,
00096 const QByteArray & plainText, bool alwaysTrust,
00097 QByteArray & cipherText ) {
00098 if ( GpgME::Error err = setup( signers, plainText ) )
00099 return std::make_pair( GpgME::SigningResult( 0, err ), GpgME::EncryptionResult() );
00100 const GpgME::Context::EncryptionFlags flags =
00101 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ;
00102 mResult = mCtx->signAndEncrypt( recipients, *mInData, *mOutData, flags );
00103 cipherText = mOutDataDataProvider->data();
00104 return mResult;
00105 }
00106
00107 void Kleo::QGpgMESignEncryptJob::doOperationDoneEvent( const GpgME::Error & ) {
00108 mResult.first = mCtx->signingResult();
00109 mResult.second = mCtx->encryptionResult();
00110 emit result( mResult.first, mResult.second, mOutDataDataProvider->data() );
00111 }
00112
00113 void Kleo::QGpgMESignEncryptJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
00114 if ( !mResult.first.error() && !mResult.second.error() )
00115 return;
00116 if ( mResult.first.error().isCanceled() || mResult.second.error().isCanceled() )
00117 return;
00118 const QString msg = mResult.first.error()
00119 ? i18n("Signing failed: %1" ).arg( QString::fromLocal8Bit( mResult.first.error().asString() ) )
00120 : i18n("Encryption failed: %1").arg( QString::fromLocal8Bit( mResult.second.error().asString() ) ) ;
00121 KMessageBox::error( parent, msg, caption );
00122 }
00123
00124 #include "qgpgmesignencryptjob.moc"
|