1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-02-26 21:03:31 +01:00

* Moved zeroconf code into a separate sip plugin (we might want to re-think the SipPlugin interface).

This commit is contained in:
Christian Muehlhaeuser 2010-12-15 15:11:33 +01:00
parent 3b507ff7a8
commit 857763e31d
10 changed files with 120 additions and 48 deletions

View File

@ -30,7 +30,6 @@
class AudioEngine;
class Database;
class SipHandler;
class TomahawkZeroconf;
class TomahawkSettings;
class XMPPBot;
@ -97,9 +96,6 @@ signals:
public slots:
QSharedPointer<QIODevice> getIODeviceForUrl( const Tomahawk::result_ptr& result );
private slots:
void lanHostFound( const QString&, int, const QString&, const QString& );
private:
void initLocalCollection();
void loadPlugins();
@ -118,7 +114,6 @@ private:
Database* m_db;
Servent m_servent;
SourceList m_sources;
TomahawkZeroconf* m_zeroconf;
SipHandler* m_sipHandler;
XMPPBot* m_xmppBot;

View File

@ -225,7 +225,6 @@ SET( tomahawkHeaders ${tomahawkHeaders}
musicscanner.h
scriptresolver.h
tomahawksettings.h
tomahawkzeroconf.h
scrobbler.h
xmppbot/xmppbot.h
@ -332,6 +331,7 @@ IF( UNIX )
ENDIF( UNIX )
ADD_SUBDIRECTORY( sip/jabber )
ADD_SUBDIRECTORY( sip/zeroconf )
kde4_add_app_icon( tomahawkSources "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/tomahawk-icon-*.png" )
qt4_add_resources( RC_SRCS "../resources.qrc" )

View File

@ -30,16 +30,17 @@ SipHandler::loadPlugins()
QDir pluginsDir( TomahawkApp::instance()->applicationDirPath() );
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
if ( pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release" )
pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (pluginsDir.dirName() == "MacOS") {
if ( pluginsDir.dirName() == "MacOS" )
{
pluginsDir.cdUp();
pluginsDir.cdUp();
pluginsDir.cdUp();
}
#endif
pluginsDir.cd("plugins");
pluginsDir.cd( "plugins" );
foreach ( QString fileName, pluginsDir.entryList( QDir::Files ) )
{
@ -122,14 +123,6 @@ SipHandler::onPeerOnline( const QString& jid )
conn->setName( jid.left( jid.indexOf( "/" ) ) );
conn->setId( nodeid );
// FIXME strip /resource, but we should use a UID per database install
//QString uniqname = jid.left( jid.indexOf("/") );
//conn->setName( uniqname ); //FIXME
// FIXME:
//QString ouruniqname = m_settings->value( "jabber/username" ).toString()
// .left( m_settings->value( "jabber/username" ).toString().indexOf("/") );
APP->servent().registerOffer( key, conn );
m["visible"] = true;
m["ip"] = APP->servent().externalAddress().toString();
@ -187,11 +180,11 @@ SipHandler::onMessage( const QString& from, const QString& msg )
APP->servent().externalAddress().toString() <= m.value( "ip" ).toString() )
{
qDebug() << "Initiate connection to" << from;
APP->servent().connectToPeer( m.value( "ip" ).toString(),
m.value( "port" ).toInt(),
m.value( "key" ).toString(),
from,
m.value( "uniqname" ).toString() );
APP->servent().connectToPeer( m.value( "ip" ).toString(),
m.value( "port" ).toInt(),
m.value( "key" ).toString(),
from,
m.value( "uniqname" ).toString() );
}
else
{
@ -201,8 +194,6 @@ SipHandler::onMessage( const QString& from, const QString& msg )
else
{
qDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm";
// if ( m_servent.visibleExternally() )
// jabberPeerOnline( from ); // HACK FIXME
}
}

View File

@ -27,7 +27,7 @@ signals:
void peerOnline( const QString& );
void peerOffline( const QString& );
void msgReceived( const QString&, const QString& );
void msgReceived( const QString& from, const QString& msg );
};
Q_DECLARE_INTERFACE( SipPlugin, "tomahawk.Sip/1.0" )

View File

@ -0,0 +1,33 @@
project( tomahawk )
include( ${QT_USE_FILE} )
add_definitions( ${QT_DEFINITIONS} )
add_definitions( -DQT_PLUGIN )
add_definitions( -DQT_SHARED )
set( zeroconfSources
zeroconf.cpp
)
set( zeroconfHeaders
zeroconf.h
tomahawkzeroconf.h
)
include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
${QT_INCLUDE_DIR}
)
qt4_wrap_cpp( zeroconfMoc ${zeroconfHeaders} )
add_library( sip_zeroconf SHARED ${zeroconfSources} ${zeroconfMoc} )
target_link_libraries( sip_zeroconf
${QT_LIBRARIES}
${GLOOX_LIBS}
)
IF( APPLE )
SET( CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-undefined dynamic_lookup" )
ENDIF( APPLE )
install( TARGETS sip_zeroconf DESTINATION . )

View File

@ -0,0 +1,30 @@
#include "zeroconf.h"
#include "tomahawk/tomahawkapp.h"
#include "tomahawksettings.h"
bool
ZeroconfPlugin::connect()
{
delete m_zeroconf;
m_zeroconf = new TomahawkZeroconf( APP->servent().port(), this );
QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ),
SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) );
m_zeroconf->advertise();
return true;
}
void
ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid )
{
qDebug() << "Found LAN host:" << host << port << nodeid;
if ( !APP->servent().connectedToSession( nodeid ) )
APP->servent().connectToPeer( host, port, "whitelist", name, nodeid );
}
Q_EXPORT_PLUGIN2( sip, ZeroconfPlugin )

