diff --git a/client/DigiDoc.cpp b/client/DigiDoc.cpp index 092686105..288ff91f9 100644 --- a/client/DigiDoc.cpp +++ b/client/DigiDoc.cpp @@ -70,9 +70,9 @@ QDateTime DigiDocSignature::claimedTime() const return toTime(s->claimedSigningTime()); } -QString DigiDocSignature::id() const +bool DigiDocSignature::isInvalid() const { - return from(s->id()); + return m_status >= Invalid; } QString DigiDocSignature::lastError() const { return m_lastError; } @@ -521,12 +521,14 @@ bool DigiDoc::open( const QString &file ) WaitDialogHolder waitDialog(parent, tr("Opening"), false); return waitFor([&] { b = Container::openPtr(to(file)); - if(b && b->mediaType() == "application/vnd.etsi.asic-s+zip" && b->dataFiles().size() == 1) + if(b && b->mediaType() == "application/vnd.etsi.asic-s+zip" && + b->dataFiles().size() == 1 && + b->signatures().size() == 1) { const DataFile *f = b->dataFiles().at(0); if(from(f->fileName()).endsWith(QStringLiteral(".ddoc"), Qt::CaseInsensitive) && CheckConnection().check(QStringLiteral("https://id.eesti.ee/config.json")) && - serviceConfirmation()) + dispatchToMain(serviceConfirmation)) { const QString tmppath = FileDialog::tempPath(FileDialog::safeName(from(f->fileName()))); f->saveAs(to(tmppath)); @@ -539,16 +541,11 @@ bool DigiDoc::open( const QString &file ) } } } - m_fileName = file; - bool isTimeStamped = false; - if(parentContainer && - parentContainer->dataFiles().size() == 1 && - parentContainer->signatures().size() == 1 && - from(parentContainer->dataFiles()[0]->fileName()).endsWith(QStringLiteral(".ddoc"), Qt::CaseInsensitive)) - isTimeStamped = parentContainer->signatures()[0]->trustedSigningTime().compare("2018-07-01T00:00:00Z") < 0; + bool isTimeStamped = parentContainer && parentContainer->signatures().at(0)->trustedSigningTime().compare("2018-07-01T00:00:00Z") < 0; for(const Signature *signature: b->signatures()) m_signatures.append(DigiDocSignature(signature, this, isTimeStamped)); - qApp->addRecent( file ); + qApp->addRecent(file); + m_fileName = file; containerState = signatures().isEmpty() ? ContainerState::UnsignedSavedContainer : ContainerState::SignedContainer; return true; }); diff --git a/client/DigiDoc.h b/client/DigiDoc.h index cd92cb80a..7d69c47c6 100644 --- a/client/DigiDoc.h +++ b/client/DigiDoc.h @@ -49,7 +49,7 @@ class DigiDocSignature QSslCertificate cert() const; QDateTime claimedTime() const; - QString id() const; + bool isInvalid() const; QString lastError() const; QString location() const; QStringList locations() const; diff --git a/client/MainWindow.cpp b/client/MainWindow.cpp index eb6f1c68d..a670062fc 100644 --- a/client/MainWindow.cpp +++ b/client/MainWindow.cpp @@ -1085,9 +1085,7 @@ bool MainWindow::validateFiles(const QString &container, const QStringList &file void MainWindow::warningClicked(const QString &link) { - if(link.startsWith(QLatin1String("#invalid-signature-"))) - emit ui->signContainerPage->details(link.mid(19)); - else if(link == QLatin1String("#unblock-PIN1")) + if(link == QLatin1String("#unblock-PIN1")) ui->accordion->changePin1Clicked (false, true); else if(link == QLatin1String("#unblock-PIN2")) ui->accordion->changePin2Clicked (false, true); diff --git a/client/Utils.h b/client/Utils.h index 671b7fe06..4bf7053ed 100644 --- a/client/Utils.h +++ b/client/Utils.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include @@ -43,6 +44,23 @@ namespace { return result; } + template + inline auto dispatchToMain(F&& function) { + typename std::invoke_result::type result{}; + QEventLoop l; + QTimer* timer = new QTimer(); + timer->moveToThread(qApp->thread()); + timer->setSingleShot(true); + QObject::connect(timer, &QTimer::timeout, timer, [&] { + result = function(); + l.exit(); + timer->deleteLater(); + }); + QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection, Q_ARG(int, 0)); + l.exec(); + return result; + } + inline QString escapeUnicode(const QString &str) { QString escaped; escaped.reserve(6 * str.size()); diff --git a/client/widgets/ContainerPage.cpp b/client/widgets/ContainerPage.cpp index 2ce90ce83..bd6fbb395 100644 --- a/client/widgets/ContainerPage.cpp +++ b/client/widgets/ContainerPage.cpp @@ -66,7 +66,6 @@ ContainerPage::ContainerPage(QWidget *parent) mobileCode = QSettings().value(QStringLiteral("MobileCode")).toString(); connect(this, &ContainerPage::moved,this, &ContainerPage::setHeader); - connect(this, &ContainerPage::details, ui->rightPane, &ItemList::details); connect(ui->changeLocation, &LabelButton::clicked, this, &ContainerPage::forward); connect(ui->cancel, &LabelButton::clicked, this, &ContainerPage::forward); connect(ui->save, &LabelButton::clicked, this, &ContainerPage::forward); @@ -329,7 +328,7 @@ void ContainerPage::transition(DigiDoc* container) for(const DigiDocSignature &c: container->timestamps()) { SignatureItem *item = new SignatureItem(c, container->state(), ui->rightPane); - if(item->isInvalid()) + if(c.isInvalid()) addError(item); ui->rightPane->addHeaderWidget(item); } @@ -338,7 +337,7 @@ void ContainerPage::transition(DigiDoc* container) for(const DigiDocSignature &c: container->signatures()) { SignatureItem *item = new SignatureItem(c, container->state(), ui->rightPane); - if(item->isInvalid()) + if(c.isInvalid()) addError(item); ui->rightPane->addWidget(item); } diff --git a/client/widgets/ContainerPage.h b/client/widgets/ContainerPage.h index cc3e87913..59e1ff71f 100644 --- a/client/widgets/ContainerPage.h +++ b/client/widgets/ContainerPage.h @@ -57,7 +57,6 @@ class ContainerPage final : public QWidget signals: void action(int code, const QString &info1 = {}, const QString &info2 = {}); void addFiles(const QStringList &files); - void details(const QString &id); void fileRemoved(int row); void keysSelected(const QList &keys); void moved(const QString &to); diff --git a/client/widgets/Item.cpp b/client/widgets/Item.cpp index de6d8a6e9..d8d2a83f6 100644 --- a/client/widgets/Item.cpp +++ b/client/widgets/Item.cpp @@ -19,8 +19,6 @@ #include "Item.h" -QString Item::id() const { return QString(); } void Item::idChanged(const SslCertificate & /* cert */) {} void Item::initTabOrder(QWidget * /* item */) {} -void Item::details() {} QWidget* Item::lastTabWidget() { return this; } diff --git a/client/widgets/Item.h b/client/widgets/Item.h index 64b6b55eb..a35d4ce03 100644 --- a/client/widgets/Item.h +++ b/client/widgets/Item.h @@ -30,14 +30,10 @@ class Item : public StyledWidget public: using StyledWidget::StyledWidget; - virtual QString id() const; + virtual void idChanged(const SslCertificate &cert); virtual void initTabOrder(QWidget *item); virtual QWidget* lastTabWidget(); -public slots: - virtual void details(); - virtual void idChanged(const SslCertificate &cert); - signals: void add(Item* item); void remove(Item* item); diff --git a/client/widgets/ItemList.cpp b/client/widgets/ItemList.cpp index d880506c5..1f95e3ee9 100644 --- a/client/widgets/ItemList.cpp +++ b/client/widgets/ItemList.cpp @@ -146,15 +146,6 @@ void ItemList::clear() (*it)->deleteLater(); } -void ItemList::details(const QString &id) -{ - for(auto item: items) - { - if(item->id() == id) - emit item->details(); - } -} - bool ItemList::eventFilter(QObject *o, QEvent *e) { if(o != ui->infoIcon) @@ -272,11 +263,6 @@ void ItemList::setRecipientTooltip() #endif } -void ItemList::setTerm(const QString &term) -{ - ui->txtFind->setText(term); -} - void ItemList::stateChange( ContainerState state ) { this->state = state; diff --git a/client/widgets/ItemList.h b/client/widgets/ItemList.h index c7c5b2220..e08b7e3a4 100644 --- a/client/widgets/ItemList.h +++ b/client/widgets/ItemList.h @@ -50,7 +50,6 @@ class ItemList : public QScrollArea ria::qdigidoc4::ContainerState getState() const; bool hasItem(const std::function &cb); virtual void removeItem(int row); - void setTerm(const QString &term); virtual void stateChange(ria::qdigidoc4::ContainerState state); signals: @@ -62,16 +61,11 @@ class ItemList : public QScrollArea void removed(int row); void search(const QString &term); -public slots: - void details(const QString &id); - -protected slots: - virtual void remove(Item *item); - protected: void changeEvent(QEvent* event) override; bool eventFilter(QObject *o, QEvent *e) override; int index(Item *item) const; + virtual void remove(Item *item); Ui::ItemList* ui; std::vector items; diff --git a/client/widgets/SignatureItem.cpp b/client/widgets/SignatureItem.cpp index d3cbdb727..8f899989d 100644 --- a/client/widgets/SignatureItem.cpp +++ b/client/widgets/SignatureItem.cpp @@ -40,7 +40,6 @@ class SignatureItem::Private: public Ui::SignatureItem explicit Private(DigiDocSignature s): signature(std::move(s)) {} DigiDocSignature signature; - bool invalid = true; ria::qdigidoc4::WarningType error = ria::qdigidoc4::NoWarning; QString nameText; QString serial; @@ -82,7 +81,6 @@ void SignatureItem::init() ui->serial.clear(); ui->status.clear(); ui->error = ria::qdigidoc4::NoWarning; - ui->invalid = signatureValidity >= DigiDocSignature::Invalid; if(!cert.isNull()) ui->nameText = cert.toString(cert.showCN() ? QStringLiteral("CN") : QStringLiteral("GN SN")).toHtmlEscaped(); else @@ -102,7 +100,7 @@ void SignatureItem::init() auto color = [](QLatin1String color, const QString &text) { return QStringLiteral("%2").arg(color, text); }; - switch( signatureValidity ) + switch(ui->signature.status()) { case DigiDocSignature::Valid: ui->status = color(QLatin1String("green"), isValid); @@ -156,13 +154,9 @@ bool SignatureItem::event(QEvent *event) return Item::event(event); } -void SignatureItem::details() -{ - (new SignatureDialog(ui->signature, this))->open(); -} - bool SignatureItem::eventFilter(QObject *o, QEvent *e) { + auto details = [this]{ (new SignatureDialog(ui->signature, this))->open(); }; switch(e->type()) { case QEvent::MouseButtonRelease: @@ -185,22 +179,12 @@ ria::qdigidoc4::WarningType SignatureItem::getError() const return ui->error; } -QString SignatureItem::id() const -{ - return ui->signature.id(); -} - void SignatureItem::initTabOrder(QWidget *item) { setTabOrder(item, ui->name); setTabOrder(ui->name, lastTabWidget()); } -bool SignatureItem::isInvalid() const -{ - return ui->invalid; -} - bool SignatureItem::isSelfSigned(const QString& cardCode, const QString& mobileCode) const { return !ui->serial.isEmpty() && (ui->serial == cardCode || ui->serial == mobileCode); @@ -231,7 +215,7 @@ void SignatureItem::updateNameField() doc.setHtml(ui->status); QString plain = doc.toPlainText(); auto red = [this](const QString &text) { - return ui->invalid ? QStringLiteral("%1").arg(text) : text; + return ui->signature.isInvalid() ? QStringLiteral("%1").arg(text) : text; }; if(ui->name->fontMetrics().boundingRect(ui->nameText + " - " + plain).width() < ui->name->width()) ui->name->setText(red(ui->nameText + " - ") + ui->status); diff --git a/client/widgets/SignatureItem.h b/client/widgets/SignatureItem.h index 2969d514b..3aa4b7974 100644 --- a/client/widgets/SignatureItem.h +++ b/client/widgets/SignatureItem.h @@ -32,11 +32,8 @@ class SignatureItem final : public Item explicit SignatureItem(DigiDocSignature s, ria::qdigidoc4::ContainerState state, QWidget *parent = nullptr); ~SignatureItem() final; - void details() final; ria::qdigidoc4::WarningType getError() const; - QString id() const final; void initTabOrder(QWidget *item) final; - bool isInvalid() const; bool isSelfSigned(const QString& cardCode, const QString& mobileCode) const; QWidget* lastTabWidget() final;