qt: Add job for tofupolicy

* lang/qt/src/job.cpp, lang/qt/src/protocol.h,
lang/qt/src/protocol_p.h: Register job.
* lang/qt/src/qgpgmetofupolicyjob.cpp,
lang/qt/src/qgpgmetofupolicyjob.h,
lang/qt/src/tofupolicyjob.h: New.
* lang/qt/src/Makefile.am: Update accordingly.
This commit is contained in:
Andre Heinecke 2016-09-16 16:55:25 +02:00
parent 4d384d7bfe
commit 77aecfb5c9
7 changed files with 237 additions and 1 deletions

View File

@ -34,6 +34,7 @@ qgpgme_sources = \
qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \
qgpgmeverifyopaquejob.cpp threadedjobmixin.cpp \
qgpgmekeyformailboxjob.cpp gpgme_backend_debug.cpp \
qgpgmetofupolicyjob.cpp \
defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp
# If you add one here make sure that you also add one in camelcase
@ -69,6 +70,7 @@ qgpgme_headers= \
listallkeysjob.h \
verifydetachedjob.h \
defaultkeygenerationjob.h \
tofupolicyjob.h \
wkspublishjob.h
camelcase_headers= \
@ -102,7 +104,8 @@ camelcase_headers= \
VerifyDetachedJob \
KeyForMailboxJob \
DefaultKeyGenerationJob \
WKSPublishJob
WKSPublishJob \
TofuPolicyJob
private_qgpgme_headers = \
qgpgme_export.h \
@ -133,6 +136,7 @@ private_qgpgme_headers = \
qgpgmeverifyopaquejob.h \
qgpgmekeyformailboxjob.h \
qgpgmewkspublishjob.h \
qgpgmetofupolicyjob.h \
specialjob.h \
threadedjobmixin.h
@ -179,6 +183,8 @@ qgpgme_moc_sources = \
qgpgmeverifydetachedjob.moc \
qgpgmeverifyopaquejob.moc \
qgpgmewkspublishjob.moc \
tofupolicyjob.moc \
qgpgmetofupolicyjob.moc \
refreshkeysjob.moc \
signencryptjob.moc \
signjob.moc \

View File

@ -57,6 +57,7 @@
#include "specialjob.h"
#include "keyformailboxjob.h"
#include "wkspublishjob.h"
#include "tofupolicyjob.h"
#include <QCoreApplication>
#include <QDebug>
@ -124,6 +125,7 @@ make_job_subclass(AddUserIDJob)
make_job_subclass(SpecialJob)
make_job_subclass(KeyForMailboxJob)
make_job_subclass(WKSPublishJob)
make_job_subclass(TofuPolicyJob)
#undef make_job_subclass
@ -154,3 +156,4 @@ make_job_subclass(WKSPublishJob)
#include "specialjob.moc"
#include "keyformailboxjob.moc"
#include "wkspublishjob.moc"
#include "tofupolicyjob.moc"

View File

