Messagelib

decryptverifybodypartmemento.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "decryptverifybodypartmemento.h"
8
9#include <QGpgME/DecryptVerifyJob>
10
11using namespace QGpgME;
12using namespace GpgME;
13using namespace MimeTreeParser;
14
15DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento(DecryptVerifyJob *job, const QByteArray &cipherText)
16 : CryptoBodyPartMemento()
17 , m_cipherText(cipherText)
18 , m_job(job)
19{
20 Q_ASSERT(m_job);
21}
22
23DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento()
24{
25 if (m_job) {
26 m_job->slotCancel();
27 }
28}
29
30bool DecryptVerifyBodyPartMemento::start()
31{
32 Q_ASSERT(m_job);
33 if (const Error err = m_job->start(m_cipherText)) {
34 m_dr = DecryptionResult(err);
35 return false;
36 }
37 connect(m_job.data(), &DecryptVerifyJob::result, this, &DecryptVerifyBodyPartMemento::slotResult);
38 setRunning(true);
39 return true;
40}
41
42void DecryptVerifyBodyPartMemento::exec()
43{
44 Q_ASSERT(m_job);
45 QByteArray plainText;
46 setRunning(true);
47 const std::pair<DecryptionResult, VerificationResult> p = m_job->exec(m_cipherText, plainText);
48 saveResult(p.first, p.second, plainText);
49 m_job->deleteLater(); // exec'ed jobs don't delete themselves
50 m_job = nullptr;
51}
52
53void DecryptVerifyBodyPartMemento::saveResult(const DecryptionResult &dr, const VerificationResult &vr, const QByteArray &plainText)
54{
55 Q_ASSERT(m_job);
56 setRunning(false);
57 m_dr = dr;
58 m_vr = vr;
59 m_plainText = plainText;
60 setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml());
61}
62
63void DecryptVerifyBodyPartMemento::slotResult(const DecryptionResult &dr, const VerificationResult &vr, const QByteArray &plainText)
64{
65 saveResult(dr, vr, plainText);
66 m_job = nullptr;
67 notify();
68}
69
70#include "moc_decryptverifybodypartmemento.cpp"
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
T * data() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:37:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.