• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • pim API Reference
  • KDE Home
  • Contact Us
 

libkleo

  • kde-4.x
  • pim
  • libkleo
  • src
  • kleo
defaultkeygenerationjob.cpp
Go to the documentation of this file.
1 /* This file is part of Kleopatra, the KDE keymanager
2  Copyright (c) 2016 Klarälvdalens Datakonsult AB
3 
4  Kleopatra is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  Kleopatra is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "defaultkeygenerationjob.h"
20 
21 #include <qgpgme/protocol.h>
22 #include <qgpgme/keygenerationjob.h>
23 
24 #include <QPointer>
25 #include <QEvent>
26 
27 using namespace Kleo;
28 
29 namespace Kleo {
30 
31 class DefaultKeyGenerationJob::Private
32 {
33 public:
34  Private()
35  {}
36 
37  ~Private()
38  {
39  if (job) {
40  job->deleteLater();
41  }
42  }
43 
44  QString passphrase;
45  QPointer<QGpgME::KeyGenerationJob> job;
46 };
47 }
48 
49 
50 DefaultKeyGenerationJob::DefaultKeyGenerationJob(QObject* parent)
51  : Job(parent)
52  , d(new DefaultKeyGenerationJob::Private())
53 {
54 }
55 
56 DefaultKeyGenerationJob::~DefaultKeyGenerationJob()
57 {
58  delete d;
59 }
60 
61 QString DefaultKeyGenerationJob::auditLogAsHtml() const
62 {
63  return d->job ? d->job->auditLogAsHtml() : QString();
64 }
65 
66 GpgME::Error DefaultKeyGenerationJob::auditLogError() const
67 {
68  return d->job ? d->job->auditLogError() : GpgME::Error();
69 }
70 
71 void DefaultKeyGenerationJob::slotCancel()
72 {
73  if (d->job) {
74  d->job->slotCancel();
75  }
76 }
77 
78 void DefaultKeyGenerationJob::setPassphrase(const QString &passphrase)
79 {
80  // null QString = ask for passphrase
81  // empty QString = empty passphrase
82  // non-empty QString = passphrase
83  d->passphrase = passphrase.isNull() ? QLatin1String("") : passphrase;
84 }
85 
86 GpgME::Error DefaultKeyGenerationJob::start(const QString &email, const QString &name)
87 {
88  const QString passphrase = d->passphrase.isNull() ? QStringLiteral("%ask-passphrase") :
89  d->passphrase.isEmpty() ? QStringLiteral("%no-protection") :
90  QStringLiteral("passphrase: %1").arg(d->passphrase);
91 
92  const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
93  "key-type: RSA\n"
94  "key-length: 2048\n"
95  "key-usage: sign\n"
96  "subkey-type: RSA\n"
97  "subkey-length: 2048\n"
98  "subkey-usage: encrypt\n"
99  "%1\n"
100  "name-email: %2\n"
101  "name-real: %3\n"
102  "</GnupgKeyParms>").arg(passphrase, email, name);
103 
104  d->job = QGpgME::openpgp()->keyGenerationJob();
105  d->job->installEventFilter(this);
106  connect(d->job.data(), &QGpgME::KeyGenerationJob::result, this, &DefaultKeyGenerationJob::result);
107  connect(d->job.data(), &QGpgME::KeyGenerationJob::done, this, &DefaultKeyGenerationJob::done);
108  connect(d->job.data(), &QGpgME::KeyGenerationJob::done, this, &QObject::deleteLater);
109  return d->job->start(args);
110 }
111 
112 bool DefaultKeyGenerationJob::eventFilter(QObject *watched, QEvent *event)
113 {
114  // Intercept the KeyGenerationJob's deferred delete event. We want the job
115  // to live at least as long as we do so we can delegate calls to it. We will
116  // delete the job manually afterwards.
117  if (watched == d->job && event->type() == QEvent::DeferredDelete) {
118  return true;
119  }
120 
121  return Job::eventFilter(watched, event);
122 }
Kleo::DefaultKeyGenerationJob::setPassphrase
void setPassphrase(const QString &passphrase)
Set key passphrase.
Definition: defaultkeygenerationjob.cpp:78
QEvent
QEvent::type
Type type() const
name
const char * name
Definition: kconfigbasedkeyfilter.cpp:127
email
static std::string email(const UserID &uid)
Definition: keycache.cpp:714
QPointer< QGpgME::KeyGenerationJob >
Kleo::DefaultKeyGenerationJob::result
void result(const GpgME::KeyGenerationResult &result, const QByteArray &pubkeyData, const QString &auditLogAsHtml, const GpgME::Error &auditLogError)
Kleo::DefaultKeyGenerationJob::auditLogError
GpgME::Error auditLogError() const override
Definition: defaultkeygenerationjob.cpp:66
Kleo::DefaultKeyGenerationJob::start
GpgME::Error start(const QString &email, const QString &name)
Definition: defaultkeygenerationjob.cpp:86
Kleo::DefaultKeyGenerationJob::slotCancel
void slotCancel() override
Definition: defaultkeygenerationjob.cpp:71
QString::isNull
bool isNull() const
QObject
Kleo::DefaultKeyGenerationJob::eventFilter
bool eventFilter(QObject *watched, QEvent *event) override
Definition: defaultkeygenerationjob.cpp:112
QObject::deleteLater
void deleteLater()
QString
Kleo::DefaultKeyGenerationJob::~DefaultKeyGenerationJob
~DefaultKeyGenerationJob() override
Definition: defaultkeygenerationjob.cpp:56
QLatin1String
defaultkeygenerationjob.h
Kleo::DefaultKeyGenerationJob::DefaultKeyGenerationJob
DefaultKeyGenerationJob(QObject *parent=nullptr)
Definition: defaultkeygenerationjob.cpp:50
Kleo::DefaultKeyGenerationJob
Generates a PGP RSA/2048 bit key pair for given name and email address.
Definition: defaultkeygenerationjob.h:37
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Kleo::DefaultKeyGenerationJob::auditLogAsHtml
QString auditLogAsHtml() const override
Definition: defaultkeygenerationjob.cpp:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Wed Dec 11 2019 06:52:29 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

pim API Reference

Skip menu "pim API Reference"
  • akonadi-calendar-tools
  •   konsolekalendar
  • akregator
  •   src
  • kalarmcal
  •   src
  •     lib
  • kdepim-runtime
  •   agents
  •   src
  • kleopatra
  •   src
  • kmailtransport
  • knotes
  • kontact
  • kontactinterface
  • kpimtextedit
  • ksmtp
  • ktnef
  • libkgapi
  • libkleo
  •   src
  •     src
  •     src

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal