diff --git a/NEWS b/NEWS index 83c8f5f2..fd26ad22 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ Noteworthy changes in version 1.10.0 (unreleased) cpp: Context::startCreateKey NEW. cpp: Context::createSubkey NEW. cpp: Context::startCreateSubkey NEW. + qt: QuickJob NEW. py: DecryptResult EXTENDED: New boolean field 'is_de_vs'. py: Signature EXTENDED: New boolean field 'is_de_vs'. py: GpgError EXTENDED: Partial results in 'results'. diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index 3b3cffc4..32251424 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -36,7 +36,7 @@ qgpgme_sources = \ qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \ qgpgmeverifyopaquejob.cpp threadedjobmixin.cpp \ qgpgmekeyformailboxjob.cpp gpgme_backend_debug.cpp \ - qgpgmetofupolicyjob.cpp \ + qgpgmetofupolicyjob.cpp qgpgmequickjob.cpp \ defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp \ dn.cpp cryptoconfig.cpp @@ -60,6 +60,7 @@ qgpgme_headers= \ protocol.h \ qgpgme_export.h \ qgpgmenewcryptoconfig.h \ + quickjob.h \ specialjob.h \ signjob.h \ signkeyjob.h \ @@ -97,6 +98,7 @@ camelcase_headers= \ MultiDeleteJob \ Protocol \ QGpgMENewCryptoConfig \ + QuickJob \ SpecialJob \ SignJob \ SignKeyJob \ @@ -145,6 +147,7 @@ private_qgpgme_headers = \ qgpgmekeyformailboxjob.h \ qgpgmewkspublishjob.h \ qgpgmetofupolicyjob.h \ + qgpgmequickjob.h \ threadedjobmixin.h qgpgme_moc_sources = \ @@ -202,7 +205,9 @@ qgpgme_moc_sources = \ keyformailboxjob.moc \ wkspublishjob.moc \ qgpgmekeyformailboxjob.moc \ - defaultkeygenerationjob.moc + defaultkeygenerationjob.moc \ + quickjob.moc \ + qgpgmequickjob.moc qgpgmeincludedir = $(includedir)/qgpgme qgpgmeinclude_HEADERS = $(qgpgme_headers) diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index 83c50441..c4270205 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -64,6 +64,7 @@ #include "wkspublishjob.h" #include "tofupolicyjob.h" #include "threadedjobmixin.h" +#include "quickjob.h" #include #include @@ -139,6 +140,7 @@ make_job_subclass(SpecialJob) make_job_subclass(KeyForMailboxJob) make_job_subclass(WKSPublishJob) make_job_subclass(TofuPolicyJob) +make_job_subclass(QuickJob) #undef make_job_subclass @@ -170,3 +172,4 @@ make_job_subclass(TofuPolicyJob) #include "keyformailboxjob.moc" #include "wkspublishjob.moc" #include "tofupolicyjob.moc" +#include "quickjob.moc" diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h index 6794bc2b..1a52097e 100644 --- a/lang/qt/src/protocol.h +++ b/lang/qt/src/protocol.h @@ -66,6 +66,7 @@ class SpecialJob; class KeyForMailboxJob; class WKSPublishJob; class TofuPolicyJob; +class QuickJob; /** The main entry point for QGpgME Comes in OpenPGP and SMIME(CMS) flavors. * @@ -157,6 +158,9 @@ public: /** A Job to set tofu policy */ virtual TofuPolicyJob *tofuPolicyJob() const = 0; + + /** A Job for the quick commands */ + virtual QuickJob *quickJob() const = 0; }; /** Obtain a reference to the OpenPGP Protocol. diff --git a/lang/qt/src/protocol_p.h b/lang/qt/src/protocol_p.h index 58a0fa6a..b6d1abfa 100644 --- a/lang/qt/src/protocol_p.h +++ b/lang/qt/src/protocol_p.h @@ -60,6 +60,7 @@ #include "qgpgmekeyformailboxjob.h" #include "qgpgmewkspublishjob.h" #include "qgpgmetofupolicyjob.h" +#include "qgpgmequickjob.h" namespace { @@ -414,6 +415,18 @@ public: } return new QGpgME::QGpgMETofuPolicyJob(context); } + + QGpgME::QuickJob *quickJob() const Q_DECL_OVERRIDE + { + if (mProtocol != GpgME::OpenPGP) { + return Q_NULLPTR; + } + GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); + if (!context) { + return Q_NULLPTR; + } + return new QGpgME::QGpgMEQuickJob(context); + } }; } diff --git a/lang/qt/src/qgpgmequickjob.cpp b/lang/qt/src/qgpgmequickjob.cpp new file mode 100644 index 00000000..13ec0a9f --- /dev/null +++ b/lang/qt/src/qgpgmequickjob.cpp @@ -0,0 +1,123 @@ +/* qgpgmequickjob.cpp + + Copyright (c) 2017 Intevation GmbH + + QGpgME is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + QGpgME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include "qgpgmequickjob.h" + +#include "context.h" +#include "key.h" +#include "util.h" + +using namespace QGpgME; +using namespace GpgME; + +QGpgMEQuickJob::QGpgMEQuickJob(Context *context) + : mixin_type(context) +{ + lateInitialization(); +} + +QGpgMEQuickJob::~QGpgMEQuickJob() {} + +static QGpgMEQuickJob::result_type createWorker(GpgME::Context *ctx, + const QString &uid, + const char *algo, + const QDateTime &expires, + const GpgME::Key &key, + unsigned int flags) +{ + auto err = ctx->createKey(uid.toUtf8().constData(), + algo, + 0, + expires.isValid() ? (unsigned long) expires.toSecsSinceEpoch() : 0, + key, + flags); + return std::make_tuple(err, QString(), Error()); +} + +static QGpgMEQuickJob::result_type addSubkeyWorker(GpgME::Context *ctx, + const GpgME::Key &key, + const char *algo, + const QDateTime &expires, + unsigned int flags) +{ + auto err = ctx->createSubkey(key, algo, 0, + expires.isValid() ? (unsigned long) expires.toSecsSinceEpoch() : 0, + flags); + return std::make_tuple(err, QString(), Error()); +} + +static QGpgMEQuickJob::result_type addUidWorker(GpgME::Context *ctx, + const GpgME::Key &key, + const QString &uid) +{ + auto err = ctx->addUid(key, uid.toUtf8().constData()); + return std::make_tuple(err, QString(), Error()); +} + +static QGpgMEQuickJob::result_type revUidWorker(GpgME::Context *ctx, + const GpgME::Key &key, + const QString &uid) +{ + auto err = ctx->revUid(key, uid.toUtf8().constData()); + return std::make_tuple(err, QString(), Error()); +} + +void QGpgMEQuickJob::startCreate(const QString &uid, + const char *algo, + const QDateTime &expires, + const GpgME::Key &key, + unsigned int flags) +{ + run(std::bind(&createWorker, std::placeholders::_1, uid, algo, + expires, key, flags)); +} + +void QGpgMEQuickJob::startAddUid(const GpgME::Key &key, const QString &uid) +{ + run(std::bind(&addUidWorker, std::placeholders::_1, key, uid)); +} + +void QGpgMEQuickJob::startRevUid(const GpgME::Key &key, const QString &uid) +{ + run(std::bind(&revUidWorker, std::placeholders::_1, key, uid)); +} + +void QGpgMEQuickJob::startAddSubkey(const GpgME::Key &key, const char *algo, + const QDateTime &expires, + unsigned int flags) +{ + run(std::bind(&addSubkeyWorker, std::placeholders::_1, key, algo, + expires, flags)); +} +#include "qgpgmequickjob.moc" diff --git a/lang/qt/src/qgpgmequickjob.h b/lang/qt/src/qgpgmequickjob.h new file mode 100644 index 00000000..82c73327 --- /dev/null +++ b/lang/qt/src/qgpgmequickjob.h @@ -0,0 +1,82 @@ +/* qgpgmequickjob.h + + Copyright (c) 2017 Intevation GmbH + + QGpgME is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + QGpgME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ +#ifndef QGPGME_QGPGMEQUICKJOB_H +#define QGPGME_QGPGMEQUICKJOB_H + +#include "quickjob.h" + +#include "threadedjobmixin.h" + +namespace GpgME { +class Key; +} + +class QDateTime; +class QString; + +namespace QGpgME{ + +/** + * Interface to the modern key manipulation functions. + */ +class QGpgMEQuickJob +#ifdef Q_MOC_RUN + : public QuickJob +#else + : public _detail::ThreadedJobMixin > +#endif +{ + Q_OBJECT +#ifdef Q_MOC_RUN +public Q_SLOTS: + void slotFinished(); +#endif +public: + explicit QGpgMEQuickJob(GpgME::Context *context); + ~QGpgMEQuickJob(); + + void startCreate(const QString &uid, + const char *algo, + const QDateTime &expires = QDateTime(), + const GpgME::Key &key = GpgME::Key(), + unsigned int flags = 0) Q_DECL_OVERRIDE; + void startAddUid(const GpgME::Key &key, const QString &uid) Q_DECL_OVERRIDE; + void startRevUid(const GpgME::Key &key, const QString &uid) Q_DECL_OVERRIDE; + void startAddSubkey(const GpgME::Key &key, const char *algo, + const QDateTime &expires = QDateTime(), + unsigned int flags = 0) Q_DECL_OVERRIDE; + +Q_SIGNALS: + void result(const GpgME::Error &error, + const QString &auditLogAsHtml, const GpgME::Error &auditLogError); +}; + +} +#endif diff --git a/lang/qt/src/quickjob.h b/lang/qt/src/quickjob.h new file mode 100644 index 00000000..c0a655b7 --- /dev/null +++ b/lang/qt/src/quickjob.h @@ -0,0 +1,83 @@ +/* quickjob.h + + Copyright (c) 2017 Intevation GmbH + + QGpgME is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + QGpgME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ +#ifndef QGPGME_QUICKJOB_H +#define QGPGME_QUICKJOB_H + +#include "job.h" + +#include "qgpgme_export.h" + +#include + +#ifdef BUILDING_QGPGME +# include "key.h" +#else +# include +#endif + +class QString; + +namespace QGpgME{ + +/** + * Interface to the modern key manipulation functions. + */ +class QGPGME_EXPORT QuickJob : public Job +{ + Q_OBJECT +public: + explicit QuickJob(QObject *parent = Q_NULLPTR); + ~QuickJob(); + + /** Start --quick-gen-key */ + virtual void startCreate(const QString &uid, + const char *algo, + const QDateTime &expires = QDateTime(), + const GpgME::Key &key = GpgME::Key(), + unsigned int flags = 0) = 0; + + /** Start --quick-adduid */ + virtual void startAddUid(const GpgME::Key &key, const QString &uid) = 0; + + /** Start --quick-revuid */ + virtual void startRevUid(const GpgME::Key &key, const QString &uid) = 0; + + /** Start --quick-add-key */ + virtual void startAddSubkey(const GpgME::Key &key, const char *algo, + const QDateTime &expires = QDateTime(), + unsigned int flags = 0) = 0; + +Q_SIGNALS: + void result(const GpgME::Error &error, + const QString &auditLogAsHtml, const GpgME::Error &auditLogError); +}; + +} +#endif