diff --git a/client/Application.cpp b/client/Application.cpp index a8b3329e6..b87d59dc4 100644 --- a/client/Application.cpp +++ b/client/Application.cpp @@ -203,9 +203,13 @@ class DigidocConf final: public digidoc::XmlConfCurrent static bool isAllowed = false; if(!isAllowed) { - QEventLoop e; - QMetaObject::invokeMethod( qApp, "showTSLWarning", Q_ARG(QEventLoop*,&e) ); - e.exec(); + dispatchToMain([] { + WarningDialog::show(Application::tr( + "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. " + "Additional information"), QString()); + }); isAllowed = true; } return isAllowed; @@ -435,9 +439,8 @@ Application::Application( int &argc, char **argv ) qDebug() << "TSL loading finished"; Q_EMIT qApp->TSLLoadingFinished(); qApp->d->ready = true; - if(ex) { + if(ex) dispatchToMain(showWarning, tr("Failed to initalize."), *ex); - } } ); } @@ -472,10 +475,10 @@ Application::Application( int &argc, char **argv ) { Settings::SHOW_INTRO = false; auto *dlg = new FirstRun(mainWindow()); - connect(dlg, &FirstRun::langChanged, this, [this](const QString& lang) { loadTranslation( lang ); }); + connect(dlg, &FirstRun::langChanged, this, &Application::loadTranslation); dlg->open(); } - }); + }, Qt::QueuedConnection); if( !args.isEmpty() || topLevelWindows().isEmpty() ) parseArgs(std::move(args)); @@ -740,7 +743,9 @@ void Application::mailTo( const QUrl &url ) QWidget* Application::mainWindow() { - if(QWidget *win = qobject_cast(activeWindow())) + if(auto *win = qobject_cast(activeWindow())) + return win; + if(auto *win = qobject_cast(activeWindow())) return win; auto list = topLevelWidgets(); // Prefer main window; on Mac also the menu is top level window @@ -748,7 +753,11 @@ QWidget* Application::mainWindow() [](QWidget *widget) { return qobject_cast(widget); }); i != list.cend()) return *i; - return list.value(0); + if(auto i = std::find_if(list.cbegin(), list.cend(), + [](QWidget *widget) { return qobject_cast(widget); }); + i != list.cend()) + return *i; + return nullptr; } bool Application::notify(QObject *object, QEvent *event) @@ -915,16 +924,6 @@ void Application::showClient(const QStringList ¶ms, bool crypto, bool sign, QMetaObject::invokeMethod(w, "open", Q_ARG(QStringList,params), Q_ARG(bool,crypto), Q_ARG(bool,sign)); } -void Application::showTSLWarning(QEventLoop *e) -{ - auto *dlg = WarningDialog::show(tr( - "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. " - "Additional information")); - connect(dlg, &WarningDialog::finished, e, &QEventLoop::quit); -} - void Application::showWarning( const QString &msg, const digidoc::Exception &e ) { digidoc::Exception::ExceptionCode code = digidoc::Exception::General; diff --git a/client/Application.h b/client/Application.h index f59ffda90..e24cbe5a9 100644 --- a/client/Application.h +++ b/client/Application.h @@ -79,7 +79,6 @@ class Application final: public Common private Q_SLOTS: static void browse(const QUrl &url); static void mailTo(const QUrl &url); - static void showTSLWarning( QEventLoop *e ); Q_SIGNALS: void TSLLoadingFinished();