[PATCH gpgme v2] qt: Add setInputEncoding to QGpgMe::EncryptJob
Carl Schwan
carl.schwan at gnupg.com
Fri Jul 28 13:52:24 CEST 2023
* lang/qt/src/encryptjob.cpp, lang/qt/src/encryptjob.h,
lang/qt/src/encryptjob_p.h: Add inputEncoding/setInputEncoding
to EncryptJob
* lang/qt/src/qgpgmeencryptjob.cpp: Use newly added inputEncoding
to set encoding hint of the encrypted content
--
This allows applications like KMail to set the input encoding of the
encrypted content, which simplify and improve the performance of
identify the content type then decrypting it.
GnuPG-bug-id: 6616
Signed-off-by: Carl Schwan <carl.schwan at gnupg.com>
---
lang/qt/src/encryptjob.cpp | 12 ++++++++++++
lang/qt/src/encryptjob.h | 4 ++++
lang/qt/src/encryptjob_p.h | 2 ++
lang/qt/src/qgpgmeencryptjob.cpp | 12 ++++++++----
4 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/lang/qt/src/encryptjob.cpp b/lang/qt/src/encryptjob.cpp
index 7b9f0f2b..48a0e24e 100644
--- a/lang/qt/src/encryptjob.cpp
+++ b/lang/qt/src/encryptjob.cpp
@@ -51,3 +51,15 @@ QString EncryptJob::fileName() const
auto d = jobPrivate<EncryptJobPrivate>(this);
return d->m_fileName;
}
+
+void EncryptJob::setInputEncoding(GpgME::Data::Encoding inputEncoding)
+{
+ auto d = jobPrivate<EncryptJobPrivate>(this);
+ d->m_inputEncoding = inputEncoding;
+}
+
+GpgME::Data::Encoding EncryptJob::inputEncoding() const
+{
+ auto d = jobPrivate<EncryptJobPrivate>(this);
+ return d->m_inputEncoding;
+}
diff --git a/lang/qt/src/encryptjob.h b/lang/qt/src/encryptjob.h
index 8135053e..ac3664fa 100644
--- a/lang/qt/src/encryptjob.h
+++ b/lang/qt/src/encryptjob.h
@@ -38,6 +38,7 @@
#define __KLEO_ENCRYPTJOB_H__
#include "job.h"
+#include "data.h"
#include <memory>
#include <vector>
@@ -85,6 +86,9 @@ public:
void setFileName(const QString &fileName);
QString fileName() const;
+ void setInputEncoding(GpgME::Data::Encoding);
+ GpgME::Data::Encoding inputEncoding() const;
+
/**
Starts the encryption operation. \a recipients is the a list of
keys to encrypt \a plainText to. Empty (null) keys are
diff --git a/lang/qt/src/encryptjob_p.h b/lang/qt/src/encryptjob_p.h
index 4a93f5b3..9bb9e952 100644
--- a/lang/qt/src/encryptjob_p.h
+++ b/lang/qt/src/encryptjob_p.h
@@ -35,6 +35,7 @@
#define __QGPGME_ENCRYPTJOB_P_H__
#include "job_p.h"
+#include "data.h"
namespace QGpgME
{
@@ -42,6 +43,7 @@ namespace QGpgME
struct EncryptJobPrivate : public JobPrivate
{
QString m_fileName;
+ GpgME::Data::Encoding m_inputEncoding;
};
}
diff --git a/lang/qt/src/qgpgmeencryptjob.cpp b/lang/qt/src/qgpgmeencryptjob.cpp
index 5ea6162c..cfb8d4ac 100644
--- a/lang/qt/src/qgpgmeencryptjob.cpp
+++ b/lang/qt/src/qgpgmeencryptjob.cpp
@@ -107,6 +107,7 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
const std::weak_ptr<QIODevice> &cipherText_,
const Context::EncryptionFlags eflags,
bool outputIsBsse64Encoded,
+ Data::Encoding inputEncoding,
const QString &fileName)
{
@@ -118,6 +119,8 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
QGpgME::QIODeviceDataProvider in(plainText);
Data indata(&in);
+ indata.setEncoding(inputEncoding);
+
if (!plainText->isSequential()) {
indata.setSizeHint(plainText->size());
}
@@ -155,20 +158,20 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
}
-static QGpgMEEncryptJob::result_type encrypt_qba(Context *ctx, const std::vector<Key> &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, const QString &fileName)
+static QGpgMEEncryptJob::result_type encrypt_qba(Context *ctx, const std::vector<Key> &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, Data::Encoding inputEncoding, const QString &fileName)
{
const std::shared_ptr<QBuffer> buffer(new QBuffer);
buffer->setData(plainText);
if (!buffer->open(QIODevice::ReadOnly)) {
assert(!"This should never happen: QBuffer::open() failed");
}
- return encrypt(ctx, nullptr, recipients, buffer, std::shared_ptr<QIODevice>(), eflags, outputIsBsse64Encoded, fileName);
+ return encrypt(ctx, nullptr, recipients, buffer, std::shared_ptr<QIODevice>(), eflags, outputIsBsse64Encoded, inputEncoding, fileName);
}
Error QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust)
{
run(std::bind(&encrypt_qba, std::placeholders::_1, recipients, plainText,
- alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded, fileName()));
+ alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded, inputEncoding(), fileName()));
return Error();
}
@@ -181,6 +184,7 @@ void QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const std::shar
std::placeholders::_3, std::placeholders::_4,
eflags,
mOutputIsBase64Encoded,
+ inputEncoding(),
fileName()),
plainText, cipherText);
}
@@ -188,7 +192,7 @@ void QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const std::shar
EncryptionResult QGpgMEEncryptJob::exec(const std::vector<Key> &recipients, const QByteArray &plainText,
const Context::EncryptionFlags eflags, QByteArray &cipherText)
{
- const result_type r = encrypt_qba(context(), recipients, plainText, eflags, mOutputIsBase64Encoded, fileName());
+ const result_type r = encrypt_qba(context(), recipients, plainText, eflags, mOutputIsBase64Encoded, inputEncoding(), fileName());
cipherText = std::get<1>(r);
resultHook(r);
return mResult;
--
2.41.0
More information about the Gnupg-devel
mailing list