@ -64,6 +64,7 @@ class AddUserIDJob;
class SpecialJob;
class KeyForMailboxJob;
class WKSPublishJob;
class TofuPolicyJob;
/** The main entry point for QGpgME Comes in OpenPGP and SMIME(CMS) flavors.
*
@ -152,6 +153,9 @@ public:
/** A Job for interacting with gnupg's wks tools. */
virtual WKSPublishJob *wksPublishJob() const = 0;
/** A Job to set tofu policy */
virtual TofuPolicyJob *tofuPolicyJob() const = 0;
};
/** Obtain a reference to the OpenPGP Protocol.

View File

@ -58,6 +58,7 @@
#include "qgpgmeadduseridjob.h"
#include "qgpgmekeyformailboxjob.h"
#include "qgpgmewkspublishjob.h"
#include "qgpgmetofupolicyjob.h"
namespace
{
@ -400,6 +401,18 @@ public:
}
return new QGpgME::QGpgMEWKSPublishJob(context.release());
}
QGpgME::TofuPolicyJob *tofuPolicyJob() 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::QGpgMETofuPolicyJob(context);
}
};
}

View File

@ -0,0 +1,65 @@
/* qgpgmetofupolicyjob.cpp
Copyright (c) 2016 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.
*/
#include "qgpgmetofupolicyjob.h"
#include "context.h"
#include "key.h"
#include "tofuinfo.h"
using namespace QGpgME;
using namespace GpgME;
QGpgMETofuPolicyJob::QGpgMETofuPolicyJob(Context *context)
: mixin_type(context)
{
lateInitialization();
}
QGpgMETofuPolicyJob::~QGpgMETofuPolicyJob() {}
static QGpgMETofuPolicyJob::result_type policy_worker(Context *ctx, const Key &key, TofuInfo::Policy policy)
{
return std::make_tuple (ctx->setTofuPolicy(key, policy),
QString(), Error());
}
void QGpgMETofuPolicyJob::start(const Key &key, TofuInfo::Policy policy)
{
run(std::bind(&policy_worker, std::placeholders::_1, key, policy));
}
Error QGpgMETofuPolicyJob::exec(const Key &key, TofuInfo::Policy policy)
{
return std::get<0>(policy_worker(context(), key, policy));
}
#include "qgpgmetofupolicyjob.moc"

View File

@ -0,0 +1,65 @@
/* qgpgmetofupolicyjob.h
Copyright (c) 2016 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_QGPGMETOFUPOLICYJOB_H
#define QGPGME_QGPGMETOFUPOLICYJOB_H
#include "tofupolicyjob.h"
#include "threadedjobmixin.h"
namespace GpgME
{
class Key;
} // namespace GpgME
namespace QGpgME {
class QGpgMETofuPolicyJob
#ifdef Q_MOC_RUN
: public TofuPolicyJob
#else
: public _detail::ThreadedJobMixin<TofuPolicyJob, std::tuple<GpgME::Error, QString, GpgME::Error> >
#endif
{
Q_OBJECT
#ifdef Q_MOC_RUN
public Q_SLOTS:
void slotFinished();
#endif
public:
explicit QGpgMETofuPolicyJob(GpgME::Context *context);
~QGpgMETofuPolicyJob();
void start(const GpgME::Key &key, GpgME::TofuInfo::Policy policy) Q_DECL_OVERRIDE;
GpgME::Error exec(const GpgME::Key &key, GpgME::TofuInfo::Policy policy) Q_DECL_OVERRIDE;
};
}
#endif

View File

@ -0,0 +1,80 @@
/* tofupolicyjob.h
Copyright (c) 2016 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_TOFUPOLICYJOB_H
#define QGPGME_TOFUPOLICYJOB_H
#include "job.h"
#include "qgpgme_export.h"
#ifdef BUILDING_QGPGME
# include "tofuinfo.h"
#else
# include <gpgme++/tofuinfo.h>
#endif
namespace GpgME
{
class Key;
} // namespace GpgME
namespace QGpgME {
/**
* Set the TOFU Policy for a key
*/
class QGPGME_EXPORT TofuPolicyJob: public Job
{
Q_OBJECT
protected:
explicit TofuPolicyJob(QObject *parent);
public:
~TofuPolicyJob();
/* Set the policy to \a policy see the gpgme manual for
* policy explanations. */
virtual void start(const GpgME::Key &key, GpgME::TofuInfo::Policy policy) = 0;
virtual GpgME::Error exec(const GpgME::Key &key, GpgME::TofuInfo::Policy policy) = 0;
Q_SIGNALS:
/* Result of the operation
*
* As usual auditLogAsHtml and auditLogError can be ignored.
**/
void result(const GpgME::Error &error,
const QString &auditLogAsHtml = QString(),
const GpgME::Error &auditLogError = GpgME::Error());
};
}
#endif