From a35d33cd6ccaebf91f4cd16ff7c858b5fbb741eb Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Fri, 10 Feb 2023 15:24:10 +0200 Subject: [PATCH] Show window, then activate window and delay parameter command parsing (#1156) IB-7526, IB-7513 Signed-off-by: Raul Metsma --- client/Application.cpp | 67 ++++++++++++++++++--------------------- client/Application.h | 33 ++++++++++--------- client/translations/en.ts | 8 ++--- client/translations/et.ts | 8 ++--- client/translations/ru.ts | 8 ++--- 5 files changed, 59 insertions(+), 65 deletions(-) diff --git a/client/Application.cpp b/client/Application.cpp index 95b5d8df0..0a8adec45 100644 --- a/client/Application.cpp +++ b/client/Application.cpp @@ -77,6 +77,8 @@ class MacMenuBar {}; #include #endif +using namespace std::chrono; + const QStringList Application::CONTAINER_EXT { QStringLiteral("asice"), QStringLiteral("sce"), QStringLiteral("asics"), QStringLiteral("scs"), @@ -170,7 +172,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent std::vector TSCerts() const final { - std::vector list = toCerts(QStringLiteral("CERT-BUNDLE")); + std::vector list = toCerts(QLatin1String("CERT-BUNDLE")); if(digidoc::X509Cert cert = toCert(fromBase64(s.value(QStringLiteral("TSA-CERT"))))) list.push_back(cert); return list; @@ -188,7 +190,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent std::string TSLUrl() const final { return valueSystemScope(QStringLiteral("TSL-URL"), digidoc::XmlConfCurrent::TSLUrl()); } std::vector TSLCerts() const final { - std::vector tslcerts = toCerts(QStringLiteral("TSL-CERTS")); + std::vector tslcerts = toCerts(QLatin1String("TSL-CERTS")); return tslcerts.empty() ? digidoc::XmlConfCurrent::TSLCerts() : tslcerts; } @@ -201,7 +203,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent } std::vector verifyServiceCerts() const final { - std::vector list = toCerts(QStringLiteral("CERT-BUNDLE")); + std::vector list = toCerts(QLatin1String("CERT-BUNDLE")); if(digidoc::X509Cert cert = verifyServiceCert()) list.push_back(cert); return list; @@ -297,7 +299,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent return digidoc::X509Cert((const unsigned char*)der.constData(), size_t(der.size())); } - std::vector toCerts(const QString &key) const + std::vector toCerts(QLatin1String key) const { std::vector certs; for(const auto &cert: obj.value(key).toArray()) @@ -319,7 +321,7 @@ class Application::Private { public: Configuration *conf {}; - QAction *closeAction {}, *newClientAction {}, *newCryptoAction {}, *helpAction {}; + QAction *closeAction {}, *newClientAction {}, *helpAction {}; MacMenuBar *bar {}; QSigner *signer {}; @@ -344,7 +346,7 @@ Application::Application( int &argc, char **argv ) d->conf = new Configuration(this); connect(d->conf, &Configuration::updateReminder, [&](bool /* expired */, const QString & /* title */, const QString &message){ - WarningDialog(message, qApp->activeWindow()).exec(); + WarningDialog::show(qApp->activeWindow(), message); }); #endif @@ -389,18 +391,16 @@ Application::Application( int &argc, char **argv ) // This is needed to release application from memory (Windows) setQuitOnLastWindowClosed( true ); d->lastWindowTimer.setSingleShot(true); - connect(&d->lastWindowTimer, &QTimer::timeout, []{ if(topLevelWindows().isEmpty()) quit(); }); - connect(this, &Application::lastWindowClosed, [&]{ d->lastWindowTimer.start(10*1000); }); + connect(&d->lastWindowTimer, &QTimer::timeout, this, []{ if(topLevelWindows().isEmpty()) quit(); }); + connect(this, &Application::lastWindowClosed, this, [&]{ d->lastWindowTimer.start(10s); }); #ifdef Q_OS_MAC d->bar = new MacMenuBar; d->bar->addAction( MacMenuBar::AboutAction, this, SLOT(showAbout()) ); d->bar->addAction( MacMenuBar::PreferencesAction, this, SLOT(showSettings()) ); d->bar->fileMenu()->addAction( d->newClientAction ); - d->bar->fileMenu()->addAction( d->newCryptoAction ); d->bar->fileMenu()->addAction( d->closeAction ); d->bar->dockMenu()->addAction( d->newClientAction ); - d->bar->dockMenu()->addAction( d->newCryptoAction ); d->helpAction = d->bar->helpMenu()->addAction(tr("DigiDoc4 Client Help"), this, &Application::openHelp); #endif @@ -454,7 +454,7 @@ Application::Application( int &argc, char **argv ) #ifdef Q_OS_MAC if(QSettings().value(QStringLiteral("plugins")).isNull()) { - WarningDialog *dlg = new WarningDialog(tr( + auto *dlg = new WarningDialog(tr( "In order to authenticate and sign in e-services with an ID-card you need to install the web browser components."), parent); dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->setCancelText(tr("Ignore forever").toUpper()); @@ -474,7 +474,7 @@ Application::Application( int &argc, char **argv ) if(QSettings().value(QStringLiteral("showIntro"), true).toBool()) { QSettings().setValue(QStringLiteral("showIntro"), false); - FirstRun *dlg = new FirstRun(parent); + auto *dlg = new FirstRun(parent); connect(dlg, &FirstRun::langChanged, this, [this](const QString& lang) { loadTranslation( lang ); }); dlg->open(); } @@ -500,7 +500,7 @@ Application::~Application() delete d; return; } - if( QtLocalPeer *obj = findChild() ) + if(auto *obj = findChild()) delete obj; #else deinitMacEvents(); @@ -536,9 +536,9 @@ void Application::activate( QWidget *w ) w->setWindowState(Qt::WindowActive); #endif w->addAction( d->closeAction ); - w->activateWindow(); w->show(); w->raise(); + w->activateWindow(); } #ifdef Q_OS_WIN @@ -566,7 +566,7 @@ void Application::clearConfValue( ConfParameter parameter ) { try { - digidoc::XmlConfCurrent *i = dynamic_cast(digidoc::Conf::instance()); + auto *i = dynamic_cast(digidoc::Conf::instance()); if(!i) return; switch( parameter ) @@ -600,7 +600,7 @@ void Application::closeWindow() w->close(); else #endif - if( QDialog *d = qobject_cast(activeWindow()) ) + if(auto *d = qobject_cast(activeWindow())) d->reject(); else if(QWidget *w = activeWindow()) w->close(); @@ -613,7 +613,7 @@ Configuration* Application::conf() QVariant Application::confValue( ConfParameter parameter, const QVariant &value ) { - DigidocConf *i = static_cast(digidoc::Conf::instance()); + auto *i = static_cast(digidoc::Conf::instance()); QByteArray r; switch( parameter ) @@ -656,7 +656,7 @@ bool Application::event(QEvent *event) case QEvent::FileOpen: { QString fileName = static_cast(event)->file().normalized(QString::NormalizationForm_C); - QTimer::singleShot(0, [this, fileName] { + QTimer::singleShot(0, this, [this, fileName] { parseArgs({ fileName }); }); return true; @@ -691,7 +691,6 @@ void Application::loadTranslation( const QString &lang ) void(d->qtTranslator.load(QStringLiteral(":/translations/qt_") + lang)); if( d->closeAction ) d->closeAction->setText( tr("Close Window") ); if( d->newClientAction ) d->newClientAction->setText( tr("New Window") ); - if( d->newCryptoAction ) d->newCryptoAction->setText( tr("New Crypto window") ); if(d->helpAction) d->helpAction->setText(tr("DigiDoc4 Client Help")); } @@ -787,7 +786,7 @@ QWidget* Application::mainWindow() QWidget* root = nullptr; if (!win) - { + { // Prefer main window; on Mac also the menu is top level window for (QWidget *widget: topLevelWidgets()) { @@ -891,7 +890,7 @@ void Application::migrateSettings() if(oldOrgSettings.contains(oldKey)){ newSettings.setValue(newKey, oldOrgSettings.value(oldKey)); - + #ifdef Q_OS_MAC if(oldKey != newKey) oldAppSettings.remove(oldKey); @@ -963,11 +962,7 @@ bool Application::notify(QObject *object, QEvent *event) void Application::openHelp() { - QString lang = language(); - QUrl u(QStringLiteral("https://www.id.ee/id-abikeskus/")); - if(lang == QLatin1String("en")) u = QStringLiteral("https://www.id.ee/en/id-help/"); - if(lang == QLatin1String("ru")) u = QStringLiteral("https://www.id.ee/ru/id-pomoshh/"); - QDesktopServices::openUrl(u); + QDesktopServices::openUrl(QUrl(tr("https://www.id.ee/en/id-help/"))); } void Application::parseArgs( const QString &msg ) @@ -1028,7 +1023,7 @@ void Application::setConfValue( ConfParameter parameter, const QVariant &value ) { try { - digidoc::XmlConfCurrent *i = dynamic_cast(digidoc::Conf::instance()); + auto *i = dynamic_cast(digidoc::Conf::instance()); if(!i) return; QByteArray v = value.toString().toUtf8(); @@ -1058,13 +1053,13 @@ void Application::setConfValue( ConfParameter parameter, const QVariant &value ) void Application::showAbout() { - if(MainWindow *w = qobject_cast(mainWindow())) + if(auto *w = qobject_cast(mainWindow())) w->showSettings(SettingsDialog::LicenseSettings); } void Application::showSettings() { - if(MainWindow *w = qobject_cast(mainWindow())) + if(auto *w = qobject_cast(mainWindow())) w->showSettings(SettingsDialog::GeneralSettings); } @@ -1081,7 +1076,7 @@ void Application::showClient(const QStringList ¶ms, bool crypto, bool sign, else if(!newWindow) { // else select first window with no open files - MainWindow *main = qobject_cast(uniqueRoot()); + auto *main = qobject_cast(uniqueRoot()); if(main && main->windowFilePath().isEmpty()) w = main; } @@ -1111,9 +1106,9 @@ void Application::showClient(const QStringList ¶ms, bool crypto, bool sign, } #endif } + activate(w); if( !params.isEmpty() ) QMetaObject::invokeMethod(w, "open", Q_ARG(QStringList,params), Q_ARG(bool,crypto), Q_ARG(bool,sign)); - activate( w ); } void Application::showTSLWarning(QEventLoop *e) @@ -1146,9 +1141,9 @@ QWidget* Application::uniqueRoot() MainWindow* root = nullptr; // Return main window if only one main window is opened - for(auto w : topLevelWidgets()) + for(auto *w : topLevelWidgets()) { - if(MainWindow *r = qobject_cast(w)) + if(auto *r = qobject_cast(w)) { if(root) return nullptr; @@ -1172,7 +1167,7 @@ void Application::waitForTSL( const QString &file ) p.setWindowFlags( (Qt::Dialog | Qt::CustomizeWindowHint | Qt::MSWindowsFixedSizeDialogHint ) & ~Qt::WindowTitleHint ); p.setWindowModality(Qt::WindowModal); p.setFixedSize( p.size() ); - if( QProgressBar *bar = p.findChild() ) + if(auto *bar = p.findChild()) bar->setTextVisible( false ); p.setMinimumWidth( 300 ); p.setRange( 0, 100 ); @@ -1182,9 +1177,9 @@ void Application::waitForTSL( const QString &file ) if(p.value() + 1 == p.maximum()) p.setValue(0); p.setValue( p.value() + 1 ); - t.start( 100 ); + t.start(100ms); }); - t.start( 100 ); + t.start(100ms); QEventLoop e; connect(this, &Application::TSLLoadingFinished, &e, &QEventLoop::quit); if( !d->ready ) diff --git a/client/Application.h b/client/Application.h index 4f8991cb8..00eea9f30 100644 --- a/client/Application.h +++ b/client/Application.h @@ -64,33 +64,32 @@ class Application final: public Common #endif Configuration *conf(); void loadTranslation( const QString &lang ); - QWidget* mainWindow(); bool notify(QObject *object, QEvent *event ) final; - void openHelp(); QSigner* signer() const; int run(); void waitForTSL( const QString &file ); - static void initDiagnosticConf(); - static uint readTSLVersion(const QString &path); static void addRecent( const QString &file ); static QVariant confValue(ConfParameter parameter, const QVariant &value = {}); static void clearConfValue( ConfParameter parameter ); + static void initDiagnosticConf(); + static QWidget* mainWindow(); + static void openHelp(); + static uint readTSLVersion(const QString &path); static void setConfValue( ConfParameter parameter, const QVariant &value ); public Q_SLOTS: - void showAbout(); - void showSettings(); void showClient(const QStringList ¶ms = {}, bool crypto = false, bool sign = false, bool newWindow = false); - void showWarning(const QString &msg, const QString &details = {}); + static void showWarning(const QString &msg, const QString &details = {}); private Q_SLOTS: - void browse( const QUrl &url ); - void closeWindow(); - void mailTo( const QUrl &url ); void parseArgs(const QString &msg = {}); - void parseArgs( const QStringList &args ); - void showTSLWarning( QEventLoop *e ); + void parseArgs(const QStringList &args); + static void browse(const QUrl &url); + static void mailTo(const QUrl &url); + static void showAbout(); + static void showSettings(); + static void showTSLWarning( QEventLoop *e ); Q_SIGNALS: void TSLLoadingFinished(); @@ -98,13 +97,13 @@ private Q_SLOTS: private: void activate( QWidget *w ); bool event(QEvent *event) final; - void migrateSettings(); + static void closeWindow(); + static void migrateSettings(); static void showWarning(const QString &msg, const digidoc::Exception &e); - QWidget* uniqueRoot(); - + static QWidget* uniqueRoot(); #if defined(Q_OS_MAC) - void initMacEvents(); - void deinitMacEvents(); + static void initMacEvents(); + static void deinitMacEvents(); #endif static const QStringList CONTAINER_EXT; diff --git a/client/translations/en.ts b/client/translations/en.ts index bbf7302b0..baa45b538 100644 --- a/client/translations/en.ts +++ b/client/translations/en.ts @@ -201,10 +201,6 @@ Caught exception! Caught exception! - - New Crypto window - New Crypto window - The renewal of Trust Service status List, used for digital signature validation, has failed. Please check your internet connection and make sure you have the latest ID-software version installed. An expired Trust Service List (TSL) will be used for signature validation. <a href="https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/">Additional information</a> The renewal of Trust Service status List, used for digital signature validation, has failed. Please check your internet connection and make sure you have the latest ID-software version installed. An expired Trust Service List (TSL) will be used for signature validation. <a href="https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/">Additional information</a> @@ -253,6 +249,10 @@ https://www.id.ee/en/article/install-id-software/ https://www.id.ee/en/article/install-id-software/ + + https://www.id.ee/en/id-help/ + https://www.id.ee/en/id-help/ + CDocumentModel diff --git a/client/translations/et.ts b/client/translations/et.ts index 3cdb0e7a4..d159f4f54 100644 --- a/client/translations/et.ts +++ b/client/translations/et.ts @@ -201,10 +201,6 @@ Caught exception! Tekkis viga! - - New Crypto window - Ava uus Krüpto aken - The renewal of Trust Service status List, used for digital signature validation, has failed. Please check your internet connection and make sure you have the latest ID-software version installed. An expired Trust Service List (TSL) will be used for signature validation. <a href="https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/">Additional information</a> Digiallkirjade kehtivuse kontrollimiseks kasutatava sertifikaatide usaldusnimekirja uuendamine ebaõnnestus. Palun kontrolli oma arvuti internetiühendust ja seda, kas arvutis on kõige uuem ID-tarkvara versioon. Allkirjade verifitseerimiseks kasutatakse aegunud nimekirja. <a href="https://www.id.ee/artikkel/digidoc4-teade-sertifikaatide-usaldusnimekirja-uuendamine-ebaonnestus/">Lisainfo</a> @@ -253,6 +249,10 @@ https://www.id.ee/en/article/install-id-software/ https://www.id.ee/artikkel/paigalda-id-tarkvara/ + + https://www.id.ee/en/id-help/ + https://www.id.ee/id-abikeskus/ + CDocumentModel diff --git a/client/translations/ru.ts b/client/translations/ru.ts index ace9160fe..c1834edd5 100644 --- a/client/translations/ru.ts +++ b/client/translations/ru.ts @@ -201,10 +201,6 @@ Caught exception! Перехвачена системная ошибка! - - New Crypto window - Новое окно Crypto - The renewal of Trust Service status List, used for digital signature validation, has failed. Please check your internet connection and make sure you have the latest ID-software version installed. An expired Trust Service List (TSL) will be used for signature validation. <a href="https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/">Additional information</a> Не удалось обновить список доверенных сертификатов, используемый для проверки действительности цифровых подписей. Пожалуйста, проверьте ваше интернет-соединение и убедитесь в том, что на компьютере установлена последняя версия программного обеспечения ID-карты. Для верификации подписей будет использован устаревший список доверенных сертификатов. <a href="https://www.id.ee/ru/artikkel/uvedomlenie-digidoc4-obnovlenie-spiska-doveriya-sertifikatov-ne-udalos/">Дополнительная информация</a> @@ -253,6 +249,10 @@ https://www.id.ee/en/article/install-id-software/ https://www.id.ee/ru/artikkel/ustanovite-id-programmu/ + + https://www.id.ee/en/id-help/ + https://www.id.ee/ru/id-pomoshh/ + CDocumentModel