View File

@ -0,0 +1,45 @@
#ifndef ZEROCONF_H
#define ZEROCONF_H
#include "SipPlugin.h"
#include "tomahawkzeroconf.h"
class ZeroconfPlugin : public SipPlugin
{
Q_OBJECT
Q_INTERFACES( SipPlugin )
public:
ZeroconfPlugin()
: m_zeroconf( 0 )
{}
virtual ~ZeroconfPlugin() {}
public slots:
virtual bool connect();
void disconnect()
{
}
void sendMsg( const QString& to, const QString& msg )
{
}
void broadcastMsg( const QString &msg )
{
}
void addContact( const QString &jid, const QString& msg = QString() )
{
}
private slots:
void lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid );
private:
TomahawkZeroconf* m_zeroconf;
};
#endif

View File

@ -21,7 +21,6 @@
#include "scriptresolver.h"
#include "audioengine.h"
#include "tomahawkzeroconf.h"
#ifndef TOMAHAWK_HEADLESS
#include "tomahawkwindow.h"
@ -102,7 +101,6 @@ using namespace Tomahawk;
TomahawkApp::TomahawkApp( int& argc, char *argv[] )
: TOMAHAWK_APPLICATION( argc, argv )
, m_audioEngine( 0 )
, m_zeroconf( 0 )
, m_settings( 0 )
, m_nam( 0 )
, m_proxy( 0 )
@ -198,15 +196,6 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
if( arguments().contains( "--http" ) || settings()->value( "network/http", true ).toBool() )
startHTTP();
if ( !arguments().contains( "--nozeroconf" ) )
{
// advertise our servent on the LAN
m_zeroconf = new TomahawkZeroconf( m_servent.port(), this );
connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ),
SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) );
m_zeroconf->advertise();
}
m_sipHandler->connect();
#ifndef TOMAHAWK_HEADLESS
@ -229,7 +218,6 @@ TomahawkApp::~TomahawkApp()
delete m_audioEngine;
#endif
delete m_zeroconf;
delete m_db;
m_db = 0;
@ -316,16 +304,6 @@ TomahawkApp::setupDatabase()
}
void
TomahawkApp::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid )
{
qDebug() << "Found LAN host:" << host << port << nodeid;
if ( !m_servent.connectedToSession( nodeid ) )
m_servent.connectToPeer( host, port, "whitelist", name, nodeid );
}
void
TomahawkApp::startHTTP()
{

View File

@ -170,7 +170,7 @@ TomahawkWindow::setupSignals()
connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() ));
connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) );
connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) );
connect( ui->statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT(toggleConnect() ) );
connect( ui->statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT( toggleConnect() ) );
// <SipHandler>
connect( APP->sipHandler(), SIGNAL( connected() ), SLOT( onSipConnected() ) );