LCOV - code coverage report
Current view: top level - lang/qt/src - defaultkeygenerationjob.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 34 0.0 %
Date: 2016-09-12 13:07:23 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             : #include "defaultkeygenerationjob.h"
      32             : #include "protocol.h"
      33             : #include "keygenerationjob.h"
      34             : 
      35             : #include <QPointer>
      36             : #include <QEvent>
      37             : 
      38             : using namespace QGpgME;
      39             : 
      40             : namespace QGpgME {
      41             : 
      42             : class DefaultKeyGenerationJob::Private
      43             : {
      44             : public:
      45           0 :     Private()
      46           0 :     {}
      47             : 
      48           0 :     ~Private()
      49           0 :     {
      50           0 :         if (job) {
      51           0 :             job->deleteLater();
      52             :         }
      53           0 :     }
      54             : 
      55             :     QPointer<KeyGenerationJob> job;
      56             : };
      57             : }
      58             : 
      59             : 
      60           0 : DefaultKeyGenerationJob::DefaultKeyGenerationJob(QObject* parent)
      61             :     : Job(parent)
      62           0 :     , d(new DefaultKeyGenerationJob::Private())
      63             : {
      64           0 : }
      65             : 
      66           0 : DefaultKeyGenerationJob::~DefaultKeyGenerationJob()
      67             : {
      68           0 :     delete d;
      69           0 : }
      70             : 
      71           0 : QString DefaultKeyGenerationJob::auditLogAsHtml() const
      72             : {
      73           0 :     return d->job ? d->job->auditLogAsHtml() : QString();
      74             : }
      75             : 
      76           0 : GpgME::Error DefaultKeyGenerationJob::auditLogError() const
      77             : {
      78           0 :     return d->job ? d->job->auditLogError() : GpgME::Error();
      79             : }
      80             : 
      81           0 : void DefaultKeyGenerationJob::slotCancel()
      82             : {
      83           0 :     if (d->job) {
      84           0 :         d->job->slotCancel();
      85             :     }
      86           0 : }
      87             : 
      88           0 : GpgME::Error DefaultKeyGenerationJob::start(const QString &email, const QString &name)
      89             : {
      90           0 :     const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
      91             :                                         "%ask-passphrase\n"
      92             :                                         "key-type:      RSA\n"
      93             :                                         "key-length:    2048\n"
      94             :                                         "key-usage:     sign\n"
      95             :                                         "subkey-type:   RSA\n"
      96             :                                         "subkey-length: 2048\n"
      97             :                                         "subkey-usage:  encrypt\n"
      98             :                                         "name-email:    %1\n"
      99             :                                         "name-real:     %2\n"
     100           0 :                                         "</GnupgKeyParms>").arg(email, name);
     101             : 
     102           0 :     d->job = openpgp()->keyGenerationJob();
     103           0 :     d->job->installEventFilter(this);
     104             :     connect(d->job, &KeyGenerationJob::result,
     105           0 :             this, &DefaultKeyGenerationJob::result);
     106             :     connect(d->job, &KeyGenerationJob::done,
     107           0 :             this, &DefaultKeyGenerationJob::done);
     108             :     connect(d->job, &KeyGenerationJob::done,
     109           0 :             this, &QObject::deleteLater);
     110           0 :     return d->job->start(args);
     111             : }
     112             : 
     113           0 : bool DefaultKeyGenerationJob::eventFilter(QObject *watched, QEvent *event)
     114             : {
     115             :     // Intercept the KeyGenerationJob's deferred delete event. We want the job
     116             :     // to live at least as long as we do so we can delegate calls to it. We will
     117             :     // delete the job manually afterwards.
     118           0 :     if (watched == d->job && event->type() == QEvent::DeferredDelete) {
     119           0 :         return true;
     120             :     }
     121             : 
     122           0 :     return Job::eventFilter(watched, event);
     123             : }
     124             : 
     125             : #include "defaultkeygenerationjob.moc"

Generated by: LCOV version 1.11