diff --git a/ui/guiutils.cpp b/ui/guiutils.cpp index c2a55c047..45656453b 100644 --- a/ui/guiutils.cpp +++ b/ui/guiutils.cpp @@ -1,361 +1,280 @@ /*************************************************************************** * Copyright (C) 2006-2007 by Pino Toscano * * * * This program 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. * ***************************************************************************/ #include "guiutils.h" // qt/kde includes #include #include #include #include #include #include #include #include // local includes #include "core/action.h" #include "core/annotations.h" #include "core/document.h" -#include "core/page.h" -#include "core/form.h" + #include struct GuiUtilsHelper { GuiUtilsHelper() { } QSvgRenderer* svgStamps(); QList il; std::unique_ptr< QSvgRenderer > svgStampFile; }; QSvgRenderer* GuiUtilsHelper::svgStamps() { if ( !svgStampFile.get() ) { const QString stampFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("okular/pics/stamps.svg") ); if ( !stampFile.isEmpty() ) { svgStampFile.reset( new QSvgRenderer( stampFile ) ); if ( !svgStampFile->isValid() ) { svgStampFile.reset(); } } } return svgStampFile.get(); } Q_GLOBAL_STATIC( GuiUtilsHelper, s_data ) namespace GuiUtils { QString captionForAnnotation( const Okular::Annotation * ann ) { Q_ASSERT( ann ); const bool hasComment = !ann->contents().isEmpty(); QString ret; switch( ann->subType() ) { case Okular::Annotation::AText: if( ( (Okular::TextAnnotation*)ann )->textType() == Okular::TextAnnotation::Linked ) ret = i18n( "Pop-up Note" ); else ret = i18n( "Inline Note" ); break; case Okular::Annotation::ALine: if( ( (Okular::LineAnnotation*)ann )->linePoints().count() == 2 ) ret = hasComment ? i18n( "Straight Line with Comment" ) : i18n( "Straight Line" ); else ret = hasComment ? i18n( "Polygon with Comment" ) : i18n( "Polygon" ); break; case Okular::Annotation::AGeom: ret = hasComment ? i18n( "Geometry with Comment" ) : i18n( "Geometry" ); break; case Okular::Annotation::AHighlight: switch ( ( (Okular::HighlightAnnotation*)ann )->highlightType() ) { case Okular::HighlightAnnotation::Highlight: ret = hasComment ? i18n( "Highlight with Comment" ) : i18n( "Highlight" ); break; case Okular::HighlightAnnotation::Squiggly: ret = hasComment ? i18n( "Squiggle with Comment" ) : i18n( "Squiggle" ); break; case Okular::HighlightAnnotation::Underline: ret = hasComment ? i18n( "Underline with Comment" ) : i18n( "Underline" ); break; case Okular::HighlightAnnotation::StrikeOut: ret = hasComment ? i18n( "Strike Out with Comment" ) : i18n( "Strike Out" ); break; } break; case Okular::Annotation::AStamp: ret = hasComment ? i18n( "Stamp with Comment" ) : i18n( "Stamp" ); break; case Okular::Annotation::AInk: ret = hasComment ? i18n( "Freehand Line with Comment" ) : i18n( "Freehand Line" ); break; case Okular::Annotation::ACaret: ret = i18n( "Caret" ); break; case Okular::Annotation::AFileAttachment: ret = i18n( "File Attachment" ); break; case Okular::Annotation::ASound: ret = i18n( "Sound" ); break; case Okular::Annotation::AMovie: ret = i18n( "Movie" ); break; case Okular::Annotation::AScreen: ret = i18nc( "Caption for a screen annotation", "Screen" ); break; case Okular::Annotation::AWidget: ret = i18nc( "Caption for a widget annotation", "Widget" ); break; case Okular::Annotation::ARichMedia: ret = i18nc( "Caption for a rich media annotation", "Rich Media" ); break; case Okular::Annotation::A_BASE: break; } return ret; } QString authorForAnnotation( const Okular::Annotation * ann ) { Q_ASSERT( ann ); return !ann->author().isEmpty() ? ann->author() : i18nc( "Unknown author", "Unknown" ); } QString contentsHtml( const Okular::Annotation * ann ) { QString text = ann->contents().toHtmlEscaped(); text.replace( QLatin1Char('\n'), QLatin1String("
") ); return text; } QString prettyToolTip( const Okular::Annotation * ann ) { Q_ASSERT( ann ); QString author = authorForAnnotation( ann ); QString contents = contentsHtml( ann ); QString tooltip = QStringLiteral( "" ) + i18n( "Author: %1", author ) + QStringLiteral( "" ); if ( !contents.isEmpty() ) tooltip += QStringLiteral( "

