Changeset View
Changeset View
Standalone View
Standalone View
ui/signaturepropertiesdialog.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 by Chinmoy Ranjan Pradhan <chinmoyrp65@gmail.com> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | ***************************************************************************/ | ||||
9 | | ||||
10 | #include "signaturepropertiesdialog.h" | ||||
11 | | ||||
12 | #include <KLocalizedString> | ||||
13 | #include <KColumnResizer> | ||||
14 | | ||||
15 | #include <QVector> | ||||
16 | #include <QLabel> | ||||
17 | #include <QPushButton> | ||||
18 | #include <QVBoxLayout> | ||||
19 | #include <QGroupBox> | ||||
20 | #include <QFormLayout> | ||||
21 | #include <QDialogButtonBox> | ||||
22 | | ||||
23 | #include "core/form.h" | ||||
24 | #include "core/document.h" | ||||
25 | | ||||
26 | #include "signatureguiutils.h" | ||||
27 | #include "revisionviewer.h" | ||||
28 | #include "certificateviewer.h" | ||||
29 | | ||||
30 | static QString getValidDisplayString( const QString &str ) | ||||
31 | { | ||||
32 | return !str.isEmpty() ? str : i18n("Not Available"); | ||||
33 | } | ||||
34 | | ||||
35 | SignaturePropertiesDialog::SignaturePropertiesDialog( Okular::Document *doc, Okular::FormFieldSignature *form, QWidget *parent ) | ||||
36 | : QDialog( parent ), m_doc( doc ), m_signatureForm( form ) | ||||
37 | { | ||||
38 | setModal( true ); | ||||
39 | setWindowTitle( i18n("Signature Properties") ); | ||||
40 | | ||||
41 | m_signatureInfo = m_signatureForm->validate(); | ||||
42 | const Okular::SignatureInfo::SignatureStatus signatureStatus = m_signatureInfo->signatureStatus(); | ||||
43 | const QString readableSignatureStatus = SignatureGuiUtils::getReadableSignatureStatus( signatureStatus ); | ||||
44 | const QString signerName = getValidDisplayString( m_signatureInfo->signerName() ); | ||||
45 | const QString signingTime = getValidDisplayString( m_signatureInfo->signingTime().toString( QStringLiteral("MMM dd yyyy hh:mm:ss") ) ); | ||||
46 | const QString signingLocation = getValidDisplayString( m_signatureInfo->location() ); | ||||
47 | const QString signingReason = getValidDisplayString( m_signatureInfo->reason() ); | ||||
48 | | ||||
49 | // signature validation status | ||||
50 | QString modificationSummary; | ||||
51 | if ( signatureStatus == Okular::SignatureInfo::SignatureValid ) | ||||
52 | { | ||||
53 | if ( m_signatureInfo->signsTotalDocument() ) | ||||
54 | { | ||||
55 | modificationSummary = i18n("The document has not been modified since it was signed."); | ||||
56 | } | ||||
57 | else | ||||
58 | { | ||||
59 | modificationSummary = i18n("The revision of the document that was covered by this signature has not been modified;\n" | ||||
60 | "however there have been subsequent changes to the document."); | ||||
61 | } | ||||
62 | } | ||||
63 | else if ( signatureStatus == Okular::SignatureInfo::SignatureDigestMismatch ) | ||||
64 | { | ||||
65 | modificationSummary = i18n("The document has been modified in a way not permitted by a previous signer."); | ||||
66 | } | ||||
67 | else | ||||
68 | { | ||||
69 | modificationSummary = i18n("The document integrity verification could not be completed."); | ||||
70 | } | ||||
71 | | ||||
72 | auto signatureStatusBox = new QGroupBox( i18n("Validity Status") ); | ||||
73 | auto signatureStatusFormLayout = new QFormLayout( signatureStatusBox ); | ||||
74 | signatureStatusFormLayout->setLabelAlignment( Qt::AlignLeft ); | ||||
75 | signatureStatusFormLayout->addRow( i18n("Signature Validity:"), new QLabel( readableSignatureStatus ) ); | ||||
76 | signatureStatusFormLayout->addRow( i18n("Document Modifications:"), new QLabel( modificationSummary ) ); | ||||
77 | | ||||
78 | // additional information | ||||
79 | auto extraInfoBox = new QGroupBox( i18n("Additional Information") ); | ||||
80 | auto extraInfoFormLayout = new QFormLayout( extraInfoBox ); | ||||
81 | extraInfoFormLayout->setLabelAlignment( Qt::AlignLeft ); | ||||
82 | extraInfoFormLayout->addRow( i18n("Signed By:"), new QLabel( signerName ) ); | ||||
83 | extraInfoFormLayout->addRow( i18n("Signing Time:"), new QLabel( signingTime ) ); | ||||
84 | extraInfoFormLayout->addRow( i18n("Reason:"), new QLabel( signingReason ) ); | ||||
85 | extraInfoFormLayout->addRow( i18n("Location:"), new QLabel( signingLocation ) ); | ||||
86 | | ||||
87 | // keep width of column 1 same | ||||
88 | auto resizer = new KColumnResizer( this ); | ||||
89 | resizer->addWidgetsFromLayout( signatureStatusFormLayout->layout(), 0 ); | ||||
90 | resizer->addWidgetsFromLayout( extraInfoFormLayout->layout(), 0 ); | ||||
91 | | ||||
92 | // document revision info | ||||
93 | auto revisionBox = new QGroupBox( i18n("Document Version") ); | ||||
94 | auto revisionLayout = new QHBoxLayout( revisionBox ); | ||||
95 | QVector<Okular::FormFieldSignature*> signatureFormFields = SignatureGuiUtils::getSignatureFormFields( m_doc, true, -1 ); | ||||
96 | revisionLayout->addWidget( new QLabel( i18nc("Document Revision <current> of <total>", "Document Revision %1 of %2", | ||||
97 | signatureFormFields.indexOf( m_signatureForm ) + 1, signatureFormFields.size() ) ) ); | ||||
98 | revisionLayout->addStretch(); | ||||
99 | auto revisionBtn = new QPushButton( i18n("View Signed Version...") ); | ||||
100 | revisionBtn->setEnabled( !m_signatureInfo->signsTotalDocument() ); | ||||
101 | connect( revisionBtn, &QPushButton::clicked, this, &SignaturePropertiesDialog::viewSignedVersion ); | ||||
102 | revisionLayout->addWidget( revisionBtn ); | ||||
103 | | ||||
104 | // button box | ||||
105 | auto btnBox = new QDialogButtonBox( QDialogButtonBox::Close, this ); | ||||
106 | auto certPropBtn = new QPushButton( i18n("Vew Certificate...") ); | ||||
107 | certPropBtn->setEnabled( !m_signatureInfo->certificateInfo()->isNull() ); | ||||
108 | btnBox->addButton( certPropBtn, QDialogButtonBox::ActionRole ); | ||||
109 | connect( btnBox, &QDialogButtonBox::rejected, this, &SignaturePropertiesDialog::reject ); | ||||
110 | connect( certPropBtn, &QPushButton::clicked, this, &SignaturePropertiesDialog::viewCertificateProperties ); | ||||
111 | | ||||
112 | auto mainLayout = new QVBoxLayout( this ); | ||||
113 | mainLayout->addWidget( signatureStatusBox ); | ||||
114 | mainLayout->addWidget( extraInfoBox ); | ||||
115 | mainLayout->addWidget( revisionBox ); | ||||
116 | mainLayout->addWidget( btnBox ); | ||||
117 | | ||||
118 | resize( mainLayout->sizeHint() ); | ||||
119 | } | ||||
120 | | ||||
121 | void SignaturePropertiesDialog::viewCertificateProperties() | ||||
122 | { | ||||
123 | CertificateViewer certViewer( m_signatureInfo->certificateInfo(), this ); | ||||
124 | certViewer.exec(); | ||||
125 | } | ||||
126 | | ||||
127 | void SignaturePropertiesDialog::viewSignedVersion() | ||||
128 | { | ||||
129 | QByteArray data; | ||||
130 | m_doc->requestSignedRevisionData( m_signatureInfo, &data ); | ||||
131 | RevisionViewer revViewer( data, this ); | ||||
132 | revViewer.viewRevision(); | ||||
133 | } | ||||
134 | | ||||
135 | #include "moc_signaturepropertiesdialog.cpp" |