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 | 543 | QObject* TabletProxy::addButton(const QVariant& properties) { |
| 544 | 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 | 546 | _tabletButtonProxies.push_back(tabletButtonProxy); |
| 547 | 547 | if (!_toolbarMode && _qmlTabletRoot) { |
| 548 | 548 | auto tablet = getQmlTablet(); |
| @@ -552,7 +552,6 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 3 unmodified lines | ||
| 552 | 552 | qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml"; |
| 553 | 553 | } |
| 554 | 554 | } else if (_toolbarMode) { |
| 555 | − | |
| 556 | 555 | auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); |
| 557 | 556 | QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); |
| 558 | 557 | |
| @@ -561,6 +560,8 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 2 unmodified lines | ||
| 561 | 560 | connectionType = Qt::BlockingQueuedConnection; |
| 562 | 561 | } |
| 563 | 562 | |
| 563 | + guard.unlock(); | |
| 564 | + | |
| 564 | 565 | // copy properties from tablet button proxy to toolbar button proxy. |
| 565 | 566 | QObject* toolbarButtonProxy = nullptr; |
| 566 | 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 | 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 | 584 | auto tablet = getQmlTablet(); |
| 584 | 585 | if (!tablet) { |
| 585 | 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 | − if (iter != _tabletButtonProxies.end()) { | |
| 590 | − if (!_toolbarMode && _qmlTabletRoot) { | |
| 591 | − (*iter)->setQmlButton(nullptr); | |
| 592 | − if (tablet) { | |
| 593 | − QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties())); | |
| 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); | |
| 589 | + QSharedPointer<TabletButtonProxy> buttonProxy; | |
| 590 | + { | |
| 591 | + auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy); | |
| 592 | + if (iter == _tabletButtonProxies.end()) { | |
| 593 | + qCWarning(scriptengine) << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; | |
| 594 | + return; | |
| 602 | 595 | } |
| 596 | + buttonProxy = *iter; | |
| 603 | 597 | _tabletButtonProxies.erase(iter); |
| 604 | − } else { | |
| 605 | − qCWarning(scriptengine) << "TabletProxy::removeButton() could not find button " << tabletButtonProxy; | |
| 598 | + } | |
| 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 | |