LCOV - code coverage report
Current view: top level - lang/qt/src - multideletejob.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 40 0.0 %
Date: 2018-11-14 16:53:58 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /*
       2             :     multideletejob.cpp
       3             : 
       4             :     This file is part of qgpgme, the Qt API binding for gpgme
       5             :     Copyright (c) 2004 Klarälvdalens Datakonsult AB
       6             : 
       7             :     QGpgME is free software; you can redistribute it and/or
       8             :     modify it under the terms of the GNU General Public License as
       9             :     published by the Free Software Foundation; either version 2 of the
      10             :     License, or (at your option) any later version.
      11             : 
      12             :     QGpgME is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :     General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program; if not, write to the Free Software
      19             :     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      20             : 
      21             :     In addition, as a special exception, the copyright holders give
      22             :     permission to link the code of this program with any edition of
      23             :     the Qt library by Trolltech AS, Norway (or with modified versions
      24             :     of Qt that use the same license as Qt), and distribute linked
      25             :     combinations including the two.  You must obey the GNU General
      26             :     Public License in all respects for all of the code used other than
      27             :     Qt.  If you modify this file, you may extend this exception to
      28             :     your version of the file, but you are not obligated to do so.  If
      29             :     you do not wish to do so, delete this exception statement from
      30             :     your version.
      31             : */
      32             : 
      33             : #ifdef HAVE_CONFIG_H
      34             :  #include "config.h"
      35             : #endif
      36             : 
      37             : #include "multideletejob.h"
      38             : #include "protocol.h"
      39             : #include "deletejob.h"
      40             : 
      41             : #include <key.h>
      42             : #include <context.h>
      43             : #include <data.h>
      44             : 
      45             : #include <iterator>
      46             : 
      47             : #include <assert.h>
      48             : 
      49           0 : QGpgME::MultiDeleteJob::MultiDeleteJob(const Protocol *protocol)
      50             :     : Job(0),
      51             :       mProtocol(protocol),
      52           0 :       mJob(0)
      53             : {
      54           0 :     assert(protocol);
      55           0 : }
      56             : 
      57           0 : QGpgME::MultiDeleteJob::~MultiDeleteJob()
      58             : {
      59             : 
      60           0 : }
      61             : 
      62           0 : GpgME::Error QGpgME::MultiDeleteJob::start(const std::vector<GpgME::Key> &keys, bool allowSecretKeyDeletion)
      63             : {
      64           0 :     mKeys = keys;
      65           0 :     mAllowSecretKeyDeletion = allowSecretKeyDeletion;
      66           0 :     mIt = mKeys.begin();
      67             : 
      68           0 :     const GpgME::Error err = startAJob();
      69             : 
      70           0 :     if (err) {
      71           0 :         deleteLater();
      72             :     }
      73           0 :     return err;
      74             : }
      75             : 
      76           0 : void QGpgME::MultiDeleteJob::slotCancel()
      77             : {
      78           0 :     if (mJob) {
      79           0 :         mJob->slotCancel();
      80             :     }
      81           0 :     mIt = mKeys.end();
      82           0 : }
      83             : 
      84           0 : void QGpgME::MultiDeleteJob::slotResult(const GpgME::Error &err)
      85             : {
      86           0 :     mJob = 0;
      87           0 :     GpgME::Error error = err;
      88           0 :     if (error ||  // error in last op
      89           0 :             mIt == mKeys.end() || // (shouldn't happen)
      90           0 :             ++mIt == mKeys.end() || // was the last key
      91           0 :             (error = startAJob())) {  // error starting the job for the new key
      92           0 :         Q_EMIT done();
      93           0 :         Q_EMIT result(error, error && mIt != mKeys.end() ? *mIt : GpgME::Key::null);
      94           0 :         deleteLater();
      95           0 :         return;
      96             :     }
      97             : 
      98           0 :     const int current = mIt - mKeys.begin();
      99           0 :     const int total = mKeys.size();
     100           0 :     Q_EMIT progress(QStringLiteral("%1/%2").arg(current).arg(total), current, total);
     101             : }
     102             : 
     103           0 : GpgME::Error QGpgME::MultiDeleteJob::startAJob()
     104             : {
     105           0 :     if (mIt == mKeys.end()) {
     106           0 :         return GpgME::Error(0);
     107             :     }
     108           0 :     mJob = mProtocol->deleteJob();
     109           0 :     assert(mJob);   // FIXME: we need a way to generate errors ourselves,
     110             :     // but I don't like the dependency on gpg-error :/
     111             : 
     112           0 :     connect(mJob.data(), &DeleteJob::result, this, &MultiDeleteJob::slotResult);
     113             : 
     114           0 :     return mJob->start(*mIt, mAllowSecretKeyDeletion);
     115             : }
     116             : 
     117             : #include "multideletejob.moc"

Generated by: LCOV version 1.13