-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
63 lines (54 loc) · 2.42 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "src/alarm/AlarmManager.h"
#include "src/datetime/DateTimeSource.h"
#include "src/location/LocationSource.h"
#include "src/network/NetworkManager.h"
#include "src/settings/SettingsManager.h"
#include "src/weather/WeatherSource.h"
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(maincpp, "main")
int main(int argc, char *argv[]) {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
qRegisterMetaType<WeatherInfo>("WeatherInfo");
qRegisterMetaType<QObjectList>("QObjectList");
QGuiApplication app(argc, argv);
DbManager dbManager;
if (!dbManager.open()) {
qCCritical(maincpp) << "Couldn't open database";
return 0;
}
QQmlApplicationEngine engine;
engine.addImportPath("qrc:///qml");
DateTimeSource dateTimeSource;
engine.rootContext()->setContextProperty("dateTimeSource", &dateTimeSource);
NetworkManager networkManager;
LocationSource locationSource(networkManager);
engine.rootContext()->setContextProperty("locationSource", &locationSource);
WeatherSource weatherSource(networkManager);
QObject::connect(&locationSource, &LocationSource::coordinateChanged,
&weatherSource, &WeatherSource::updateWeather);
engine.rootContext()->setContextProperty("weatherSource", &weatherSource);
AlarmManager alarmManager(dbManager);
engine.rootContext()->setContextProperty("alarmManager", &alarmManager);
SettingsManager settingsManager(dbManager);
QObject::connect(&settingsManager, &SettingsManager::languageChanged, &engine,
&QQmlApplicationEngine::retranslate);
QObject::connect(&settingsManager, &SettingsManager::localeChanged,
&dateTimeSource, &DateTimeSource::processNewLocale);
QObject::connect(&settingsManager, &SettingsManager::localeChanged,
&locationSource, &LocationSource::processNewLocale);
settingsManager.updateTranslations();
engine.rootContext()->setContextProperty("settingsManager", &settingsManager);
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) {
QCoreApplication::exit(-1);
}
},
Qt::QueuedConnection);
engine.load(url);
return app.exec();
}