qt: Port to new setExpire()

* lang/qt/src/qgpgmechangeexpiryjob.cpp (change_expiry): Use new
setExpire() instead of edit() with GpgSetExpiryTimeEditInteractor
--

Using the new setExpire() (which uses --quick-set-expire) is a lot less
complex than using gpg's edit interface. It also feels faster. Next,
I'll add support for changing the expiration time of subkeys.

GnuPG-bug-id: 5003
This commit is contained in:
Ingo Klöcker 2020-08-05 16:49:18 +02:00
parent 84c6b6e2fe
commit 8950150913

View File

@ -38,19 +38,11 @@
#include "qgpgmechangeexpiryjob.h"
#include "dataprovider.h"
#include "context.h"
#include "data.h"
#include "gpgsetexpirytimeeditinteractor.h"
#include "key.h"
#include <QDateTime>
#include <cassert>
#include <memory>
#include <string>
using namespace QGpgME;
using namespace GpgME;
@ -64,17 +56,13 @@ QGpgMEChangeExpiryJob::~QGpgMEChangeExpiryJob() {}
static QGpgMEChangeExpiryJob::result_type change_expiry(Context *ctx, const Key &key, const QDateTime &expiry)
{
EditInteractor *ei = expiry.isValid()
? new GpgSetExpiryTimeEditInteractor(expiry.date().toString(Qt::ISODate).toStdString())
: new GpgSetExpiryTimeEditInteractor();
// convert expiry to "seconds from now"; use 1 second from now if expiry is before the current datetime
const unsigned long expires = expiry.isValid()
? std::max<qint64>(QDateTime::currentDateTime().secsTo(expiry), 1)
: 0;
QGpgME::QByteArrayDataProvider dp;
Data data(&dp);
assert(!data.isNull());
const Error err = ctx->edit(key, std::unique_ptr<EditInteractor> (ei), data);
Error ae;
const QString log = _detail::audit_log_as_html(ctx, ae);
return std::make_tuple(err, log, ae);
auto err = ctx->setExpire(key, expires);
return std::make_tuple(err, QString(), Error());
}
Error QGpgMEChangeExpiryJob::start(const Key &key, const QDateTime &expiry)