-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
128 lines (99 loc) · 4.41 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <QGuiApplication>
#include <QQuickStyle>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <TabListModel.h>
#include "AccentsListModel.h"
#include "BuildConfig.h"
#include "NotificationHelper.h"
#include "PlatformHelper.h"
#include "Flags.h"
#include "Globals.h"
#include "ConnManager.h"
#include "TopicListModel.h"
#include "TopicStore.h"
#include <QTimer>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
app.setOrganizationName(BuildConfig.ORG_NAME);
app.setApplicationName(BuildConfig.APP_NAME);
app.setApplicationVersion(BuildConfig.versionString());
app.setWindowIcon(QIcon(":/" + BuildConfig.APP_NAME));
app.setDesktopFileName("" + BuildConfig.APP_NAME);
QQuickStyle::setStyle("Universal");
TopicStore store(&app);
TopicListModel *topics = new TopicListModel(store, &app);
SettingsManager *settings = new SettingsManager(&app);
TabListModel *tlm = new TabListModel(settings, &app);
ConnManager *conn = new ConnManager(&app);
AccentsListModel *accents = new AccentsListModel(&app);
accents->load();
PlatformHelper *platform = new PlatformHelper(&app);
NotificationHelper *notification = new NotificationHelper(&app);
Globals::inst.AddConnectionListener(true, [topics, &store, conn] (const nt::Event &event) {
bool connected = event.Is(nt::EventFlags::kConnected);
store.connect(connected);
if (!connected) {
QMetaObject::invokeMethod(topics, &TopicListModel::clear);
} else {
conn->setAddress(QString::fromStdString(event.GetConnectionInfo()->remote_ip));
}
conn->setConnected(connected);
});
Globals::inst.StartClient4(BuildConfig.APP_NAME.toStdString());
Globals::inst.StartDSClient(NT_DEFAULT_PORT4);
Globals::inst.AddListener({{""}}, nt::EventFlags::kTopic, [topics] (const nt::Event &event) {
std::string topicName(event.GetTopicInfo()->name);
if (event.Is(nt::EventFlags::kPublish)) {
QMetaObject::invokeMethod(topics, [topics, topicName] {
topics->add(QString::fromStdString(topicName));
});
} else if (event.Is(nt::EventFlags::kUnpublish)) {
// TODO: handle unpublishing
// topics->remove(QString::fromStdString(topicName));
}
});
nt::NetworkTableEntry tabEntry = Globals::inst.GetEntry("/QFRCDashboard/Tab");
Globals::inst.AddListener(tabEntry, nt::EventFlags::kValueAll, [tlm] (const nt::Event &event) {
std::string_view value = event.GetValueEventData()->value.GetString();
QString qvalue = QString::fromStdString(std::string{value});
QMetaObject::invokeMethod(tlm, [tlm, qvalue] {
tlm->selectTab(qvalue);
});
});
nt::NetworkTableEntry notificationEntry = Globals::inst.GetEntry("/QFRCDashboard/RobotNotifications");
Globals::inst.AddListener(notificationEntry, nt::EventFlags::kValueAll, [tlm, &app, notification] (const nt::Event &event) {
std::string_view value = event.GetValueEventData()->value.GetString();
QString qvalue = QString::fromStdString(std::string{value});
QJsonDocument doc = QJsonDocument::fromJson(qvalue.toUtf8());
QMetaObject::invokeMethod(notification, [doc, notification] {
notification->fromJson(doc);
});
});
qmlRegisterUncreatableMetaObject(
QFDFlags::staticMetaObject,
"QFDFlags",
1, 0,
"QFDFlags",
"Attempt to create uninstantiable object \"QFDFlags\" ignored"
);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("topics", topics);
engine.rootContext()->setContextProperty("settings", settings);
engine.rootContext()->setContextProperty("topicStore", &store);
engine.rootContext()->setContextProperty("tlm", tlm);
engine.rootContext()->setContextProperty("conn", conn);
engine.rootContext()->setContextProperty("accents", accents);
engine.rootContext()->setContextProperty("platformHelper", platform);
engine.rootContext()->setContextProperty("notificationHelper", notification);
engine.rootContext()->setContextProperty("buildConfig", &BuildConfig);
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("QFRCDashboard", "Main");
return app.exec();
}