mirror of
https://invent.kde.org/graphics/okular
synced 2024-07-05 00:58:46 +00:00
Allow open certificate with kleopatra
If the active backend is gnupg (e.g. if only compiled-in backend, or later when configurabitily thru okular has been merged), we can offer to view and edit certificates with Kleopatra (KDE's certificate manager)
This commit is contained in:
parent
034397dae1
commit
d1133be5fc
|
@ -48,6 +48,7 @@ public:
|
|||
int publicKeyStrength = -1;
|
||||
bool isSelfSigned = false;
|
||||
QByteArray certificateData;
|
||||
CertificateInfo::Backend backend = CertificateInfo::Backend::Unknown;
|
||||
std::function<bool(QString)> checkPasswordFunction;
|
||||
};
|
||||
|
||||
|
@ -249,6 +250,16 @@ void CertificateInfo::setCertificateData(const QByteArray &certificateData)
|
|||
d->certificateData = certificateData;
|
||||
}
|
||||
|
||||
CertificateInfo::Backend CertificateInfo::backend() const
|
||||
{
|
||||
return d->backend;
|
||||
}
|
||||
|
||||
void CertificateInfo::setBackend(Backend backend)
|
||||
{
|
||||
d->backend = backend;
|
||||
}
|
||||
|
||||
bool CertificateInfo::checkPassword(const QString &password) const
|
||||
{
|
||||
if (d->checkPasswordFunction) {
|
||||
|
|
|
@ -25,6 +25,21 @@ class CertificateInfoPrivate;
|
|||
class OKULARCORE_EXPORT CertificateInfo
|
||||
{
|
||||
public:
|
||||
/** The certificate backend is mostly
|
||||
important if there is a wish to integrate
|
||||
third party viewers, where some third party
|
||||
viewers only interacts with some and not other
|
||||
backend */
|
||||
enum class Backend {
|
||||
/** The backend is either unknown
|
||||
or known, but not something there is
|
||||
currently supported need for*/
|
||||
Unknown,
|
||||
/** The certificates in question originates
|
||||
in gpg and thus can be queried using e.g.
|
||||
KDE's certificate manager Kleopatra */
|
||||
Gpg
|
||||
};
|
||||
/**
|
||||
* The algorithm of public key.
|
||||
*/
|
||||
|
@ -223,6 +238,20 @@ public:
|
|||
*/
|
||||
void setCertificateData(const QByteArray &certificateData);
|
||||
|
||||
/**
|
||||
* The backend where the certificate originates.
|
||||
* see @ref Backend for details
|
||||
* @since 23.08
|
||||
*/
|
||||
Backend backend() const;
|
||||
|
||||
/**
|
||||
* Sets the backend for this certificate.
|
||||
* see @ref Backend for details
|
||||
* @since 23.08
|
||||
*/
|
||||
void setBackend(Backend backend);
|
||||
|
||||
/**
|
||||
* Checks if the given password is the correct one for this certificate
|
||||
*
|
||||
|
|
|
@ -92,6 +92,11 @@ Okular::CertificateInfo fromPoppler(const Poppler::CertificateInfo &pInfo)
|
|||
#endif
|
||||
return pInfo.checkPassword(password);
|
||||
});
|
||||
#if POPPLER_VERSION_MACRO >= QT_VERSION_CHECK(23, 06, 0)
|
||||
if (Poppler::activeCryptoSignBackend() == Poppler::CryptoSignBackend::GPG) {
|
||||
oInfo.setBackend(Okular::CertificateInfo::Backend::Gpg);
|
||||
}
|
||||
#endif
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
#include <QFormLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <QStandardPaths>
|
||||
#include <QVBoxLayout>
|
||||
#include <QVector>
|
||||
|
||||
|
@ -37,6 +39,8 @@ SignaturePropertiesDialog::SignaturePropertiesDialog(Okular::Document *doc, cons
|
|||
setModal(true);
|
||||
setWindowTitle(i18n("Signature Properties"));
|
||||
|
||||
m_kleopatraPath = QStandardPaths::findExecutable(QStringLiteral("kleopatra"));
|
||||
|
||||
const Okular::SignatureInfo &signatureInfo = form->signatureInfo();
|
||||
const Okular::SignatureInfo::SignatureStatus signatureStatus = signatureInfo.signatureStatus();
|
||||
const QString readableSignatureStatus = SignatureGuiUtils::getReadableSignatureStatus(signatureStatus);
|
||||
|
@ -85,9 +89,21 @@ SignaturePropertiesDialog::SignaturePropertiesDialog(Okular::Document *doc, cons
|
|||
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
|
||||
auto certPropBtn = new QPushButton(i18n("View Certificate..."));
|
||||
certPropBtn->setEnabled(!signatureInfo.certificateInfo().isNull());
|
||||
auto certManagerBtn = new QPushButton(i18n("View in Certificate Manager"));
|
||||
certManagerBtn->setVisible(signatureInfo.certificateInfo().backend() == Okular::CertificateInfo::Backend::Gpg);
|
||||
certManagerBtn->setEnabled(!m_kleopatraPath.isEmpty());
|
||||
if (m_kleopatraPath.isEmpty()) {
|
||||
certManagerBtn->setToolTip(i18n("KDE Certificate Manager (kleopatra) not found"));
|
||||
}
|
||||
btnBox->addButton(certPropBtn, QDialogButtonBox::ActionRole);
|
||||
btnBox->addButton(certManagerBtn, QDialogButtonBox::ActionRole);
|
||||
connect(btnBox, &QDialogButtonBox::rejected, this, &SignaturePropertiesDialog::reject);
|
||||
connect(certPropBtn, &QPushButton::clicked, this, &SignaturePropertiesDialog::viewCertificateProperties);
|
||||
connect(certManagerBtn, &QPushButton::clicked, this, [this]() {
|
||||
QStringList args;
|
||||
args << QStringLiteral("--parent-windowid") << QString::number(static_cast<qlonglong>(window()->winId())) << QStringLiteral("--query") << m_signatureForm->signatureInfo().certificateInfo().nickName();
|
||||
QProcess::startDetached(m_kleopatraPath, args);
|
||||
});
|
||||
|
||||
auto mainLayout = new QVBoxLayout(this);
|
||||
mainLayout->addWidget(signatureStatusBox);
|
||||
|
|
|
@ -31,6 +31,7 @@ public Q_SLOTS:
|
|||
private:
|
||||
Okular::Document *m_doc;
|
||||
const Okular::FormFieldSignature *m_signatureForm;
|
||||
QString m_kleopatraPath;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user