qt: Allow refreshing a list of keys
* lang/qt/src/refreshkeysjob.h (class RefreshKeysJob): Add pure virtual member function start taking a list of keys. * lang/qt/src/qgpgmerefreshsmimekeysjob.h, lang/qt/src/qgpgmerefreshsmimekeysjob.cpp (class QGpgMERefreshSMIMEKeysJob): Implement new member function. -- The new overload makes it easier to refresh some keys if one does already have Keys. GnuPG-bug-id: 5951
This commit is contained in:
parent
62e7709717
commit
fd97cbaa44
@ -44,8 +44,11 @@
|
|||||||
#include "qgpgme_debug.h"
|
#include "qgpgme_debug.h"
|
||||||
|
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
#include <key.h>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QMetaObject>
|
||||||
|
#include <QProcess>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include <gpg-error.h>
|
#include <gpg-error.h>
|
||||||
@ -81,6 +84,31 @@ GpgME::Error QGpgMERefreshSMIMEKeysJob::start(const QStringList &patterns)
|
|||||||
return startAProcess();
|
return startAProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GpgME::Error QGpgMERefreshSMIMEKeysJob::start(const std::vector<GpgME::Key> &keys)
|
||||||
|
{
|
||||||
|
if (keys.empty()) {
|
||||||
|
QMetaObject::invokeMethod(this, [this]() {
|
||||||
|
Q_EMIT slotProcessExited(0, QProcess::NormalExit);
|
||||||
|
}, Qt::QueuedConnection);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool gotWrongKeys = std::any_of(std::begin(keys), std::end(keys), [](const auto &k) {
|
||||||
|
return k.protocol() != GpgME::CMS;
|
||||||
|
});
|
||||||
|
if (gotWrongKeys) {
|
||||||
|
qCDebug(QGPGME_LOG) << "Error: At least one of the keys is not an S/MIME 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);
|
||||||
|
}
|
||||||
|
|
||||||
#if MAX_CMD_LENGTH < 65 + 128
|
#if MAX_CMD_LENGTH < 65 + 128
|
||||||
#error MAX_CMD_LENGTH is too low
|
#error MAX_CMD_LENGTH is too low
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,6 +58,8 @@ public:
|
|||||||
/* from RefreshKeysJob */
|
/* from RefreshKeysJob */
|
||||||
GpgME::Error start(const QStringList &patterns) Q_DECL_OVERRIDE;
|
GpgME::Error start(const QStringList &patterns) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
GpgME::Error start(const std::vector<GpgME::Key> &keys) override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
/* from Job */
|
/* from Job */
|
||||||
void slotCancel() Q_DECL_OVERRIDE;
|
void slotCancel() Q_DECL_OVERRIDE;
|
||||||
|
@ -73,19 +73,20 @@ public:
|
|||||||
~RefreshKeysJob();
|
~RefreshKeysJob();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Starts the keylist operation. \a pattern is a list of patterns
|
Starts the refresh operation. \a pattern is a list of patterns
|
||||||
used to restrict the list of keys returned. Empty patterns are
|
used to restrict the list of keys returned. Empty patterns are
|
||||||
ignored. If \a pattern is empty or contains only empty strings,
|
ignored. If \a pattern is empty or contains only empty strings,
|
||||||
all keys are returned (however, the backend is free to truncate
|
all keys are refreshed.
|
||||||
the result and should do so; when this happens, it will be
|
|
||||||
reported by the reult object).
|
|
||||||
|
|
||||||
If \a secretOnly is true, only keys for which the secret key is
|
Only implemented for S/MIME.
|
||||||
also available are returned. Use this if you need to select a
|
|
||||||
key for signing.
|
|
||||||
*/
|
*/
|
||||||
virtual GpgME::Error start(const QStringList &patterns) = 0;
|
virtual GpgME::Error start(const QStringList &patterns) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Starts a refresh of the \a keys.
|
||||||
|
*/
|
||||||
|
virtual GpgME::Error start(const std::vector<GpgME::Key> &keys) = 0;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void result(const GpgME::Error &error);
|
void result(const GpgME::Error &error);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user