certmanager/lib
qgpgmeencryptjob.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 "qgpgmeencryptjob.h"
00038
00039 #include "ui/messagebox.h"
00040
00041 #include <qgpgme/eventloopinteractor.h>
00042 #include <qgpgme/dataprovider.h>
00043
00044 #include <gpgmepp/context.h>
00045 #include <gpgmepp/encryptionresult.h>
00046 #include <gpgmepp/data.h>
00047
00048 #include <klocale.h>
00049
00050 #include <assert.h>
00051
00052 Kleo::QGpgMEEncryptJob::QGpgMEEncryptJob( GpgME::Context * context )
00053 : EncryptJob( QGpgME::EventLoopInteractor::instance(), "Kleo::QGpgMEEncryptJob" ),
00054 QGpgMEJob( this, context )
00055 {
00056 assert( context );
00057 }
00058
00059 Kleo::QGpgMEEncryptJob::~QGpgMEEncryptJob() {
00060 }
00061
00062 void Kleo::QGpgMEEncryptJob::setup( const QByteArray & plainText ) {
00063 assert( !mInData );
00064 assert( !mOutData );
00065
00066 createInData( plainText );
00067 createOutData();
00068 }
00069
00070 GpgME::Error Kleo::QGpgMEEncryptJob::start( const std::vector<GpgME::Key> & recipients,
00071 const QByteArray & plainText, bool alwaysTrust ) {
00072 setup( plainText );
00073
00074 hookupContextToEventLoopInteractor();
00075
00076 const GpgME::Context::EncryptionFlags flags =
00077 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None;
00078 const GpgME::Error err = mCtx->startEncryption( recipients, *mInData, *mOutData, flags );
00079
00080 if ( err )
00081 deleteLater();
00082 mResult = GpgME::EncryptionResult( err );
00083 return err;
00084 }
00085
00086 GpgME::EncryptionResult Kleo::QGpgMEEncryptJob::exec( const std::vector<GpgME::Key> & recipients,
00087 const QByteArray & plainText,
00088 bool alwaysTrust,
00089 QByteArray & ciphertext ) {
00090 setup( plainText );
00091 const GpgME::Context::EncryptionFlags flags =
00092 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None;
00093 mResult = mCtx->encrypt( recipients, *mInData, *mOutData, flags );
00094 ciphertext = mOutDataDataProvider->data();
00095 getAuditLog();
00096 return mResult;
00097 }
00098
00099 void Kleo::QGpgMEEncryptJob::doOperationDoneEvent( const GpgME::Error & ) {
00100 emit result( mResult = mCtx->encryptionResult(), mOutDataDataProvider->data() );
00101 }
00102
00103 void Kleo::QGpgMEEncryptJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
00104 if ( mResult.error() && !mResult.error().isCanceled() )
00105 Kleo::MessageBox::error( parent, mResult, this, caption );
00106 }
00107
00108 #include "qgpgmeencryptjob.moc"
|