diff options
Diffstat (limited to 'lang/qt/src')
-rw-r--r-- | lang/qt/src/Makefile.am | 6 | ||||
-rw-r--r-- | lang/qt/src/job.cpp | 3 | ||||
-rw-r--r-- | lang/qt/src/protocol.h | 7 | ||||
-rw-r--r-- | lang/qt/src/protocol_p.h | 13 | ||||
-rw-r--r-- | lang/qt/src/qgpgmesetprimaryuseridjob.cpp | 75 | ||||
-rw-r--r-- | lang/qt/src/qgpgmesetprimaryuseridjob.h | 64 | ||||
-rw-r--r-- | lang/qt/src/setprimaryuseridjob.h | 69 |
7 files changed, 237 insertions, 0 deletions
diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index 199db9b9..3923e5bf 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -37,6 +37,7 @@ qgpgme_sources = \ qgpgmereceivekeysjob.cpp \ qgpgmerefreshsmimekeysjob.cpp \ qgpgmerevokekeyjob.cpp \ + qgpgmesetprimaryuseridjob.cpp \ qgpgmesignencryptjob.cpp \ qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \ qgpgmeverifyopaquejob.cpp qgpgmewkdlookupjob.cpp threadedjobmixin.cpp \ @@ -73,6 +74,7 @@ qgpgme_headers= \ quickjob.h \ receivekeysjob.h \ revokekeyjob.h \ + setprimaryuseridjob.h \ specialjob.h \ signjob.h \ signkeyjob.h \ @@ -118,6 +120,7 @@ camelcase_headers= \ QuickJob \ ReceiveKeysJob \ RevokeKeyJob \ + SetPrimaryUserIDJob \ SpecialJob \ SignJob \ SignKeyJob \ @@ -164,6 +167,7 @@ private_qgpgme_headers = \ qgpgmereceivekeysjob.h \ qgpgmerefreshsmimekeysjob.h \ qgpgmerevokekeyjob.h \ + qgpgmesetprimaryuseridjob.h \ qgpgmesignencryptjob.h \ qgpgmesignjob.h \ qgpgmesignkeyjob.h \ @@ -218,6 +222,7 @@ qgpgme_moc_sources = \ qgpgmereceivekeysjob.moc \ qgpgmerefreshsmimekeysjob.moc \ qgpgmerevokekeyjob.moc \ + qgpgmesetprimaryuseridjob.moc \ qgpgmesignencryptjob.moc \ qgpgmesignjob.moc \ qgpgmesignkeyjob.moc \ @@ -230,6 +235,7 @@ qgpgme_moc_sources = \ receivekeysjob.moc \ refreshkeysjob.moc \ revokekeyjob.moc \ + setprimaryuseridjob.moc \ signencryptjob.moc \ signjob.moc \ signkeyjob.moc \ diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index dba7556b..98f408b4 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -73,6 +73,7 @@ #include "gpgcardjob.h" #include "receivekeysjob.h" #include "revokekeyjob.h" +#include "setprimaryuseridjob.h" #include <QCoreApplication> #include <QDebug> @@ -174,6 +175,7 @@ make_job_subclass(TofuPolicyJob) make_job_subclass(QuickJob) make_job_subclass(GpgCardJob) make_job_subclass(RevokeKeyJob) +make_job_subclass(SetPrimaryUserIDJob) #undef make_job_subclass @@ -211,3 +213,4 @@ make_job_subclass(RevokeKeyJob) #include "gpgcardjob.moc" #include "receivekeysjob.moc" #include "revokekeyjob.moc" +#include "setprimaryuseridjob.moc" diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h index 7c24186c..019633a8 100644 --- a/lang/qt/src/protocol.h +++ b/lang/qt/src/protocol.h @@ -72,6 +72,7 @@ class QuickJob; class GpgCardJob; class ReceiveKeysJob; class RevokeKeyJob; +class SetPrimaryUserIDJob; /** The main entry point for QGpgME Comes in OpenPGP and SMIME(CMS) flavors. * @@ -182,6 +183,12 @@ public: virtual ReceiveKeysJob *receiveKeysJob() const = 0; virtual RevokeKeyJob *revokeKeyJob() const = 0; + + /** + * Returns a job for flagging a user ID as the primary user ID of an + * OpenPGP key. + */ + virtual SetPrimaryUserIDJob *setPrimaryUserIDJob() 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 0b022dda..685ac4dd 100644 --- a/lang/qt/src/protocol_p.h +++ b/lang/qt/src/protocol_p.h @@ -66,6 +66,7 @@ #include "qgpgmequickjob.h" #include "qgpgmereceivekeysjob.h" #include "qgpgmerevokekeyjob.h" +#include "qgpgmesetprimaryuseridjob.h" namespace { @@ -493,6 +494,18 @@ public: } return new QGpgME::QGpgMERevokeKeyJob(context); } + + QGpgME::SetPrimaryUserIDJob *setPrimaryUserIDJob() const override + { + if (mProtocol != GpgME::OpenPGP) { + return nullptr; + } + GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); + if (!context) { + return nullptr; + } + return new QGpgME::QGpgMESetPrimaryUserIDJob{context}; + } }; } diff --git a/lang/qt/src/qgpgmesetprimaryuseridjob.cpp b/lang/qt/src/qgpgmesetprimaryuseridjob.cpp new file mode 100644 index 00000000..32da1fc2 --- /dev/null +++ b/lang/qt/src/qgpgmesetprimaryuseridjob.cpp @@ -0,0 +1,75 @@ +/* + qgpgmesetprimaryuseridjob.cpp + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2022 g10 Code GmbH + Software engineering by Ingo Klöcker <[email protected]> + + 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 "qgpgmesetprimaryuseridjob.h" + +#include "util.h" + +#include <engineinfo.h> + +using namespace QGpgME; +using namespace GpgME; + +static bool quickSetPrimayUidSupportsUidHash() +{ + return GpgME::engineInfo(GpgME::GpgEngine).engineVersion() >= "2.3.8"; +} + +static QGpgMESetPrimaryUserIDJob::result_type set_primary_userid(Context *ctx, const GpgME::UserID &userId) +{ + auto err = ctx->setPrimaryUid(userId.parent(), quickSetPrimayUidSupportsUidHash() ? userId.uidhash() : userId.id()); + return std::make_tuple(err, QString(), Error()); +} + +QGpgMESetPrimaryUserIDJob::QGpgMESetPrimaryUserIDJob(Context *context) + : mixin_type{context} +{ + lateInitialization(); +} + +QGpgMESetPrimaryUserIDJob::~QGpgMESetPrimaryUserIDJob() = default; + +GpgME::Error QGpgMESetPrimaryUserIDJob::start(const GpgME::UserID &userId) +{ + if (userId.isNull()) { + return Error{make_error(GPG_ERR_INV_ARG)}; + } + run([userId](Context *ctx) { return set_primary_userid(ctx, userId); }); + return {}; +} + +#include "qgpgmesetprimaryuseridjob.moc" diff --git a/lang/qt/src/qgpgmesetprimaryuseridjob.h b/lang/qt/src/qgpgmesetprimaryuseridjob.h new file mode 100644 index 00000000..4ee967ae --- /dev/null +++ b/lang/qt/src/qgpgmesetprimaryuseridjob.h @@ -0,0 +1,64 @@ +/* + qgpgmesetprimaryuseridjob.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2022 g10 Code GmbH + Software engineering by Ingo Klöcker <[email protected]> + + 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_QGPGMESETPRIMARYUSERIDJOB_H__ +#define __QGPGME_QGPGMESETPRIMARYUSERIDJOB_H__ + +#include "setprimaryuseridjob.h" +#include "threadedjobmixin.h" + +namespace QGpgME +{ + +class QGpgMESetPrimaryUserIDJob +#ifdef Q_MOC_RUN + : public SetPrimaryUserIDJob +#else + : public _detail::ThreadedJobMixin<SetPrimaryUserIDJob> +#endif +{ + Q_OBJECT +#ifdef Q_MOC_RUN +public Q_SLOTS: + void slotFinished(); +#endif +public: + explicit QGpgMESetPrimaryUserIDJob(GpgME::Context *context); + ~QGpgMESetPrimaryUserIDJob() override; + + GpgME::Error start(const GpgME::UserID &userId) override; +}; + +} + +#endif // __QGPGME_QGPGMESETPRIMARYUSERIDJOB_H__ diff --git a/lang/qt/src/setprimaryuseridjob.h b/lang/qt/src/setprimaryuseridjob.h new file mode 100644 index 00000000..fa76199c --- /dev/null +++ b/lang/qt/src/setprimaryuseridjob.h @@ -0,0 +1,69 @@ +/* + setprimaryuseridjob.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2022 g10 Code GmbH + Software engineering by Ingo Klöcker <[email protected]> + + 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_SETPRIMARYUSERIDJOB_H__ +#define __QGPGME_SETPRIMARYUSERIDJOB_H__ + +#include "job.h" + +#include "qgpgme_export.h" + +namespace GpgME +{ +class Error; +class UserID; +} + +namespace QGpgME +{ + +class QGPGME_EXPORT SetPrimaryUserIDJob : public Job +{ + Q_OBJECT +public: + explicit SetPrimaryUserIDJob(QObject *parent); + ~SetPrimaryUserIDJob() override; + + /** + * Starts setting user ID \a userId as the primary user ID. + */ + virtual GpgME::Error start(const GpgME::UserID &userId) = 0; + +Q_SIGNALS: + void result(const GpgME::Error &error, + const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error()); +}; + +} + +#endif // __QGPGME_SETPRIMARYUSERIDJOB_H__ |