History

Added username to tablet header

Anthony J. Thibault committed 9 years ago

Commit bff0eee1 parent d2f024e3 files · +48 −9Browse files

Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 3 files). Show all

Unified · Split

libraries/script-engine/src/TabletScriptingInterface.cpp+22−1
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111 #include <QtCore/QThread>
1212
1313 #include <AudioInjector.h>
14+#include <AccountManager.h>
1415 #include <PathUtils.h>
1516 #include <RegisteredMetaTypes.h>
1617 #include "ScriptEngineLogging.h"
@@ -166,6 +167,16 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 149 unmodified lines
166167 buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton));
167168 }
168169
170+static QString getUsername() {
171+ QString username = "Unknown user";
172+ auto accountManager = DependencyManager::get<AccountManager>();
173+ if (accountManager->isLoggedIn()) {
174+ return accountManager->getAccountInfo().getUsername();
175+ } else {
176+ return "Unknown user";
177+ }
178+}
179+
169180 void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) {
170181 std::lock_guard<std::mutex> guard(_mutex);
171182 _qmlOffscreenSurface = qmlOffscreenSurface;
@@ -173,6 +184,16 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr · 1 unmodified line
173184 if (_qmlTabletRoot && _qmlOffscreenSurface) {
174185 QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant)));
175186 gotoHomeScreen();
187+
188+ QMetaObject::invokeMethod(_qmlTabletRoot, "setUsername", Q_ARG(const QVariant&, QVariant(getUsername())));
189+
190+ // hook up username changed signal.
191+ auto accountManager = DependencyManager::get<AccountManager>();
192+ QObject::connect(accountManager.data(), &AccountManager::profileChanged, [this]() {
193+ if (_qmlTabletRoot) {
194+ QMetaObject::invokeMethod(_qmlTabletRoot, "setUsername", Q_ARG(const QVariant&, QVariant(getUsername())));
195+ }
196+ });
176197 } else {
177198 removeButtonsFromHomeScreen();
178199 _state = State::Uninitialized;
@@ -196,7 +217,7 @@ void TabletProxy::gotoHomeScreen() { · 17 unmodified lines
196217 auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
197218 QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
198219 QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL)));
199− QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound");
220+ QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound");
200221 _state = State::Home;
201222 }
202223 }