Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -11,6 +11,7 @@ · 10 unmodified lines | |||
| 11 | #include <QtCore/QThread> | 11 | #include <QtCore/QThread> |
| 12 | 12 | ||
| 13 | #include <AudioInjector.h> | 13 | #include <AudioInjector.h> |
| 14 | #include <AccountManager.h> | ||
| 14 | #include <PathUtils.h> | 15 | #include <PathUtils.h> |
| 15 | #include <RegisteredMetaTypes.h> | 16 | #include <RegisteredMetaTypes.h> |
| 16 | #include "ScriptEngineLogging.h" | 17 | #include "ScriptEngineLogging.h" |
| @@ -166,6 +167,16 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 149 unmodified lines | |||
| 166 | buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton)); | 167 | buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton)); |
| 167 | } | 168 | } |
| 168 | 169 | ||
| 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 | |||
| 169 | void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) { | 180 | void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) { |
| 170 | std::lock_guard<std::mutex> guard(_mutex); | 181 | std::lock_guard<std::mutex> guard(_mutex); |
| 171 | _qmlOffscreenSurface = qmlOffscreenSurface; | 182 | _qmlOffscreenSurface = qmlOffscreenSurface; |
| @@ -173,6 +184,16 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr · 1 unmodified line | |||
| 173 | if (_qmlTabletRoot && _qmlOffscreenSurface) { | 184 | if (_qmlTabletRoot && _qmlOffscreenSurface) { |
| 174 | QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant))); | 185 | QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant))); |
| 175 | gotoHomeScreen(); | 186 | 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 | }); | ||
| 176 | } else { | 197 | } else { |
| 177 | removeButtonsFromHomeScreen(); | 198 | removeButtonsFromHomeScreen(); |
| 178 | _state = State::Uninitialized; | 199 | _state = State::Uninitialized; |
| @@ -196,7 +217,7 @@ void TabletProxy::gotoHomeScreen() { · 17 unmodified lines | |||
| 196 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); | 217 | auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); |
| 197 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); | 218 | QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); |
| 198 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); | 219 | QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); |
| 199 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); | 220 | QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound"); |
| 200 | _state = State::Home; | 221 | _state = State::Home; |
| 201 | } | 222 | } |
| 202 | } | 223 | } |