passwordmanager/quickgui/initiatequick.cpp

109 lines
3.4 KiB
C++
Raw Normal View History

2015-09-06 20:33:09 +02:00
#include "./initiatequick.h"
#include "./controller.h"
#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"
2015-12-05 22:52:00 +01:00
#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 <QGuiApplication>
#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 <QTextCodec>
#include <QtQml>
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
#include <QApplication>
#endif
2018-09-02 19:07:02 +02:00
#ifdef Q_OS_ANDROID
#include <QtAndroid>
#endif
2015-09-01 20:18:13 +02:00
using namespace ApplicationUtilities;
2015-04-22 19:30:09 +02:00
namespace QtGui {
2018-09-02 19:07:02 +02:00
#ifdef Q_OS_ANDROID
namespace Android {
namespace WindowManager {
namespace LayoutParams {
enum RelevantFlags {
TranslucentStatus = 0x04000000,
DrawsSystemBarBackgrounds = 0x80000000,
};
}
} // namespace WindowManager
} // namespace Android
2018-09-02 19:07:02 +02:00
#endif
int runQuickGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs, const QString &file)
2015-04-22 19:30:09 +02:00
{
// init application
2015-09-01 20:18:13 +02:00
SET_QT_APPLICATION_INFO;
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
2015-04-22 19:30:09 +02:00
QApplication a(argc, argv);
#else
QGuiApplication a(argc, argv);
#endif
2015-09-01 20:18:13 +02:00
// apply settings specified via command line args
qtConfigArgs.applySettings();
qtConfigArgs.applySettingsForQuickGui();
2018-08-31 22:29:01 +02:00
#ifdef Q_OS_ANDROID
// assume we're bundling breeze icons under Android
if (QIcon::themeName().isEmpty()) {
QIcon::setThemeName(QStringLiteral("breeze"));
}
#endif
2018-06-16 15:07:46 +02:00
// load settings from configuration file
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME));
// load translations
LOAD_QT_TRANSLATIONS;
// determine user paths
const QVariantMap userPaths{
{ QStringLiteral("desktop"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) },
{ QStringLiteral("documents"), QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) },
{ QStringLiteral("music"), QStandardPaths::writableLocation(QStandardPaths::MusicLocation) },
{ QStringLiteral("movies"), QStandardPaths::writableLocation(QStandardPaths::MoviesLocation) },
{ QStringLiteral("pictures"), QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) },
{ QStringLiteral("home"), QStandardPaths::writableLocation(QStandardPaths::HomeLocation) },
};
// init Quick GUI
QQmlApplicationEngine engine;
2018-06-16 15:07:46 +02:00
Controller controller(settings, file);
#ifdef Q_OS_ANDROID
registerControllerForAndroid(&controller);
#endif
2018-09-02 19:07:02 +02:00
auto *const context(engine.rootContext());
context->setContextProperty(QStringLiteral("userPaths"), userPaths);
context->setContextProperty(QStringLiteral("nativeInterface"), &controller);
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
2018-09-02 19:07:02 +02:00
#ifdef Q_OS_ANDROID
QtAndroid::runOnAndroidThread([=]() {
QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
window.callMethod<void>("addFlags", "(I)V", Android::WindowManager::LayoutParams::DrawsSystemBarBackgrounds);
window.callMethod<void>("clearFlags", "(I)V", Android::WindowManager::LayoutParams::TranslucentStatus);
window.callMethod<void>("setStatusBarColor", "(I)V", QColor("#2196f3").rgba());
window.callMethod<void>("setNavigationBarColor", "(I)V", QColor("#2196f3").rgba());
});
#endif
// run event loop
return a.exec();
2015-04-22 19:30:09 +02:00
}
2017-09-29 17:17:12 +02:00
} // namespace QtGui