Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Add text export to certificate details

This adds an easy copy & paste export without the extra
file step. Good for message boards etc.
For OpenPGP it adds comments about the user ids / type etc
like it's done by the S/MIME Export anyway.

GnuPG-Bug-Id: 3605
parent 215ba942
......@@ -120,6 +120,7 @@ set(_kleopatra_SRCS
dialogs/trustchainwidget.cpp
dialogs/weboftrustwidget.cpp
dialogs/weboftrustdialog.cpp
dialogs/exportdialog.cpp
dialogs/subkeyswidget.cpp
dialogs/gencardkeydialog.cpp
dialogs/updatenotification.cpp
......
/* Copyright (c) 2016 Klarälvdalens Datakonsult AB
2017 Intevation GmbH
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -18,6 +19,7 @@
#include "certificatedetailswidget.h"
#include "ui_certificatedetailswidget.h"
#include "kleopatra_debug.h"
#include "exportdialog.h"
#include "trustchainwidget.h"
#include "subkeyswidget.h"
#include "weboftrustdialog.h"
......@@ -66,6 +68,7 @@ public:
void genRevokeCert();
void certifyClicked();
void webOfTrustClicked();
void exportClicked();
void addUserID();
void changePassphrase();
void changeExpiration();
......@@ -235,6 +238,13 @@ void CertificateDetailsWidget::Private::webOfTrustClicked()
dlg->exec();
}
void CertificateDetailsWidget::Private::exportClicked()
{
QScopedPointer<ExportDialog> dlg(new ExportDialog(q));
dlg->setKey(key);
dlg->exec();
}
void CertificateDetailsWidget::Private::addUserID()
{
auto cmd = new Kleo::Commands::AddUserIDCommand(key);
......@@ -457,6 +467,8 @@ CertificateDetailsWidget::CertificateDetailsWidget(QWidget *parent)
this, [this]() { d->certifyClicked(); });
connect(d->ui.webOfTrustBtn, &QPushButton::clicked,
this, [this]() { d->webOfTrustClicked(); });
connect(d->ui.exportBtn, &QPushButton::clicked,
this, [this]() { d->exportClicked(); });
connect(Kleo::KeyCache::instance().get(), &Kleo::KeyCache::keysMayHaveChanged,
this, [this]() { d->keysMayHaveChanged(); });
......
......@@ -256,6 +256,13 @@ to retract such a revocation certificate once it has been published.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportBtn">
<property name="text">
<string>&amp;Export...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="webOfTrustBtn">
<property name="text">
......
/* Copyright (c) 2017 Intevation GmbH
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kleopatra 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "exportdialog.h"
#include "kleopatra_debug.h"
#include "view/waitwidget.h"
#include <QDialog>
#include <QDialogButtonBox>
#include <QFontDatabase>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <gpgme++/key.h>
#include <QGpgME/Protocol>
#include <QGpgME/ExportJob>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KConfigGroup>
#include <Libkleo/Formatting>
using namespace Kleo;
class ExportWidget::Private
{
public:
Private(ExportWidget *qq)
: q(qq)
{}
void setupUi();
GpgME::Key key;
QTextEdit *textEdit;
WaitWidget *waitWidget;
private:
ExportWidget *q;
};
void ExportWidget::Private::setupUi()
{
auto vlay = new QVBoxLayout;
textEdit = new QTextEdit;
textEdit->setVisible(false);
textEdit->setReadOnly(true);
textEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
textEdit->setReadOnly(true);
vlay->addWidget(textEdit);
waitWidget = new WaitWidget;
waitWidget->setText(i18n("Exporting ..."));
vlay->addWidget(waitWidget);
q->setLayout(vlay);
}
ExportWidget::ExportWidget(QWidget *parent)
: QWidget(parent)
, d(new Private(this))
{
d->setupUi();
}
ExportWidget::~ExportWidget()
{
}
static QString injectComments(const GpgME::Key &key, const QByteArray &data)
{
QString ret = QString::fromUtf8(data);
if (key.protocol() != GpgME::OpenPGP) {
return ret;
}
auto overView = Formatting::toolTip(key, Formatting::Fingerprint |
Formatting::UserIDs |
Formatting::Issuer |
Formatting::Subject |
Formatting::ExpiryDates |
Formatting::CertificateType |
Formatting::CertificateUsage);
// Fixup the HTML coming from the toolTip for our own format.
overView.replace(QLatin1String("<tr><th>"), "");
overView.replace(QLatin1String("</th><td>"), "\t");
overView.replace(QLatin1String("</td></tr>"), "\n");
overView.replace(QLatin1String("<table border=\"0\">"), "");
overView.replace(QLatin1String("\n</table>"), "");
overView.replace(QLatin1String("&lt;"), "<");
overView.replace(QLatin1String("&gt;"), ">");
auto overViewLines = overView.split(QLatin1Char('\n'));
// Format comments so that they fit for RFC 4880
auto comments = QString("Comment: ");
comments += overViewLines.join("\nComment: ") + QLatin1Char('\n');
ret.insert(37 /* -----BEGIN PGP PUBLIC KEY BLOCK-----\n */, comments);
return ret;
}
void ExportWidget::exportResult(const GpgME::Error &err, const QByteArray &data)
{
d->waitWidget->setVisible(false);
d->textEdit->setVisible(true);
if (err) {
/* Should not happen. But well,.. */
d->textEdit->setText(i18nc("%1 is error message", "Failed to export: '%1'").arg(err.asString()));
}
d->textEdit->setText(injectComments(d->key, data));
}
void ExportWidget::setKey(const GpgME::Key &key)
{
d->waitWidget->setVisible(true);
d->textEdit->setVisible(false);
d->key = key;
auto protocol = key.protocol() == GpgME::CMS ?
QGpgME::smime() : QGpgME::openpgp();
auto job = protocol->publicKeyExportJob(true);
/* New style connect does not work on Windows. */
connect(job, SIGNAL(result(GpgME::Error, QByteArray)),
this, SLOT(exportResult(GpgME::Error, QByteArray)));
job->start(QStringList() << key.primaryFingerprint());
}
GpgME::Key ExportWidget::key() const
{
return d->key;
}
ExportDialog::ExportDialog(QWidget *parent)
: QDialog(parent),
mWidget(new ExportWidget(this))
{
KConfigGroup dialog(KSharedConfig::openConfig(), "ExportDialog");
const auto size = dialog.readEntry("Size", QSize(600, 800));
if (size.isValid()) {
resize(size);
}
setWindowTitle(i18n("Export..."));
auto l = new QVBoxLayout(this);
l->addWidget(mWidget);
auto bbox = new QDialogButtonBox(this);
auto btn = bbox->addButton(QDialogButtonBox::Close);
connect(btn, &QPushButton::pressed, this, &QDialog::accept);
l->addWidget(bbox);
}
ExportDialog::~ExportDialog()
{
KConfigGroup dialog(KSharedConfig::openConfig(), "ExportDialog");
dialog.writeEntry("Size", size());
dialog.sync();
}
void ExportDialog::setKey(const GpgME::Key &key)
{
mWidget->setKey(key);
}
GpgME::Key ExportDialog::key() const
{
return mWidget->key();
}
/* Copyright (c) 2017 Intevation GmbH
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kleopatra 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KLEO_EXPORTDIALOG_H
#define KLEO_EXPORTDIALOG_H
#include <QWidget>
#include <QDialog>
namespace GpgME {
class Key;
class Error;
}
namespace Kleo {
class ExportWidget : public QWidget
{
Q_OBJECT
public:
explicit ExportWidget(QWidget *parent = nullptr);
~ExportWidget();
void setKey(const GpgME::Key &key);
GpgME::Key key() const;
private Q_SLOTS:
void exportResult(const GpgME::Error &err, const QByteArray &data);
private:
class Private;
const QScopedPointer<Private> d;
};
class ExportDialog : public QDialog
{
Q_OBJECT
public:
explicit ExportDialog(QWidget *parent = nullptr);
~ExportDialog();
void setKey(const GpgME::Key &key);
GpgME::Key key() const;
private:
ExportWidget *mWidget;
};
} // namespace Kleo
#endif
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