Showing the changes to interface/src/ui/EntityScriptServerLogDialog.cpp (1 of 6 files). Show all
Unified · Split
| @@ -11,58 +11,13 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | #include "EntityScriptServerLogDialog.h" |
| 13 | 13 | |
| 14 | +#include <EntityScriptServerLogClient.h> | |
| 15 | + | |
| 14 | 16 | EntityScriptServerLogDialog::EntityScriptServerLogDialog(QWidget* parent) : BaseLogDialog(parent) { |
| 15 | 17 | setWindowTitle("Entity Script Server Log"); |
| 16 | 18 | |
| 17 | − auto nodeList = DependencyManager::get<NodeList>(); | |
| 18 | − auto& packetReceiver = nodeList->getPacketReceiver(); | |
| 19 | − packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket"); | |
| 20 | − | |
| 21 | − QObject::connect(nodeList.data(), &NodeList::nodeActivated, this, &EntityScriptServerLogDialog::nodeActivated); | |
| 22 | − QObject::connect(nodeList.data(), &NodeList::nodeKilled, this, &EntityScriptServerLogDialog::nodeKilled); | |
| 23 | − | |
| 24 | − QObject::connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptServerLogDialog::enableToEntityServerScriptLog); | |
| 25 | − enableToEntityServerScriptLog(nodeList->getThisNodeCanRez()); | |
| 26 | −} | |
| 27 | − | |
| 28 | −EntityScriptServerLogDialog::~EntityScriptServerLogDialog() { | |
| 29 | − enableToEntityServerScriptLog(false); | |
| 30 | −} | |
| 31 | −void EntityScriptServerLogDialog::enableToEntityServerScriptLog(bool enable) { | |
| 32 | − auto nodeList = DependencyManager::get<NodeList>(); | |
| 33 | − | |
| 34 | − if (auto node = nodeList->soloNodeOfType(NodeType::EntityScriptServer)) { | |
| 35 | − auto packet = NLPacket::create(PacketType::EntityServerScriptLog, sizeof(bool), true); | |
| 36 | − packet->writePrimitive(enable); | |
| 37 | − nodeList->sendPacket(std::move(packet), *node); | |
| 38 | − | |
| 39 | − if (_subscribed != enable) { | |
| 40 | − if (enable) { | |
| 41 | − appendLogLine("====================== Subscribded to the Entity Script Server's log ======================"); | |
| 42 | − } else { | |
| 43 | − appendLogLine("==================== Unsubscribded from the Entity Script Server's log ===================="); | |
| 44 | − } | |
| 45 | − } | |
| 46 | − _subscribed = enable; | |
| 47 | − } else { | |
| 48 | − qWarning() << "Entity Script Server not found"; | |
| 49 | − } | |
| 50 | −} | |
| 51 | − | |
| 52 | −void EntityScriptServerLogDialog::handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) { | |
| 53 | − auto lines = QString::fromUtf8(message->readAll()); | |
| 54 | − QMetaObject::invokeMethod(this, "appendLogLine", Q_ARG(QString, lines)); | |
| 55 | −} | |
| 56 | − | |
| 57 | −void EntityScriptServerLogDialog::nodeActivated(SharedNodePointer activatedNode) { | |
| 58 | − if (_subscribed && activatedNode->getType() == NodeType::EntityScriptServer) { | |
| 59 | − _subscribed = false; | |
| 60 | − enableToEntityServerScriptLog(DependencyManager::get<NodeList>()->getThisNodeCanRez()); | |
| 61 | − } | |
| 62 | −} | |
| 63 | 19 | |
| 64 | −void EntityScriptServerLogDialog::nodeKilled(SharedNodePointer killedNode) { | |
| 65 | − if (killedNode->getType() == NodeType::EntityScriptServer) { | |
| 66 | − appendLogLine("====================== Connection to the Entity Script Server lost ======================"); | |
| 67 | − } | |
| 20 | + auto client = DependencyManager::get<EntityScriptServerLogClient>(); | |
| 21 | + QObject::connect(client.data(), &EntityScriptServerLogClient::receivedNewLogLines, | |
| 22 | + this, &EntityScriptServerLogDialog::appendLogLine); | |
| 68 | 23 | } |