passwordmanager/quickgui/initiatequick.cpp

111 lines
3.3 KiB
C++
Raw Normal View History

2015-09-06 20:33:09 +02:00
#include "./initiatequick.h"
#include "./controller.h"
2018-09-04 00:52:43 +02:00
#ifdef Q_OS_ANDROID
#include "./android.h"
#endif
2015-04-22 19:30:09 +02:00
2016-04-25 22:06:24 +02:00
#include "resources/config.h"
2019-03-13 19:09:31 +01:00
#include "resources/qtconfig.h"
2015-12-05 22:52:00 +01:00
// enable inline helper functions for Qt Quick provided by qtutilities
#define QT_UTILITIES_GUI_QTQUICK
2015-09-01 20:18:13 +02:00
#include <qtutilities/resources/qtconfigarguments.h>
2015-04-22 19:30:09 +02:00
#include <qtutilities/resources/resources.h>
#include <passwordfile/util/openssl.h>
2015-04-22 19:30:09 +02:00
#include <QGuiApplication>
2018-09-04 00:52:43 +02:00
#include <QIcon>
2017-05-01 03:26:04 +02:00
#include <QQmlApplicationEngine>
2018-09-02 19:07:02 +02:00
#include <QQmlContext>
2018-06-16 15:07:46 +02:00
#include <QSettings>
2015-04-22 19:30:09 +02:00
#include <QtQml>
#ifdef Q_OS_ANDROID
#include <QDebug>
#include <QDirIterator>
#endif
2015-04-22 19:30:09 +02:00
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
#include <QApplication>
#endif
2019-06-10 22:44:59 +02:00
using namespace CppUtilities;
using namespace Util;
2015-09-01 20:18:13 +02:00
2015-04-22 19:30:09 +02:00
namespace QtGui {
int runQuickGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs, const QString &file)
2015-04-22 19:30:09 +02:00
{
// setup Android-specifics (logging, theming)
2018-09-04 00:52:43 +02:00
#ifdef Q_OS_ANDROID
setupAndroidSpecifics();
2018-09-04 00:52:43 +02:00
#endif
// work around kirigami plugin trying to be clever
if (!qEnvironmentVariableIsSet("XDG_CURRENT_DESKTOP")) {
qputenv("XDG_CURRENT_DESKTOP", QByteArray("please don't override my settings"));
}
// init OpenSSL
OpenSsl::init();
2015-04-22 19:30:09 +02:00
// init application
2015-09-01 20:18:13 +02:00
SET_QT_APPLICATION_INFO;
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
QApplication application(argc, argv);
2015-04-22 19:30:09 +02:00
#else
QGuiApplication application(argc, argv);
2015-04-22 19:30:09 +02:00
#endif
2015-09-01 20:18:13 +02:00
// apply settings specified via command line args
qtConfigArgs.applySettings();
qtConfigArgs.applySettingsForQuickGui();
// assume we're bundling breeze icons
2018-08-31 22:29:01 +02:00
if (QIcon::themeName().isEmpty()) {
QIcon::setThemeName(QStringLiteral("breeze"));
}
// log resource information
2019-06-12 21:02:57 +02:00
#if defined(Q_OS_ANDROID) && defined(CPP_UTILITIES_DEBUG_BUILD)
qDebug() << "Using icon theme" << QIcon::themeName();
qDebug() << "Icon theme search paths" << QIcon::themeSearchPaths();
qDebug() << "Resources:";
QDirIterator it(QStringLiteral(":/"), QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.next();
}
#endif
2018-06-16 15:07:46 +02:00
// load settings from configuration file
auto settings = QtUtilities::getSettings(QStringLiteral(PROJECT_NAME));
2018-06-16 15:07:46 +02:00
// load translations
LOAD_QT_TRANSLATIONS;
// init Quick GUI
auto controller = Controller(*settings, file);
auto engine = QQmlApplicationEngine();
2018-09-04 00:52:43 +02:00
#ifdef Q_OS_ANDROID
registerControllerForAndroid(&controller);
#endif
2018-09-02 19:07:02 +02:00
auto *const context(engine.rootContext());
context->setContextProperty(QStringLiteral("nativeInterface"), &controller);
context->setContextProperty(QStringLiteral("app"), &application);
2018-12-03 18:11:42 +01:00
context->setContextProperty(QStringLiteral("description"), QStringLiteral(APP_DESCRIPTION));
context->setContextProperty(QStringLiteral("dependencyVersions"), QStringList(DEPENCENCY_VERSIONS));
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
const auto importPaths = qEnvironmentVariable(PROJECT_VARNAME_UPPER "_QML_IMPORT_PATHS").split(QChar(':'));
for (const auto &path : importPaths) {
engine.addImportPath(path);
}
#endif
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
// run event loop
QObject::connect(&application, &QCoreApplication::aboutToQuit, &OpenSsl::clean);
return application.exec();
2015-04-22 19:30:09 +02:00
}
2017-09-29 17:17:12 +02:00
} // namespace QtGui