@@ -241,8 +241,8 @@ void WebEidDialog::showAboutPage()
241
241
d->ui ->aboutAlert ->hide ();
242
242
auto * app = qApp;
243
243
if (app->isSafariExtensionContainingApp ()) {
244
- d->setupOK ([app] { app->showSafariSettings (); },
245
- [] { return tr ( " Open Safari settings... " ); }, true );
244
+ d->setupOK ([app] { app->showSafariSettings (); }, QT_TR_NOOP ( " Open Safari settings... " ),
245
+ true );
246
246
connect (app, &Application::safariExtensionEnabled, d, [d](bool value) {
247
247
d->ui ->aboutAlert ->setHidden (value);
248
248
d->resizeHeight ();
@@ -260,7 +260,7 @@ void WebEidDialog::showAboutPage()
260
260
void WebEidDialog::showFatalErrorPage ()
261
261
{
262
262
auto * d = new WebEidDialog ();
263
- d->setTrText (d->ui ->messagePageTitleLabel , []() -> QString { return tr ( " Operation failed" ); } );
263
+ d->setTrText (d->ui ->messagePageTitleLabel , QT_TR_NOOP ( " Operation failed" ));
264
264
d->ui ->fatalError ->show ();
265
265
d->ui ->fatalHelp ->show ();
266
266
d->ui ->connectCardLabel ->hide ();
@@ -294,12 +294,8 @@ void WebEidDialog::onSmartCardStatusUpdate(const RetriableError status)
294
294
{
295
295
currentCommand = CommandType::INSERT_CARD;
296
296
297
- setTrText (ui->connectCardLabel , [status]() -> QString {
298
- return std::get<0 >(retriableErrorToTextTitleAndIcon (status));
299
- });
300
- setTrText (ui->messagePageTitleLabel , [status]() -> QString {
301
- return std::get<1 >(retriableErrorToTextTitleAndIcon (status));
302
- });
297
+ setTrText (ui->connectCardLabel , std::get<0 >(retriableErrorToTextTitleAndIcon (status)));
298
+ setTrText (ui->messagePageTitleLabel , std::get<1 >(retriableErrorToTextTitleAndIcon (status)));
303
299
ui->cardChipIcon ->setPixmap (std::get<2 >(retriableErrorToTextTitleAndIcon (status)));
304
300
305
301
// In case the insert card page is not shown, switch back to it.
@@ -382,29 +378,29 @@ void WebEidDialog::onSingleCertificateReady(const QUrl& origin,
382
378
return ;
383
379
case CommandType::AUTHENTICATE:
384
380
ui->pinInputCertificateInfo ->setCertificateInfo (certAndPin);
385
- setTrText (ui->pinInputPageTitleLabel , []() -> QString { return tr ( " Authenticate" ); } );
386
- setTrText (ui->pinInputDescriptionLabel , []() -> QString {
387
- return tr (" By authenticating, I agree to the transfer of my name and personal "
388
- " identification code to the service provider." );
389
- });
390
- setTrText ( ui->pinTitleLabel , [useExternalPinDialog]() -> QString {
391
- return useExternalPinDialog
392
- ? tr ( " Please enter PIN for authentication in the PIN dialog window that opens. " )
393
- : tr ( " Enter PIN1 for authentication" );
394
- } );
381
+ setTrText (ui->pinInputPageTitleLabel , QT_TR_NOOP ( " Authenticate" ));
382
+ setTrText (ui->pinInputDescriptionLabel ,
383
+ QT_TR_NOOP (" By authenticating, I agree to the transfer of my name and personal "
384
+ " identification code to the service provider." ) );
385
+ setTrText (
386
+ ui->pinTitleLabel ,
387
+ useExternalPinDialog
388
+ ? QT_TR_NOOP (
389
+ " Please enter PIN for authentication in the PIN dialog window that opens. " )
390
+ : QT_TR_NOOP ( " Enter PIN1 for authentication " ) );
395
391
break ;
396
392
case CommandType::SIGN:
397
393
ui->pinInputCertificateInfo ->setCertificateInfo (certAndPin);
398
- setTrText (ui->pinInputPageTitleLabel , []() -> QString { return tr ( " Signing" ); } );
399
- setTrText (ui-> pinInputDescriptionLabel , []() -> QString {
400
- return tr ( " By signing, I agree to the transfer of my name and personal identification "
401
- " code to the service provider. " );
402
- } );
403
- setTrText (ui-> pinTitleLabel , [useExternalPinDialog]() -> QString {
404
- return useExternalPinDialog
405
- ? tr ( " Please enter PIN for signing in the PIN dialog window that opens. " )
406
- : tr ( " Enter PIN2 for signing" );
407
- } );
394
+ setTrText (ui->pinInputPageTitleLabel , QT_TR_NOOP ( " Signing" ));
395
+ setTrText (
396
+ ui-> pinInputDescriptionLabel ,
397
+ QT_TR_NOOP ( " By signing, I agree to the transfer of my name and personal identification "
398
+ " code to the service provider. " ) );
399
+ setTrText (
400
+ ui-> pinTitleLabel ,
401
+ useExternalPinDialog
402
+ ? QT_TR_NOOP ( " Please enter PIN for signing in the PIN dialog window that opens. " )
403
+ : QT_TR_NOOP ( " Enter PIN2 for signing " ) );
408
404
break ;
409
405
default :
410
406
emit failure (QStringLiteral (" Only SELECT_CERTIFICATE, AUTHENTICATE or SIGN allowed" ));
@@ -430,15 +426,14 @@ void WebEidDialog::onSingleCertificateReady(const QUrl& origin,
430
426
431
427
void WebEidDialog::onRetry (const RetriableError error)
432
428
{
433
- onRetryImpl ([error] { return std::get<0 >(retriableErrorToTextTitleAndIcon (error)); } );
429
+ onRetryImpl (std::get<0 >(retriableErrorToTextTitleAndIcon (error)));
434
430
}
435
431
436
432
void WebEidDialog::onSigningCertificateMismatch ()
437
433
{
438
- onRetryImpl ([] {
439
- return tr (" The certificate of the ID card in the reader does not match the originally "
440
- " submitted certificate. Please insert the original ID card." );
441
- });
434
+ onRetryImpl (
435
+ QT_TR_NOOP (" The certificate of the ID card in the reader does not match the originally "
436
+ " submitted certificate. Please insert the original ID card." ));
442
437
}
443
438
444
439
void WebEidDialog::onVerifyPinFailed (const VerifyPinFailed::Status status, const qint8 retriesLeft)
@@ -523,19 +518,25 @@ template <typename Text>
523
518
void WebEidDialog::onRetryImpl (Text text)
524
519
{
525
520
setTrText (ui->connectCardLabel , std::forward<Text>(text));
526
- setTrText (ui->messagePageTitleLabel , []() -> QString { return tr ( " Operation failed" ); } );
521
+ setTrText (ui->messagePageTitleLabel , QT_TR_NOOP ( " Operation failed" ));
527
522
ui->cardChipIcon ->setPixmap (pixmap (" no-id-card" _L1));
528
- setupOK ([this ] { emit retry (); }, []() -> QString { return tr ( " Try again" ); } , true );
523
+ setupOK ([this ] { emit retry (); }, QT_TR_NOOP ( " Try again" ), true );
529
524
ui->pageStack ->setCurrentIndex (int (Page::ALERT));
530
525
}
531
526
532
527
template <typename Text>
533
528
void WebEidDialog::setTrText (QWidget* label, Text text) const
534
529
{
535
530
disconnect (this , &WebEidDialog::languageChange, label, nullptr );
536
- label->setProperty (" text" , text ());
537
- connect (this , &WebEidDialog::languageChange, label,
538
- [label, text = std::forward<Text>(text)] { label->setProperty (" text" , text ()); });
531
+ if constexpr (std::is_same_v<Text, const char *>) {
532
+ label->setProperty (" text" , tr (text));
533
+ connect (this , &WebEidDialog::languageChange, label,
534
+ [label, text] { label->setProperty (" text" , tr (text)); });
535
+ } else {
536
+ label->setProperty (" text" , text ());
537
+ connect (this , &WebEidDialog::languageChange, label,
538
+ [label, text = std::forward<Text>(text)] { label->setProperty (" text" , text ()); });
539
+ }
539
540
}
540
541
541
542
void WebEidDialog::connectOkToCachePinAndEmitSelectedCertificate (
@@ -650,13 +651,13 @@ void WebEidDialog::setupPinInput(const CardCertificateAndPinInfo& certAndPin)
650
651
}
651
652
652
653
template <typename Func>
653
- void WebEidDialog::setupOK (Func&& func, const std::function<QString()>& text, bool enabled)
654
+ void WebEidDialog::setupOK (Func&& func, const char * text, bool enabled)
654
655
{
655
656
ui->okButton ->disconnect ();
656
657
connect (ui->okButton , &QPushButton::clicked, this , std::forward<Func>(func));
657
658
ui->okButton ->show ();
658
659
ui->okButton ->setEnabled (enabled);
659
- setTrText (ui->okButton , text ? text : []() -> QString { return tr ( " Confirm" ); } );
660
+ setTrText (ui->okButton , text ? text : QT_TR_NOOP ( " Confirm" ));
660
661
ui->cancelButton ->show ();
661
662
ui->cancelButton ->setEnabled (true );
662
663
ui->helpButton ->hide ();
@@ -669,8 +670,7 @@ void WebEidDialog::displayPinBlockedError()
669
670
ui->pinTimeoutTimer ->stop ();
670
671
ui->pinTimeRemaining ->hide ();
671
672
ui->pinEntryTimeoutProgressBar ->hide ();
672
- setTrText (ui->pinErrorLabel ,
673
- []() -> QString { return tr (" PIN is locked. Unblock and try again." ); });
673
+ setTrText (ui->pinErrorLabel , QT_TR_NOOP (" PIN is locked. Unblock and try again." ));
674
674
ui->pinErrorLabel ->show ();
675
675
ui->okButton ->hide ();
676
676
ui->cancelButton ->setEnabled (true );
@@ -697,77 +697,90 @@ QPixmap WebEidDialog::pixmap(QLatin1String name)
697
697
.arg (name, Application::isDarkTheme () ? " _dark" _L1 : QLatin1String ())};
698
698
}
699
699
700
- std::tuple<QString, QString , QPixmap>
700
+ std::tuple<const char *, const char * , QPixmap>
701
701
WebEidDialog::retriableErrorToTextTitleAndIcon (const RetriableError error)
702
702
{
703
703
switch (error) {
704
704
case RetriableError::SMART_CARD_SERVICE_IS_NOT_RUNNING:
705
- return {tr (" The smart card service required to use the ID-card is not running. Please "
706
- " start the smart card service and try again." ),
707
- tr (" Launch the Smart Card service" ), pixmap (" cardreader" _L1)};
705
+ return {
706
+ QT_TR_NOOP (" The smart card service required to use the ID-card is not running. Please "
707
+ " start the smart card service and try again." ),
708
+ QT_TR_NOOP (" Launch the Smart Card service" ), pixmap (" cardreader" _L1)};
708
709
case RetriableError::NO_SMART_CARD_READERS_FOUND:
709
- return {tr (" <b>Card reader not connected.</b> Please connect the card reader to "
710
- " the computer." ),
711
- tr (" Connect the card reader" ), pixmap (" cardreader" _L1)};
710
+ return {QT_TR_NOOP (" <b>Card reader not connected.</b> Please connect the card reader to "
711
+ " the computer." ),
712
+ QT_TR_NOOP (" Connect the card reader" ), pixmap (" cardreader" _L1)};
712
713
713
714
case RetriableError::NO_SMART_CARDS_FOUND:
714
715
case RetriableError::PKCS11_TOKEN_NOT_PRESENT:
715
- return {tr (" <b>ID-card not found.</b> Please insert the ID-card into the reader." ),
716
- tr (" Insert the ID-card" ), pixmap (" no-id-card" _L1)};
716
+ return {QT_TR_NOOP (" <b>ID-card not found.</b> Please insert the ID-card into the reader." ),
717
+ QT_TR_NOOP (" Insert the ID-card" ), pixmap (" no-id-card" _L1)};
717
718
case RetriableError::SMART_CARD_WAS_REMOVED:
718
719
case RetriableError::PKCS11_TOKEN_REMOVED:
719
- return {tr (" The ID-card was removed from the reader. Please insert the ID-card into the "
720
- " reader." ),
721
- tr (" Insert the ID-card" ), pixmap (" no-id-card" _L1)};
720
+ return {QT_TR_NOOP (
721
+ " The ID-card was removed from the reader. Please insert the ID-card into the "
722
+ " reader." ),
723
+ QT_TR_NOOP (" Insert the ID-card" ), pixmap (" no-id-card" _L1)};
722
724
723
725
case RetriableError::SMART_CARD_TRANSACTION_FAILED:
724
- return {tr (" Operation failed. Make sure that the ID-card and the card reader are connected "
725
- " correctly." ),
726
- tr (" Check the ID-card and the reader connection" ), pixmap (" no-id-card" _L1)};
726
+ return {
727
+ QT_TR_NOOP (
728
+ " Operation failed. Make sure that the ID-card and the card reader are connected "
729
+ " correctly." ),
730
+ QT_TR_NOOP (" Check the ID-card and the reader connection" ), pixmap (" no-id-card" _L1)};
727
731
case RetriableError::FAILED_TO_COMMUNICATE_WITH_CARD_OR_READER:
728
- return {tr (" Connection to the ID-card or reader failed. Make sure that the ID-card and the "
729
- " card reader are connected correctly." ),
730
- tr (" Check the ID-card and the reader connection" ), pixmap (" no-id-card" _L1)};
732
+ return {
733
+ QT_TR_NOOP (
734
+ " Connection to the ID-card or reader failed. Make sure that the ID-card and the "
735
+ " card reader are connected correctly." ),
736
+ QT_TR_NOOP (" Check the ID-card and the reader connection" ), pixmap (" no-id-card" _L1)};
731
737
732
738
case RetriableError::SMART_CARD_CHANGE_REQUIRED:
733
- return {tr (" The desired operation cannot be performed with the inserted ID-card. Make sure "
734
- " that the ID-card is supported by the Web eID application." ),
735
- tr (" Operation not supported" ), pixmap (" no-id-card" _L1)};
739
+ return {
740
+ QT_TR_NOOP (
741
+ " The desired operation cannot be performed with the inserted ID-card. Make sure "
742
+ " that the ID-card is supported by the Web eID application." ),
743
+ QT_TR_NOOP (" Operation not supported" ), pixmap (" no-id-card" _L1)};
736
744
737
745
case RetriableError::SMART_CARD_COMMAND_ERROR:
738
- return {tr (" Error communicating with the card." ), tr (" Operation failed" ),
746
+ return {QT_TR_NOOP (" Error communicating with the card." ), QT_TR_NOOP (" Operation failed" ),
739
747
pixmap (" no-id-card" _L1)};
740
748
// TODO: what action should the user take? Should this be fatal?
741
749
case RetriableError::PKCS11_ERROR:
742
- return {tr (" Card driver error. Please try again." ), tr (" Card driver error" ),
750
+ return {QT_TR_NOOP (" Card driver error. Please try again." ), QT_TR_NOOP (" Card driver error" ),
743
751
pixmap (" no-id-card" _L1)};
744
752
// TODO: what action should the user take? Should this be fatal?
745
753
case RetriableError::SCARD_ERROR:
746
- return {tr (" An error occurred in the Smart Card service required to use the ID-card. Make "
747
- " sure that the ID-card and the card reader are connected correctly or relaunch "
748
- " the Smart Card service." ),
749
- tr (" Operation failed" ), pixmap (" no-id-card" _L1)};
754
+ return {QT_TR_NOOP (
755
+ " An error occurred in the Smart Card service required to use the ID-card. Make "
756
+ " sure that the ID-card and the card reader are connected correctly or relaunch "
757
+ " the Smart Card service." ),
758
+ QT_TR_NOOP (" Operation failed" ), pixmap (" no-id-card" _L1)};
750
759
751
760
case RetriableError::UNSUPPORTED_CARD:
752
- return {tr (" The card in the reader is not supported. Make sure that the entered ID-card is "
753
- " supported by the Web eID application." ),
754
- tr (" Operation not supported" ), pixmap (" no-id-card" _L1)};
761
+ return {
762
+ QT_TR_NOOP (
763
+ " The card in the reader is not supported. Make sure that the entered ID-card is "
764
+ " supported by the Web eID application." ),
765
+ QT_TR_NOOP (" Operation not supported" ), pixmap (" no-id-card" _L1)};
755
766
756
767
case RetriableError::NO_VALID_CERTIFICATE_AVAILABLE:
757
- return {tr (" The inserted ID-card does not contain a certificate for the requested "
758
- " operation. Please insert an ID-card that supports the requested operation." ),
759
- tr (" Operation not supported" ), pixmap (" no-id-card" _L1)};
768
+ return {QT_TR_NOOP (
769
+ " The inserted ID-card does not contain a certificate for the requested "
770
+ " operation. Please insert an ID-card that supports the requested operation." ),
771
+ QT_TR_NOOP (" Operation not supported" ), pixmap (" no-id-card" _L1)};
760
772
761
773
case RetriableError::PIN_VERIFY_DISABLED:
762
774
return {
763
- tr (" Operation failed. Make sure that the driver of the corresponding card reader is "
764
- " used. Read more <a "
765
- " href=\" https://www.id.ee/en/article/using-pinpad-card-reader-drivers/\" >here</"
766
- " a>." ),
767
- tr (" Card driver error" ), QStringLiteral (" :/images/cardreader.svg" )};
775
+ QT_TR_NOOP (
776
+ " Operation failed. Make sure that the driver of the corresponding card reader is "
777
+ " used. Read more <a "
778
+ " href=\" https://www.id.ee/en/article/using-pinpad-card-reader-drivers/\" >here</"
779
+ " a>." ),
780
+ QT_TR_NOOP (" Card driver error" ), QStringLiteral (" :/images/cardreader.svg" )};
768
781
769
782
case RetriableError::UNKNOWN_ERROR:
770
- return {tr (" Unknown error" ), tr (" Unknown error" ), pixmap (" no-id-card" _L1)};
783
+ return {QT_TR_NOOP (" Unknown error" ), QT_TR_NOOP (" Unknown error" ), pixmap (" no-id-card" _L1)};
771
784
}
772
- return {tr (" Unknown error" ), tr (" Unknown error" ), pixmap (" no-id-card" _L1)};
785
+ return {QT_TR_NOOP (" Unknown error" ), QT_TR_NOOP (" Unknown error" ), pixmap (" no-id-card" _L1)};
773
786
}
0 commit comments