certmanager/lib
qgpgmesignjob.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 "qgpgmesignjob.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/signingresult.h>
00046 #include <gpgmepp/data.h>
00047 #include <gpgmepp/key.h>
00048
00049 #include <klocale.h>
00050
00051 #include <assert.h>
00052
00053 Kleo::QGpgMESignJob::QGpgMESignJob( GpgME::Context * context )
00054 : SignJob( QGpgME::EventLoopInteractor::instance(), "Kleo::QGpgMESignJob" ),
00055 QGpgMEJob( this, context )
00056 {
00057 assert( context );
00058 }
00059
00060 Kleo::QGpgMESignJob::~QGpgMESignJob() {
00061 }
00062
00063 GpgME::Error Kleo::QGpgMESignJob::setup( const std::vector<GpgME::Key> & signers,
00064 const QByteArray & plainText ) {
00065 assert( !mInData );
00066 assert( !mOutData );
00067
00068 createInData( plainText );
00069 createOutData();
00070
00071 return setSigningKeys( signers );
00072 }
00073
00074 GpgME::Error Kleo::QGpgMESignJob::start( const std::vector<GpgME::Key> & signers,
00075 const QByteArray & plainText,
00076 GpgME::Context::SignatureMode mode ) {
00077 if ( const GpgME::Error error = setup( signers, plainText ) ) {
00078 deleteLater();
00079 return error;
00080 }
00081
00082 hookupContextToEventLoopInteractor();
00083
00084 const GpgME::Error err = mCtx->startSigning( *mInData, *mOutData, mode );
00085
00086 if ( err )
00087 deleteLater();
00088 mResult = GpgME::SigningResult( err );
00089 return err;
00090 }
00091
00092 GpgME::SigningResult Kleo::QGpgMESignJob::exec( const std::vector<GpgME::Key> & signers,
00093 const QByteArray & plainText,
00094 GpgME::Context::SignatureMode mode,
00095 QByteArray & signature ) {
00096 if ( const GpgME::Error err = setup( signers, plainText ) )
00097 return mResult = GpgME::SigningResult( 0, err );
00098 mResult = mCtx->sign( *mInData, *mOutData, mode );
00099 signature = mOutDataDataProvider->data();
00100 getAuditLog();
00101 return mResult;
00102 }
00103
00104 void Kleo::QGpgMESignJob::doOperationDoneEvent( const GpgME::Error & ) {
00105 mResult = mCtx->signingResult();
00106 const QByteArray signature = mOutDataDataProvider->data();
00107 getAuditLog();
00108 emit result( mResult, signature );
00109 }
00110
00111 void Kleo::QGpgMESignJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
00112 if ( mResult.error() && !mResult.error().isCanceled() )
00113 Kleo::MessageBox::error( parent, mResult, this, caption );
00114 }
00115
00116 #include "qgpgmesignjob.moc"
|