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 return err;
00089 }
00090
00091 std::pair<GpgME::SigningResult,GpgME::EncryptionResult>
00092 Kleo::QGpgMESignEncryptJob::exec( const std::vector<GpgME::Key> & signers,
00093 const std::vector<GpgME::Key> & recipients,
00094 const QByteArray & plainText, bool alwaysTrust,
00095 QByteArray & cipherText ) {
00096 if ( GpgME::Error err = setup( signers, plainText ) )
00097 return std::make_pair( GpgME::SigningResult( 0, err ), GpgME::EncryptionResult() );
00098 const GpgME::Context::EncryptionFlags flags =
00099 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ;
00100 const std::pair<GpgME::SigningResult,GpgME::EncryptionResult> result =
00101 mCtx->signAndEncrypt( recipients, *mInData, *mOutData, flags );
00102 cipherText = mOutDataDataProvider->data();
00103 return result;
00104 }
00105
00106 void Kleo::QGpgMESignEncryptJob::doOperationDoneEvent( const GpgME::Error & ) {
00107 emit result( mCtx->signingResult(),
00108 mCtx->encryptionResult(),
00109 mOutDataDataProvider->data() );
00110 }
00111
00112 void Kleo::QGpgMESignEncryptJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
00113 if ( !mResult.first.error() && !mResult.second.error() )
00114 return;
00115 if ( mResult.first.error().isCanceled() || mResult.second.error().isCanceled() )
00116 return;
00117 const QString msg = mResult.first.error()
00118 ? i18n("Signing failed: %1" ).arg( QString::fromLocal8Bit( mResult.first.error().asString() ) )
00119 : i18n("Encryption failed: %1").arg( QString::fromLocal8Bit( mResult.second.error().asString() ) ) ;
00120 KMessageBox::error( parent, msg, caption );
00121 }
00122
00123 #include "qgpgmesignencryptjob.moc"
|