certmanager/lib

multideletejob.cpp

00001 /*
00002     multideletejob.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 Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), 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     Qt.  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 "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 || // error in last op
00084        mIt == mKeys.end() || // (shouldn't happen)
00085        ++mIt == mKeys.end() || // was the last key
00086        (error = startAJob()) ) { // error starting the job for the new key
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 ); // FIXME: we need a way to generate errors ourselves,
00103           // but I don't like the dependency on gpg-error :/
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"
KDE Home | KDE Accessibility Home | Description of Access Keys