Commit 92cd3893 authored by Sandro Knauß's avatar Sandro Knauß

move writeCertificateImportResult from otp -> messagepart

parent e02882f9
...@@ -1625,6 +1625,66 @@ CertMessagePart::~CertMessagePart() ...@@ -1625,6 +1625,66 @@ CertMessagePart::~CertMessagePart()
} }
void CertMessagePart::writeCertificateImportResult()
{
MimeTreeParser::HtmlWriter *writer = mOtp->htmlWriter();
if (mImportResult.error()) {
writer->queue(i18n("Sorry, certificate could not be imported.<br />"
"Reason: %1", QString::fromLocal8Bit(mImportResult.error().asString())));
return;
}
const int nImp = mImportResult.numImported();
const int nUnc = mImportResult.numUnchanged();
const int nSKImp = mImportResult.numSecretKeysImported();
const int nSKUnc = mImportResult.numSecretKeysUnchanged();
if (!nImp && !nSKImp && !nUnc && !nSKUnc) {
writer->queue(i18n("Sorry, no certificates were found in this message."));
return;
}
QString comment = QLatin1String("<b>") + i18n("Certificate import status:") + QLatin1String("</b><br/>&nbsp;<br/>");
if (nImp)
comment += i18np("1 new certificate was imported.",
"%1 new certificates were imported.", nImp) + QLatin1String("<br/>");
if (nUnc)
comment += i18np("1 certificate was unchanged.",
"%1 certificates were unchanged.", nUnc) + QLatin1String("<br/>");
if (nSKImp)
comment += i18np("1 new secret key was imported.",
"%1 new secret keys were imported.", nSKImp) + QLatin1String("<br/>");
if (nSKUnc)
comment += i18np("1 secret key was unchanged.",
"%1 secret keys were unchanged.", nSKUnc) + QLatin1String("<br/>");
comment += QLatin1String("&nbsp;<br/>");
writer->queue(comment);
if (!nImp && !nSKImp) {
writer->queue(QStringLiteral("<hr/>"));
return;
}
const std::vector<GpgME::Import> imports = mImportResult.imports();
if (imports.empty()) {
writer->queue(i18n("Sorry, no details on certificate import available.") + QLatin1String("<hr/>"));
return;
}
writer->queue(QLatin1String("<b>") + i18n("Certificate import details:") + QLatin1String("</b><br/>"));
std::vector<GpgME::Import>::const_iterator end(imports.end());
for (std::vector<GpgME::Import>::const_iterator it = imports.begin(); it != end; ++it) {
if ((*it).error()) {
writer->queue(i18nc("Certificate import failed.", "Failed: %1 (%2)", QLatin1String((*it).fingerprint()),
QString::fromLocal8Bit((*it).error().asString())));
} else if ((*it).status() & ~GpgME::Import::ContainedSecretKey) {
if ((*it).status() & GpgME::Import::ContainedSecretKey) {
writer->queue(i18n("New or changed: %1 (secret key available)", QLatin1String((*it).fingerprint())));
} else {
writer->queue(i18n("New or changed: %1", QLatin1String((*it).fingerprint())));
}
}
writer->queue(QStringLiteral("<br/>"));
}
writer->queue(QStringLiteral("<hr/>"));
}
void CertMessagePart::html(bool decorate) void CertMessagePart::html(bool decorate)
{ {
Q_UNUSED(decorate); Q_UNUSED(decorate);
...@@ -1636,7 +1696,7 @@ void CertMessagePart::html(bool decorate) ...@@ -1636,7 +1696,7 @@ void CertMessagePart::html(bool decorate)
const HTMLBlock::Ptr aBlock(attachmentBlock()); const HTMLBlock::Ptr aBlock(attachmentBlock());
mOtp->writeCertificateImportResult(mImportResult); writeCertificateImportResult();
} }
QString CertMessagePart::text() const QString CertMessagePart::text() const
......
...@@ -374,6 +374,9 @@ public: ...@@ -374,6 +374,9 @@ public:
void html(bool decorate) Q_DECL_OVERRIDE; void html(bool decorate) Q_DECL_OVERRIDE;
private: private:
/** Writes out the information contained in a GpgME::ImportResult */
void writeCertificateImportResult();
KMime::Content *mNode; KMime::Content *mNode;
bool mAutoImport; bool mAutoImport;
GpgME::ImportResult mImportResult; GpgME::ImportResult mImportResult;
......
...@@ -57,10 +57,6 @@ ...@@ -57,10 +57,6 @@
#include <MessageCore/StringUtil> #include <MessageCore/StringUtil>
#include <Libkleo/CryptoBackendFactory> #include <Libkleo/CryptoBackendFactory>
#include <Libkleo/ImportJob>
#include <gpgme++/importresult.h>
#include <gpgme.h>
#include <KMime/Headers> #include <KMime/Headers>
#include <KMime/Message> #include <KMime/Message>
...@@ -463,69 +459,6 @@ void ProcessResult::adjustCryptoStatesOfNode(KMime::Content *node) const ...@@ -463,69 +459,6 @@ void ProcessResult::adjustCryptoStatesOfNode(KMime::Content *node) const
} }
} }
//////////////////
//////////////////
//////////////////
void ObjectTreeParser::writeCertificateImportResult(const GpgME::ImportResult &res)
{
if (res.error()) {
htmlWriter()->queue(i18n("Sorry, certificate could not be imported.<br />"
"Reason: %1", QString::fromLocal8Bit(res.error().asString())));
return;
}
const int nImp = res.numImported();
const int nUnc = res.numUnchanged();
const int nSKImp = res.numSecretKeysImported();
const int nSKUnc = res.numSecretKeysUnchanged();
if (!nImp && !nSKImp && !nUnc && !nSKUnc) {
htmlWriter()->queue(i18n("Sorry, no certificates were found in this message."));
return;
}
QString comment = QLatin1String("<b>") + i18n("Certificate import status:") + QLatin1String("</b><br/>&nbsp;<br/>");
if (nImp)
comment += i18np("1 new certificate was imported.",
"%1 new certificates were imported.", nImp) + QLatin1String("<br/>");
if (nUnc)
comment += i18np("1 certificate was unchanged.",
"%1 certificates were unchanged.", nUnc) + QLatin1String("<br/>");
if (nSKImp)
comment += i18np("1 new secret key was imported.",
"%1 new secret keys were imported.", nSKImp) + QLatin1String("<br/>");
if (nSKUnc)
comment += i18np("1 secret key was unchanged.",
"%1 secret keys were unchanged.", nSKUnc) + QLatin1String("<br/>");
comment += QLatin1String("&nbsp;<br/>");
htmlWriter()->queue(comment);
if (!nImp && !nSKImp) {
htmlWriter()->queue(QStringLiteral("<hr/>"));
return;
}
const std::vector<GpgME::Import> imports = res.imports();
if (imports.empty()) {
htmlWriter()->queue(i18n("Sorry, no details on certificate import available.") + QLatin1String("<hr/>"));
return;
}
htmlWriter()->queue(QLatin1String("<b>") + i18n("Certificate import details:") + QLatin1String("</b><br/>"));
std::vector<GpgME::Import>::const_iterator end(imports.end());
for (std::vector<GpgME::Import>::const_iterator it = imports.begin(); it != end; ++it) {
if ((*it).error()) {
htmlWriter()->queue(i18nc("Certificate import failed.", "Failed: %1 (%2)", QLatin1String((*it).fingerprint()),
QString::fromLocal8Bit((*it).error().asString())));
} else if ((*it).status() & ~GpgME::Import::ContainedSecretKey) {
if ((*it).status() & GpgME::Import::ContainedSecretKey) {
htmlWriter()->queue(i18n("New or changed: %1 (secret key available)", QLatin1String((*it).fingerprint())));
} else {
htmlWriter()->queue(i18n("New or changed: %1", QLatin1String((*it).fingerprint())));
}
}
htmlWriter()->queue(QStringLiteral("<br/>"));
}
htmlWriter()->queue(QStringLiteral("<hr/>"));
}
void ObjectTreeParser::extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart) void ObjectTreeParser::extractNodeInfos(KMime::Content *curNode, bool isFirstTextPart)
{ {
if (isFirstTextPart) { if (isFirstTextPart) {
......
...@@ -354,9 +354,6 @@ private: ...@@ -354,9 +354,6 @@ private:
MessagePartPtr defaultHandling(KMime::Content *node, ProcessResult &result); MessagePartPtr defaultHandling(KMime::Content *node, ProcessResult &result);
/** Writes out the information contained in a GpgME::ImportResult */
void writeCertificateImportResult(const GpgME::ImportResult &res);
public:// (during refactoring) public:// (during refactoring)
MessagePartPtr processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result); MessagePartPtr processApplicationPkcs7MimeSubtype(KMime::Content *node, ProcessResult &result);
...@@ -422,7 +419,6 @@ private: ...@@ -422,7 +419,6 @@ private:
friend class PartNodeBodyPart; friend class PartNodeBodyPart;
friend class MessagePart; friend class MessagePart;
friend class CryptoMessagePart; friend class CryptoMessagePart;
friend class CertMessagePart;
friend class EncapsulatedRfc822MessagePart; friend class EncapsulatedRfc822MessagePart;
friend class TextMessagePart; friend class TextMessagePart;
friend class HtmlMessagePart; friend class HtmlMessagePart;
......
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