" ) + contents; tooltip += QLatin1String("
"); return tooltip; } QPixmap loadStamp( const QString& _name, const QSize& size, int iconSize ) { const QString name = _name.toLower(); QSvgRenderer * r = nullptr; if ( ( r = s_data->svgStamps() ) && r->elementExists( name ) ) { const QRectF stampElemRect = r->boundsOnElement( name ); const QRectF stampRect( size.isValid() ? QRectF( QPointF( 0, 0 ), size ) : stampElemRect ); QPixmap pixmap( stampRect.size().toSize() ); pixmap.fill( Qt::transparent ); QPainter p( &pixmap ); r->render( &p, name ); p.end(); return pixmap; } QPixmap pixmap; const KIconLoader * il = iconLoader(); QString path; const int minSize = iconSize > 0 ? iconSize : qMin( size.width(), size.height() ); pixmap = il->loadIcon( name, KIconLoader::User, minSize, KIconLoader::DefaultState, QStringList(), &path, true ); if ( path.isEmpty() ) pixmap = il->loadIcon( name, KIconLoader::NoGroup, minSize ); return pixmap; } void addIconLoader( KIconLoader * loader ) { s_data->il.append( loader ); } void removeIconLoader( KIconLoader * loader ) { s_data->il.removeAll( loader ); } KIconLoader* iconLoader() { return s_data->il.isEmpty() ? KIconLoader::global() : s_data->il.back(); } void saveEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent ) { const QString caption = i18n( "Where do you want to save %1?", ef->name() ); const QString path = QFileDialog::getSaveFileName( parent, caption, ef->name() ); if ( path.isEmpty() ) return; QFile targetFile( path ); writeEmbeddedFile( ef, parent, targetFile ); } void writeEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent, QFile& target ) { if ( !target.open( QIODevice::WriteOnly ) ) { KMessageBox::error( parent, i18n( "Could not open \"%1\" for writing. File was not saved.", target.fileName() ) ); return; } target.write( ef->data() ); target.close(); } Okular::Movie* renditionMovieFromScreenAnnotation( const Okular::ScreenAnnotation *annotation ) { if ( !annotation ) return nullptr; if ( annotation->action() && annotation->action()->actionType() == Okular::Action::Rendition ) { Okular::RenditionAction *renditionAction = static_cast< Okular::RenditionAction * >( annotation->action() ); return renditionAction->movie(); } return nullptr; } // from Arthur - qt4 static inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; } void colorizeImage( QImage & grayImage, const QColor & color, unsigned int destAlpha ) { // Make sure that the image is Format_ARGB32_Premultiplied if ( grayImage.format() != QImage::Format_ARGB32_Premultiplied ) grayImage = grayImage.convertToFormat( QImage::Format_ARGB32_Premultiplied ); // iterate over all pixels changing the alpha component value unsigned int * data = (unsigned int *)grayImage.bits(); unsigned int pixels = grayImage.width() * grayImage.height(); int red = color.red(), green = color.green(), blue = color.blue(); int source, sourceSat, sourceAlpha; for( unsigned int i = 0; i < pixels; ++i ) { // optimize this loop keeping byte order into account source = data[i]; sourceSat = qRed( source ); int newR = qt_div_255( sourceSat * red ), newG = qt_div_255( sourceSat * green ), newB = qt_div_255( sourceSat * blue ); if ( (sourceAlpha = qAlpha( source )) == 255 ) { // use destAlpha data[i] = qRgba( newR, newG, newB, destAlpha ); } else { // use destAlpha * sourceAlpha product if ( destAlpha < 255 ) sourceAlpha = qt_div_255( destAlpha * sourceAlpha ); data[i] = qRgba( newR, newG, newB, sourceAlpha ); } } } -QVector getSignatureFormFields( Okular::Document *doc ) -{ - QVector signatureFormFields; - uint pageCount = doc->pages(); - for ( uint i=0; ipage( i )->formFields() ) - { - if ( f->type() == Okular::FormField::FormSignature ) - { - signatureFormFields.append( static_cast( f ) ); - } - } - } - return signatureFormFields; -} - -QString getReadableSigState( Okular::SignatureInfo::SignatureStatus sigStatus ) -{ - switch ( sigStatus ) - { - case Okular::SignatureInfo::SignatureValid: - return i18n("The signature is cryptographically valid."); - case Okular::SignatureInfo::SignatureInvalid: - return i18n("The signature is cryptographically invalid."); - case Okular::SignatureInfo::SignatureDigestMismatch: - return i18n("Digest Mismatch occurred."); - case Okular::SignatureInfo::SignatureDecodingError: - return i18n("The signature CMS/PKCS7 structure is malformed."); - case Okular::SignatureInfo::SignatureNotFound: - return i18n("The requested signature is not present in the document."); - default: - return i18n("The signature could not be verified."); - } -} - -QString getReadableCertState( Okular::SignatureInfo::CertificateStatus certStatus ) -{ - switch ( certStatus ) - { - case Okular::SignatureInfo::CertificateTrusted: - return i18n("Certificate is Trusted."); - case Okular::SignatureInfo::CertificateUntrustedIssuer: - return i18n("Certificate issuer isn't Trusted."); - case Okular::SignatureInfo::CertificateUnknownIssuer: - return i18n("Certificate issuer is unknown."); - case Okular::SignatureInfo::CertificateRevoked: - return i18n("Certificate has been Revoked."); - case Okular::SignatureInfo::CertificateExpired: - return i18n("Certificate has Expired."); - case Okular::SignatureInfo::CertificateNotVerified: - return i18n("Certificate has not yet been verified."); - default: - return i18n("Unknown issue with Certificate or corrupted data."); - } -} - -QString getReadableHashAlgorithm( Okular::SignatureInfo::HashAlgorithm hashAlg ) -{ - switch ( hashAlg ) - { - case Okular::SignatureInfo::HashAlgorithmMd2: - return i18n("MD2"); - case Okular::SignatureInfo::HashAlgorithmMd5: - return i18n("MD5"); - case Okular::SignatureInfo::HashAlgorithmSha1: - return i18n("SHA1"); - case Okular::SignatureInfo::HashAlgorithmSha256: - return i18n("SHA256"); - case Okular::SignatureInfo::HashAlgorithmSha384: - return i18n("SHA384"); - case Okular::SignatureInfo::HashAlgorithmSha512: - return i18n("SHA512"); - case Okular::SignatureInfo::HashAlgorithmSha224: - return i18n("SHA224"); - default: - return i18n("Unknown"); - } -} - } diff --git a/ui/guiutils.h b/ui/guiutils.h index d431d66b6..295dfa93d 100644 --- a/ui/guiutils.h +++ b/ui/guiutils.h @@ -1,75 +1,63 @@ /*************************************************************************** * Copyright (C) 2006-2007 by Pino Toscano * * * * This program 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. * ***************************************************************************/ #ifndef OKULAR_GUIUTILS_H #define OKULAR_GUIUTILS_H #include -#include - -#include "core/signatureutils.h" class QColor; class QImage; class QPixmap; class QSize; class QWidget; class QFile; class KIconLoader; namespace Okular { class Annotation; class EmbeddedFile; class Movie; class ScreenAnnotation; -class Document; -class Page; -class FormFieldSignature; } namespace GuiUtils { /** * Returns the translated string with the type of the given @p annotation. */ QString captionForAnnotation( const Okular::Annotation * annotation ); QString authorForAnnotation( const Okular::Annotation * annotation ); QString contentsHtml( const Okular::Annotation * annotation ); QString prettyToolTip( const Okular::Annotation * annotation ); QPixmap loadStamp( const QString& name, const QSize& size, int iconSize = 0 ); void addIconLoader( KIconLoader * loader ); void removeIconLoader( KIconLoader * loader ); KIconLoader* iconLoader(); void saveEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent ); void writeEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent, QFile& targetFile ); /** * Returns the movie object that is referenced by a rendition action of the passed screen @p annotation * or @c 0 if the screen annotation has no rendition action set or the rendition action does not contain * a media rendition. */ Okular::Movie* renditionMovieFromScreenAnnotation( const Okular::ScreenAnnotation * annotation ); // colorize a gray image to the given color void colorizeImage( QImage & image, const QColor & color, unsigned int alpha = 255 ); - - //for digital signature - QVector getSignatureFormFields( Okular::Document *doc ); - QString getReadableSigState( Okular::SignatureInfo::SignatureStatus sigStatus ); - QString getReadableCertState( Okular::SignatureInfo::CertificateStatus certStatus ); - QString getReadableHashAlgorithm( Okular::SignatureInfo::HashAlgorithm hashAlg ); } #endif diff --git a/ui/signaturewidgets.cpp b/ui/signaturewidgets.cpp index c3730d175..97e8c4cf5 100644 --- a/ui/signaturewidgets.cpp +++ b/ui/signaturewidgets.cpp @@ -1,361 +1,434 @@ /*************************************************************************** * Copyright (C) 2018 by Chinmoy Ranjan Pradhan * * * * This program 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. * ***************************************************************************/ #include "signaturewidgets.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "core/form.h" #include "core/page.h" #include "core/document.h" #include "core/sourcereference.h" #include "core/form.h" #include "settings.h" -#include "guiutils.h" +static QVector getSignatureFormFields( Okular::Document *doc ) +{ + QVector signatureFormFields; + uint pageCount = doc->pages(); + for ( uint i=0; ipage( i )->formFields() ) + { + if ( f->type() == Okular::FormField::FormSignature ) + { + signatureFormFields.append( static_cast( f ) ); + } + } + } + return signatureFormFields; +} + +static QString getReadableSigState( Okular::SignatureInfo::SignatureStatus sigStatus ) +{ + switch ( sigStatus ) + { + case Okular::SignatureInfo::SignatureValid: + return i18n("The signature is cryptographically valid."); + case Okular::SignatureInfo::SignatureInvalid: + return i18n("The signature is cryptographically invalid."); + case Okular::SignatureInfo::SignatureDigestMismatch: + return i18n("Digest Mismatch occurred."); + case Okular::SignatureInfo::SignatureDecodingError: + return i18n("The signature CMS/PKCS7 structure is malformed."); + case Okular::SignatureInfo::SignatureNotFound: + return i18n("The requested signature is not present in the document."); + default: + return i18n("The signature could not be verified."); + } +} + +static QString getReadableCertState( Okular::SignatureInfo::CertificateStatus certStatus ) +{ + switch ( certStatus ) + { + case Okular::SignatureInfo::CertificateTrusted: + return i18n("Certificate is Trusted."); + case Okular::SignatureInfo::CertificateUntrustedIssuer: + return i18n("Certificate issuer isn't Trusted."); + case Okular::SignatureInfo::CertificateUnknownIssuer: + return i18n("Certificate issuer is unknown."); + case Okular::SignatureInfo::CertificateRevoked: + return i18n("Certificate has been Revoked."); + case Okular::SignatureInfo::CertificateExpired: + return i18n("Certificate has Expired."); + case Okular::SignatureInfo::CertificateNotVerified: + return i18n("Certificate has not yet been verified."); + default: + return i18n("Unknown issue with Certificate or corrupted data."); + } +} + +static QString getReadableHashAlgorithm( Okular::SignatureInfo::HashAlgorithm hashAlg ) +{ + switch ( hashAlg ) + { + case Okular::SignatureInfo::HashAlgorithmMd2: + return i18n("MD2"); + case Okular::SignatureInfo::HashAlgorithmMd5: + return i18n("MD5"); + case Okular::SignatureInfo::HashAlgorithmSha1: + return i18n("SHA1"); + case Okular::SignatureInfo::HashAlgorithmSha256: + return i18n("SHA256"); + case Okular::SignatureInfo::HashAlgorithmSha384: + return i18n("SHA384"); + case Okular::SignatureInfo::HashAlgorithmSha512: + return i18n("SHA512"); + case Okular::SignatureInfo::HashAlgorithmSha224: + return i18n("SHA224"); + default: + return i18n("Unknown"); + } +} CertificateViewerModel::CertificateViewerModel( Okular::SignatureInfo *sigInfo, QObject * parent ) : QAbstractTableModel( parent ) { m_sigProperties.append( qMakePair( i18n("Subject Name"), sigInfo->subjectName() ) ); m_sigProperties.append( qMakePair( i18n("Subject Distinguished Name"), sigInfo->subjectDN() ) ); m_sigProperties.append( qMakePair( i18n("Signing Time"), sigInfo->signingTime().toString( QStringLiteral("MMM dd yyyy hh:mm:ss") ) ) ); - m_sigProperties.append( qMakePair( i18n("Hash Algorithm"), GuiUtils::getReadableHashAlgorithm( sigInfo->hashAlgorithm() ) ) ); - m_sigProperties.append( qMakePair( i18n("Signature Status"), GuiUtils::getReadableSigState( sigInfo->signatureStatus() ) ) ); - m_sigProperties.append( qMakePair( i18n("Certificate Status"), GuiUtils::getReadableCertState( sigInfo->certificateStatus() ) ) ); + m_sigProperties.append( qMakePair( i18n("Hash Algorithm"), getReadableHashAlgorithm( sigInfo->hashAlgorithm() ) ) ); + m_sigProperties.append( qMakePair( i18n("Signature Status"), getReadableSigState( sigInfo->signatureStatus() ) ) ); + m_sigProperties.append( qMakePair( i18n("Certificate Status"), getReadableCertState( sigInfo->certificateStatus() ) ) ); m_sigProperties.append( qMakePair( i18n("Signature Data"), QString::fromUtf8( sigInfo->signature().toHex(' ') ) ) ); m_sigProperties.append( qMakePair( i18n("Location"), QString( sigInfo->location() ) ) ); m_sigProperties.append( qMakePair( i18n("Reason"), QString( sigInfo->reason() ) ) ); m_sigProperties.append( qMakePair( QStringLiteral("----------"), QString("------Certificate Properties--------") ) ); Okular::CertificateInfo *certInfo = sigInfo->certificateInfo(); m_sigProperties.append( qMakePair( i18n("Version"), certInfo->version() ) ); m_sigProperties.append( qMakePair( i18n("Issuer Name"), certInfo->issuerName() ) ); m_sigProperties.append( qMakePair( i18n("Issuer Distinguished Name"), certInfo->issuerDN() ) ); m_sigProperties.append( qMakePair( i18n("Serial Number"), certInfo->serialNumber() ) ); m_sigProperties.append( qMakePair( i18n("Validity Start"), certInfo->validityStart().toString( QStringLiteral("MMM dd yyyy hh:mm:ss") ) ) ); m_sigProperties.append( qMakePair( i18n("Validity End"), certInfo->validityEnd().toString( QStringLiteral("MMM dd yyyy hh:mm:ss") ) ) ); m_sigProperties.append( qMakePair( i18n("Public Key"), certInfo->publicKey() ) ); m_sigProperties.append( qMakePair( i18n("Is Self Signed"), certInfo->isSelfSigned() ? QString("true") : QString("false") ) ); } -int CertificateViewerModel::columnCount( const QModelIndex & ) const +int CertificateViewerModel::columnCount( const QModelIndex &parent ) const { - return 2; + return parent.isValid() ? 0 : 2; } -int CertificateViewerModel::rowCount( const QModelIndex & ) const +int CertificateViewerModel::rowCount( const QModelIndex &parent ) const { - return m_sigProperties.size(); + return parent.isValid() ? 0 : m_sigProperties.size(); } QVariant CertificateViewerModel::data( const QModelIndex &index, int role ) const { int row = index.row(); if ( !index.isValid() || row < 0 || row >= m_sigProperties.count() ) return QVariant(); switch ( role ) { case Qt::DisplayRole: case Qt::ToolTipRole: switch ( index.column() ) { case 0: return m_sigProperties[row].first; case 1: return m_sigProperties[row].second; default: return QString(); } case PropertyValueRole: return m_sigProperties[row].second; } return QVariant(); } QVariant CertificateViewerModel::headerData( int section, Qt::Orientation orientation, int role ) const { if ( role == Qt::TextAlignmentRole ) return QVariant( Qt::AlignLeft ); if ( orientation != Qt::Horizontal || role != Qt::DisplayRole) return QVariant(); switch ( section ) { case 0: return i18n("Property"); case 1: return i18n("Value"); default: return QVariant(); } } CertificateViewer::CertificateViewer( Okular::SignatureInfo *sigInfo, QWidget *parent ) : QDialog( parent ), m_sigInfo( sigInfo ) { setModal( true ); setFixedSize( QSize( 450, 500 )); setWindowTitle( i18n("Signature Properties") ); auto sigPropLabel = new QLabel( this ); sigPropLabel->setText( i18n("Signature Properties:") ); auto sigPropTree = new QTreeView( this ); sigPropTree->setIndentation( 0 ); m_sigPropModel = new CertificateViewerModel( m_sigInfo, this ); sigPropTree->setModel( m_sigPropModel ); connect( sigPropTree, &QTreeView::clicked, this, &CertificateViewer::updateText ); m_sigPropText = new QTextEdit( this ); m_sigPropText->setReadOnly( true ); auto btnBox = new QDialogButtonBox( QDialogButtonBox::Close, this ); btnBox->button( QDialogButtonBox::Close )->setDefault( true ); connect( btnBox, &QDialogButtonBox::rejected, this, &SignaturePropertiesDialog::reject ); auto mainLayout = new QVBoxLayout( this ); mainLayout->addWidget( sigPropLabel ); mainLayout->addWidget( sigPropTree ); mainLayout->addWidget( m_sigPropText ); mainLayout->addWidget( btnBox ); setLayout( mainLayout ); } void CertificateViewer::updateText( const QModelIndex &index ) { m_sigPropText->setText( m_sigPropModel->data( index, CertificateViewerModel::PropertyValueRole ).toString() ); } SignaturePropertiesDialog::SignaturePropertiesDialog( Okular::Document *doc, Okular::FormFieldSignature *form, QWidget *parent ) : QDialog( parent ), m_doc( doc ), m_signatureForm( form ) { setModal( true ); setWindowTitle( i18n("Signature Properties") ); m_signatureInfo = m_signatureForm->validate(); auto mainLayout = new QVBoxLayout; // signature validation status auto sigStatusBox = new QGroupBox( i18n("Validity Status") ); auto hBoxLayout = new QHBoxLayout; auto pixmapLabel = new QLabel; pixmapLabel->setPixmap( KIconLoader::global()->loadIcon( QLatin1String("application-certificate"), KIconLoader::Desktop, KIconLoader::SizeSmallMedium ) ); hBoxLayout->addWidget( pixmapLabel ); auto sigStatusFormLayout = new QFormLayout; const Okular::SignatureInfo::SignatureStatus sigStatus = m_signatureInfo->signatureStatus(); - sigStatusFormLayout->addRow( i18n("Signature Validity:"), new QLabel( GuiUtils::getReadableSigState( sigStatus ) ) ); + sigStatusFormLayout->addRow( i18n("Signature Validity:"), new QLabel( getReadableSigState( sigStatus ) ) ); QString modString; if ( sigStatus == Okular::SignatureInfo::SignatureValid ) { if ( m_signatureInfo->signsTotalDocument() ) { modString = i18n("The document has not been modified since it was signed."); } else { modString = i18n("The revision of the document that was covered by this signature has not been modified;\n" "however there have been subsequent changes to the document."); } } else if ( sigStatus == Okular::SignatureInfo::SignatureDigestMismatch ) { modString = i18n("The document has been modified in a way not permitted by a previous signer."); } else { modString = i18n("The document integrity verification could not be completed."); } sigStatusFormLayout->addRow( i18n("Document Modifications:"), new QLabel( modString ) ); hBoxLayout->addLayout( sigStatusFormLayout ); sigStatusBox->setLayout( hBoxLayout ); mainLayout->addWidget( sigStatusBox ); // additional information auto extraInfoBox = new QGroupBox( i18n("Additional Information") ); auto extraInfoFormLayout = new QFormLayout; extraInfoFormLayout->addRow( i18n("Signed By:"), new QLabel( m_signatureInfo->subjectName() ) ); extraInfoFormLayout->addRow( i18n("Signing Time:"), new QLabel( m_signatureInfo->signingTime().toString( QStringLiteral("MMM dd yyyy hh:mm:ss") ) ) ); auto getValidString = [=]( const QString &str ) -> QString { return !str.isEmpty() ? str : i18n("Not Available"); }; // optional info extraInfoFormLayout->addRow( i18n("Reason:"), new QLabel( getValidString( m_signatureInfo->reason() ) ) ); extraInfoFormLayout->addRow( i18n("Location:"), new QLabel( getValidString( m_signatureInfo->location() ) ) ); extraInfoBox->setLayout( extraInfoFormLayout ); mainLayout->addWidget( extraInfoBox ); // document version auto revisionBox = new QGroupBox( i18n("Document Version") ); auto revisionLayout = new QHBoxLayout; - QVector signatureFormFields = GuiUtils::getSignatureFormFields( m_doc ); + QVector signatureFormFields = getSignatureFormFields( m_doc ); revisionLayout->addWidget( new QLabel( i18nc("Document Revision of ", "Document Revision %1 of %2", signatureFormFields.indexOf( m_signatureForm ) + 1, signatureFormFields.size() ) ) ); revisionLayout->addStretch(); auto revisionBtn = new QPushButton( i18n( "View Signed Version...") ); revisionBtn->setEnabled( !m_signatureInfo->signsTotalDocument() ); connect( revisionBtn, &QPushButton::clicked, this, &SignaturePropertiesDialog::viewSignedVersion ); revisionLayout->addWidget( revisionBtn ); revisionBox->setLayout( revisionLayout ); mainLayout->addWidget( revisionBox ); // button box auto btnBox = new QDialogButtonBox( QDialogButtonBox::Close, this ); auto certPropBtn = new QPushButton( i18n( "Vew Certificate..."), this ); btnBox->button( QDialogButtonBox::Close )->setDefault( true ); btnBox->addButton( certPropBtn, QDialogButtonBox::ActionRole ); connect( btnBox, &QDialogButtonBox::rejected, this, &SignaturePropertiesDialog::reject ); connect( certPropBtn, &QPushButton::clicked, this, &SignaturePropertiesDialog::viewCertificateProperties ); mainLayout->addWidget( btnBox ); setLayout( mainLayout ); resize( mainLayout->sizeHint() ); } void SignaturePropertiesDialog::viewCertificateProperties() { CertificateViewer sigPropDlg( m_signatureInfo, this ); sigPropDlg.exec(); } void SignaturePropertiesDialog::viewSignedVersion() { QByteArray data; m_doc->requestSignedRevisionData( m_signatureInfo, &data ); const QString tmpDir = QStandardPaths::writableLocation( QStandardPaths::TempLocation ); QTemporaryFile tf( tmpDir + "/revision_XXXXXX.pdf" ); if ( !tf.open() ) { KMessageBox::error( this, i18n("Could not open revision for preview" ) ); return; } tf.write(data); RevisionViewer view( tf.fileName(), this); view.exec(); tf.close(); } -RevisionViewer::RevisionViewer( const QString &filename, QWidget *parent ) - : FilePrinterPreview( filename, parent ) -{ - setWindowTitle( i18n("Revision Preview") ); -} - -RevisionViewer::~RevisionViewer() -{ -} - TreeView1::TreeView1(Okular::Document *document, QWidget *parent) : QTreeView( parent ), m_document( document ) { } void TreeView1::paintEvent( QPaintEvent *event ) { bool hasSignatures = false; - for ( uint i = 0; i < m_document->pages(); i++ ) + for ( int i = 0; i < m_document->pages(); i++ ) { foreach (Okular::FormField *f, m_document->page( i )->formFields() ) { if ( f->type() == Okular::FormField::FormSignature ) { hasSignatures = true; break; } } } if ( !hasSignatures ) { QPainter p( viewport() ); p.setRenderHint( QPainter::Antialiasing, true ); p.setClipRect( event->rect() ); QTextDocument document; document.setHtml( i18n( "

