From 89501509134ab9cff87219fcaee9c1a758efa2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 5 Aug 2020 16:49:18 +0200 Subject: [PATCH] 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 --- lang/qt/src/qgpgmechangeexpiryjob.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lang/qt/src/qgpgmechangeexpiryjob.cpp b/lang/qt/src/qgpgmechangeexpiryjob.cpp index faa4e793..6eb5855f 100644 --- a/lang/qt/src/qgpgmechangeexpiryjob.cpp +++ b/lang/qt/src/qgpgmechangeexpiryjob.cpp @@ -38,19 +38,11 @@ #include "qgpgmechangeexpiryjob.h" -#include "dataprovider.h" - #include "context.h" -#include "data.h" -#include "gpgsetexpirytimeeditinteractor.h" #include "key.h" #include -#include -#include -#include - 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(QDateTime::currentDateTime().secsTo(expiry), 1) + : 0; - QGpgME::QByteArrayDataProvider dp; - Data data(&dp); - assert(!data.isNull()); - const Error err = ctx->edit(key, std::unique_ptr (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)