2015-09-06 20:33:09 +02:00
|
|
|
#include "./initiatequick.h"
|
2018-05-20 01:54:08 +02:00
|
|
|
#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
|
|
|
|
2018-12-15 23:10:53 +01:00
|
|
|
// enable inline helper functions for Qt Quick provided by qtutilities
|
2018-06-16 13:23:13 +02:00
|
|
|
#define QT_UTILITIES_GUI_QTQUICK
|
2018-12-15 23:10:53 +01:00
|
|
|
|
2024-04-08 12:39:46 +02:00
|
|
|
// ensure QGuiApplication is defined before resources.h for desktop file name
|
|
|
|
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
|
|
|
#include <QApplication>
|
|
|
|
using App = QApplication;
|
|
|
|
#else
|
|
|
|
#include <QGuiApplication>
|
|
|
|
using App = QGuiApplication;
|
|
|
|
#endif
|
|
|
|
|
2024-03-31 13:49:34 +02:00
|
|
|
#include <qtutilities/misc/desktoputils.h>
|
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>
|
2024-03-26 22:54:10 +01:00
|
|
|
#include <qtutilities/settingsdialog/qtsettings.h>
|
2015-04-22 19:30:09 +02:00
|
|
|
|
2019-09-14 19:38:06 +02:00
|
|
|
#include <passwordfile/util/openssl.h>
|
|
|
|
|
2024-03-31 13:49:44 +02:00
|
|
|
#include <QDebug>
|
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
|
|
|
|
2024-03-31 22:43:09 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2019-06-10 22:44:59 +02:00
|
|
|
using namespace CppUtilities;
|
2019-09-14 19:38:06 +02:00
|
|
|
using namespace Util;
|
2015-09-01 20:18:13 +02:00
|
|
|
|
2015-04-22 19:30:09 +02:00
|
|
|
namespace QtGui {
|
|
|
|
|
2018-04-22 20:38:29 +02:00
|
|
|
int runQuickGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs, const QString &file)
|
2015-04-22 19:30:09 +02:00
|
|
|
{
|
2018-12-08 19:18:12 +01:00
|
|
|
// setup Android-specifics (logging, theming)
|
2018-09-04 00:52:43 +02:00
|
|
|
#ifdef Q_OS_ANDROID
|
2018-12-08 19:18:12 +01:00
|
|
|
setupAndroidSpecifics();
|
2018-09-04 00:52:43 +02:00
|
|
|
#endif
|
|
|
|
|
2019-09-14 19:38:06 +02:00
|
|
|
// 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;
|
2024-03-31 22:46:01 +02:00
|
|
|
auto application = App(argc, argv);
|
|
|
|
QObject::connect(&application, &QCoreApplication::aboutToQuit, &OpenSsl::clean);
|
2018-04-22 20:38:29 +02:00
|
|
|
|
2024-03-26 22:54:10 +01:00
|
|
|
// restore Qt settings
|
|
|
|
auto qtSettings = QtUtilities::QtSettings();
|
|
|
|
auto settings = QtUtilities::getSettings(QStringLiteral(PROJECT_NAME));
|
|
|
|
if (auto settingsError = QtUtilities::errorMessageForSettings(*settings); !settingsError.isEmpty()) {
|
|
|
|
qDebug() << settingsError;
|
|
|
|
}
|
|
|
|
qtSettings.restore(*settings);
|
|
|
|
qtSettings.apply();
|
2024-03-31 22:53:32 +02:00
|
|
|
|
|
|
|
// create controller and handle dark mode
|
|
|
|
// note: Not handling changes of the dark mode setting dynamically yet because it does not work with Kirigami.
|
|
|
|
// It looks like Kirigami does not follow the QCC2 theme (the Material.theme/Material.theme settings) but
|
|
|
|
// instead uses colors based on the initial palette. Not sure how to toggle Kirigami's palette in accordance
|
|
|
|
// with the QCC2 theme. Hence this code is disabled via APPLY_COLOR_SCHEME_DYNAMICALLY for now.
|
|
|
|
auto controller = Controller(*settings, file);
|
|
|
|
#ifdef APPLY_COLOR_SCHEME_DYNAMICALLY
|
|
|
|
QtUtilities::onDarkModeChanged(
|
|
|
|
[&qtSettings, &controller](bool isDarkModeEnabled) {
|
|
|
|
qtSettings.reapplyDefaultIconTheme(isDarkModeEnabled);
|
|
|
|
controller.setDarkModeEnabled(isDarkModeEnabled);
|
|
|
|
},
|
|
|
|
&controller);
|
|
|
|
#else
|
|
|
|
const auto isDarkModeEnabled = QtUtilities::isDarkModeEnabled().value_or(false);
|
|
|
|
qtSettings.reapplyDefaultIconTheme(isDarkModeEnabled);
|
|
|
|
controller.setDarkModeEnabled(isDarkModeEnabled);
|
2024-03-31 13:49:34 +02:00
|
|
|
#endif
|
2024-03-26 22:54:10 +01:00
|
|
|
|
2015-09-01 20:18:13 +02:00
|
|
|
// apply settings specified via command line args
|
2024-03-26 22:54:10 +01:00
|
|
|
qtConfigArgs.applySettings(qtSettings.hasCustomFont());
|
2018-06-16 13:23:13 +02:00
|
|
|
qtConfigArgs.applySettingsForQuickGui();
|
2024-03-26 22:54:10 +01:00
|
|
|
LOAD_QT_TRANSLATIONS;
|
2018-08-31 22:29:01 +02:00
|
|
|
|
2024-03-31 22:46:01 +02:00
|
|
|
// init QML engine
|
2024-03-17 23:06:06 +01:00
|
|
|
auto engine = QQmlApplicationEngine();
|
2018-09-04 00:52:43 +02:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
registerControllerForAndroid(&controller);
|
|
|
|
#endif
|
2024-03-31 22:43:09 +02:00
|
|
|
auto *const context = engine.rootContext();
|
2018-05-20 01:54:08 +02:00
|
|
|
context->setContextProperty(QStringLiteral("nativeInterface"), &controller);
|
2019-09-14 19:38:06 +02:00
|
|
|
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));
|
2022-05-02 21:08:31 +02:00
|
|
|
#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
|
2018-04-22 20:38:29 +02:00
|
|
|
|
2024-03-31 22:43:09 +02:00
|
|
|
// load main QML file; run event loop or exit if it cannot be loaded
|
|
|
|
const auto mainUrl = QUrl(QStringLiteral("qrc:/qml/main.qml"));
|
|
|
|
QObject::connect(
|
|
|
|
&engine, &QQmlApplicationEngine::objectCreated, &application,
|
|
|
|
[&mainUrl](QObject *obj, const QUrl &objUrl) {
|
|
|
|
if (!obj && objUrl == mainUrl) {
|
|
|
|
QCoreApplication::exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
engine.load(mainUrl);
|
2019-09-14 19:38:06 +02:00
|
|
|
return application.exec();
|
2015-04-22 19:30:09 +02:00
|
|
|
}
|
2017-09-29 17:17:12 +02:00
|
|
|
} // namespace QtGui
|