Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 385 files). Show all
Unified · Split
| @@ -542,7 +542,7 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS · 541 unmodified lines | |||
| 542 | 542 | ||
| 543 | QObject* TabletProxy::addButton(const QVariant& properties) { | 543 | QObject* TabletProxy::addButton(const QVariant& properties) { |
| 544 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); | 544 | auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap())); |
| 545 | std::lock_guard<std::mutex> guard(_tabletMutex); | 545 | std::unique_lock<std::mutex> guard(_tabletMutex); |
| 546 | _tabletButtonProxies.push_back(tabletButtonProxy); | 546 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 547 | if (!_toolbarMode && _qmlTabletRoot) { | 547 | if (!_toolbarMode && _qmlTabletRoot) { |
| 548 | auto tablet = getQmlTablet(); | 548 | auto tablet = getQmlTablet(); |
| @@ -552,7 +552,6 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 3 unmodified lines | |||
| 552 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; | 552 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; |
| 553 | } | 553 | } |
| 554 | } else if (_toolbarMode) { | 554 | } else if (_toolbarMode) { |
| 555 | |||
| 556 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | 555 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); |
| 557 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); | 556 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); |
| 558 | 557 | ||
| @@ -561,6 +560,8 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 2 unmodified lines | |||
| 561 | connectionType = Qt::BlockingQueuedConnection; | 560 | connectionType = Qt::BlockingQueuedConnection; |
| 562 | } | 561 | } |
| 563 | 562 | ||
| 563 | guard.unlock(); | ||
| 564 | |||
| 564 | // copy properties from tablet button proxy to toolbar button proxy. | 565 | // copy properties from tablet button proxy to toolbar button proxy. |
| 565 | QObject* toolbarButtonProxy = nullptr; | 566 | QObject* toolbarButtonProxy = nullptr; |
| 566 | bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, tabletButtonProxy->getProperties())); | 567 | bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, tabletButtonProxy->getProperties())); |
| @@ -578,31 +579,38 @@ bool TabletProxy::onHomeScreen() { · 11 unmodified lines | |||
| 578 | } | 579 | } |
| 579 | 580 | ||
| 580 | void TabletProxy::removeButton(QObject* tabletButtonProxy) { | 581 | void TabletProxy::removeButton(QObject* tabletButtonProxy) { |
| 581 | std::lock_guard<std::mutex> guard(_tabletMutex); | 582 | std::unique_lock<std::mutex> guard(_tabletMutex); |
| 582 | 583 | ||
| 583 | auto tablet = getQmlTablet(); | 584 | auto tablet = getQmlTablet(); |
| 584 | if (!tablet) { | 585 | if (!tablet) { |
| 585 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; | 586 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; |
| 586 | } | 587 | } |
| 587 | 588 | ||
| 588 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); | 589 | QSharedPointer<TabletButtonProxy> buttonProxy; |
| 589 | if (iter != _tabletButtonProxies.end()) { | 590 | { |
| 590 | if (!_toolbarMode && _qmlTabletRoot) { | 591 | auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); |
| 591 | (*iter)->setQmlButton(nullptr); | 592 | if (iter == _tabletButtonProxies.end()) { |
| 592 | if (tablet) { | 593 | qCWarning(scriptengine) << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; |
| 593 | QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | 594 | return; |
| 594 | } | ||
| 595 | } else if (_toolbarMode) { | ||
| 596 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | ||
| 597 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); | ||
| 598 | |||
| 599 | // remove button from toolbarProxy | ||
| 600 | QMetaObject::invokeMethod(toolbarProxy, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getUuid().toString())); | ||
| 601 | (*iter)->setToolbarButtonProxy(nullptr); | ||
| 602 | } | 595 | } |
| 596 | buttonProxy = *iter; | ||
| 603 | _tabletButtonProxies.erase(iter); | 597 | _tabletButtonProxies.erase(iter); |
| 604 | } else { | 598 | } |
| 605 | qCWarning(scriptengine) << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; | 599 | |
| 600 | if (!_toolbarMode && _qmlTabletRoot) { | ||
| 601 | buttonProxy->setQmlButton(nullptr); | ||
| 602 | if (tablet) { | ||
| 603 | guard.unlock(); | ||
| 604 | QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getProperties())); | ||
| 605 | } | ||
| 606 | } else if (_toolbarMode) { | ||
| 607 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); | ||
| 608 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); | ||
| 609 | |||
| 610 | // remove button from toolbarProxy | ||
| 611 | guard.unlock(); | ||
| 612 | QMetaObject::invokeMethod(toolbarProxy, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getUuid().toString())); | ||
| 613 | buttonProxy->setToolbarButtonProxy(nullptr); | ||
| 606 | } | 614 | } |
| 607 | } | 615 | } |
| 608 | 616 | ||