qgpgmesignjob.cpp
00001 /* 00002 qgpgmesignjob.cpp 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klarälvdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. 00011 00012 Libkleopatra is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the TQt library by Trolltech AS, Norway (or with modified versions 00024 of TQt that use the same license as TQt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 TQt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 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 TQByteArray & 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 TQByteArray & 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 TQByteArray & plainText, 00094 GpgME::Context::SignatureMode mode, 00095 TQByteArray & 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 TQByteArray signature = mOutDataDataProvider->data(); 00107 getAuditLog(); 00108 emit result( mResult, signature ); 00109 } 00110 00111 void Kleo::QGpgMESignJob::showErrorDialog( TQWidget * parent, const TQString & caption ) const { 00112 if ( mResult.error() && !mResult.error().isCanceled() ) 00113 Kleo::MessageBox::error( parent, mResult, this, caption ); 00114 } 00115 00116 #include "qgpgmesignjob.moc"