qt: Specify import options as list of strings instead of as string

* lang/qt/src/importjob.cpp, lang/qt/src/importjob.h (setImportOptions):
Change type of argument "options" to QStringList.
(importOptions): Change return type to QStringList.
* lang/qt/src/importjob_p.h (struct ImportJobPrivate): Change type of
member m_importOptions to QStringList.
* lang/qt/src/qgpgmeimportjob.cpp (import_qba): Change type of argument
"importOptions" to QStringList. Join list of import options with ','
when setting the "import-options" context flag.

* lang/qt/tests/t-import.cpp (ImportTest::testImportWithImportOptions):
Adapt to API change.
--

This makes the API that was introduced with the previous commit easier
to use.

GnuPG-bug-id: 7152
This commit is contained in:
Ingo Klöcker 2024-06-13 09:53:13 +02:00
parent 6c90ec7be2
commit 60b96d149c
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
6 changed files with 14 additions and 10 deletions

6
NEWS
View File

@ -9,7 +9,7 @@ Noteworthy changes in version 1.24.0 (unrelease)
* Add information about designated revocation keys. [T7118] * Add information about designated revocation keys. [T7118]
* New context flag "import-options". [#7152] * New context flag "import-options". [T7152]
* cpp: Provide information about designated revocation keys for a Key. * cpp: Provide information about designated revocation keys for a Key.
[T7118] [T7118]
@ -20,6 +20,8 @@ Noteworthy changes in version 1.24.0 (unrelease)
* qt: Allow writing the decrypted/encrypted/signed/verified data directly * qt: Allow writing the decrypted/encrypted/signed/verified data directly
to files. [T6550] to files. [T6550]
* qt: Allow specifying import options when importing keys. [T7152]
* Interface changes relative to the 1.23.2 release: * Interface changes relative to the 1.23.2 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GPGME_ENCRYPT_FILE NEW. GPGME_ENCRYPT_FILE NEW.
@ -71,6 +73,8 @@ Noteworthy changes in version 1.24.0 (unrelease)
qt: VerifyOpaqueJob::inputFile NEW. qt: VerifyOpaqueJob::inputFile NEW.
qt: VerifyOpaqueJob::setOutputFile NEW. qt: VerifyOpaqueJob::setOutputFile NEW.
qt: VerifyOpaqueJob::outputFile NEW. qt: VerifyOpaqueJob::outputFile NEW.
qt: ImportJob::setImportOptions NEW.
qt: ImportJob::importOptions NEW.
Noteworthy changes in version 1.23.2 (2023-11-28) Noteworthy changes in version 1.23.2 (2023-11-28)

View File

@ -55,13 +55,13 @@ QString QGpgME::ImportJob::importFilter() const
return d->m_importFilter; return d->m_importFilter;
} }
void QGpgME::ImportJob::setImportOptions(const QString &options) void QGpgME::ImportJob::setImportOptions(const QStringList &options)
{ {
const auto d = jobPrivate<ImportJobPrivate>(this); const auto d = jobPrivate<ImportJobPrivate>(this);
d->m_importOptions = options; d->m_importOptions = options;
} }
QString QGpgME::ImportJob::importOptions() const QStringList QGpgME::ImportJob::importOptions() const
{ {
const auto d = jobPrivate<ImportJobPrivate>(this); const auto d = jobPrivate<ImportJobPrivate>(this);
return d->m_importOptions; return d->m_importOptions;

View File

@ -79,8 +79,8 @@ public:
void setImportFilter(const QString &filter); void setImportFilter(const QString &filter);
QString importFilter() const; QString importFilter() const;
void setImportOptions(const QString &options); void setImportOptions(const QStringList &options);
QString importOptions() const; QStringList importOptions() const;
void setKeyOrigin(GpgME::Key::Origin origin, const QString &url = {}); void setKeyOrigin(GpgME::Key::Origin origin, const QString &url = {});
GpgME::Key::Origin keyOrigin() const; GpgME::Key::Origin keyOrigin() const;

View File

@ -44,7 +44,7 @@ namespace QGpgME
struct ImportJobPrivate : public JobPrivate struct ImportJobPrivate : public JobPrivate
{ {
QString m_importFilter; QString m_importFilter;
QString m_importOptions; QStringList m_importOptions;
GpgME::Key::Origin m_keyOrigin = GpgME::Key::OriginUnknown; GpgME::Key::Origin m_keyOrigin = GpgME::Key::OriginUnknown;
QString m_keyOriginUrl; QString m_keyOriginUrl;
}; };

View File

@ -106,14 +106,14 @@ static const char *originToString(Key::Origin origin)
} }
static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &certData, const QString &importFilter, static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &certData, const QString &importFilter,
const QString &importOptions, Key::Origin keyOrigin, const QStringList &importOptions, Key::Origin keyOrigin,
const QString &keyOriginUrl) const QString &keyOriginUrl)
{ {
if (!importFilter.isEmpty()) { if (!importFilter.isEmpty()) {
ctx->setFlag("import-filter", importFilter.toStdString().c_str()); ctx->setFlag("import-filter", importFilter.toStdString().c_str());
} }
if (!importOptions.isEmpty()) { if (!importOptions.empty()) {
ctx->setFlag("import-options", importOptions.toStdString().c_str()); ctx->setFlag("import-options", importOptions.join(QLatin1Char{','}).toStdString().c_str());
} }
if (keyOrigin != Key::OriginUnknown) { if (keyOrigin != Key::OriginUnknown) {
if (const auto origin = originToString(keyOrigin)) { if (const auto origin = originToString(keyOrigin)) {

View File

@ -143,7 +143,7 @@ private Q_SLOTS:
"-----END PGP PUBLIC KEY BLOCK-----\n"; "-----END PGP PUBLIC KEY BLOCK-----\n";
auto *job = openpgp()->importJob(); auto *job = openpgp()->importJob();
job->setImportOptions(QLatin1String{"show-only"}); job->setImportOptions({QStringLiteral("show-only")});
connect(job, &ImportJob::result, this, connect(job, &ImportJob::result, this,
[this](ImportResult result, QString, Error) [this](ImportResult result, QString, Error)
{ {