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
This commit is contained in:
Ingo Klöcker 2022-05-02 15:04:37 +02:00
parent 97e09fb964
commit 0c304beeaa
3 changed files with 23 additions and 6 deletions

View File

@ -39,6 +39,7 @@
#endif
#include "qgpgmerefreshsmimekeysjob.h"
#include "util.h"
#include <QDebug>
#include "qgpgme_debug.h"
@ -101,12 +102,7 @@ GpgME::Error QGpgMERefreshSMIMEKeysJob::start(const std::vector<GpgME::Key> &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

View File

@ -38,6 +38,10 @@
#include "util.h"
#include <QStringList>
#include <key.h>
#include <algorithm>
#include <functional>
std::vector<std::string> toStrings(const QStringList &l)
@ -49,3 +53,13 @@ std::vector<std::string> toStrings(const QStringList &l)
std::mem_fn(&QString::toStdString));
return v;
}
QStringList toFingerprints(const std::vector<GpgME::Key> &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;
}

View File

@ -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<std::string> toStrings(const QStringList &l);
QStringList toFingerprints(const std::vector<GpgME::Key> &keys);
#endif // __QGPGME_UTIL_H__