From 0c304beeaab54dc25a8572270704fd5fa90cf836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 2 May 2022 15:04:37 +0200 Subject: [PATCH] qt: Factor out helper for getting the fingerprints of some keys * lang/qt/src/util.h, lang/qt/src/util.cpp (toFingerprints): New. * lang/qt/src/qgpgmerefreshsmimekeysjob.cpp: Use the helper. -- GnuPG-bug-id: 5951 --- lang/qt/src/qgpgmerefreshsmimekeysjob.cpp | 8 ++------ lang/qt/src/util.cpp | 14 ++++++++++++++ lang/qt/src/util.h | 7 +++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp b/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp index 84bf0245..3187a0cd 100644 --- a/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp +++ b/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp @@ -39,6 +39,7 @@ #endif #include "qgpgmerefreshsmimekeysjob.h" +#include "util.h" #include #include "qgpgme_debug.h" @@ -101,12 +102,7 @@ GpgME::Error QGpgMERefreshSMIMEKeysJob::start(const std::vector &key return GpgME::Error::fromCode(GPG_ERR_INV_VALUE); } - QStringList fprs; - fprs.reserve(keys.size()); - std::transform(std::begin(keys), std::end(keys), std::back_inserter(fprs), [](const auto &k) { - return QString::fromLatin1(k.primaryFingerprint()); - }); - return start(fprs); + return start(toFingerprints(keys)); } #if MAX_CMD_LENGTH < 65 + 128 diff --git a/lang/qt/src/util.cpp b/lang/qt/src/util.cpp index 81cdf077..66c7eedd 100644 --- a/lang/qt/src/util.cpp +++ b/lang/qt/src/util.cpp @@ -38,6 +38,10 @@ #include "util.h" #include + +#include + +#include #include std::vector toStrings(const QStringList &l) @@ -49,3 +53,13 @@ std::vector toStrings(const QStringList &l) std::mem_fn(&QString::toStdString)); return v; } + +QStringList toFingerprints(const std::vector &keys) +{ + QStringList fprs; + fprs.reserve(keys.size()); + std::transform(std::begin(keys), std::end(keys), std::back_inserter(fprs), [](const auto &k) { + return QString::fromLatin1(k.primaryFingerprint()); + }); + return fprs; +} diff --git a/lang/qt/src/util.h b/lang/qt/src/util.h index 94c97333..c6aa87ce 100644 --- a/lang/qt/src/util.h +++ b/lang/qt/src/util.h @@ -41,6 +41,11 @@ class QStringList; +namespace GpgME +{ +class Key; +} + static inline gpgme_error_t make_error(gpgme_err_code_t code) { return gpgme_err_make((gpgme_err_source_t)22, code); @@ -48,4 +53,6 @@ static inline gpgme_error_t make_error(gpgme_err_code_t code) std::vector toStrings(const QStringList &l); +QStringList toFingerprints(const std::vector &keys); + #endif // __QGPGME_UTIL_H__