From be6762d48f3d8c6dde06347c79a0f97da0833851 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Wed, 22 Oct 2025 09:57:27 +0300 Subject: [PATCH] Cleanup warning handling IB-8462 Signed-off-by: Raul Metsma --- client/Application.cpp | 2 +- client/CMakeLists.txt | 1 - client/CryptoDoc.cpp | 16 +- client/DigiDoc.cpp | 15 +- client/DocumentModel.cpp | 31 ++++ client/DocumentModel.h | 4 +- client/MainWindow.cpp | 268 +++++++++++++++---------------- client/MainWindow.h | 8 +- client/MainWindow_MyEID.cpp | 124 -------------- client/QPKCS11.cpp | 2 +- client/QSigner.cpp | 2 +- client/QSmartCard.cpp | 94 ++++++----- client/common_enums.h | 1 + client/translations/en.ts | 20 +-- client/translations/et.ts | 20 +-- client/translations/ru.ts | 22 +-- client/widgets/ContainerPage.cpp | 49 ++++-- client/widgets/ContainerPage.h | 4 +- client/widgets/FileList.cpp | 6 +- client/widgets/WarningItem.cpp | 8 +- client/widgets/WarningItem.h | 2 +- client/widgets/WarningList.cpp | 29 +--- client/widgets/WarningList.h | 3 - 23 files changed, 306 insertions(+), 425 deletions(-) delete mode 100644 client/MainWindow_MyEID.cpp diff --git a/client/Application.cpp b/client/Application.cpp index 14dd6aee5..99541868e 100644 --- a/client/Application.cpp +++ b/client/Application.cpp @@ -940,7 +940,7 @@ void Application::showClient(QStringList files, bool crypto, bool sign, bool new QMetaObject::invokeMethod(w, [&] { using enum ria::qdigidoc4::Pages; w->selectPage(crypto && !sign ? CryptoIntro : SignIntro); - w->openFiles(files, false, sign); + w->openFiles(std::move(files), false, sign); }); } diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 1a14a7f05..6c5776854 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -65,7 +65,6 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE LdapSearch.cpp LdapSearch.h MainWindow.cpp - MainWindow_MyEID.cpp MainWindow.h MainWindow.ui PrintSheet.cpp diff --git a/client/CryptoDoc.cpp b/client/CryptoDoc.cpp index 3da60461d..2b197b64a 100644 --- a/client/CryptoDoc.cpp +++ b/client/CryptoDoc.cpp @@ -100,11 +100,9 @@ bool CDocumentModel::addFile(const QString &file, const QString &mime) return false; QFileInfo info(file); - if(info.size() == 0) - { - WarningDialog::show(DocumentModel::tr("Cannot add empty file to the container.")); + if(!addFileCheck(d->fileName, info)) return false; - } + if(d->cdoc->version() == 1 && info.size() > 120*1024*1024) { WarningDialog::show(tr("Added file(s) exceeds the maximum size limit of the container (∼120MB). " @@ -112,15 +110,6 @@ bool CDocumentModel::addFile(const QString &file, const QString &mime) return false; } - QString fileName(info.fileName()); - if(std::any_of(d->cdoc->files.cbegin(), d->cdoc->files.cend(), - [&fileName](const auto &containerFile) { return containerFile.name == fileName; })) - { - WarningDialog::show(DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.") - .arg(FileDialog::normalized(fileName))); - return false; - } - auto data = std::make_unique(file); if(!data->open(QFile::ReadOnly)) return false; @@ -196,7 +185,6 @@ bool CDocumentModel::removeRow(int row) } d->cdoc->files.erase(d->cdoc->files.cbegin() + row); - emit removed(row); return true; } diff --git a/client/DigiDoc.cpp b/client/DigiDoc.cpp index 4020f327f..fe198e11c 100644 --- a/client/DigiDoc.cpp +++ b/client/DigiDoc.cpp @@ -289,26 +289,14 @@ SDocumentModel::SDocumentModel(DigiDoc *container) bool SDocumentModel::addFile(const QString &file, const QString &mime) { QFileInfo info(file); - if(info.size() == 0) - { - WarningDialog::show(DocumentModel::tr("Cannot add empty file to the container.")); + if(!addFileCheck(doc->fileName(), info)) return false; - } QString fileName(info.fileName()); if(fileName == QStringLiteral("mimetype")) { WarningDialog::show(DocumentModel::tr("Cannot add file with name 'mimetype' to the envelope.")); return false; } - for(int row = 0; row < rowCount(); row++) - { - if(fileName == from(doc->b->dataFiles().at(size_t(row))->fileName())) - { - WarningDialog::show(DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.") - .arg(FileDialog::normalized(fileName))); - return false; - } - } if(doc->addFile(file, mime)) { emit added(FileDialog::normalized(fileName)); @@ -372,7 +360,6 @@ bool SDocumentModel::removeRow(int row) { doc->b->removeDataFile(unsigned(row)); doc->modified = true; - emit removed(row); return true; } catch( const Exception &e ) { DigiDoc::setLastError(tr("Failed remove document from container"), e); } diff --git a/client/DocumentModel.cpp b/client/DocumentModel.cpp index 0920c0815..61b1c7ab0 100644 --- a/client/DocumentModel.cpp +++ b/client/DocumentModel.cpp @@ -27,6 +27,37 @@ #include #include +bool DocumentModel::addFileCheck(const QString &container, QFileInfo file) +{ + // Check that container is not dropped into itself + if(QFileInfo(container) == file) + { + auto *dlg = new WarningDialog(tr("Cannot add container to same container\n%1") + .arg(FileDialog::normalized(container))); + dlg->setCancelText(WarningDialog::Cancel); + dlg->open(); + return false; + } + + if(file.size() == 0) + { + WarningDialog::show(tr("Cannot add empty file to the container.")); + return false; + } + QString fileName = file.fileName(); + for(int row = 0; row < rowCount(); row++) + { + if(fileName == data(row)) + { + WarningDialog::show(tr("Cannot add the file to the envelope. File '%1' is already in container.") + .arg(FileDialog::normalized(fileName))); + return false; + } + } + + return true; +} + void DocumentModel::addTempFiles(const QStringList &files) { for(const QString &file: files) diff --git a/client/DocumentModel.h b/client/DocumentModel.h index 1b20916ac..192b9ed21 100644 --- a/client/DocumentModel.h +++ b/client/DocumentModel.h @@ -20,6 +20,8 @@ #include +class QFileInfo; + class DocumentModel: public QObject { Q_OBJECT @@ -40,8 +42,8 @@ class DocumentModel: public QObject signals: void added(const QString &file); - void removed(int row); protected: + bool addFileCheck(const QString &container, QFileInfo file); static bool verifyFile(const QString &f); }; diff --git a/client/MainWindow.cpp b/client/MainWindow.cpp index 1a1b83866..2bebe0c91 100644 --- a/client/MainWindow.cpp +++ b/client/MainWindow.cpp @@ -69,7 +69,15 @@ MainWindow::MainWindow( QWidget *parent ) ui->pageButtonGroup->setId(ui->crypto, Pages::CryptoIntro); ui->pageButtonGroup->setId(ui->myEid, Pages::MyEid); - connect(ui->pageButtonGroup, &QButtonGroup::idToggled, this, &MainWindow::pageSelected); + connect(ui->pageButtonGroup, &QButtonGroup::idToggled, this, [this](int page, bool checked) { + if(!checked) + return; + if(page == SignIntro && digiDoc) + page = SignDetails; + if(page == CryptoIntro && cryptoDoc) + page = CryptoDetails; + selectPage(Pages(page)); + }); connect(ui->help, &QToolButton::clicked, qApp, &Application::openHelp); connect(ui->settings, &QToolButton::clicked, this, [this] { showSettings(SettingsDialog::GeneralSettings); }); @@ -87,12 +95,10 @@ MainWindow::MainWindow( QWidget *parent ) // Refresh ID card info in card widget connect(qApp->signer(), &QSigner::cacheChanged, this, &MainWindow::updateSelector); connect(qApp->signer(), &QSigner::signDataChanged, this, [this](const TokenData &token) { - updateSelector(); updateMyEID(token); ui->signContainerPage->cardChanged(token.cert(), token.data(QStringLiteral("blocked")).toBool()); }); connect(qApp->signer(), &QSigner::authDataChanged, this, [this](const TokenData &token) { - updateSelector(); updateMyEID(token); ui->cryptoContainerPage->cardChanged(token.cert(), token.data(QStringLiteral("blocked")).toBool()); }); @@ -104,7 +110,6 @@ MainWindow::MainWindow( QWidget *parent ) connect(ui->cryptoIntroButton, &QPushButton::clicked, this, [this] { openContainer(false); }); connect(ui->signContainerPage, &ContainerPage::action, this, &MainWindow::onSignAction); connect(ui->signContainerPage, &ContainerPage::addFiles, this, [this](const QStringList &files) { openFiles(files, true); } ); - connect(ui->signContainerPage, &ContainerPage::fileRemoved, this, &MainWindow::removeSignatureFile); connect(ui->signContainerPage, &ContainerPage::removed, this, &MainWindow::removeSignature); connect(ui->signContainerPage, &ContainerPage::warning, this, [this](WarningText warningText) { ui->warnings->showWarning(std::move(warningText)); @@ -113,7 +118,6 @@ MainWindow::MainWindow( QWidget *parent ) connect(ui->cryptoContainerPage, &ContainerPage::action, this, &MainWindow::onCryptoAction); connect(ui->cryptoContainerPage, &ContainerPage::addFiles, this, [this](const QStringList &files) { openFiles(files, true); } ); - connect(ui->cryptoContainerPage, &ContainerPage::fileRemoved, this, &MainWindow::removeCryptoFile); connect(ui->cryptoContainerPage, &ContainerPage::warning, this, [this](WarningText warningText) { ui->warnings->showWarning(std::move(warningText)); ui->crypto->warningIcon(true); @@ -122,7 +126,6 @@ MainWindow::MainWindow( QWidget *parent ) connect(ui->accordion, &Accordion::changePinClicked, this, &MainWindow::changePinClicked); connect(ui->cardInfo, &CardWidget::selected, ui->selector, &QToolButton::toggle); - updateSelector(); updateMyEID(qApp->signer()->tokensign()); ui->signContainerPage->cardChanged(qApp->signer()->tokensign().cert()); ui->cryptoContainerPage->cardChanged(qApp->signer()->tokenauth().cert()); @@ -136,17 +139,6 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::pageSelected(int page, bool checked) -{ - if(!checked) - return; - if(page == SignIntro && digiDoc) - page = SignDetails; - if(page == CryptoIntro && cryptoDoc) - page = CryptoDetails; - selectPage(Pages(page)); -} - void MainWindow::adjustDrops() { setAcceptDrops(currentState() != SignedContainer); @@ -165,6 +157,12 @@ void MainWindow::changeEvent(QEvent* event) QWidget::changeEvent(event); } +void MainWindow::changePinClicked(QSmartCardData::PinType type, QSmartCard::PinAction action) +{ + if(qApp->signer()->smartcard()->pinChange(type, action, ui->topBar)) + updateMyEid(qApp->signer()->smartcard()->data()); +} + void MainWindow::closeEvent(QCloseEvent * /*event*/) { cryptoDoc.reset(); @@ -182,23 +180,10 @@ ContainerState MainWindow::currentState() return cryptoDoc->state(); } else if(digiDoc) - { return digiDoc->state(); - } - return ContainerState::Uninitialized; } -bool MainWindow::decrypt() -{ - if(!cryptoDoc) - return false; - - WaitDialogHolder waitDialog(this, tr("Decrypting")); - - return cryptoDoc->decrypt(); -} - void MainWindow::dragEnterEvent(QDragEnterEvent *event) { if(!event->source() && !dropEventFiles(event).isEmpty()) @@ -226,7 +211,7 @@ void MainWindow::dropEvent(QDropEvent *event) if(!files.isEmpty()) { event->acceptProposedAction(); - openFiles(files, true); + openFiles(std::move(files), true); } else event->ignore(); @@ -281,7 +266,7 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea if(page == SignDetails) { navigate = false; - std::unique_ptr signatureContainer(new DigiDoc(this)); + auto signatureContainer = std::make_unique(this); if(create) { QString filename = FileDialog::createNewFileName(files[0], true, this); @@ -307,7 +292,6 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea { navigate = false; auto cryptoContainer = std::make_unique(this); - if(create) { QString filename = FileDialog::createNewFileName(files[0], false, this); @@ -361,7 +345,10 @@ void MainWindow::onSignAction(int action, const QString &idCode, const QString & case ClearSignatureWarning: ui->signature->warningIcon(false); ui->warnings->closeWarnings(SignDetails); - ui->warnings->closeWarning(EmptyFileWarning); + break; + case ContainerClose: + digiDoc.reset(); + selectPage(Pages::SignIntro); break; case ContainerCancel: resetDigiDoc({}); @@ -411,6 +398,7 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString { switch(action) { + case ContainerClose: case ContainerCancel: cryptoDoc.reset(); selectPage(Pages::CryptoIntro); @@ -421,12 +409,17 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString break; case DecryptContainer: case DecryptToken: - if(decrypt()) + { + if(!cryptoDoc) + break; + WaitDialogHolder waitDialog(this, tr("Decrypting")); + if(cryptoDoc->decrypt()) { ui->cryptoContainerPage->transition(cryptoDoc.get(), qApp->signer()->tokenauth().cert()); FadeInNotification::success(ui->topBar, tr("Decryption succeeded!")); } break; + } case EncryptContainer: if(encrypt()) { @@ -443,7 +436,7 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString } } -void MainWindow::openFiles(const QStringList &files, bool addFile, bool forceCreate) +void MainWindow::openFiles(QStringList files, bool addFile, bool forceCreate) { /* 1. If containers are not open: @@ -461,7 +454,6 @@ void MainWindow::openFiles(const QStringList &files, bool addFile, bool forceCre - else open file in another view */ auto current = ui->startScreen->currentIndex(); - QStringList content(files); ContainerState state = currentState(); Pages page = (current == CryptoIntro) ? CryptoDetails : SignDetails; bool create = true; @@ -469,9 +461,9 @@ void MainWindow::openFiles(const QStringList &files, bool addFile, bool forceCre { case Uninitialized: // Case 1. - if(content.size() == 1) + if(files.size() == 1) { - auto fileType = FileDialog::detect(content[0]); + auto fileType = FileDialog::detect(files[0]); if(current == MyEid) page = (fileType == FileDialog::CryptoDocument) ? CryptoDetails : SignDetails; create = forceCreate || ( @@ -486,31 +478,25 @@ void MainWindow::openFiles(const QStringList &files, bool addFile, bool forceCre if(addFile) { page = (state == ContainerState::UnencryptedContainer) ? CryptoDetails : SignDetails; - if(validateFiles(page == CryptoDetails ? cryptoDoc->fileName() : digiDoc->fileName(), content)) - { - if(page != CryptoDetails && digiDoc->isPDF() && !wrap(digiDoc->fileName(), true)) - return; - DocumentModel* model = (current == CryptoDetails) ? - cryptoDoc->documentModel() : digiDoc->documentModel(); - for(const auto &file: content) - model->addFile(file); - selectPage(page); + if(page != CryptoDetails && digiDoc->isPDF() && !wrap(digiDoc->fileName(), true)) return; - } - } - else - { - // If browsed (double-clicked in Explorer/Finder, clicked on bdoc/cdoc in opened container) - // or recently opened file is opened, then new container should be created. - page = (state == ContainerState::UnencryptedContainer) ? SignDetails : CryptoDetails; + DocumentModel* model = (current == CryptoDetails) ? + cryptoDoc->documentModel() : digiDoc->documentModel(); + for(const auto &file: files) + model->addFile(file); + selectPage(page); + return; } + // If browsed (double-clicked in Explorer/Finder, clicked on bdoc/cdoc in opened container) + // or recently opened file is opened, then new container should be created. + page = (state == ContainerState::UnencryptedContainer) ? SignDetails : CryptoDetails; break; default: if(addFile) { bool crypto = state & CryptoContainers; if(wrapContainer(!crypto)) - content.insert(content.begin(), digiDoc->fileName()); + files.insert(files.begin(), digiDoc->fileName()); else create = false; @@ -526,8 +512,7 @@ void MainWindow::openFiles(const QStringList &files, bool addFile, bool forceCre break; } - if(create || current != page) - navigateToPage(page, content, create); + navigateToPage(page, files, create); } void MainWindow::openContainer(bool signature) @@ -540,7 +525,7 @@ void MainWindow::openContainer(bool signature) filter = filter.arg(QLatin1String("*.cdoc *.cdoc2")); QStringList files = FileDialog::getOpenFileNames(this, tr("Select documents"), {}, filter); if(!files.isEmpty()) - openFiles(files); + openFiles(std::move(files)); } void MainWindow::resetDigiDoc(std::unique_ptr &&doc) @@ -652,7 +637,7 @@ void MainWindow::sign(F &&sign) if(!sign(city, state, zip, country, role)) { digiDoc.reset(); - navigateToPage(SignDetails, {std::move(wrappedFile)}, false); + openFiles({std::move(wrappedFile)}); return; } } @@ -668,52 +653,6 @@ void MainWindow::sign(F &&sign) adjustDrops(); } -void MainWindow::removeCryptoFile(int index) -{ - if(!cryptoDoc) - return; - - if(removeFile(cryptoDoc->documentModel(), index)) - { - if(QFile::exists(cryptoDoc->fileName())) - QFile::remove(cryptoDoc->fileName()); - cryptoDoc.reset(); - selectPage(Pages::CryptoIntro); - } -} - -bool MainWindow::removeFile(DocumentModel *model, int index) -{ - auto count = model->rowCount(); - if(count != 1) - { - model->removeRow(index); - } - else - { - auto *dlg = new WarningDialog(tr("You are about to delete the last file in the container, it is removed along with the container."), this); - dlg->setCancelText(WarningDialog::Cancel); - dlg->resetCancelStyle(false); - dlg->addButton(WarningDialog::Remove, QMessageBox::Ok, true); - if (dlg->exec() == QMessageBox::Ok) { - window()->setWindowFilePath({}); - window()->setWindowTitle(tr("DigiDoc4 Client")); - return true; - } - } - - for(auto i = 0; i < model->rowCount(); ++i) { - if(model->fileSize(i) > 0) - continue; - ui->warnings->closeWarning(EmptyFileWarning); - if(digiDoc) - ui->signContainerPage->transition(digiDoc.get()); - break; - } - - return false; -} - void MainWindow::removeSignature(int index) { if(!digiDoc) @@ -725,41 +664,13 @@ void MainWindow::removeSignature(int index) adjustDrops(); } -void MainWindow::removeSignatureFile(int index) -{ - if(!digiDoc) - return; - - if(removeFile(digiDoc->documentModel(), index)) - { - if(QFile::exists(digiDoc->fileName())) - QFile::remove(digiDoc->fileName()); - digiDoc.reset(); - selectPage(Pages::SignIntro); - } -} - -bool MainWindow::validateFiles(const QString &container, const QStringList &files) -{ - // Check that container is not dropped into itself - QFileInfo containerInfo(container); - if(std::none_of(files.cbegin(), files.cend(), - [containerInfo] (const QString &file) { return containerInfo == QFileInfo(file); })) - return true; - auto *dlg = new WarningDialog(tr("Cannot add container to same container\n%1") - .arg(FileDialog::normalized(container)), this); - dlg->setCancelText(WarningDialog::Cancel); - dlg->open(); - return false; -} - bool MainWindow::wrap(const QString& wrappedFile, bool pdf) { QString filename = FileDialog::createNewFileName(wrappedFile, true, this); if(filename.isNull()) return false; - std::unique_ptr signatureContainer(new DigiDoc(this)); + auto signatureContainer = std::make_unique(this); signatureContainer->create(filename); // If pdf, add whole file to signature container; otherwise content only @@ -788,6 +699,93 @@ bool MainWindow::wrapContainer(bool signing) return dlg->exec() == QMessageBox::Ok; } +void MainWindow::updateMyEID(const TokenData &t) +{ + updateSelector(); + ui->myEid->invalidIcon(false); + ui->myEid->warningIcon(false); + ui->warnings->closeWarnings(MyEid); + SslCertificate cert(t.cert()); + auto type = cert.type(); + ui->infoStack->setHidden(type == SslCertificate::UnknownType); + ui->accordion->setHidden(type == SslCertificate::UnknownType); + ui->noReaderInfo->setVisible(type == SslCertificate::UnknownType); + + auto setText = [this](const char *text) { + ui->noReaderInfoText->setProperty("currenttext", text); + ui->noReaderInfoText->setText(tr(text)); + }; + if(!t.isNull()) + { + setText(QT_TR_NOOP("The card in the card reader is not an Estonian ID-card")); + if(ui->cardInfo->token().card() != t.card()) + ui->accordion->clear(); + if(type & SslCertificate::TempelType) + { + ui->infoStack->update(cert); + ui->accordion->updateInfo(cert); + } + } + else + { + ui->infoStack->clearData(); + ui->accordion->clear(); + setText(QT_TR_NOOP("Connect the card reader to your computer and insert your ID card into the reader")); + } +} + +void MainWindow::updateMyEid(const QSmartCardData &data) +{ + ui->infoStack->update(data); + ui->accordion->updateInfo(data); + ui->myEid->warningIcon(false); + ui->myEid->invalidIcon(false); + ui->warnings->closeWarnings(MyEid); + if(data.isNull()) + return; + bool pin1Blocked = data.retryCount(QSmartCardData::Pin1Type) == 0; + bool pin2Blocked = data.retryCount(QSmartCardData::Pin2Type) == 0; + bool pin2Locked = data.pinLocked(QSmartCardData::Pin2Type); + ui->myEid->warningIcon( + pin1Blocked || + pin2Blocked || pin2Locked || + data.retryCount(QSmartCardData::PukType) == 0); + ui->signContainerPage->cardChanged(data.signCert(), pin2Blocked || pin2Locked); + ui->cryptoContainerPage->cardChanged(data.authCert(), pin1Blocked); + + if(pin1Blocked) + ui->warnings->showWarning({WarningType::UnblockPin1Warning, 0, + [this]{ changePinClicked(QSmartCardData::Pin1Type, QSmartCard::UnblockWithPuk); }}); + + if(pin2Locked && pin2Blocked) + ui->warnings->showWarning({WarningType::ActivatePin2WithPUKWarning, 0, + [this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPuk); }}); + else if(pin2Blocked) + ui->warnings->showWarning({WarningType::UnblockPin2Warning, 0, + [this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::UnblockWithPuk); }}); + else if(pin2Locked) + ui->warnings->showWarning({WarningType::ActivatePin2Warning, 0, + [this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPin); }}); + + const qint64 DAY = 24 * 60 * 60; + qint64 expiresIn = 106 * DAY; + for(const QSslCertificate &cert: {data.authCert(), data.signCert()}) + { + if(!cert.isNull()) + expiresIn = std::min(expiresIn, QDateTime::currentDateTime().secsTo(cert.expiryDate().toLocalTime())); + } + if(expiresIn <= 0) + { + ui->myEid->invalidIcon(true); + ui->warnings->showWarning({WarningType::CertExpiredError}); + } + else if(expiresIn <= 105 * DAY) + { + ui->myEid->warningIcon(true); + ui->warnings->showWarning({WarningType::CertExpiryWarning}); + } +} + void MainWindow::updateSelector() { TokenData selected; diff --git a/client/MainWindow.h b/client/MainWindow.h index 1ff103ea4..ba2e18fd5 100644 --- a/client/MainWindow.h +++ b/client/MainWindow.h @@ -44,7 +44,7 @@ class MainWindow final : public QWidget explicit MainWindow(QWidget *parent = nullptr); ~MainWindow() final; - void openFiles(const QStringList &files, bool addFile = false, bool forceCreate = false); + void openFiles(QStringList files, bool addFile = false, bool forceCreate = false); void selectPage(ria::qdigidoc4::Pages page); void showSettings(int page); @@ -62,23 +62,17 @@ class MainWindow final : public QWidget void changePinClicked(QSmartCardData::PinType type, QSmartCard::PinAction action); void convertToCDoc(); ria::qdigidoc4::ContainerState currentState(); - bool decrypt(); bool encrypt(); void loadPicture(); void navigateToPage( ria::qdigidoc4::Pages page, const QStringList &files = QStringList(), bool create = true ); void onCryptoAction(int action, const QString &id, const QString &phone); void onSignAction(int action, const QString &idCode, const QString &info2); void openContainer(bool signature); - void pageSelected(int page, bool checked = true); void resetDigiDoc(std::unique_ptr &&doc); - void removeCryptoFile(int index); - bool removeFile(DocumentModel *model, int index); void removeSignature(int index); - void removeSignatureFile(int index); bool save(); template void sign(F &&sign); - bool validateFiles(const QString &container, const QStringList &files); void updateSelector(); void updateMyEID(const TokenData &t); void updateMyEid(const QSmartCardData &data); diff --git a/client/MainWindow_MyEID.cpp b/client/MainWindow_MyEID.cpp deleted file mode 100644 index a7af5cd9c..000000000 --- a/client/MainWindow_MyEID.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * QDigiDoc4 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "MainWindow.h" -#include "ui_MainWindow.h" - -#include "Application.h" -#include "QSigner.h" -#include "SslCertificate.h" -#include "widgets/WarningItem.h" -#include "widgets/WarningList.h" - -#include -#include - -using namespace ria::qdigidoc4; - -void MainWindow::changePinClicked(QSmartCardData::PinType type, QSmartCard::PinAction action) -{ - if(qApp->signer()->smartcard()->pinChange(type, action, ui->topBar)) - updateMyEid(qApp->signer()->smartcard()->data()); -} - -void MainWindow::updateMyEID(const TokenData &t) -{ - ui->warnings->clearMyEIDWarnings(); - SslCertificate cert(t.cert()); - auto type = cert.type(); - ui->infoStack->setHidden(type == SslCertificate::UnknownType); - ui->accordion->setHidden(type == SslCertificate::UnknownType); - ui->noReaderInfo->setVisible(type == SslCertificate::UnknownType); - - auto setText = [this](const char *text) { - ui->noReaderInfoText->setProperty("currenttext", text); - ui->noReaderInfoText->setText(tr(text)); - }; - if(!t.isNull()) - { - setText(QT_TR_NOOP("The card in the card reader is not an Estonian ID-card")); - if(ui->cardInfo->token().card() != t.card()) - ui->accordion->clear(); - if(type & SslCertificate::TempelType) - { - ui->infoStack->update(cert); - ui->accordion->updateInfo(cert); - } - } - else - { - ui->infoStack->clearData(); - ui->accordion->clear(); - ui->myEid->invalidIcon(false); - ui->myEid->warningIcon(false); - setText(QT_TR_NOOP("Connect the card reader to your computer and insert your ID card into the reader")); - } -} - -void MainWindow::updateMyEid(const QSmartCardData &data) -{ - ui->infoStack->update(data); - ui->accordion->updateInfo(data); - ui->myEid->warningIcon(false); - ui->myEid->invalidIcon(false); - ui->warnings->clearMyEIDWarnings(); - if(data.isNull()) - return; - bool pin1Blocked = data.retryCount(QSmartCardData::Pin1Type) == 0; - bool pin2Blocked = data.retryCount(QSmartCardData::Pin2Type) == 0; - bool pin2Locked = data.pinLocked(QSmartCardData::Pin2Type); - ui->myEid->warningIcon( - pin1Blocked || - pin2Blocked || pin2Locked || - data.retryCount(QSmartCardData::PukType) == 0); - ui->signContainerPage->cardChanged(data.signCert(), pin2Blocked || pin2Locked); - ui->cryptoContainerPage->cardChanged(data.authCert(), pin1Blocked); - - if(pin1Blocked) - ui->warnings->showWarning({WarningType::UnblockPin1Warning, 0, - [this]{ changePinClicked(QSmartCardData::Pin1Type, QSmartCard::UnblockWithPuk); }}); - - if(pin2Locked && pin2Blocked) - ui->warnings->showWarning({WarningType::ActivatePin2WithPUKWarning, 0, - [this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPuk); }}); - else if(pin2Blocked) - ui->warnings->showWarning({WarningType::UnblockPin2Warning, 0, - [this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::UnblockWithPuk); }}); - else if(pin2Locked) - ui->warnings->showWarning({WarningType::ActivatePin2Warning, 0, - [this]{ changePinClicked(QSmartCardData::Pin2Type, QSmartCard::ActivateWithPin); }}); - - const qint64 DAY = 24 * 60 * 60; - qint64 expiresIn = 106 * DAY; - for(const QSslCertificate &cert: {data.authCert(), data.signCert()}) - { - if(!cert.isNull()) - expiresIn = std::min(expiresIn, QDateTime::currentDateTime().secsTo(cert.expiryDate().toLocalTime())); - } - if(expiresIn <= 0) - { - ui->myEid->invalidIcon(true); - ui->warnings->showWarning({WarningType::CertExpiredError}); - } - else if(expiresIn <= 105 * DAY) - { - ui->myEid->warningIcon(true); - ui->warnings->showWarning({WarningType::CertExpiryWarning}); - } -} diff --git a/client/QPKCS11.cpp b/client/QPKCS11.cpp index bb36153df..078df9d4c 100644 --- a/client/QPKCS11.cpp +++ b/client/QPKCS11.cpp @@ -303,7 +303,7 @@ QList QPKCS11::tokens() const t.setReader(toQString(slotInfo.slotDescription).trimmed()); t.setData(QStringLiteral("slot"), QVariant::fromValue(slot)); t.setData(QStringLiteral("id"), id); - t.setData(QStringLiteral("blocked"), (token.flags & CKF_USER_PIN_LOCKED) > 0); + t.setData(QStringLiteral("blocked"), (token.flags & (CKF_USER_PIN_LOCKED|CKF_USER_PIN_TO_BE_CHANGED)) > 0); CK_KEY_TYPE keyType = CKK_RSA; CK_ATTRIBUTE attribute { CKA_KEY_TYPE, &keyType, sizeof(keyType) }; diff --git a/client/QSigner.cpp b/client/QSigner.cpp index a7b57e000..467c3f29e 100644 --- a/client/QSigner.cpp +++ b/client/QSigner.cpp @@ -352,7 +352,6 @@ void QSigner::run() void QSigner::selectCard(const TokenData &token) { - d->smartcard->reloadCard(token, false); bool isSign = SslCertificate(token.cert()).keyUsage().contains(SslCertificate::NonRepudiation); if(isSign) Q_EMIT signDataChanged(d->sign = token); @@ -370,6 +369,7 @@ void QSigner::selectCard(const TokenData &token) Q_EMIT signDataChanged(d->sign = other); break; } + d->smartcard->reloadCard(token, false); } std::vector QSigner::sign(const std::string &method, const std::vector &digest ) const diff --git a/client/QSmartCard.cpp b/client/QSmartCard.cpp index 0607f13c4..a78d22705 100644 --- a/client/QSmartCard.cpp +++ b/client/QSmartCard.cpp @@ -616,60 +616,58 @@ void QSmartCard::reloadCard(const TokenData &token, bool reloadCounters) if(!reloadCounters && !d->t.isNull() && !d->t.card().isEmpty() && d->t.card() == d->token.card()) return; - std::thread([&] { - // check if selected card is same as signer - if(!d->t.card().isEmpty() && d->token.card() != d->t.card()) - d->t.d = new QSmartCardDataPrivate(); + // check if selected card is same as signer + if(!d->t.card().isEmpty() && d->token.card() != d->t.card()) + d->t.d = new QSmartCardDataPrivate(); - // select signer card - if(d->t.card().isEmpty() || d->t.card() != d->token.card()) - { - QSharedDataPointer t = d->t.d; - t->card = d->token.card(); - t->data.clear(); - t->authCert.clear(); - t->signCert.clear(); - d->t.d = std::move(t); - } + // select signer card + if(d->t.card().isEmpty() || d->t.card() != d->token.card()) + { + QSharedDataPointer t = d->t.d; + t->card = d->token.card(); + t->data.clear(); + t->authCert.clear(); + t->signCert.clear(); + d->t.d = std::move(t); + } - if(!reloadCounters && (!d->t.isNull() || d->token.reader().isEmpty())) - return; + if(!reloadCounters && (!d->t.isNull() || d->token.reader().isEmpty())) + return; - QString reader = d->token.reader(); - if(d->token.reader().endsWith(QLatin1String("..."))) { - for(const QString &test: QPCSC::instance().readers()) { - if(test.startsWith(d->token.reader().left(d->token.reader().size() - 3))) - reader = test; - } + QString reader = d->token.reader(); + if(d->token.reader().endsWith(QLatin1String("..."))) { + for(const QString &test: QPCSC::instance().readers()) { + if(test.startsWith(d->token.reader().left(d->token.reader().size() - 3))) + reader = test; } + } - qCDebug(CLog) << "Read" << reader; - QPCSCReader selectedReader(reader, &QPCSC::instance()); - if(!selectedReader.connect()) - return; - - if(auto atr = selectedReader.atr(); - IDEMIACard::isSupported(atr)) - d->card = std::make_unique(); - else if(THALESCard::isSupported(atr)) - d->card = std::make_unique(); - else { - qCDebug(CLog) << "Unsupported card"; - return; - } + qCDebug(CLog) << "Read" << reader; + QPCSCReader selectedReader(reader, &QPCSC::instance()); + if(auto atr = selectedReader.atr(); + IDEMIACard::isSupported(atr)) + d->card = std::make_unique(); + else if(THALESCard::isSupported(atr)) + d->card = std::make_unique(); + else { + qCDebug(CLog) << "Unsupported card"; + d->card.reset(); + return; + } - qCDebug(CLog) << "Read card" << d->token.card() << "info"; - QSharedDataPointer t = d->t.d; - t->reader = selectedReader.name(); - t->pinpad = selectedReader.isPinPad(); - if(d->card->loadPerso(&selectedReader, t)) - { - d->t.d = std::move(t); - emit dataChanged(d->t); - } - else - qCDebug(CLog) << "Failed to read card info, try again next round"; - }).detach(); + if(!selectedReader.connect()) + return; + qCDebug(CLog) << "Read card" << d->token.card() << "info"; + QSharedDataPointer t = d->t.d; + t->reader = selectedReader.name(); + t->pinpad = selectedReader.isPinPad(); + if(d->card->loadPerso(&selectedReader, t)) + { + d->t.d = std::move(t); + emit dataChanged(d->t); + } + else + qCDebug(CLog) << "Failed to read card info, try again next round"; } TokenData QSmartCard::tokenData() const { return d->token; } diff --git a/client/common_enums.h b/client/common_enums.h index 0d02eee69..81e99cf34 100644 --- a/client/common_enums.h +++ b/client/common_enums.h @@ -36,6 +36,7 @@ enum ContainerState : unsigned char { }; enum Actions : unsigned char { + ContainerClose, ContainerCancel, ContainerConvert, ContainerEncrypt, diff --git a/client/translations/en.ts b/client/translations/en.ts index fce61f2ef..be3ffe60a 100644 --- a/client/translations/en.ts +++ b/client/translations/en.ts @@ -461,6 +461,10 @@ In order to view Validity Confirmation Sheet there has to be at least one printer installed! In order to view Validity Confirmation Sheet there has to be at least one printer installed! + + You are about to delete the last file in the container, it is removed along with the container. + You are about to delete the last file in the container, it is removed along with the container. + Change Change @@ -789,6 +793,12 @@ DocumentModel + + Cannot add container to same container +%1 + Cannot add container to same container +%1 + A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it. A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it. @@ -1365,10 +1375,6 @@ ID-Card Converted to crypto container! Converted to crypto container! - - You are about to delete the last file in the container, it is removed along with the container. - You are about to delete the last file in the container, it is removed along with the container. - Removing signature Removing signature @@ -1381,12 +1387,6 @@ ID-Card Files can not be added to the cryptocontainer. The system will create a new container which shall contain the cypto-document and the files you wish to add. Files can not be added to the cryptocontainer. The system will create a new container which shall contain the cypto-document and the files you wish to add. - - Cannot add container to same container -%1 - Cannot add container to same container -%1 - Connect the card reader to your computer and insert your ID card into the reader Connect the card reader to your computer and insert your ID-card into the reader diff --git a/client/translations/et.ts b/client/translations/et.ts index 36f1e50c2..5eb82a8a2 100644 --- a/client/translations/et.ts +++ b/client/translations/et.ts @@ -461,6 +461,10 @@ In order to view Validity Confirmation Sheet there has to be at least one printer installed! Digitaalallkirjade kinnituslehe kuvamiseks peab olema arvutis vähemalt üks printer seadistatud! + + You are about to delete the last file in the container, it is removed along with the container. + Oled kustutamas viimast faili ümbrikus, koos sellega eemaldatakse ka ümbrik. + Change Muuda @@ -789,6 +793,12 @@ DocumentModel + + Cannot add container to same container +%1 + Ümbriku lisamine samasse ümbrikusse ebaõnnestus +%1 + A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it. Sellise laiendiga faili ei ole võimalik avada DigiDoc4 kliendis. Faili vaatamiseks laadi see alla. @@ -1365,10 +1375,6 @@ ID-kaardiga Converted to crypto container! Konverteeritud turvaümbrikuks! - - You are about to delete the last file in the container, it is removed along with the container. - Oled kustutamas viimast faili ümbrikus, koos sellega eemaldatakse ka ümbrik. - Removing signature Allkirja eemaldamine @@ -1381,12 +1387,6 @@ ID-kaardiga Files can not be added to the cryptocontainer. The system will create a new container which shall contain the cypto-document and the files you wish to add. Krüpto-ümbrikusse ei saa faile lisada. Süsteem loob uue ümbriku, kuhu lisatakse krüpteeritud dokument ja Sinu valitud failid. - - Cannot add container to same container -%1 - Ümbriku lisamine samasse ümbrikusse ebaõnnestus -%1 - Connect the card reader to your computer and insert your ID card into the reader Ühenda kaardilugeja arvutiga ja sisesta ID-kaart lugejasse diff --git a/client/translations/ru.ts b/client/translations/ru.ts index 0a25e33aa..3fee1e545 100644 --- a/client/translations/ru.ts +++ b/client/translations/ru.ts @@ -461,6 +461,10 @@ In order to view Validity Confirmation Sheet there has to be at least one printer installed! Для отображения листа подтверждения действительности цифровой подписи на компьютере должен быть установлен как минимум один принтер! + + You are about to delete the last file in the container, it is removed along with the container. + Вы собираетесь удалить последний файл в контейнере, он удаляется вместе с контейнером. + Change Поменять @@ -789,6 +793,12 @@ DocumentModel + + Cannot add container to same container +%1 + Невозможно добавить контейнер в тот же контейнер +%1 + A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it. Файл с таким расширением не может быть открыт в клиенте DigiDoc4. Загрузите файл, чтобы просмотреть его. @@ -1365,10 +1375,6 @@ ID-картой Converted to crypto container! Переделан в контейнер для зашифровывания! - - You are about to delete the last file in the container, it is removed along with the container. - Вы собираетесь удалить последний файл в контейнере, он удаляется вместе с контейнером. - Removing signature Удаление подписи @@ -1381,12 +1387,6 @@ ID-картой Files can not be added to the cryptocontainer. The system will create a new container which shall contain the cypto-document and the files you wish to add. Файлы не могут быть добавлены в криптоконтейнер. Система создаст новый контейнер, в который будет добавлен зашифрованный документ и выбранные вами файлы. - - Cannot add container to same container -%1 - Невозможно добавить контейнер в тот же контейнер -%1 - Connect the card reader to your computer and insert your ID card into the reader Подключите устройство чтения карт к компьютеру и вставьте ID-карту в устройство чтения @@ -2807,7 +2807,7 @@ Additional licenses and components PIN%1 code must be changed in order to authenticate - Чтобы аутентифицироваться, необходимо изменить PIN%1. + Чтобы аутентифицироваться, необходимо изменить PIN%1 PIN%1 code must be changed in order to sign diff --git a/client/widgets/ContainerPage.cpp b/client/widgets/ContainerPage.cpp index bb1e37cd5..a01f10963 100644 --- a/client/widgets/ContainerPage.cpp +++ b/client/widgets/ContainerPage.cpp @@ -68,7 +68,6 @@ ContainerPage::ContainerPage(QWidget *parent) connectCode(ui->convert, Actions::ContainerConvert); connectCode(ui->save, Actions::ContainerSave); connect(ui->leftPane, &FileList::addFiles, this, &ContainerPage::addFiles); - connect(ui->leftPane, &ItemList::removed, this, &ContainerPage::fileRemoved); connect(ui->leftPane, &ItemList::addItem, this, [this](int code) { emit action(code); }); connect(ui->rightPane, &ItemList::addItem, this, [this](int code) { emit action(code); }); connect(ui->rightPane, &ItemList::removed, this, &ContainerPage::removed); @@ -196,6 +195,27 @@ void ContainerPage::changeEvent(QEvent* event) QWidget::changeEvent(event); } +template +void ContainerPage::deleteConfirm(C *c, int index) +{ + if(c->documentModel()->rowCount() > 1) + { + ui->leftPane->removeItem(index); + return; + } + auto *dlg = new WarningDialog(tr("You are about to delete the last file in the container, it is removed along with the container."), this); + dlg->setCancelText(WarningDialog::Cancel); + dlg->resetCancelStyle(false); + dlg->addButton(WarningDialog::Remove, QMessageBox::Ok, true); + if (dlg->exec() != QMessageBox::Ok) + return; + window()->setWindowFilePath({}); + window()->setWindowTitle(tr("DigiDoc4 Client")); + if(QFile::exists(c->fileName())) + QFile::remove(c->fileName()); + emit action(ContainerClose); +} + void ContainerPage::setHeader(const QString &file) { fileName = QDir::toNativeSeparators (file); @@ -216,7 +236,7 @@ void ContainerPage::showMainAction(const QList &actions) bool isSignMobile = !isSignCard && (actions.contains(SignatureMobile) || actions.contains(SignatureSmartID)); bool isEncrypt = actions.contains(EncryptContainer) && !ui->rightPane->findChildren().isEmpty(); bool isDecrypt = !isBlocked && (actions.contains(DecryptContainer) || actions.contains(DecryptToken)); - mainAction->setButtonEnabled(isSupported && !hasEmptyFile && + mainAction->setButtonEnabled(isSupported && (isEncrypt || isDecrypt || isSignMobile || (isSignCard && !isBlocked && !isExpired))); ui->mainActionSpacer->changeSize(198, 20, QSizePolicy::Fixed); ui->navigationArea->layout()->invalidate(); @@ -224,7 +244,7 @@ void ContainerPage::showMainAction(const QList &actions) void ContainerPage::showSigningButton() { - if (!isSupported || hasEmptyFile) + if (!isSupported) { if(mainAction) mainAction->hide(); @@ -241,6 +261,10 @@ void ContainerPage::showSigningButton() void ContainerPage::transition(CryptoDoc *container, const QSslCertificate &cert) { + disconnect(ui->leftPane, &ItemList::removed, container, nullptr); + connect(ui->leftPane, &ItemList::removed, container, [this, container](int index) { + deleteConfirm(container, index); + }); disconnect(ui->rightPane, &ItemList::add, container, nullptr); connect(ui->rightPane, &ItemList::add, container, [this, container] { AddRecipients dlg(ui->rightPane, this); @@ -256,8 +280,8 @@ void ContainerPage::transition(CryptoDoc *container, const QSslCertificate &cert } showMainAction({ EncryptContainer }); }); - disconnect(this, &ContainerPage::removed, container, nullptr); - connect(this, &ContainerPage::removed, container, [this, container](int index) { + disconnect(ui->rightPane, &ItemList::removed, container, nullptr); + connect(ui->rightPane, &ItemList::removed, container, [this, container](int index) { container->removeKey(index); ui->rightPane->removeItem(index); showMainAction({ EncryptContainer }); @@ -292,7 +316,7 @@ void ContainerPage::transition(CryptoDoc *container, const QSslCertificate &cert bool hasUnsupported = false; for(CKey &key: container->keys()) { - hasUnsupported = std::max(hasUnsupported, key.unsupported); + hasUnsupported = hasUnsupported || key.unsupported; ui->rightPane->addWidget(new AddressItem(std::move(key), AddressItem::Icon, ui->rightPane)); } if(hasUnsupported) @@ -303,6 +327,10 @@ void ContainerPage::transition(CryptoDoc *container, const QSslCertificate &cert void ContainerPage::transition(DigiDoc* container) { + disconnect(ui->leftPane, &ItemList::removed, container, nullptr); + connect(ui->leftPane, &ItemList::removed, container, [this, container](int index) { + deleteConfirm(container, index); + }); disconnect(this, &ContainerPage::certChanged, container, nullptr); connect(this, &ContainerPage::certChanged, container, [this](const SslCertificate &) { showSigningButton(); @@ -378,17 +406,18 @@ void ContainerPage::transition(DigiDoc* container) if(container->isCades()) emit warning({UnsupportedAsicCadesWarning}); - hasEmptyFile = false; - for (auto i = 0; i < container->documentModel()->rowCount(); i++) + isSupported = container->isSupported() || container->isPDF(); + + for (auto i = 0, count = container->documentModel()->rowCount(); i < count; i++) { if(container->documentModel()->fileSize(i) == 0) { emit warning({EmptyFileWarning}); - hasEmptyFile = true; + isSupported = false; + break; } } - isSupported = container->isSupported() || container->isPDF(); showSigningButton(); ui->leftPane->setModel(container->documentModel()); diff --git a/client/widgets/ContainerPage.h b/client/widgets/ContainerPage.h index b88be81ea..b75a1663e 100644 --- a/client/widgets/ContainerPage.h +++ b/client/widgets/ContainerPage.h @@ -55,13 +55,14 @@ class ContainerPage final : public QWidget void action(int code, const QString &idCode = {}, const QString &info2 = {}); void addFiles(const QStringList &files); void certChanged(const SslCertificate &cert); - void fileRemoved(int row); void removed(int row); void warning(const WarningText &warningText); private: void changeEvent(QEvent* event) final; void clear(int code); + template + void deleteConfirm(C *c, int index); void elideFileName(); bool eventFilter(QObject *o, QEvent *e) final; void showMainAction(const QList &actions); @@ -79,7 +80,6 @@ class ContainerPage final : public QWidget const char *cancelText = QT_TR_NOOP("Cancel"); const char *convertText = QT_TR_NOOP("Encrypt"); bool isSupported = false; - bool hasEmptyFile = false; bool isSeal = false; bool isExpired = false; bool isBlocked = false; diff --git a/client/widgets/FileList.cpp b/client/widgets/FileList.cpp index fdfed6367..4156ace78 100644 --- a/client/widgets/FileList.cpp +++ b/client/widgets/FileList.cpp @@ -117,8 +117,9 @@ void FileList::open(FileItem *item) const void FileList::removeItem(int row) { + if(!documentModel->removeRow(row)) + return; ItemList::removeItem(row); - updateDownload(); } @@ -203,9 +204,8 @@ void FileList::setModel(DocumentModel *documentModel) { this->documentModel = documentModel; disconnect(documentModel, &DocumentModel::added, nullptr, nullptr); - disconnect(documentModel, &DocumentModel::removed, nullptr, nullptr); connect(documentModel, &DocumentModel::added, this, &FileList::addFile); - connect(documentModel, &DocumentModel::removed, this, &FileList::removeItem); + auto count = documentModel->rowCount(); for(int i = 0; i < count; i++) addFile(documentModel->data(i)); diff --git a/client/widgets/WarningItem.cpp b/client/widgets/WarningItem.cpp index c91e0dc35..d7b2423e8 100644 --- a/client/widgets/WarningItem.cpp +++ b/client/widgets/WarningItem.cpp @@ -76,10 +76,12 @@ void WarningItem::lookupWarning() setObjectName("WarningItemError"); ui->warningText->setText(tr("Certificates have expired!")); url = tr("https://www.politsei.ee/en/instructions/applying-for-an-id-card-for-an-adult/"); + _page = MyEid; break; case CertExpiryWarning: ui->warningText->setText(tr("Certificates expire soon!")); url = tr("https://www.politsei.ee/en/instructions/applying-for-an-id-card-for-an-adult/"); + _page = MyEid; break; case ActivatePin1WithPUKWarning: case UnblockPin1Warning: @@ -87,6 +89,7 @@ void WarningItem::lookupWarning() VerifyCert::tr("PIN%1 has been blocked because PIN%1 code has been entered incorrectly 3 times.").arg(1), VerifyCert::tr("Unblock to reuse PIN%1.").arg(1))); ui->warningAction->setText(VerifyCert::tr("Unblock")); + _page = MyEid; break; case ActivatePin2WithPUKWarning: case UnblockPin2Warning: @@ -94,11 +97,13 @@ void WarningItem::lookupWarning() VerifyCert::tr("PIN%1 has been blocked because PIN%1 code has been entered incorrectly 3 times.").arg(2), VerifyCert::tr("Unblock to reuse PIN%1.").arg(2))); ui->warningAction->setText(VerifyCert::tr("Unblock")); + _page = MyEid; break; case ActivatePin2Warning: ui->warningText->setText(tr("Signing with an ID-card isn't possible yet. PIN%1 code must be changed in order to sign.").arg(2)); ui->warningAction->setText(tr("Additional information")); url = tr("https://www.id.ee/en/article/changing-id-card-pin-codes-and-puk-code/"); + _page = MyEid; break; // SignDetails case InvalidSignatureError: @@ -153,7 +158,8 @@ void WarningItem::lookupWarning() ui->warningAction->hide(); _page = SignDetails; break; - default: break; + case NoWarning: + break; } } diff --git a/client/widgets/WarningItem.h b/client/widgets/WarningItem.h index 3613881de..a9d971eac 100644 --- a/client/widgets/WarningItem.h +++ b/client/widgets/WarningItem.h @@ -50,5 +50,5 @@ class WarningItem final: public StyledWidget Ui::WarningItem *ui; WarningText warnText; QString url; - int _page = -1; + ria::qdigidoc4::Pages _page = ria::qdigidoc4::MyEid; }; diff --git a/client/widgets/WarningList.cpp b/client/widgets/WarningList.cpp index 8adfa6362..e76287d9b 100644 --- a/client/widgets/WarningList.cpp +++ b/client/widgets/WarningList.cpp @@ -4,41 +4,16 @@ #include -using namespace ria::qdigidoc4; - WarningList::WarningList(QWidget *parent) : StyledWidget(parent) {} -void WarningList::clearMyEIDWarnings() -{ - static const QList warningTypes { - CertExpiredError, CertExpiryWarning, - UnblockPin1Warning, UnblockPin2Warning, - ActivatePin2Warning, - }; - for(auto *warning: findChildren()) - { - if(warningTypes.contains(warning->warningType())) - warning->deleteLater(); - } -} - -void WarningList::closeWarning(int warningType) -{ - for(auto *warning: findChildren()) - { - if(warning->warningType() == warningType) - warning->deleteLater(); - } -} - void WarningList::closeWarnings(int page) { for(auto *warning: findChildren()) { if(warning->page() == page) - warning->deleteLater(); + delete warning; } } @@ -56,5 +31,5 @@ void WarningList::showWarning(WarningText warningText) void WarningList::updateWarnings(int page) { for(auto *warning: findChildren()) - warning->setVisible(warning->page() == page || warning->page() == -1); + warning->setVisible(warning->page() == page || warning->page() == ria::qdigidoc4::MyEid); } diff --git a/client/widgets/WarningList.h b/client/widgets/WarningList.h index 518b47a10..d3da2b809 100644 --- a/client/widgets/WarningList.h +++ b/client/widgets/WarningList.h @@ -29,10 +29,7 @@ class WarningList: public StyledWidget public: explicit WarningList(QWidget *parent = nullptr); - void clearMyEIDWarnings(); - void closeWarning(int warningType); void closeWarnings(int page); void showWarning(WarningText warningText); void updateWarnings(int page); - };