diff --git a/core/document.cpp b/core/document.cpp index 793d8bfd5..a097f4758 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -2799,6 +2799,11 @@ bool Document::canProvideFontInformation() const return d->m_generator ? d->m_generator->hasFeature(Generator::FontInfo) : false; } +bool Document::canSign() const +{ + return d->m_generator ? d->m_generator->canSign() : false; +} + const QList *Document::embeddedFiles() const { return d->m_generator ? d->m_generator->embeddedFiles() : nullptr; diff --git a/core/document.h b/core/document.h index ca90e58b2..bdc0315e4 100644 --- a/core/document.h +++ b/core/document.h @@ -281,6 +281,11 @@ public: */ bool canProvideFontInformation() const; + /** + * Whether the current document can perform digital signing. + */ + bool canSign() const; + /** * Returns the list of embedded files or 0 if no embedded files * are available. diff --git a/generators/poppler/CMakeLists.txt b/generators/poppler/CMakeLists.txt index a0f295418..7befc57cc 100644 --- a/generators/poppler/CMakeLists.txt +++ b/generators/poppler/CMakeLists.txt @@ -15,6 +15,14 @@ int main() } " HAVE_POPPLER_0_87) +check_cxx_source_compiles(" +#include +int main() +{ + auto f = &Poppler::Document::sign; +} +" HAVE_POPPLER_SIGNING) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h diff --git a/generators/poppler/config-okular-poppler.h.cmake b/generators/poppler/config-okular-poppler.h.cmake index 0aa62f078..613e1a4da 100644 --- a/generators/poppler/config-okular-poppler.h.cmake +++ b/generators/poppler/config-okular-poppler.h.cmake @@ -1,3 +1,5 @@ /* Defined if we have the 0.87 version of the Poppler library */ #cmakedefine HAVE_POPPLER_0_87 1 +/* Defined if we have the pdf signature feature in the Poppler library */ +#cmakedefine HAVE_POPPLER_SIGNING 1 diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 1c3a31172..b954db79a 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -1856,10 +1856,14 @@ Okular::AnnotationProxy *PDFGenerator::annotationProxy() const void PDFGenerator::sign( const Okular::Annotation* pWhichAnnotation ) { +#ifdef HAVE_POPPLER_SIGNING const Okular::WidgetAnnotation* wa = dynamic_cast(pWhichAnnotation); Poppler::Annotation *popplerAnn = qvariant_cast< Poppler::Annotation * >( pWhichAnnotation->nativeId() ); pdfdoc->sign( popplerAnn, wa->certificateCN(), wa->password() ); +#else + Q_UNUSED( pWhichAnnotation ); +#endif } #include "generator_pdf.moc" diff --git a/part/pageview.cpp b/part/pageview.cpp index 73e889d1d..340e8c442 100644 --- a/part/pageview.cpp +++ b/part/pageview.cpp @@ -1218,7 +1218,10 @@ void PageView::updateActionState(bool haspages, bool hasformwidgets) } if ( d->aSignature ) - d->aSignature->setEnabled( haspages ); + { + const bool canSign = d->document->canSign(); + d->aSignature->setEnabled( canSign && haspages ); + } #ifdef HAVE_SPEECH if (d->aSpeakDoc) { diff --git a/part/preferencesdialog.cpp b/part/preferencesdialog.cpp index 0f7c1c867..d187d934e 100644 --- a/part/preferencesdialog.cpp +++ b/part/preferencesdialog.cpp @@ -11,6 +11,7 @@ #include "preferencesdialog.h" #include +#include "../generators/poppler/config-okular-poppler.h" // single config pages #include "dlgaccessibility.h" @@ -48,11 +49,15 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, KConfigSkeleton *skeleton, m_presentation = new DlgPresentation(this); m_annotations = new DlgAnnotations(this); m_editor = new DlgEditor(this); +#ifdef HAVE_POPPLER_SIGNING m_signatures = new DlgSignatures(this); +#endif addPage(m_presentation, i18n("Presentation"), QStringLiteral("view-presentation"), i18n("Options for Presentation Mode")); m_annotationsPage = addPage(m_annotations, i18n("Annotations"), QStringLiteral("draw-freehand"), i18n("Annotation Options")); addPage(m_editor, i18n("Editor"), QStringLiteral("accessories-text-editor"), i18n("Editor Options")); +#ifdef HAVE_POPPLER_SIGNING addPage(m_signatures, i18n("Signatures"), QStringLiteral("application-pkcs7-signature"), i18n("Digital Signatures")); +#endif } #ifdef OKULAR_DEBUG_CONFIGPAGE addPage(m_debug, "Debug", "system-run", "Debug options");