aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2020-08-05 14:49:18 +0000
committerIngo Klöcker <[email protected]>2020-08-05 14:49:18 +0000
commit89501509134ab9cff87219fcaee9c1a758efa2fe (patch)
tree64cd1a8513501eff796495c9996f99495cb7ac49
parentqt: Add test for setExpire (diff)
downloadgpgme-89501509134ab9cff87219fcaee9c1a758efa2fe.tar.gz
gpgme-89501509134ab9cff87219fcaee9c1a758efa2fe.zip
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
-rw-r--r--lang/qt/src/qgpgmechangeexpiryjob.cpp24
1 files 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 <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)