1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 22:56:42 +02:00

Add 60 second timer to send out zeroconf advertisements. Fixes issues with peers never appearing.

This commit is contained in:
Jeff Mitchell
2011-09-24 13:13:41 -04:00
parent 999e0ad4c2
commit f61d0a07b1
2 changed files with 23 additions and 4 deletions

View File

@@ -20,6 +20,8 @@
#include <QtPlugin> #include <QtPlugin>
#include <QtCore/QTimer>
#include "tomahawksettings.h" #include "tomahawksettings.h"
#include "utils/logger.h" #include "utils/logger.h"
@@ -39,6 +41,9 @@ ZeroconfPlugin::ZeroconfPlugin ( const QString& pluginId )
, m_cachedNodes() , m_cachedNodes()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_advertisementTimer.setInterval( 60000 );
m_advertisementTimer.setSingleShot( false );
connect( &m_advertisementTimer, SIGNAL( timeout() ), this, SLOT( advertise() ) );
} }
ZeroconfPlugin::~ZeroconfPlugin() {} ZeroconfPlugin::~ZeroconfPlugin() {}
@@ -75,16 +80,14 @@ ZeroconfFactory::icon() const
bool bool
ZeroconfPlugin::connectPlugin( bool startup ) ZeroconfPlugin::connectPlugin( bool /*startup*/ )
{ {
Q_UNUSED( startup );
delete m_zeroconf; delete m_zeroconf;
m_zeroconf = new TomahawkZeroconf( Servent::instance()->port(), this ); m_zeroconf = new TomahawkZeroconf( Servent::instance()->port(), this );
QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( QString, int, QString, QString ) ), QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( QString, int, QString, QString ) ),
SLOT( lanHostFound( QString, int, QString, QString ) ) ); SLOT( lanHostFound( QString, int, QString, QString ) ) );
m_zeroconf->advertise(); advertise();
m_state = Connected; m_state = Connected;
foreach( const QStringList& nodeSet, m_cachedNodes ) foreach( const QStringList& nodeSet, m_cachedNodes )
@@ -93,12 +96,16 @@ ZeroconfPlugin::connectPlugin( bool startup )
Servent::instance()->connectToPeer( nodeSet[0], nodeSet[1].toInt(), "whitelist", nodeSet[2], nodeSet[3] ); Servent::instance()->connectToPeer( nodeSet[0], nodeSet[1].toInt(), "whitelist", nodeSet[2], nodeSet[3] );
} }
m_cachedNodes.clear(); m_cachedNodes.clear();
m_advertisementTimer.start();
return true; return true;
} }
void void
ZeroconfPlugin::disconnectPlugin() ZeroconfPlugin::disconnectPlugin()
{ {
m_advertisementTimer.stop();
m_state = Disconnected; m_state = Disconnected;
delete m_zeroconf; delete m_zeroconf;
@@ -112,6 +119,13 @@ ZeroconfPlugin::icon() const
} }
void
ZeroconfPlugin::advertise()
{
m_zeroconf->advertise();
}
void void
ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ) ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid )
{ {

View File

@@ -24,6 +24,8 @@
#include "../sipdllmacro.h" #include "../sipdllmacro.h"
#include <QtCore/QTimer>
#define MYNAME "Local Network" #define MYNAME "Local Network"
class SIPDLLEXPORT ZeroconfFactory : public SipPluginFactory class SIPDLLEXPORT ZeroconfFactory : public SipPluginFactory
@@ -65,6 +67,8 @@ public slots:
virtual bool connectPlugin( bool startup ); virtual bool connectPlugin( bool startup );
void disconnectPlugin(); void disconnectPlugin();
void advertise();
void sendMsg( const QString& , const QString& ) {} void sendMsg( const QString& , const QString& ) {}
void broadcastMsg( const QString & ) {} void broadcastMsg( const QString & ) {}
void addContact( const QString &, const QString& ) {} void addContact( const QString &, const QString& ) {}
@@ -76,6 +80,7 @@ private:
TomahawkZeroconf* m_zeroconf; TomahawkZeroconf* m_zeroconf;
ConnectionState m_state; ConnectionState m_state;
QVector<QStringList> m_cachedNodes; QVector<QStringList> m_cachedNodes;
QTimer m_advertisementTimer;
}; };
#endif #endif