Show the "No signing certs" warning earlier

No need to ask for the user to draw a rectangle for the signature
if there's no certs to sign anyway

CCBUGS: 446549
remotes/origin/work/aacid/android_ci_and_default_is_mobile_ui
Albert Astals Cid 4 years ago
parent 09a2b506ed
commit 62eec7d5b1
  1. 17
      core/signatureutils.cpp
  2. 9
      core/signatureutils.h
  3. 26
      part/pageview.cpp
  4. 2
      part/pageview.h
  5. 34
      part/pageviewannotator.cpp

@ -175,3 +175,20 @@ QList<CertificateInfo *> CertificateStore::signingCertificates(bool *userCancell
*userCancelled = false;
return QList<CertificateInfo *>();
}
QList<CertificateInfo *> CertificateStore::signingCertificatesForNow(bool *userCancelled, bool *nonDateValidCerts) const
{
const QDateTime now = QDateTime::currentDateTime();
QList<Okular::CertificateInfo *> certs = signingCertificates(userCancelled);
auto it = certs.begin();
*nonDateValidCerts = false;
while (it != certs.end()) {
if ((*it)->validityStart() > now || now > (*it)->validityEnd()) {
it = certs.erase(it);
*nonDateValidCerts = true;
} else {
++it;
}
}
return certs;
}

@ -266,6 +266,15 @@ public:
*/
virtual QList<CertificateInfo *> signingCertificates(bool *userCancelled) const;
/**
* Returns list of valid, usable signing certificates for current date and time.
*
* This can ask the user for a password, userCancelled will be true if the user decided not to enter it.
*
* nonDateValidCerts is true if the user has signing certificates but their validity start date is in the future or past their validity end date.
*/
QList<CertificateInfo *> signingCertificatesForNow(bool *userCancelled, bool *nonDateValidCerts) const;
protected:
CertificateStore();

@ -4880,6 +4880,20 @@ void PageView::slotSetMouseTableSelect()
d->annotator->detachAnnotation();
}
void PageView::showNoSigningCertificatesDialog(bool nonDateValidCerts)
{
if (nonDateValidCerts) {
KMessageBox::information(this, i18n("All your signing certificates are either not valid yet or are past their validity date."));
} else {
KMessageBox::information(this,
i18n("There are no available signing certificates.<br/>For more information, please see the section about <a href=\"%1\">Adding Digital Signatures</a> in the manual.",
QStringLiteral("help:/okular/signatures.html#adding_digital_signatures")),
QString(),
QString(),
KMessageBox::Notify | KMessageBox::AllowLink);
}
}
void PageView::slotSignature()
{
if (!d->document->isHistoryClean()) {
@ -4887,6 +4901,18 @@ void PageView::slotSignature()
return;
}
const Okular::CertificateStore *certStore = d->document->certificateStore();
bool userCancelled, nonDateValidCerts;
const QList<Okular::CertificateInfo *> &certs = certStore->signingCertificatesForNow(&userCancelled, &nonDateValidCerts);
if (userCancelled) {
return;
}
if (certs.isEmpty()) {
showNoSigningCertificatesDialog(nonDateValidCerts);
return;
}
d->messageWindow->display(i18n("Draw a rectangle to insert the signature field"), QString(), PageViewMessage::Info, -1);
d->annotator->setSignatureMode(true);

@ -115,6 +115,8 @@ public:
void highlightSignatureFormWidget(const Okular::FormFieldSignature *form);
void showNoSigningCertificatesDialog(bool nonDateValidCerts);
public Q_SLOTS:
void copyTextSelection() const;
void selectAll();

@ -355,39 +355,27 @@ public:
}
const Okular::CertificateStore *certStore = m_document->certificateStore();
bool userCancelled;
const QList<Okular::CertificateInfo *> &certs = certStore->signingCertificates(&userCancelled);
bool userCancelled, nonDateValidCerts;
const QList<Okular::CertificateInfo *> &certs = certStore->signingCertificatesForNow(&userCancelled, &nonDateValidCerts);
if (userCancelled) {
m_aborted = true;
return {};
}
QStringList items;
QHash<QString, Okular::CertificateInfo *> nickToCert;
const QDateTime now = QDateTime::currentDateTime();
for (auto cert : certs) {
if (cert->validityStart() <= now && now <= cert->validityEnd()) {
items.append(cert->nickName());
nickToCert[cert->nickName()] = cert;
}
}
if (items.isEmpty()) {
if (certs.isEmpty()) {
m_creationCompleted = false;
clicked = false;
if (certs.isEmpty()) {
KMessageBox::information(m_pageView,
i18n("There are no available signing certificates.<br/>For more information, please see the section about <a href=\"%1\">Adding Digital Signatures</a> in the manual.",
QStringLiteral("help:/okular/signatures.html#adding_digital_signatures")),
QString(),
QString(),
KMessageBox::Notify | KMessageBox::AllowLink);
} else {
KMessageBox::information(m_pageView, i18n("All your signing certificates are either not valid yet or are past their validity date."));
}
m_pageView->showNoSigningCertificatesDialog(nonDateValidCerts);
return {};
}
QStringList items;
QHash<QString, Okular::CertificateInfo *> nickToCert;
for (auto cert : certs) {
items.append(cert->nickName());
nickToCert[cert->nickName()] = cert;
}
bool resok = false;
certNicknameToUse = QInputDialog::getItem(m_pageView, i18n("Select certificate to sign with"), i18n("Certificates:"), items, 0, false, &resok);

Loading…
Cancel
Save