Commit f8323130 authored by Sandro Knauß's avatar Sandro Knauß
Browse files

Messagecomposer: Run encrypt/sign in async mode.

GnuPG can run jobs in async mode, so we no not have to block the event
loop till the process is done.
parent cac51f5f
Pipeline #46569 passed with stage
in 17 minutes and 52 seconds
......@@ -233,7 +233,6 @@ void EncryptJob::process()
qCDebug(MESSAGECOMPOSER_LOG) << "got backend, starting job";
QGpgME::EncryptJob *eJob = proto->encryptJob(!d->binaryHint(d->format), d->format == Kleo::InlineOpenPGPFormat);
/*
QObject::connect(eJob, &QGpgME::EncryptJob::result, this, [this, d](const GpgME::EncryptionResult &result,
const QByteArray &cipherText,
const QString &auditLogAsHtml, const GpgME::Error &auditLogError) {
......@@ -249,20 +248,12 @@ void EncryptJob::process()
emitResult();
});
eJob->start(d->keys, content, true);
*/
//TODO: use async GPG again!!!
QByteArray cipherText;
auto result = eJob->exec(d->keys, content, true, cipherText);
if (result.error()) {
setError(result.error().code());
setErrorText(QString::fromLocal8Bit(result.error().asString()));
const auto error = eJob->start(d->keys, content, true);
if (error.code()) {
eJob->deleteLater();
setError(error.code());
setErrorText(QString::fromLocal8Bit(error.asString()));
emitResult();
return;
}
d->resultContent = MessageComposer::Util::composeHeadersAndBody(d->content, cipherText, d->format, false);
emitResult();
}
......@@ -220,7 +220,7 @@ void SignEncryptJob::process()
//d->resultContent = new KMime::Content;
qCDebug(MESSAGECOMPOSER_LOG) << "creating signencrypt from:" << proto->name() << proto->displayName();
std::unique_ptr<QGpgME::SignEncryptJob> job(proto->signEncryptJob(!d->binaryHint(d->format), d->format == Kleo::InlineOpenPGPFormat));
QByteArray encBody;
d->content->assemble();
......@@ -235,33 +235,40 @@ void SignEncryptJob::process()
content = d->content->encodedContent();
}
// FIXME: Make this async
const std::pair<GpgME::SigningResult, GpgME::EncryptionResult> res = job->exec(d->signers, d->encKeys,
content,
false,
encBody);
QGpgME::SignEncryptJob *job(proto->signEncryptJob(!d->binaryHint(d->format), d->format == Kleo::InlineOpenPGPFormat));
QObject::connect(job, &QGpgME::SignEncryptJob::result, this, [this, d](
const GpgME::SigningResult &signingResult,
const GpgME::EncryptionResult &encryptionResult,
const QByteArray &cipherText,
const QString &auditLogAsHtml, const GpgME::Error &auditLogError) {
Q_UNUSED(auditLogAsHtml)
Q_UNUSED(auditLogError)
if (signingResult.error()) {
qCDebug(MESSAGECOMPOSER_LOG) << "signing failed:" << signingResult.error().asString();
setError(signingResult.error().code());
setErrorText(QString::fromLocal8Bit(signingResult.error().asString()));
emitResult();
return;
}
if (encryptionResult.error()) {
qCDebug(MESSAGECOMPOSER_LOG) << "encrypting failed:" << encryptionResult.error().asString();
setError(encryptionResult.error().code());
setErrorText(QString::fromLocal8Bit(encryptionResult.error().asString()));
emitResult();
return;
}
// exec'ed jobs don't delete themselves
job->deleteLater();
QByteArray signatureHashAlgo = signingResult.createdSignature(0).hashAlgorithmAsString();
d->resultContent = MessageComposer::Util::composeHeadersAndBody(d->content, cipherText, d->format, false, signatureHashAlgo);
if (res.first.error()) {
qCDebug(MESSAGECOMPOSER_LOG) << "signing failed:" << res.first.error().asString();
setError(res.first.error().code());
setErrorText(QString::fromLocal8Bit(res.first.error().asString()));
emitResult();
return;
}
if (res.second.error()) {
qCDebug(MESSAGECOMPOSER_LOG) << "encrypting failed:" << res.second.error().asString();
setError(res.second.error().code());
setErrorText(QString::fromLocal8Bit(res.second.error().asString()));
});
const auto error = job->start(d->signers, d->encKeys, content, false);
if (error.code()) {
job->deleteLater();
setError(error.code());
setErrorText(QString::fromLocal8Bit(error.asString()));
emitResult();
return;
}
const QByteArray signatureHashAlgo = res.first.createdSignature(0).hashAlgorithmAsString();
d->resultContent = MessageComposer::Util::composeHeadersAndBody(d->content, encBody, d->format, false, signatureHashAlgo);
emitResult();
}
......@@ -193,7 +193,6 @@ void SignJob::process()
Q_ASSERT(proto);
qCDebug(MESSAGECOMPOSER_LOG) << "creating signJob from:" << proto->name() << proto->displayName();
std::unique_ptr<QGpgME::SignJob> job(proto->signJob(!d->binaryHint(d->format), d->format == Kleo::InlineOpenPGPFormat));
// for now just do the main recipients
QByteArray signature;
......@@ -261,24 +260,32 @@ void SignJob::process()
content = d->content->encodedContent();
}
// FIXME: Make this async
GpgME::SigningResult res = job->exec(d->signers,
content,
d->signingMode(d->format),
signature);
// exec'ed jobs don't delete themselves
job->deleteLater();
if (res.error().code()) {
qCDebug(MESSAGECOMPOSER_LOG) << "signing failed:" << res.error().asString();
// job->showErrorDialog( globalPart()->parentWidgetForGui() );
setError(res.error().code());
setErrorText(QString::fromLocal8Bit(res.error().asString()));
} else {
QByteArray signatureHashAlgo = res.createdSignature(0).hashAlgorithmAsString();
QGpgME::SignJob *job(proto->signJob(!d->binaryHint(d->format), d->format == Kleo::InlineOpenPGPFormat));
QObject::connect(job, &QGpgME::SignJob::result, this, [this, d](const GpgME::SigningResult &result,
const QByteArray &signature,
const QString &auditLogAsHtml, const GpgME::Error &auditLogError) {
Q_UNUSED(auditLogAsHtml)
Q_UNUSED(auditLogError)
if (result.error().code()) {
qCDebug(MESSAGECOMPOSER_LOG) << "signing failed:" << result.error().asString();
// job->showErrorDialog( globalPart()->parentWidgetForGui() );
setError(result.error().code());
setErrorText(QString::fromLocal8Bit(result.error().asString()));
emitResult();
return;
}
QByteArray signatureHashAlgo = result.createdSignature(0).hashAlgorithmAsString();
d->resultContent = MessageComposer::Util::composeHeadersAndBody(d->content, signature, d->format, true, signatureHashAlgo);
}
emitResult();
emitResult();
});
const auto error = job->start(d->signers, content, d->signingMode(d->format));
if (error.code()) {
job->deleteLater();
setError(error.code());
setErrorText(QString::fromLocal8Bit(error.asString()));
emitResult();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment