diff --git a/part.h b/part.h --- a/part.h +++ b/part.h @@ -234,6 +234,7 @@ void enableTOC(bool enable); void slotRebuildBookmarkMenu(); void enableLayers( bool enable ); + void slotShowSigStatus( bool allSignaturesValid ); public Q_SLOTS: bool saveFile() override; diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -540,6 +540,7 @@ connect( m_reviewsWidget.data(), &Reviews::openAnnotationWindow, m_pageView.data(), &PageView::openAnnotationWindow ); + connect( m_pageView, &PageView::signatureValidationComplete, this, &Part::slotShowSigStatus ); // add document observers m_document->addObserver( this ); @@ -619,7 +620,7 @@ updateViewActions(); // also update the state of the actions in the page view - m_pageView->updateActionState( false, false, false ); + m_pageView->updateActionState( false, false, false, false ); if ( m_embedMode == NativeShellMode ) m_sidebar->setAutoFillBackground( false ); @@ -1550,7 +1551,14 @@ // m_pageView->toggleFormsAction() may be null on dummy mode else if ( ok && m_pageView->toggleFormsAction() && m_pageView->toggleFormsAction()->isEnabled() ) { - m_formsMessage->setText( i18n( "This document has forms. Click on the button to interact with them, or use View -> Show Forms." ) ); + if ( m_pageView->validateSignaturesAction() && m_pageView->validateSignaturesAction()->isEnabled() ) + { + m_formsMessage->setText( i18n( "This document has forms of which atleast one is a signature form. Click on the buttons to interact with them." ) ); + } + else + { + m_formsMessage->setText( i18n( "This document has forms. Click on the button to interact with them, or use View -> Show Forms." ) ); + } m_formsMessage->setMessageType( KMessageWidget::Information ); m_formsMessage->setVisible( true ); } @@ -3372,6 +3380,7 @@ m_pageView->setupActions( actionCollection() ); + m_formsMessage->addAction( m_pageView->validateSignaturesAction() ); // attach the actions of the children widgets too m_formsMessage->addAction( m_pageView->toggleFormsAction() ); @@ -3557,6 +3566,12 @@ ReadWritePart::setReadWrite( readwrite ); } +void Part::slotShowSigStatus( bool allSignaturesValid ) +{ + const QString message = allSignaturesValid ? i18n( "All signatures are valid." ) : i18n( "Atleast one signature has problem." ); + m_pageView->displayMessage( message, QString(), allSignaturesValid ? PageViewMessage::Info : PageViewMessage::Error, 10000 ); +} + } // namespace Okular #include "part.moc" diff --git a/ui/pageview.h b/ui/pageview.h --- a/ui/pageview.h +++ b/ui/pageview.h @@ -72,7 +72,7 @@ void setupBaseActions( KActionCollection * collection ); void setupViewerActions( KActionCollection * collection ); void setupActions( KActionCollection * collection ); - void updateActionState( bool docHasPages, bool docChanged, bool docHasFormWidgets ); + void updateActionState(bool docHasPages, bool docChanged, bool docHasFormWidgets , bool docHasSignatureForms ); // misc methods (from RMB menu/children) bool canFitPageWidth() const; @@ -102,6 +102,7 @@ KActionCollection *actionCollection() const; QAction *toggleFormsAction() const; + QAction *validateSignaturesAction() const; int contentAreaWidth() const; int contentAreaHeight() const; @@ -130,6 +131,7 @@ void mouseForwardButtonClick(); void escPressed(); void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize ); + void signatureValidationComplete( bool allSignaturesValid ); protected: bool event( QEvent * event ) override; @@ -271,6 +273,7 @@ void slotProcessRenditionAction( const Okular::RenditionAction *action ); void slotToggleChangeColors(); void slotFitWindowToPage(); + void slotValidateSignatures(); }; #endif diff --git a/ui/pageview.cpp b/ui/pageview.cpp --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -235,6 +235,7 @@ KActionCollection * actionCollection; QActionGroup * mouseModeActionGroup; QAction * aFitWindowToPage; + QAction * aValidateSignatures; int setting_viewCols; bool rtl_Mode; @@ -363,6 +364,7 @@ d->aMouseMagnifier = nullptr; d->aFitWindowToPage = nullptr; d->trimBoundingBox = Okular::NormalizedRect(); // Null box + d->aValidateSignatures = nullptr; switch( Okular::Settings::zoomMode() ) { @@ -722,6 +724,12 @@ d->aToggleForms->setEnabled( false ); toggleFormWidgets( false ); + d->aValidateSignatures = new QAction( this ); + ac->addAction( QStringLiteral("validate_signatures"), d->aValidateSignatures ); + connect( d->aValidateSignatures, &QAction::triggered, this, &PageView::slotValidateSignatures ); + d->aValidateSignatures->setText( i18n("Validate All signatures")); + d->aValidateSignatures->setEnabled( false ); + // Setup undo and redo actions QAction *kundo = KStandardAction::create( KStandardAction::Undo, d->document, SLOT(undo()), ac ); QAction *kredo = KStandardAction::create( KStandardAction::Redo, d->document, SLOT(redo()), ac ); @@ -868,6 +876,11 @@ return d->aToggleForms; } +QAction *PageView::validateSignaturesAction() const +{ + return d->aValidateSignatures; +} + int PageView::contentAreaWidth() const { return horizontalScrollBar()->maximum() + viewport()->width(); @@ -981,6 +994,7 @@ } } + //BEGIN DocumentObserver inherited methods void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, int setupFlags ) { @@ -1088,6 +1102,7 @@ bool haspages = !pageSet.isEmpty(); bool hasformwidgets = false; + bool hassignatureforms = false; // create children widgets QVector< Okular::Page * >::const_iterator setIt = pageSet.constBegin(), setEnd = pageSet.constEnd(); for ( ; setIt != setEnd; ++setIt ) @@ -1111,6 +1126,8 @@ w->setCanBeFilled( allowfillforms ); item->formWidgets().insert( w ); hasformwidgets = true; + if ( w->formField()->type() == Okular::FormField::FormSignature ) + hassignatureforms = true; } } @@ -1147,7 +1164,7 @@ QString(), PageViewMessage::Info, 4000 ); - updateActionState( haspages, documentChanged, hasformwidgets ); + updateActionState( haspages, documentChanged, hasformwidgets, hassignatureforms ); // We need to assign it to a different list otherwise slotAnnotationWindowDestroyed // will bite us and clear d->m_annowindows @@ -1158,7 +1175,7 @@ selectionClear(); } -void PageView::updateActionState( bool haspages, bool documentChanged, bool hasformwidgets ) +void PageView::updateActionState( bool haspages, bool documentChanged, bool hasformwidgets, bool hassignatureforms ) { if ( d->aPageSizes ) { // may be null if dummy mode is on @@ -1245,6 +1262,8 @@ d->aMouseMagnifier->setEnabled(d->document->supportsTiles()); if ( d->aFitWindowToPage ) d->aFitWindowToPage->setEnabled( haspages && !Okular::Settings::viewContinuous() ); + if ( d->aValidateSignatures ) + d->aValidateSignatures->setEnabled( haspages && hasformwidgets && hassignatureforms ); } bool PageView::areSourceLocationsShownGraphically() const @@ -5525,6 +5544,25 @@ emit fitWindowToPage( viewportSize, pageSize ); } +void PageView::slotValidateSignatures() +{ + bool allSignaturesValid = true; + foreach ( PageViewItem * item, d->items ) + { + foreach ( FormWidgetIface * w, item->formWidgets() ) + { + if ( w->formField()->type() == Okular::FormField::FormSignature ) + { + Okular::SignatureInfo * sigInfo = static_cast< SignatureEdit * >( w )->validate(); + if ( sigInfo->signatureStatus() != Okular::SignatureInfo::SignatureValid ) + allSignaturesValid = false; + } + } + } + d->aValidateSignatures->setEnabled( false ); + emit signatureValidationComplete( allSignaturesValid ); +} + //END private SLOTS #include "moc_pageview.cpp"