LCOV - code coverage report
Current view: top level - lang/qt/src - defaultkeygenerationjob.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 37 0.0 %
Date: 2016-12-01 18:45:36 Functions: 0 11 0.0 %

          Line data    Source code
       1             : /* defaultkeygenerationjob.cpp
       2             : 
       3             :     Copyright (c) 2016 Klarälvdalens Datakonsult AB
       4             : 
       5             :     QGpgME is free software; you can redistribute it and/or
       6             :     modify it under the terms of the GNU General Public License as
       7             :     published by the Free Software Foundation; either version 2 of the
       8             :     License, or (at your option) any later version.
       9             : 
      10             :     QGpgME is distributed in the hope that it will be useful,
      11             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :     General Public License for more details.
      14             : 
      15             :     You should have received a copy of the GNU General Public License along
      16             :     with this program; if not, write to the Free Software Foundation, Inc.,
      17             :     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      18             : 
      19             :     In addition, as a special exception, the copyright holders give
      20             :     permission to link the code of this program with any edition of
      21             :     the Qt library by Trolltech AS, Norway (or with modified versions
      22             :     of Qt that use the same license as Qt), and distribute linked
      23             :     combinations including the two.  You must obey the GNU General
      24             :     Public License in all respects for all of the code used other than
      25             :     Qt.  If you modify this file, you may extend this exception to
      26             :     your version of the file, but you are not obligated to do so.  If
      27             :     you do not wish to do so, delete this exception statement from
      28             :     your version.
      29             : */
      30             : 
      31             : #ifdef HAVE_CONFIG_H
      32             :  #include "config.h"
      33             : #endif
      34             : 
      35             : #include "defaultkeygenerationjob.h"
      36             : #include "protocol.h"
      37             : #include "keygenerationjob.h"
      38             : 
      39             : #include <QPointer>
      40             : #include <QEvent>
      41             : 
      42             : using namespace QGpgME;
      43             : 
      44             : namespace QGpgME {
      45             : 
      46             : class DefaultKeyGenerationJob::Private
      47             : {
      48             : public:
      49           0 :     Private()
      50           0 :     {}
      51             : 
      52           0 :     ~Private()
      53           0 :     {
      54           0 :         if (job) {
      55           0 :             job->deleteLater();
      56             :         }
      57           0 :     }
      58             : 
      59             :     QPointer<KeyGenerationJob> job;
      60             : };
      61             : }
      62             : 
      63             : 
      64           0 : DefaultKeyGenerationJob::DefaultKeyGenerationJob(QObject* parent)
      65             :     : Job(parent)
      66           0 :     , d(new DefaultKeyGenerationJob::Private())
      67             : {
      68           0 : }
      69             : 
      70           0 : DefaultKeyGenerationJob::~DefaultKeyGenerationJob()
      71             : {
      72           0 :     delete d;
      73           0 : }
      74             : 
      75           0 : QString DefaultKeyGenerationJob::auditLogAsHtml() const
      76             : {
      77           0 :     return d->job ? d->job->auditLogAsHtml() : QString();
      78             : }
      79             : 
      80           0 : GpgME::Error DefaultKeyGenerationJob::auditLogError() const
      81             : {
      82           0 :     return d->job ? d->job->auditLogError() : GpgME::Error();
      83             : }
      84             : 
      85           0 : void DefaultKeyGenerationJob::slotCancel()
      86             : {
      87           0 :     if (d->job) {
      88           0 :         d->job->slotCancel();
      89             :     }
      90           0 : }
      91             : 
      92           0 : GpgME::Error DefaultKeyGenerationJob::start(const QString &email, const QString &name)
      93             : {
      94           0 :     const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
      95             :                                         "%ask-passphrase\n"
      96             :                                         "key-type:      RSA\n"
      97             :                                         "key-length:    2048\n"
      98             :                                         "key-usage:     sign\n"
      99             :                                         "subkey-type:   RSA\n"
     100             :                                         "subkey-length: 2048\n"
     101             :                                         "subkey-usage:  encrypt\n"
     102             :                                         "name-email:    %1\n"
     103             :                                         "name-real:     %2\n"
     104           0 :                                         "</GnupgKeyParms>").arg(email, name);
     105             : 
     106           0 :     d->job = openpgp()->keyGenerationJob();
     107           0 :     d->job->installEventFilter(this);
     108           0 :     connect(d->job.data(), &KeyGenerationJob::result,
     109           0 :             this, &DefaultKeyGenerationJob::result);
     110           0 :     connect(d->job.data(), &KeyGenerationJob::done,
     111           0 :             this, &DefaultKeyGenerationJob::done);
     112           0 :     connect(d->job.data(), &KeyGenerationJob::done,
     113           0 :             this, &QObject::deleteLater);
     114           0 :     return d->job->start(args);
     115             : }
     116             : 
     117           0 : bool DefaultKeyGenerationJob::eventFilter(QObject *watched, QEvent *event)
     118             : {
     119             :     // Intercept the KeyGenerationJob's deferred delete event. We want the job
     120             :     // to live at least as long as we do so we can delegate calls to it. We will
     121             :     // delete the job manually afterwards.
     122           0 :     if (watched == d->job && event->type() == QEvent::DeferredDelete) {
     123           0 :         return true;
     124             :     }
     125             : 
     126           0 :     return Job::eventFilter(watched, event);
     127             : }
     128             : 
     129             : #include "defaultkeygenerationjob.moc"

Generated by: LCOV version 1.11