From bdc31a3b480e72f9f8d5b4853e0b30a03ca1b804 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jan 2014 11:38:05 -0800 Subject: [PATCH] replace the DomainChangeListener class with a signal/slot combo --- interface/src/Application.cpp | 10 +++++----- interface/src/Application.h | 6 +++--- libraries/shared/src/NodeList.cpp | 25 ++----------------------- libraries/shared/src/NodeList.h | 12 ++---------- 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5a6aec5fe8..ddec0554f8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -176,7 +176,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : nodeList->addHook(&_voxels); nodeList->addHook(this); - nodeList->addDomainListener(this); + + connect(nodeList, SIGNAL(domainChanged(const QString&)), SLOT(domainChanged(const QString&))); // network receive thread and voxel parsing thread are both controlled by the --nonblocking command line _enableProcessVoxelsThread = _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking"); @@ -265,7 +266,6 @@ Application::~Application() { storeSizeAndPosition(); NodeList::getInstance()->removeHook(&_voxels); NodeList::getInstance()->removeHook(this); - NodeList::getInstance()->removeDomainListener(this); _sharedVoxelSystem.changeTree(new VoxelTree); @@ -4184,9 +4184,9 @@ void Application::updateWindowTitle(){ _window->setWindowTitle(title); } -void Application::domainChanged(QString domain) { +void Application::domainChanged(const QString& domainHostname) { // update the user's last domain in their Profile (which will propagate to data-server) - _profile.updateDomain(domain); + _profile.updateDomain(domainHostname); updateWindowTitle(); @@ -4199,7 +4199,7 @@ void Application::domainChanged(QString domain) { _particleServerJurisdictions.clear(); // reset our persist thread - qDebug() << "domainChanged()... domain=" << domain << " swapping persist cache\n"; + qDebug() << "domainChanged()... domain=" << domainHostname << " swapping persist cache\n"; updateLocalOctreeCache(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 1da7de0224..876454d396 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -95,7 +95,7 @@ static const float NODE_KILLED_RED = 1.0f; static const float NODE_KILLED_GREEN = 0.0f; static const float NODE_KILLED_BLUE = 0.0f; -class Application : public QApplication, public NodeListHook, public PacketSenderNotify, public DomainChangeListener { +class Application : public QApplication, public NodeListHook, public PacketSenderNotify { Q_OBJECT friend class VoxelPacketProcessor; @@ -198,8 +198,6 @@ public: virtual void nodeKilled(Node* node); virtual void packetSentNotification(ssize_t length); - virtual void domainChanged(QString domain); - VoxelShader& getVoxelShader() { return _voxelShader; } PointShader& getPointShader() { return _pointShader; } FileLogger* getLogger() { return _logger; } @@ -214,6 +212,8 @@ public: void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } public slots: + void domainChanged(const QString& domainHostname); + void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data); void exportVoxels(); void importVoxels(); diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 0a50a659b2..8df4b6008f 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -103,7 +103,7 @@ void NodeList::setDomainHostname(const QString& domainHostname) { // reset our _domainIP to the null address so that a lookup happens on next check in _domainSockAddr.setAddress(QHostAddress::Null); - notifyDomainChanged(); + emit domainChanged(_domainHostname); } } @@ -848,7 +848,7 @@ void NodeList::loadData(QSettings *settings) { if (domainServerHostname.size() > 0) { _domainHostname = domainServerHostname; - notifyDomainChanged(); + emit domainChanged(_domainHostname); } settings->endGroup(); @@ -942,21 +942,6 @@ void NodeListIterator::skipDeadAndStopIncrement() { } } -void NodeList::addDomainListener(DomainChangeListener* listener) { - _domainListeners.push_back(listener); - QString domain = _domainHostname.isEmpty() ? _domainSockAddr.getAddress().toString() : _domainHostname; - listener->domainChanged(domain); -} - -void NodeList::removeDomainListener(DomainChangeListener* listener) { - for (int i = 0; i < _domainListeners.size(); i++) { - if (_domainListeners[i] == listener) { - _domainListeners.erase(_domainListeners.begin() + i); - return; - } - } -} - void NodeList::addHook(NodeListHook* hook) { _hooks.push_back(hook); } @@ -983,9 +968,3 @@ void NodeList::notifyHooksOfKilledNode(Node* node) { _hooks[i]->nodeKilled(node); } } - -void NodeList::notifyDomainChanged() { - for (int i = 0; i < _domainListeners.size(); i++) { - _domainListeners[i]->domainChanged(_domainHostname); - } -} diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 47cdbac99d..62137f34f1 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -52,11 +52,6 @@ public: virtual void nodeKilled(Node* node) = 0; }; -class DomainChangeListener { -public: - virtual void domainChanged(QString domain) = 0; -}; - class NodeList : public QObject { Q_OBJECT public: @@ -134,14 +129,13 @@ public: void notifyHooksOfAddedNode(Node* node); void notifyHooksOfKilledNode(Node* node); - void addDomainListener(DomainChangeListener* listener); - void removeDomainListener(DomainChangeListener* listener); - const HifiSockAddr* getNodeActiveSocketOrPing(Node* node); public slots: void sendDomainServerCheckIn(); void pingInactiveNodes(); void removeSilentNodes(); +signals: + void domainChanged(const QString& domainHostname); private: static NodeList* _sharedInstance; @@ -175,10 +169,8 @@ private: void timePingReply(const HifiSockAddr& nodeAddress, unsigned char *packetData); std::vector _hooks; - std::vector _domainListeners; void resetDomainData(char domainField[], const char* domainData); - void notifyDomainChanged(); void domainLookup(); };