certmanager/lib
multideletejob.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 "multideletejob.h"
00038 #include "cryptobackend.h"
00039 #include "deletejob.h"
00040
00041 #include <klocale.h>
00042
00043 #include <gpgmepp/key.h>
00044 #include <gpgmepp/context.h>
00045 #include <gpgmepp/data.h>
00046
00047 #include <iterator>
00048
00049 #include <assert.h>
00050
00051 Kleo::MultiDeleteJob::MultiDeleteJob( const CryptoBackend::Protocol * protocol )
00052 : Job( 0, "Kleo::MultiDeleteJob" ),
00053 mProtocol( protocol ),
00054 mJob( 0 )
00055 {
00056 assert( protocol );
00057 }
00058
00059 Kleo::MultiDeleteJob::~MultiDeleteJob() {
00060
00061 }
00062
00063 GpgME::Error Kleo::MultiDeleteJob::start( const std::vector<GpgME::Key> & keys, bool allowSecretKeyDeletion ) {
00064 mKeys = keys;
00065 mAllowSecretKeyDeletion = allowSecretKeyDeletion;
00066 mIt = mKeys.begin();
00067
00068 const GpgME::Error err = startAJob();
00069
00070 if ( err )
00071 deleteLater();
00072 return err;
00073 }
00074
00075 void Kleo::MultiDeleteJob::slotCancel() {
00076 if ( mJob ) mJob->slotCancel();
00077 mIt = mKeys.end();
00078 }
00079
00080 void Kleo::MultiDeleteJob::slotResult( const GpgME::Error & err ) {
00081 mJob = 0;
00082 GpgME::Error error = err;
00083 if ( error ||
00084 mIt == mKeys.end() ||
00085 ++mIt == mKeys.end() ||
00086 (error = startAJob()) ) {
00087 emit done();
00088 emit result( error, error && mIt != mKeys.end() ? *mIt : GpgME::Key::null );
00089 deleteLater();
00090 return;
00091 }
00092
00093 const int current = mIt - mKeys.begin();
00094 const int total = mKeys.size();
00095 emit progress( i18n("progress info: \"%1 of %2\"","%1/%2").arg( current ).arg( total ), current, total );
00096 }
00097
00098 GpgME::Error Kleo::MultiDeleteJob::startAJob() {
00099 if ( mIt == mKeys.end() )
00100 return 0;
00101 mJob = mProtocol->deleteJob();
00102 assert( mJob );
00103
00104
00105 connect( mJob, SIGNAL(result(const GpgME::Error&)), SLOT(slotResult(const GpgME::Error&)) );
00106
00107 return mJob->start( *mIt, mAllowSecretKeyDeletion );
00108 }
00109
00110 #include "multideletejob.moc"
|