87 lines
2.3 KiB
C++
Raw Normal View History

2020-05-23 02:31:12 +03:00
/*
* Copyright (C) 2018-2021 QuasarApp.
2020-05-23 02:31:12 +03:00
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
2020-04-01 09:36:17 +03:00
#include <QGuiApplication>
2018-05-13 23:11:35 +03:00
#include <QFont>
#include <QFontDatabase>
2018-05-12 17:24:40 +03:00
#include <iostream>
2018-01-20 17:44:28 +03:00
#include <QQmlApplicationEngine>
#include <QQmlComponent>
2019-10-07 18:16:54 +03:00
#include <QQmlContext>
2018-04-11 20:27:22 +03:00
#include "backEnd.h"
2018-04-11 23:10:52 +03:00
#include <QTranslator>
#include <qmlnotifyservice.h>
2021-03-19 22:02:37 +03:00
#include <credits.h>
2018-05-13 23:11:35 +03:00
2020-04-01 09:36:17 +03:00
void setFont(const QGuiApplication& app){
2018-05-13 23:11:35 +03:00
QString fontPath = "://ubuntu";
int fontId = QFontDatabase::addApplicationFont(fontPath);
if (fontId != -1)
{
QFont font(QFontDatabase::applicationFontFamilies(fontId).at(0));
app.setFont(font);
}
}
2020-04-01 09:36:17 +03:00
bool initLocale(const QString &locale, QGuiApplication& app, QTranslator &translator){
2018-05-12 17:24:40 +03:00
QString defaultLocale = QLocale::system().name();
defaultLocale.truncate(defaultLocale.lastIndexOf('_'));
if(!locale.isEmpty() && translator.load(QString(":/languages/%0").arg(locale))){
return app.installTranslator(&translator);
}
if(!translator.load(QString(":/languages/%0").arg(defaultLocale))){
return false;
}
return app.installTranslator(&translator);
}
2018-01-20 17:44:28 +03:00
int main(int argc, char *argv[])
{
2020-05-05 09:43:18 +03:00
QGuiApplication::setApplicationName("HanoiTowers"); // <--
QGuiApplication::setOrganizationName("QuasarApp"); // <--
QGuiApplication::setOrganizationDomain("https://github.com/QuasarApp"); // <--
2018-07-15 12:18:30 +03:00
2020-04-01 09:36:17 +03:00
QGuiApplication app(argc, argv);
2018-05-13 23:11:35 +03:00
setFont(app);
2018-04-11 23:10:52 +03:00
QTranslator translator;
2018-05-12 17:24:40 +03:00
QString locale = "";
if(argc > 1) {
locale = QString::fromLatin1(argv[1]);
}
2018-04-11 23:10:52 +03:00
2018-05-12 17:24:40 +03:00
if(!initLocale(locale, app, translator)){
std::cout << "error load language : " << locale.toStdString() <<std::endl;
}
2018-04-11 23:10:52 +03:00
2018-01-20 17:44:28 +03:00
QQmlApplicationEngine engine;
2020-05-24 02:24:49 +03:00
BackEnd back(&engine);
2019-10-07 18:16:54 +03:00
auto root = engine.rootContext();
if (!QmlNotificationService::init(&engine)) {
return 1;
}
2021-03-19 22:02:37 +03:00
if (!QuasarAppCredits::init(&engine)) {
return 2;
}
2019-10-07 18:16:54 +03:00
root->setContextProperty("backEnd", &back);
root->setContextProperty("OnlineStatusQml", QVariant::fromValue(OnlineStatusQml{}));
2019-09-30 18:02:01 +03:00
2018-01-20 17:44:28 +03:00
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}