From 0a3913970345f43dbaac55993934cfa360767a8c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 13 Feb 2011 00:22:53 -0500 Subject: [PATCH] Now zeroconf doesn't connect when offline either --- src/sip/zeroconf/zeroconf.cpp | 25 +++++++++++++++++++++++++ src/sip/zeroconf/zeroconf.h | 8 +++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/sip/zeroconf/zeroconf.cpp b/src/sip/zeroconf/zeroconf.cpp index c4b692214..e4d7783c7 100644 --- a/src/sip/zeroconf/zeroconf.cpp +++ b/src/sip/zeroconf/zeroconf.cpp @@ -17,15 +17,40 @@ ZeroconfPlugin::connectPlugin( bool /*startup*/ ) SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) ); m_zeroconf->advertise(); + + m_isOnline = true; + + foreach( QStringList *currNode, m_cachedNodes ) + { + QStringList nodeSet = *currNode; + if ( !Servent::instance()->connectedToSession( nodeSet[3] ) ) + Servent::instance()->connectToPeer( nodeSet[0], nodeSet[1].toInt(), "whitelist", nodeSet[2], nodeSet[3] ); + delete currNode; + } + m_cachedNodes.empty(); return true; } +void +ZeroconfPlugin::disconnectPlugin() +{ + m_isOnline = false; +} void ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ) { qDebug() << "Found LAN host:" << host << port << nodeid; + + if ( !m_isOnline ) + { + qDebug() << "Not online, so not connecting"; + QStringList *nodeSet = new QStringList(); + *nodeSet << host << QString::number( port ) << name << nodeid; + m_cachedNodes.insert( nodeSet ); + return; + } if ( !Servent::instance()->connectedToSession( nodeid ) ) Servent::instance()->connectToPeer( host, port, "whitelist", name, nodeid ); diff --git a/src/sip/zeroconf/zeroconf.h b/src/sip/zeroconf/zeroconf.h index 164a1c545..727bb84c0 100644 --- a/src/sip/zeroconf/zeroconf.h +++ b/src/sip/zeroconf/zeroconf.h @@ -16,6 +16,8 @@ class SIPDLLEXPORT ZeroconfPlugin : public SipPlugin public: ZeroconfPlugin() : m_zeroconf( 0 ) + , m_isOnline( false ) + , m_cachedNodes() {} virtual ~ZeroconfPlugin() {} @@ -26,9 +28,7 @@ public: public slots: virtual bool connectPlugin( bool startup ); - void disconnectPlugin() - { - } + void disconnectPlugin(); void sendMsg( const QString& to, const QString& msg ) { @@ -47,6 +47,8 @@ private slots: private: TomahawkZeroconf* m_zeroconf; + bool m_isOnline; + QSet< QStringList* > m_cachedNodes; }; #endif