diff options
Diffstat (limited to 'lang/qt/src')
| -rw-r--r-- | lang/qt/src/qgpgmewkdrefreshjob.cpp | 40 | ||||
| -rw-r--r-- | lang/qt/src/wkdrefreshjob.cpp | 7 | ||||
| -rw-r--r-- | lang/qt/src/wkdrefreshjob.h | 15 | ||||
| -rw-r--r-- | lang/qt/src/wkdrefreshjob_p.h | 1 | 
4 files changed, 46 insertions, 17 deletions
| diff --git a/lang/qt/src/qgpgmewkdrefreshjob.cpp b/lang/qt/src/qgpgmewkdrefreshjob.cpp index 8bad1ef1..f590ed4b 100644 --- a/lang/qt/src/qgpgmewkdrefreshjob.cpp +++ b/lang/qt/src/qgpgmewkdrefreshjob.cpp @@ -88,6 +88,21 @@ static QStringList toEmailAddressesOriginatingFromWKD(const std::vector<GpgME::K      return emails;  } +static QStringList toEmailAddresses(const std::vector<GpgME::UserID> &userIds) +{ +    const QStringList emails = std::accumulate( +        std::begin(userIds), +        std::end(userIds), +        QStringList{}, +        [](QStringList &emails, const UserID &userId) { +            if (!userId.isRevoked() && !userId.addrSpec().empty()) { +                emails.push_back(QString::fromStdString(userId.addrSpec())); +            } +            return emails; +        }); +    return emails; +} +  }  QGpgMEWKDRefreshJob::QGpgMEWKDRefreshJob(Context *context) @@ -99,12 +114,11 @@ QGpgMEWKDRefreshJob::QGpgMEWKDRefreshJob(Context *context)  QGpgMEWKDRefreshJob::~QGpgMEWKDRefreshJob() = default; -static ImportResult locate_external_keys(Context *ctx, const std::vector<Key> &keys) +static QGpgMEWKDRefreshJob::result_type locate_external_keys(Context *ctx, const QStringList &emails)  { -    const auto emails = toEmailAddressesOriginatingFromWKD(keys);      qCDebug(QGPGME_LOG) << __func__ << "locating external keys for" << emails;      if (emails.empty()) { -        return ImportResult{}; +        return std::make_tuple(ImportResult{}, QString{}, Error{});      }      Context::KeyListModeSaver saver{ctx}; @@ -121,24 +135,22 @@ static ImportResult locate_external_keys(Context *ctx, const std::vector<Key> &k      qCDebug(QGPGME_LOG) << __func__ << "result:" << toLogString(result).c_str();      job.release(); -    return result; -} - -static QGpgMEWKDRefreshJob::result_type refresh_keys(Context *ctx, const std::vector<Key> &keys) -{ -    const auto result = locate_external_keys(ctx, keys); -      return std::make_tuple(result, QString{}, Error{});  }  GpgME::Error QGpgMEWKDRefreshJobPrivate::startIt()  { -    if (m_keys.empty()) { -        return Error::fromCode(GPG_ERR_INV_VALUE); +    QStringList emails; +    if (!m_keys.empty()) { +        emails = toEmailAddressesOriginatingFromWKD(m_keys); +    } else { +        emails = toEmailAddresses(m_userIds);      } +    std::sort(emails.begin(), emails.end()); +    emails.erase(std::unique(emails.begin(), emails.end()), emails.end()); -    q->run([=](Context *ctx) { -        return refresh_keys(ctx, m_keys); +    q->run([emails](Context *ctx) { +        return locate_external_keys(ctx, emails);      });      return {}; diff --git a/lang/qt/src/wkdrefreshjob.cpp b/lang/qt/src/wkdrefreshjob.cpp index 37b990c8..f79df2c5 100644 --- a/lang/qt/src/wkdrefreshjob.cpp +++ b/lang/qt/src/wkdrefreshjob.cpp @@ -54,4 +54,11 @@ GpgME::Error WKDRefreshJob::start(const std::vector<GpgME::Key> &keys)      return d->startIt();  } +GpgME::Error WKDRefreshJob::start(const std::vector<GpgME::UserID> &userIDs) +{ +    auto d = jobPrivate<WKDRefreshJobPrivate>(this); +    d->m_userIds = userIDs; +    return d->startIt(); +} +  #include "wkdrefreshjob.moc" diff --git a/lang/qt/src/wkdrefreshjob.h b/lang/qt/src/wkdrefreshjob.h index c3aec65f..cbaaf6b0 100644 --- a/lang/qt/src/wkdrefreshjob.h +++ b/lang/qt/src/wkdrefreshjob.h @@ -43,14 +43,14 @@ namespace GpgME  {  class Error;  class Key; +class UserID;  }  namespace QGpgME  {  /** - * This job refreshes OpenPGP keys via WKD. Only user IDs that have WKD set as - * origin are used for the WKD lookup. Revoked user IDs are ignored. + * This job refreshes OpenPGP keys via WKD.   */  class QGPGME_EXPORT WKDRefreshJob : public AbstractImportJob  { @@ -61,9 +61,18 @@ public:      ~WKDRefreshJob() override;      /** -     * Starts a refresh of the \a keys. +     * Starts a refresh of the \a keys. Only user IDs that have WKD set as +     * origin are used for the WKD lookup. Revoked user IDs are ignored. +     * +     * Use the other start overload to use all user IDs for the WKD lookup.       */      GpgME::Error start(const std::vector<GpgME::Key> &keys); + +    /** +     * Starts a refresh of the keys belonging to the user IDs \a userIDs. +     * All user IDs are used for the WKD lookup. Revoked user IDs are ignored. +     */ +    GpgME::Error start(const std::vector<GpgME::UserID> &userIDs);  };  } diff --git a/lang/qt/src/wkdrefreshjob_p.h b/lang/qt/src/wkdrefreshjob_p.h index 377350f3..60fdfedd 100644 --- a/lang/qt/src/wkdrefreshjob_p.h +++ b/lang/qt/src/wkdrefreshjob_p.h @@ -44,6 +44,7 @@ namespace QGpgME  struct WKDRefreshJobPrivate : public JobPrivate  {      std::vector<GpgME::Key> m_keys; +    std::vector<GpgME::UserID> m_userIds;  };  } | 
