AusweisApp2/src/main.cpp

235 lines
6.1 KiB
C++
Raw Normal View History

2017-12-20 14:54:05 +01:00
/*
2019-05-22 10:08:38 +02:00
* \copyright Copyright (c) 2014-2019 Governikus GmbH & Co. KG, Germany
2017-12-20 14:54:05 +01:00
*/
2017-07-03 09:30:10 +02:00
#include "controller/AppController.h"
2017-09-15 10:23:30 +02:00
#include "CommandLineParser.h"
2017-07-03 09:30:10 +02:00
#include "global/BuildHelper.h"
#include "global/LogHandler.h"
2017-09-15 10:23:30 +02:00
#include "SignalHandler.h"
2017-07-03 09:30:10 +02:00
2019-01-03 15:06:22 +01:00
#include <openssl/crypto.h> // version API
2017-07-03 09:30:10 +02:00
#include <QLoggingCategory>
2019-09-30 17:22:19 +02:00
#include <QProcess>
2019-01-03 15:06:22 +01:00
#include <QScopedPointer>
2017-07-03 09:30:10 +02:00
#include <QSslSocket>
#include <QtPlugin>
2017-09-15 10:23:30 +02:00
#include <QThread>
2017-07-03 09:30:10 +02:00
2019-01-03 15:06:22 +01:00
#include "config.h" // use in main only!
#ifdef ANDROID_BUILD_AAR
#include <QAndroidService>
#define QAPP QAndroidService
#elif defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_WINRT)
#ifdef Q_OS_ANDROID
#include <QAndroidService>
#include <QtAndroid>
#endif
#include <QGuiApplication>
#define QAPP QGuiApplication
2017-07-03 09:30:10 +02:00
#else
2019-01-03 15:06:22 +01:00
#include <QApplication>
#define QAPP QApplication
2017-07-03 09:30:10 +02:00
#endif
2019-01-03 15:06:22 +01:00
#if !defined(Q_OS_WINRT) && !defined(ANDROID_BUILD_AAR)
2017-12-20 14:54:05 +01:00
Q_IMPORT_PLUGIN(RemoteReaderManagerPlugIn)
#endif
2017-07-03 09:33:28 +02:00
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(Q_OS_WINRT)
2017-07-03 09:30:10 +02:00
Q_IMPORT_PLUGIN(PcscReaderManagerPlugIn)
Q_IMPORT_PLUGIN(WebserviceActivationHandler)
#endif
Q_IMPORT_PLUGIN(InternalActivationHandler)
#if defined(Q_OS_ANDROID)
Q_IMPORT_PLUGIN(NfcReaderManagerPlugIn)
2019-01-03 15:06:22 +01:00
#ifndef ANDROID_BUILD_AAR
2017-07-03 09:30:10 +02:00
Q_IMPORT_PLUGIN(IntentActivationHandler)
#endif
2019-01-03 15:06:22 +01:00
#endif
2017-07-03 09:30:10 +02:00
#if defined(Q_OS_IOS)
2019-09-30 17:22:19 +02:00
Q_IMPORT_PLUGIN(QIOSIntegrationPlugin)
Q_IMPORT_PLUGIN(IosReaderManagerPlugIn)
2017-07-03 09:30:10 +02:00
Q_IMPORT_PLUGIN(CustomSchemeActivationHandler)
2017-12-20 14:54:05 +01:00
Q_IMPORT_PLUGIN(QJpegPlugin)
Q_IMPORT_PLUGIN(QSvgPlugin)
Q_IMPORT_PLUGIN(QtQmlModelsPlugin)
Q_IMPORT_PLUGIN(QtQmlStateMachinePlugin)
Q_IMPORT_PLUGIN(QtGraphicalEffectsPlugin)
Q_IMPORT_PLUGIN(QtGraphicalEffectsPrivatePlugin)
// Do not delete the comments to avoid searching for the class name
//Q_IMPORT_PLUGIN(QtQuickControls2MaterialStylePlugin)
//Q_IMPORT_PLUGIN(QtQuickControls2UniversalStylePlugin)
Q_IMPORT_PLUGIN(QtQuickControls2Plugin)
Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
//Q_IMPORT_PLUGIN(QQmlLocalStoragePlugin)
//Q_IMPORT_PLUGIN(QtQuick2ParticlesPlugin)
Q_IMPORT_PLUGIN(QtQuickTemplates2Plugin)
Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
Q_IMPORT_PLUGIN(QtQuick2Plugin)
2017-07-03 09:30:10 +02:00
#endif
2019-01-03 15:06:22 +01:00
#if (defined(Q_OS_ANDROID) && !defined(ANDROID_BUILD_AAR)) || defined(Q_OS_IOS) || (defined(Q_OS_LINUX) && !defined(QT_NO_DEBUG) && !defined(ANDROID_BUILD_AAR))
2017-07-03 09:30:10 +02:00
Q_IMPORT_PLUGIN(BluetoothReaderManagerPlugIn)
#endif
2017-07-03 09:33:28 +02:00
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(Q_OS_WINRT)
2017-07-03 09:30:10 +02:00
Q_IMPORT_PLUGIN(UIPlugInWidgets)
#endif
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || !defined(QT_NO_DEBUG)
Q_IMPORT_PLUGIN(UIPlugInAidl)
2019-01-03 15:06:22 +01:00
#endif
2019-09-30 17:22:19 +02:00
#ifndef ANDROID_BUILD_AAR
2017-07-03 09:30:10 +02:00
Q_IMPORT_PLUGIN(UIPlugInQml)
#endif
2019-09-30 17:22:19 +02:00
Q_IMPORT_PLUGIN(UIPlugInJson)
2017-07-03 09:30:10 +02:00
Q_IMPORT_PLUGIN(UIPlugInWebSocket)
using namespace governikus;
Q_DECLARE_LOGGING_CATEGORY(init)
static inline void printInfo()
{
2019-01-03 15:06:22 +01:00
qCDebug(init) << "Logging to" << *Env::getSingleton<LogHandler>();
2017-07-03 09:30:10 +02:00
qCInfo(init) << "##################################################";
2019-05-22 10:08:38 +02:00
const auto& info = BuildHelper::getInformationHeader();
for (const auto& entry : info)
{
qCInfo(init).noquote().nospace() << "### " << entry.first << ": " << entry.second;
}
2017-07-03 09:30:10 +02:00
qCInfo(init) << "##################################################";
2019-01-03 15:06:22 +01:00
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#define OpenSSL_version SSLeay_version
#define OPENSSL_VERSION SSLEAY_VERSION
#endif
if (QSslSocket::sslLibraryVersionString() != QLatin1String(OpenSSL_version(OPENSSL_VERSION)))
2017-07-03 09:30:10 +02:00
{
2019-01-03 15:06:22 +01:00
qCWarning(init) << "Linked OpenSSL Version differs:" << OpenSSL_version(OPENSSL_VERSION);
2017-07-03 09:30:10 +02:00
}
const auto libPathes = QCoreApplication::libraryPaths();
for (const auto& path : libPathes)
{
qCDebug(init) << "Library path:" << path;
}
}
2019-01-03 15:06:22 +01:00
static inline QCoreApplication* initQt(int& argc, char** argv)
2017-07-03 09:30:10 +02:00
{
2019-01-03 15:06:22 +01:00
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
2017-12-20 14:54:05 +01:00
QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
#endif
2019-09-30 17:22:19 +02:00
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
2017-12-20 14:54:05 +01:00
2017-07-03 09:30:10 +02:00
QCoreApplication::setOrganizationName(QStringLiteral(VENDOR));
QCoreApplication::setOrganizationDomain(QStringLiteral(VENDOR_DOMAIN));
2017-12-20 14:54:05 +01:00
QCoreApplication::setApplicationName(QStringLiteral(PRODUCT));
2017-07-03 09:30:10 +02:00
QCoreApplication::setApplicationVersion(QStringLiteral(VERSION));
2019-01-03 15:06:22 +01:00
#ifndef ANDROID_BUILD_AAR
2017-07-03 09:30:10 +02:00
QGuiApplication::setQuitOnLastWindowClosed(false);
2019-01-03 15:06:22 +01:00
#endif
2019-09-30 17:22:19 +02:00
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
QGuiApplication::setDesktopSettingsAware(false);
#endif
2019-01-03 15:06:22 +01:00
#if defined(Q_OS_ANDROID) && !defined(ANDROID_BUILD_AAR)
if (QtAndroid::androidService().isValid())
{
return new QAndroidService(argc, argv);
}
#endif
2017-07-03 09:30:10 +02:00
2019-01-03 15:06:22 +01:00
return new QAPP(argc, argv);
}
2019-09-30 17:22:19 +02:00
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) || (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID))
void restartApp(const QString& pApplicationFilePath, QStringList pArgumentList, int pArgc)
{
if (pArgumentList.size() == pArgc)
{
pArgumentList.removeFirst();
}
qCInfo(init) << "Attempting to start new process:" << pApplicationFilePath << ", args:" << pArgumentList;
qint64 pid = -1;
const bool restartSuccessful = QProcess::startDetached(pApplicationFilePath, pArgumentList, QString(), &pid);
if (restartSuccessful)
{
qCInfo(init) << "New process successfully launched, PID:" << pid;
}
else
{
qCCritical(init) << "Could not launch new process.";
}
}
#endif
2019-01-03 15:06:22 +01:00
Q_DECL_EXPORT int main(int argc, char** argv)
{
const QScopedPointer<QCoreApplication> app(initQt(argc, argv));
2017-07-03 09:30:10 +02:00
QThread::currentThread()->setObjectName(QStringLiteral("MainThread"));
CommandLineParser::getInstance().parse();
2019-01-03 15:06:22 +01:00
Env::getSingleton<LogHandler>()->init();
SignalHandler::getInstance().init();
2017-07-03 09:30:10 +02:00
printInfo();
AppController controller;
if (!controller.start())
{
qCCritical(init) << "Cannot start application controller, exit application";
return EXIT_FAILURE;
}
SignalHandler::getInstance().setController(controller);
2019-09-30 17:22:19 +02:00
if (SignalHandler::getInstance().shouldQuit())
{
return EXIT_SUCCESS;
}
const int returnCode = app->exec();
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) || (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID))
if (controller.shouldApplicationRestart())
{
restartApp(app->applicationFilePath(), app->arguments(), argc);
}
#endif
return returnCode;
2017-07-03 09:30:10 +02:00
}