qt: Add setInputEncoding to QGpgMe::EncryptJob
* 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 identifying the content type then decrypting it. GnuPG-bug-id: 6616 Signed-off-by: Carl Schwan <carl.schwan@gnupg.com>
This commit is contained in:
parent
a9b28c79e9
commit
d91d037fc1
@ -51,3 +51,15 @@ QString EncryptJob::fileName() const
|
|||||||
auto d = jobPrivate<EncryptJobPrivate>(this);
|
auto d = jobPrivate<EncryptJobPrivate>(this);
|
||||||
return d->m_fileName;
|
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;
|
||||||
|
}
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#define __KLEO_ENCRYPTJOB_H__
|
#define __KLEO_ENCRYPTJOB_H__
|
||||||
|
|
||||||
#include "job.h"
|
#include "job.h"
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -85,6 +86,9 @@ public:
|
|||||||
void setFileName(const QString &fileName);
|
void setFileName(const QString &fileName);
|
||||||
QString fileName() const;
|
QString fileName() const;
|
||||||
|
|
||||||
|
void setInputEncoding(GpgME::Data::Encoding);
|
||||||
|
GpgME::Data::Encoding inputEncoding() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Starts the encryption operation. \a recipients is the a list of
|
Starts the encryption operation. \a recipients is the a list of
|
||||||
keys to encrypt \a plainText to. Empty (null) keys are
|
keys to encrypt \a plainText to. Empty (null) keys are
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#define __QGPGME_ENCRYPTJOB_P_H__
|
#define __QGPGME_ENCRYPTJOB_P_H__
|
||||||
|
|
||||||
#include "job_p.h"
|
#include "job_p.h"
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
namespace QGpgME
|
namespace QGpgME
|
||||||
{
|
{
|
||||||
@ -42,6 +43,7 @@ namespace QGpgME
|
|||||||
struct EncryptJobPrivate : public JobPrivate
|
struct EncryptJobPrivate : public JobPrivate
|
||||||
{
|
{
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
|
GpgME::Data::Encoding m_inputEncoding;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,7 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
|
|||||||
const std::weak_ptr<QIODevice> &cipherText_,
|
const std::weak_ptr<QIODevice> &cipherText_,
|
||||||
const Context::EncryptionFlags eflags,
|
const Context::EncryptionFlags eflags,
|
||||||
bool outputIsBsse64Encoded,
|
bool outputIsBsse64Encoded,
|
||||||
|
Data::Encoding inputEncoding,
|
||||||
const QString &fileName)
|
const QString &fileName)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -118,6 +119,8 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
|
|||||||
|
|
||||||
QGpgME::QIODeviceDataProvider in(plainText);
|
QGpgME::QIODeviceDataProvider in(plainText);
|
||||||
Data indata(&in);
|
Data indata(&in);
|
||||||
|
indata.setEncoding(inputEncoding);
|
||||||
|
|
||||||
if (!plainText->isSequential()) {
|
if (!plainText->isSequential()) {
|
||||||
indata.setSizeHint(plainText->size());
|
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);
|
const std::shared_ptr<QBuffer> buffer(new QBuffer);
|
||||||
buffer->setData(plainText);
|
buffer->setData(plainText);
|
||||||
if (!buffer->open(QIODevice::ReadOnly)) {
|
if (!buffer->open(QIODevice::ReadOnly)) {
|
||||||
assert(!"This should never happen: QBuffer::open() failed");
|
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)
|
Error QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const QByteArray &plainText, bool alwaysTrust)
|
||||||
{
|
{
|
||||||
run(std::bind(&encrypt_qba, std::placeholders::_1, recipients, plainText,
|
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();
|
return Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +184,7 @@ void QGpgMEEncryptJob::start(const std::vector<Key> &recipients, const std::shar
|
|||||||
std::placeholders::_3, std::placeholders::_4,
|
std::placeholders::_3, std::placeholders::_4,
|
||||||
eflags,
|
eflags,
|
||||||
mOutputIsBase64Encoded,
|
mOutputIsBase64Encoded,
|
||||||
|
inputEncoding(),
|
||||||
fileName()),
|
fileName()),
|
||||||
plainText, cipherText);
|
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,
|
EncryptionResult QGpgMEEncryptJob::exec(const std::vector<Key> &recipients, const QByteArray &plainText,
|
||||||
const Context::EncryptionFlags eflags, QByteArray &cipherText)
|
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);
|
cipherText = std::get<1>(r);
|
||||||
resultHook(r);
|
resultHook(r);
|
||||||
return mResult;
|
return mResult;
|
||||||
|
Loading…
Reference in New Issue
Block a user