Showing the changes to interface/src/ui/EntityScriptServerLogDialog.cpp (1 of 11 files). Show all
Unified · Split
| @@ -0,0 +1,58 @@ | ||
| 1 | +// | |
| 2 | +// EntityScriptServerLogDialog.cpp | |
| 3 | +// interface/src/ui | |
| 4 | +// | |
| 5 | +// Created by Clement Brisset on 1/31/17. | |
| 6 | +// Copyright 2017 High Fidelity, Inc. | |
| 7 | +// | |
| 8 | +// Distributed under the Apache License, Version 2.0. | |
| 9 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 10 | +// | |
| 11 | + | |
| 12 | +#include "EntityScriptServerLogDialog.h" | |
| 13 | + | |
| 14 | +EntityScriptServerLogDialog::EntityScriptServerLogDialog(QWidget* parent) : BaseLogDialog(parent) { | |
| 15 | + setWindowTitle("Entity Script Server Log"); | |
| 16 | + | |
| 17 | + auto nodeList = DependencyManager::get<NodeList>(); | |
| 18 | + auto& packetReceiver = nodeList->getPacketReceiver(); | |
| 19 | + packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket"); | |
| 20 | + | |
| 21 | + auto shouldEnableLog = [this] { | |
| 22 | + auto nodeList = DependencyManager::get<NodeList>(); | |
| 23 | + enableToEntityServerScriptLog(nodeList->getThisNodeCanRez() || nodeList->getThisNodeCanRezTmp()); | |
| 24 | + }; | |
| 25 | + QObject::connect(nodeList.data(), &NodeList::canRezChanged, this, shouldEnableLog); | |
| 26 | + QObject::connect(nodeList.data(), &NodeList::canRezTmpChanged, this, shouldEnableLog); | |
| 27 | + shouldEnableLog(); | |
| 28 | +} | |
| 29 | + | |
| 30 | +EntityScriptServerLogDialog::~EntityScriptServerLogDialog() { | |
| 31 | + enableToEntityServerScriptLog(false); | |
| 32 | +} | |
| 33 | + | |
| 34 | +void EntityScriptServerLogDialog::enableToEntityServerScriptLog(bool enable) { | |
| 35 | + auto nodeList = DependencyManager::get<NodeList>(); | |
| 36 | + | |
| 37 | + if (auto node = nodeList->soloNodeOfType(NodeType::EntityScriptServer)) { | |
| 38 | + auto packet = NLPacket::create(PacketType::EntityServerScriptLog, sizeof(bool), true); | |
| 39 | + packet->writePrimitive(enable); | |
| 40 | + nodeList->sendPacket(std::move(packet), *node); | |
| 41 | + | |
| 42 | + if (_subscribed != enable) { | |
| 43 | + if (enable) { | |
| 44 | + appendLogLine("====================== Subscribded to the Entity Script Server's log ======================"); | |
| 45 | + } else { | |
| 46 | + appendLogLine("==================== Unsubscribded from the Entity Script Server's log ===================="); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + _subscribed = enable; | |
| 50 | + } else { | |
| 51 | + qWarning() << "Entity Script Server not found"; | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |
| 55 | +void EntityScriptServerLogDialog::handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) { | |
| 56 | + auto lines = QString::fromUtf8(message->readAll()); | |
| 57 | + QMetaObject::invokeMethod(this, "appendLogLine", Q_ARG(QString, lines)); | |
| 58 | +} | |