qgpgmesignencryptjob.cpp
00001 /* 00002 qgpgmesignencryptjob.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 "qgpgmesignencryptjob.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/data.h> 00046 #include <gpgmepp/key.h> 00047 00048 #include <tdelocale.h> 00049 00050 #include <assert.h> 00051 00052 Kleo::QGpgMESignEncryptJob::QGpgMESignEncryptJob( GpgME::Context * context ) 00053 : SignEncryptJob( QGpgME::EventLoopInteractor::instance(), "Kleo::QGpgMESignEncryptJob" ), 00054 QGpgMEJob( this, context ) 00055 { 00056 assert( context ); 00057 } 00058 00059 Kleo::QGpgMESignEncryptJob::~QGpgMESignEncryptJob() { 00060 } 00061 00062 GpgME::Error Kleo::QGpgMESignEncryptJob::setup( const std::vector<GpgME::Key> & signers, 00063 const TQByteArray & plainText ) { 00064 assert( !mInData ); 00065 assert( !mOutData ); 00066 00067 createInData( plainText ); 00068 createOutData(); 00069 00070 return setSigningKeys( signers ); 00071 } 00072 00073 GpgME::Error Kleo::QGpgMESignEncryptJob::start( const std::vector<GpgME::Key> & signers, 00074 const std::vector<GpgME::Key> & recipients, 00075 const TQByteArray & plainText, bool alwaysTrust ) { 00076 if ( const GpgME::Error error = setup( signers, plainText ) ) { 00077 deleteLater(); 00078 return error; 00079 } 00080 00081 hookupContextToEventLoopInteractor(); 00082 00083 const GpgME::Context::EncryptionFlags flags = 00084 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ; 00085 const GpgME::Error err = mCtx->startCombinedSigningAndEncryption( recipients, *mInData, *mOutData, flags ); 00086 00087 if ( err ) 00088 deleteLater(); 00089 mResult.first = GpgME::SigningResult( err ); 00090 mResult.second = GpgME::EncryptionResult( err ); 00091 return err; 00092 } 00093 00094 std::pair<GpgME::SigningResult,GpgME::EncryptionResult> 00095 Kleo::QGpgMESignEncryptJob::exec( const std::vector<GpgME::Key> & signers, 00096 const std::vector<GpgME::Key> & recipients, 00097 const TQByteArray & plainText, bool alwaysTrust, 00098 TQByteArray & cipherText ) { 00099 if ( GpgME::Error err = setup( signers, plainText ) ) 00100 return std::make_pair( GpgME::SigningResult( 0, err ), GpgME::EncryptionResult() ); 00101 const GpgME::Context::EncryptionFlags flags = 00102 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ; 00103 mResult = mCtx->signAndEncrypt( recipients, *mInData, *mOutData, flags ); 00104 cipherText = mOutDataDataProvider->data(); 00105 getAuditLog(); 00106 return mResult; 00107 } 00108 00109 void Kleo::QGpgMESignEncryptJob::doOperationDoneEvent( const GpgME::Error & ) { 00110 mResult.first = mCtx->signingResult(); 00111 mResult.second = mCtx->encryptionResult(); 00112 const TQByteArray cipherText = mOutDataDataProvider->data(); 00113 getAuditLog(); 00114 emit result( mResult.first, mResult.second, cipherText ); 00115 } 00116 00117 void Kleo::QGpgMESignEncryptJob::showErrorDialog( TQWidget * parent, const TQString & caption ) const { 00118 if ( (mResult.first.error() && !mResult.first.error().isCanceled()) || 00119 (mResult.second.error() && !mResult.second.error().isCanceled()) ) 00120 Kleo::MessageBox::error( parent, mResult.first, mResult.second, this, caption ); 00121 } 00122 00123 #include "qgpgmesignencryptjob.moc"