diff --git a/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeyformatter.cpp b/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeyformatter.cpp index 177486d1..81f42756 100644 --- a/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeyformatter.cpp +++ b/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeyformatter.cpp @@ -1,127 +1,131 @@ /* Copyright (c) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "pgpkeyformatter.h" #include "pgpkeymessagepart.h" #include "pgpkeymemento.h" #include #include #include #include #include #include #include #include using namespace MimeTreeParser::Interface; MimeTreeParser::MessagePartPtr ApplicationPGPKeyFormatter::process(MimeTreeParser::Interface::BodyPart &part) const { auto mp = new PgpKeyMessagePart(&part); PgpKeyMemento *m = dynamic_cast(mp->memento()); if (!m) { auto memento = new PgpKeyMemento(); auto nodeHelper = part.nodeHelper(); if (nodeHelper) { QObject::connect(memento, &PgpKeyMemento::update, nodeHelper, &MimeTreeParser::NodeHelper::update); memento->start(mp->fingerprint()); } else { memento->exec(mp->fingerprint()); m = memento; } mp->setMemento(memento); - } else if (m->isRunning()) { + mp->setSearchRunning(memento->isRunning()); + } else if (m && m->isRunning()) { + mp->setSearchRunning(m->isRunning()); m = nullptr; } if (m) { + mp->setSearchRunning(m->isRunning()); Q_ASSERT(!m->isRunning()); mp->setError(m->error()); mp->setKey(m->key()); } return MimeTreeParser::MessagePartPtr(mp); } bool ApplicationPGPKeyFormatter::render(const MimeTreeParser::MessagePartPtr &msgPart, MimeTreeParser::HtmlWriter *htmlWriter, MessageViewer::RenderContext *context) const { Q_UNUSED(context); auto mp = msgPart.dynamicCast(); if (!mp) { return false; } GrantleeTheme::Engine engine; engine.localizer()->setApplicationDomain(QByteArrayLiteral("messageviewer_application_gnupgwks_plugin")); engine.addTemplateLoader(QSharedPointer::create()); Grantlee::Template tpl = engine.loadByName(QStringLiteral(":/pgpkeymessagepart.html")); Grantlee::Context ctx; ctx.setLocalizer(engine.localizer()); QObject block; block.setProperty("showKeyDetails", mp->source()->showSignatureDetails()); block.setProperty("error", mp->error()); block.setProperty("importUrl", mp->makeLink(QStringLiteral("pgpkey")) + QStringLiteral("?action=import")); + block.setProperty("searchRunning", mp->searchRunning()); const auto key = mp->key(); if (key.isNull()) { block.setProperty("uid", mp->userID()); block.setProperty("fingerprint", mp->fingerprint()); block.setProperty("created", mp->keyDate().toString(Qt::SystemLocaleDate)); } else { const auto uid = key.userID(0); block.setProperty("hasKey", true); if (uid.email() && *uid.email() && uid.name() && *uid.name()) { block.setProperty("uid", QStringLiteral("%1 <%2>").arg(QString::fromUtf8(uid.name()), QString::fromUtf8(uid.email()))); } else if (uid.name() && *uid.name()) { block.setProperty("uid", QString::fromUtf8(uid.name())); } else if (uid.email() && *uid.email()) { block.setProperty("uid", QString::fromUtf8(uid.email())); } else { block.setProperty("uid", i18n("Unknown identity")); } block.setProperty("created", QDateTime::fromTime_t(key.subkey(0).creationTime()).toString(Qt::SystemLocaleDate)); block.setProperty("fingerprint", QString::fromLatin1(key.primaryFingerprint())); block.setProperty("keyUrl", QStringLiteral("kmail:showCertificate#GpgME ### gpgme ### %1").arg(QString::fromLatin1(key.keyID()))); } QObject style; const auto bgColor = QApplication::palette().color(QPalette::Base); if (bgColor.value() < 128) { // HSV value (brightness): 0 = darkest, 255 = brightest style.setProperty("borderColor", QColor(Qt::white).name()); style.setProperty("frameTextColor", QColor(Qt::black).name()); } else { style.setProperty("borderColor", QColor(Qt::black).name()); style.setProperty("frameTextColor", QColor(Qt::white).name()); } ctx.insert(QStringLiteral("block"), &block); ctx.insert(QStringLiteral("style"), &style); Grantlee::OutputStream s(htmlWriter->stream()); tpl->render(&s, &ctx); return true; } diff --git a/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.cpp b/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.cpp index eaa002a2..4e07f405 100644 --- a/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.cpp +++ b/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.cpp @@ -1,121 +1,133 @@ /* Copyright (c) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "pgpkeymessagepart.h" #include #include #include PgpKeyMessagePart::PgpKeyMessagePart(MimeTreeParser::Interface::BodyPart *part) : MimeTreeParser::MessagePart(part->objectTreeParser(), QString()) + , mSearchRunning(false) { setContent(part->content()); parseContent(part->content()); } QDateTime PgpKeyMessagePart::keyDate() const { return mKeyDate; } QString PgpKeyMessagePart::keyID() const { return mKeyID; } QString PgpKeyMessagePart::userID() const { return mUserID; } QString PgpKeyMessagePart::fingerprint() const { return mFingerprint; } GpgME::Key PgpKeyMessagePart::key() const { return mKey; } void PgpKeyMessagePart::setKey(const GpgME::Key &key) { mKey = key; } QString PgpKeyMessagePart::error() const { return mError; } void PgpKeyMessagePart::setError(const QString &error) { mError = error; } QByteArray PgpKeyMessagePart::rawKey() const { return content()->decodedContent(); } +void PgpKeyMessagePart::setSearchRunning(bool searchRunning) +{ + mSearchRunning = searchRunning; +} + +bool PgpKeyMessagePart::searchRunning() const +{ + return mSearchRunning; +} + + void PgpKeyMessagePart::parseContent(KMime::Content *node) { QProcess p; p.start(QStringLiteral("gpg"), { QStringLiteral("--with-colons"), QStringLiteral("--fixed-list-mode"), QStringLiteral("--with-fingerprint")}); p.waitForStarted(); p.write(node->decodedContent()); p.closeWriteChannel(); p.waitForReadyRead(); const QByteArray result = p.readAllStandardOutput(); p.waitForFinished(); const auto lines = result.split('\n'); for (const auto &line : lines) { const auto cols = line.split(':'); if (cols.isEmpty()) { continue; } const int size = cols.size(); // "pub" line can appear multiple times, but we are only interested in // the first one if (cols[0] == "pub" && mKeyID.isEmpty()) { if (size > 4) { mKeyID = QString::fromUtf8(cols[4]); } // gpg1: "pub" contains UID if (size > 9) { mUserID = QString::fromUtf8(cols[9]); } if (size > 6) { mKeyDate = QDateTime::fromTime_t(cols[5].toUInt()); } // gpg2: UID is on a separate line } else if (cols[0] == "uid" && size > 9 && mUserID.isEmpty()) { mUserID = QString::fromUtf8(cols[9]); } else if (cols[0] == "fpr" && size > 9 && mFingerprint.isEmpty()) { mFingerprint = QString::fromLatin1(cols[9]); } } } diff --git a/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.h b/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.h index 645b2741..fc947f8c 100644 --- a/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.h +++ b/plugins/messageviewer/bodypartformatter/gnupgwks/pgpkeymessagepart.h @@ -1,70 +1,74 @@ /* Copyright (c) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PGPKEYMESSAGEPART_H_ #define PGPKEYMESSAGEPART_H_ #include #include #include #include namespace MimeTreeParser { namespace Interface { class BodyPart; } } namespace KMime { class Content; } class PgpKeyMessagePart : public MimeTreeParser::MessagePart { Q_OBJECT public: explicit PgpKeyMessagePart(MimeTreeParser::Interface::BodyPart *part); ~PgpKeyMessagePart() = default; QDateTime keyDate() const; QString userID() const; QString keyID() const; QString fingerprint() const; QString error() const; void setError(const QString &error); void setKey(const GpgME::Key &key); GpgME::Key key() const; QByteArray rawKey() const; + void setSearchRunning(bool searchRunning); + bool searchRunning() const; + protected: void parseContent(KMime::Content *node); QDateTime mKeyDate; QString mUserID; QString mKeyID; QString mFingerprint; QString mError; GpgME::Key mKey; + bool mSearchRunning; }; #endif diff --git a/plugins/messageviewer/bodypartformatter/gnupgwks/templates/pgpkeymessagepart.html b/plugins/messageviewer/bodypartformatter/gnupgwks/templates/pgpkeymessagepart.html index 244e6ce1..18ea8082 100644 --- a/plugins/messageviewer/bodypartformatter/gnupgwks/templates/pgpkeymessagepart.html +++ b/plugins/messageviewer/bodypartformatter/gnupgwks/templates/pgpkeymessagepart.html @@ -1,54 +1,55 @@
{% i18n "OpenPGP Key" %}

{% i18n "This is an OpenPGP key, which can be used to sign or encrypt emails." %}

{% if block.showKeyDetails %} - {% if block.hasKey %} - - - - + {% if block.searchRunning %} +

{% i18n "Loading key details..." %}

+ {% endif %} + {% if not block.error %} +
{% i18n "Owner:" %} {{ block.uid }}
+ + + {% if block.created %} - - - + + + {% endif %} {% if block.fingerprint %} - - - + + + {% endif %} -
{% i18n "Owner:" %} {{ block.uid }}
{% i18n "Created:" %} {{ block.created }}
{% i18n "Created:" %} {{ block.created }}
{% i18n "Fingerprint:" %} {{ block.fingerprint }}
{% i18n "Fingerprint:" %} {{ block.fingerprint }}
+
+ {% else %} +

{% i18n "Error while loading key: %1" block.error %}

+ {% endif %} {% i18n "Hide key details" %} {% if block.keyUrl %} - | {% i18n "Open in Kleopatra" %} - {% endif %} - {% elif block.error %} -

{% i18n "Error while loading key: %1" key.error %}

- {% else %} -

{% i18n "Loading key details..." %}

+ | {% i18n "Open in Kleopatra" %} {% endif %} {% else %} {% i18n "Show key details ..." %} - {% endif %} + {% endif %} | {% i18n "Import key" %}