No Signatures

" "To create new annotations press F6 or select Tools -> Review" " from the menu.
" ) ); document.setTextWidth( width() - 50 ); const uint w = document.size().width() + 20; const uint h = document.size().height() + 20; p.setBrush( palette().background() ); p.translate( 0.5, 0.5 ); p.drawRoundRect( 15, 15, w, h, (8*200)/w, (8*200)/h ); p.translate( 20, 20 ); document.drawContents( &p ); } else { QTreeView::paintEvent( event ); } } SignaturePanel::SignaturePanel( QWidget *parent, Okular::Document *document ) : QWidget( parent ), m_document( document ) { auto vLayout = new QVBoxLayout( this ); vLayout->setMargin( 0 ); vLayout->setSpacing( 6 ); m_view = new TreeView1( m_document, this ); m_view->setAlternatingRowColors( true ); m_view->setSelectionMode( QAbstractItemView::ExtendedSelection ); m_view->header()->hide(); - //m_model = new SignatureModel( m_document, this ); - - //m_view->setModel( m_model ); - vLayout->addWidget( m_view ); } SignaturePanel::~SignaturePanel() { - m_document->removeObserver( this ); } -void SignaturePanel::notifySetup(const QVector &, int ) +void SignaturePanel::notifySetup(const QVector &pages, int setupFlags) { +} +RevisionViewer::RevisionViewer( const QString &filename, QWidget *parent ) + : FilePrinterPreview( filename, parent ) +{ + setWindowTitle( i18n("Revision Preview") ); } + +RevisionViewer::~RevisionViewer() +{ +} + #include "moc_signaturewidgets.cpp" diff --git a/ui/signaturewidgets.h b/ui/signaturewidgets.h index 94de05e6d..18b213d39 100644 --- a/ui/signaturewidgets.h +++ b/ui/signaturewidgets.h @@ -1,120 +1,117 @@ /*************************************************************************** * Copyright (C) 2018 by Chinmoy Ranjan Pradhan * * * * This program 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. * ***************************************************************************/ #ifndef OKULAR_SIGNATUREWIDGETS_H #define OKULAR_SIGNATUREWIDGETS_H #include #include #include #include #include "core/signatureutils.h" #include "core/observer.h" #include "fileprinterpreview.h" -//#include "signaturemodel.h" class QTextEdit; namespace Okular { class Document; class FormFieldSignature; class SignatureInfo; } +class TreeView1 : public QTreeView +{ + Q_OBJECT + + public: + TreeView1( Okular::Document *document, QWidget *parent = Q_NULLPTR ); + protected: + void paintEvent( QPaintEvent *event ) override; + + private: + Okular::Document *m_document; +}; + class CertificateViewerModel : public QAbstractTableModel { Q_OBJECT public: explicit CertificateViewerModel( Okular::SignatureInfo *sigInfo, QObject * parent = nullptr ); enum { PropertyValueRole = Qt::UserRole }; int columnCount( const QModelIndex &parent = QModelIndex() ) const override; int rowCount( const QModelIndex &parent = QModelIndex() ) const override; QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override; QVariant headerData( int section, Qt::Orientation orientation, int role ) const override; private: QVector< QPair > m_sigProperties; }; class CertificateViewer : public QDialog { Q_OBJECT public: CertificateViewer( Okular::SignatureInfo *sigInfo, QWidget *parent ); private Q_SLOTS: void updateText( const QModelIndex &index ); private: CertificateViewerModel *m_sigPropModel; QTextEdit *m_sigPropText; Okular::SignatureInfo *m_sigInfo; }; class SignaturePropertiesDialog : public QDialog { Q_OBJECT public: SignaturePropertiesDialog( Okular::Document *doc, Okular::FormFieldSignature *form, QWidget *parent ); private Q_SLOTS: void viewSignedVersion(); void viewCertificateProperties(); private: Okular::Document *m_doc; Okular::FormFieldSignature *m_signatureForm; Okular::SignatureInfo *m_signatureInfo; }; -class RevisionViewer : public Okular::FilePrinterPreview -{ - Q_OBJECT - public: - RevisionViewer( const QString &filename, QWidget *parent = nullptr ); - ~RevisionViewer(); -}; - -class TreeView1 : public QTreeView -{ - Q_OBJECT - - public: - TreeView1( Okular::Document *document, QWidget *parent = Q_NULLPTR ); - protected: - void paintEvent( QPaintEvent *event ) override; - - private: - Okular::Document *m_document; -}; - class SignaturePanel : public QWidget, public Okular::DocumentObserver { Q_OBJECT public: SignaturePanel( QWidget * parent, Okular::Document * document ); ~SignaturePanel(); void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags ) override; private: Okular::Document *m_document; TreeView1 *m_view; - //SignatureModel *m_model; }; +class RevisionViewer : public Okular::FilePrinterPreview +{ + Q_OBJECT + public: + RevisionViewer( const QString &filename, QWidget *parent = nullptr ); + ~RevisionViewer(); +}; #endif