mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Merge remote branch 'origin/master' into osxrelesae
This commit is contained in:
@@ -3,14 +3,6 @@ SET( OS_SPECIFIC_LINK_LIBRARIES
|
|||||||
tomahawklib
|
tomahawklib
|
||||||
)
|
)
|
||||||
|
|
||||||
IF( "${gui}" STREQUAL "no" )
|
|
||||||
ELSE()
|
|
||||||
SET( OS_SPECIFIC_LINK_LIBRARIES
|
|
||||||
${OS_SPECIFIC_LINK_LIBRARIES}
|
|
||||||
gnutls
|
|
||||||
)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
FILE( GLOB _icons "${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon-*.png" )
|
FILE( GLOB _icons "${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon-*.png" )
|
||||||
FOREACH( _file ${_icons} )
|
FOREACH( _file ${_icons} )
|
||||||
STRING( REPLACE "${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon-" "" _res ${_file} )
|
STRING( REPLACE "${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon-" "" _res ${_file} )
|
||||||
|
@@ -122,13 +122,13 @@ void DiagnosticsDialog::updateLogView()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap sipInfo = SipHandler::instance()->sipInfo( peerId );
|
SipInfo sipInfo = SipHandler::instance()->sipInfo( peerId );
|
||||||
if( sipInfo.value( "visible").toBool() )
|
if( sipInfo.isVisible() )
|
||||||
log.append(
|
log.append(
|
||||||
QString(" %1: %2:%3 (%4)\n")
|
QString(" %1: %2:%3 (%4)\n")
|
||||||
.arg( peerId )
|
.arg( peerId )
|
||||||
.arg( sipInfo.value( "ip" ).toString() )
|
.arg( sipInfo.host().hostName() )
|
||||||
.arg( sipInfo.value( "port" ).toString() )
|
.arg( sipInfo.port() )
|
||||||
.arg( connected ? "connected" : "not connected")
|
.arg( connected ? "connected" : "not connected")
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
|
@@ -34,6 +34,7 @@ set( libSources
|
|||||||
sip/SipPlugin.cpp
|
sip/SipPlugin.cpp
|
||||||
sip/SipHandler.cpp
|
sip/SipHandler.cpp
|
||||||
sip/SipModel.cpp
|
sip/SipModel.cpp
|
||||||
|
sip/sipinfo.cpp
|
||||||
|
|
||||||
audio/audioengine.cpp
|
audio/audioengine.cpp
|
||||||
|
|
||||||
@@ -195,6 +196,7 @@ set( libHeaders
|
|||||||
sip/SipPlugin.h
|
sip/SipPlugin.h
|
||||||
sip/SipHandler.h
|
sip/SipHandler.h
|
||||||
sip/SipModel.h
|
sip/SipModel.h
|
||||||
|
sip/sipinfo.h
|
||||||
|
|
||||||
audio/audioengine.h
|
audio/audioengine.h
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
#include "functimeout.h"
|
#include "functimeout.h"
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
|
|
||||||
#define CONCURRENT_QUERIES 8
|
#define CONCURRENT_QUERIES 4
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -160,42 +160,50 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results )
|
|||||||
Q_ASSERT( false );
|
Q_ASSERT( false );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !m_qidsState.contains( qid ) )
|
|
||||||
{
|
|
||||||
qDebug() << "reportResults called for unknown QID-state" << qid;
|
|
||||||
Q_ASSERT( false );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const query_ptr& q = m_qids.value( qid );
|
const query_ptr& q = m_qids.value( qid );
|
||||||
if ( !results.isEmpty() )
|
if ( !results.isEmpty() )
|
||||||
{
|
{
|
||||||
//qDebug() << Q_FUNC_INFO << qid;
|
//qDebug() << Q_FUNC_INFO << qid;
|
||||||
//qDebug() << "solved query:" << (qlonglong)q.data() << q->toString();
|
|
||||||
|
|
||||||
q->addResults( results );
|
q->addResults( results );
|
||||||
|
|
||||||
foreach( const result_ptr& r, q->results() )
|
foreach( const result_ptr& r, q->results() )
|
||||||
{
|
{
|
||||||
m_rids.insert( r->id(), r );
|
m_rids.insert( r->id(), r );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( q->solved() )
|
if ( q->solved() )
|
||||||
|
{
|
||||||
|
qDebug() << "FINISHED RESOLVING EARLY" << q->toString();
|
||||||
q->onResolvingFinished();
|
q->onResolvingFinished();
|
||||||
|
|
||||||
|
setQIDState( q, 0 );
|
||||||
|
if ( m_qidsTimeout.contains( q->id() ) )
|
||||||
|
m_qidsTimeout.remove( q->id() );
|
||||||
|
|
||||||
|
qDebug() << "Queries running:" << m_qidsState.count();
|
||||||
|
|
||||||
|
shuntNext();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( decQIDState( q ) == 0 )
|
if ( decQIDState( q ) == 0 )
|
||||||
{
|
{
|
||||||
// All resolvers have reported back their results for this query now
|
|
||||||
qDebug() << "Finished resolving:" << q->toString() << q->numResults();
|
|
||||||
|
|
||||||
if ( !q->solved() )
|
if ( !q->solved() )
|
||||||
q->onResolvingFinished();
|
q->onResolvingFinished();
|
||||||
|
|
||||||
|
if ( m_qidsTimeout.contains( q->id() ) )
|
||||||
|
m_qidsTimeout.remove( q->id() );
|
||||||
|
|
||||||
|
qDebug() << "Queries running:" << m_qidsState.count();
|
||||||
shuntNext();
|
shuntNext();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new FuncTimeout( 500, boost::bind( &Pipeline::timeoutShunt, this, q ), this );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -229,11 +237,22 @@ Pipeline::shuntNext()
|
|||||||
q->setLastPipelineWeight( 101 );
|
q->setLastPipelineWeight( 101 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !q.isNull() )
|
setQIDState( q, m_resolvers.count() );
|
||||||
|
new FuncTimeout( 500, boost::bind( &Pipeline::shunt, this, q ), this );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Pipeline::timeoutShunt( const query_ptr& q )
|
||||||
|
{
|
||||||
|
// are we still waiting for a timeout?
|
||||||
|
if ( m_qidsTimeout.contains( q->id() ) )
|
||||||
{
|
{
|
||||||
incQIDState( q );
|
m_qidsTimeout.remove( q->id() );
|
||||||
shunt( q ); // bump into next stage of pipeline (highest weights are 100)
|
shunt( q );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
qDebug() << Q_FUNC_INFO << q->toString() << "Ignoring timeout";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -243,18 +262,10 @@ Pipeline::shunt( const query_ptr& q )
|
|||||||
qDebug() << Q_FUNC_INFO << q->solved() << q->toString() << q->id();
|
qDebug() << Q_FUNC_INFO << q->solved() << q->toString() << q->id();
|
||||||
unsigned int lastweight = 0;
|
unsigned int lastweight = 0;
|
||||||
unsigned int lasttimeout = 0;
|
unsigned int lasttimeout = 0;
|
||||||
|
|
||||||
if ( q->solved() )
|
|
||||||
{
|
|
||||||
// qDebug() << "Query solved, pipeline aborted:" << q->toString()
|
|
||||||
// << "numresults:" << q->results().length();
|
|
||||||
|
|
||||||
QList< result_ptr > rl;
|
|
||||||
reportResults( q->id(), rl );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int thisResolver = 0;
|
int thisResolver = 0;
|
||||||
|
|
||||||
|
if ( !q->resolvingFinished() )
|
||||||
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach( Resolver* r, m_resolvers )
|
foreach( Resolver* r, m_resolvers )
|
||||||
{
|
{
|
||||||
@@ -274,15 +285,14 @@ Pipeline::shunt( const query_ptr& q )
|
|||||||
if ( r->timeout() < lasttimeout )
|
if ( r->timeout() < lasttimeout )
|
||||||
lasttimeout = r->timeout();
|
lasttimeout = r->timeout();
|
||||||
|
|
||||||
// resolvers aren't allowed to block in this call:
|
|
||||||
qDebug() << "Dispatching to resolver" << r->name() << q->toString();
|
qDebug() << "Dispatching to resolver" << r->name() << q->toString();
|
||||||
|
|
||||||
thisResolver = i;
|
thisResolver = i;
|
||||||
r->resolve( q );
|
r->resolve( q );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( lastweight > 0 )
|
if ( lastweight > 0 )
|
||||||
{
|
{
|
||||||
@@ -290,18 +300,18 @@ Pipeline::shunt( const query_ptr& q )
|
|||||||
|
|
||||||
if ( thisResolver < m_resolvers.count() )
|
if ( thisResolver < m_resolvers.count() )
|
||||||
{
|
{
|
||||||
incQIDState( q );
|
qDebug() << "Shunting in" << lasttimeout << "ms, q:" << q->toString();
|
||||||
// qDebug() << "Shunting in" << lasttimeout << "ms, q:" << q->toString();
|
|
||||||
new FuncTimeout( lasttimeout, boost::bind( &Pipeline::shunt, this, q ), this );
|
m_qidsTimeout.insert( q->id(), true );
|
||||||
|
new FuncTimeout( lasttimeout, boost::bind( &Pipeline::timeoutShunt, this, q ), this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//qDebug() << "Reached end of pipeline for:" << q->toString();
|
|
||||||
// reached end of pipeline
|
// reached end of pipeline
|
||||||
QList< result_ptr > rl;
|
qDebug() << "Reached end of pipeline for:" << q->toString();
|
||||||
reportResults( q->id(), rl );
|
setQIDState( q, 0 );
|
||||||
return;
|
qDebug() << "Queries running:" << m_qidsState.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
shuntNext();
|
shuntNext();
|
||||||
@@ -318,6 +328,24 @@ Pipeline::resolverSorter( const Resolver* left, const Resolver* right )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Pipeline::setQIDState( const Tomahawk::query_ptr& query, int state )
|
||||||
|
{
|
||||||
|
QMutexLocker lock( &m_mut );
|
||||||
|
|
||||||
|
if ( state > 0 )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state;
|
||||||
|
m_qidsState.insert( query->id(), state );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "removing" << query->id() << state;
|
||||||
|
m_qidsState.remove( query->id() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Pipeline::incQIDState( const Tomahawk::query_ptr& query )
|
Pipeline::incQIDState( const Tomahawk::query_ptr& query )
|
||||||
{
|
{
|
||||||
@@ -329,7 +357,7 @@ Pipeline::incQIDState( const Tomahawk::query_ptr& query )
|
|||||||
state = m_qidsState.value( query->id() ) + 1;
|
state = m_qidsState.value( query->id() ) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state;
|
qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state;
|
||||||
m_qidsState.insert( query->id(), state );
|
m_qidsState.insert( query->id(), state );
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
@@ -341,15 +369,18 @@ Pipeline::decQIDState( const Tomahawk::query_ptr& query )
|
|||||||
{
|
{
|
||||||
QMutexLocker lock( &m_mut );
|
QMutexLocker lock( &m_mut );
|
||||||
|
|
||||||
|
if ( !m_qidsState.contains( query->id() ) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
int state = m_qidsState.value( query->id() ) - 1;
|
int state = m_qidsState.value( query->id() ) - 1;
|
||||||
if ( state )
|
if ( state )
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO << "replacing" << query->id() << state;
|
qDebug() << Q_FUNC_INFO << "replacing" << query->id() << state;
|
||||||
m_qidsState.insert( query->id(), state );
|
m_qidsState.insert( query->id(), state );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO << "removing" << query->id() << state;
|
qDebug() << Q_FUNC_INFO << "removing" << query->id() << state;
|
||||||
m_qidsState.remove( query->id() );
|
m_qidsState.remove( query->id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -73,17 +73,20 @@ signals:
|
|||||||
void idle();
|
void idle();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void timeoutShunt( const query_ptr& q );
|
||||||
void shunt( const query_ptr& q );
|
void shunt( const query_ptr& q );
|
||||||
void shuntNext();
|
void shuntNext();
|
||||||
|
|
||||||
void indexReady();
|
void indexReady();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setQIDState( const Tomahawk::query_ptr& query, int state );
|
||||||
int incQIDState( const Tomahawk::query_ptr& query );
|
int incQIDState( const Tomahawk::query_ptr& query );
|
||||||
int decQIDState( const Tomahawk::query_ptr& query );
|
int decQIDState( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
QList< Resolver* > m_resolvers;
|
QList< Resolver* > m_resolvers;
|
||||||
|
|
||||||
|
QMap< QID, bool > m_qidsTimeout;
|
||||||
QMap< QID, unsigned int > m_qidsState;
|
QMap< QID, unsigned int > m_qidsState;
|
||||||
QMap< QID, query_ptr > m_qids;
|
QMap< QID, query_ptr > m_qids;
|
||||||
QMap< RID, result_ptr > m_rids;
|
QMap< RID, result_ptr > m_rids;
|
||||||
|
@@ -80,7 +80,7 @@ const QPixmap SipHandler::avatar( const QString& name ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVariantMap
|
const SipInfo
|
||||||
SipHandler::sipInfo(const QString& peerId) const
|
SipHandler::sipInfo(const QString& peerId) const
|
||||||
{
|
{
|
||||||
return m_peersSipInfos.value( peerId );
|
return m_peersSipInfos.value( peerId );
|
||||||
@@ -193,6 +193,7 @@ SipHandler::hookUpPlugin( SipPlugin* sip )
|
|||||||
QObject::connect( sip, SIGNAL( peerOnline( QString ) ), SLOT( onPeerOnline( QString ) ) );
|
QObject::connect( sip, SIGNAL( peerOnline( QString ) ), SLOT( onPeerOnline( QString ) ) );
|
||||||
QObject::connect( sip, SIGNAL( peerOffline( QString ) ), SLOT( onPeerOffline( QString ) ) );
|
QObject::connect( sip, SIGNAL( peerOffline( QString ) ), SLOT( onPeerOffline( QString ) ) );
|
||||||
QObject::connect( sip, SIGNAL( msgReceived( QString, QString ) ), SLOT( onMessage( QString, QString ) ) );
|
QObject::connect( sip, SIGNAL( msgReceived( QString, QString ) ), SLOT( onMessage( QString, QString ) ) );
|
||||||
|
QObject::connect( sip, SIGNAL( sipInfoReceived( QString, SipInfo ) ), SLOT( onSipInfo( QString, SipInfo ) ) );
|
||||||
|
|
||||||
QObject::connect( sip, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) );
|
QObject::connect( sip, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) );
|
||||||
QObject::connect( sip, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), SLOT( onStateChanged( SipPlugin::ConnectionState ) ) );
|
QObject::connect( sip, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), SLOT( onStateChanged( SipPlugin::ConnectionState ) ) );
|
||||||
@@ -367,6 +368,7 @@ SipHandler::connectPlugin( bool startup, const QString &pluginId )
|
|||||||
if ( sip->pluginId() == pluginId )
|
if ( sip->pluginId() == pluginId )
|
||||||
{
|
{
|
||||||
Q_ASSERT( m_enabledPlugins.contains( sip ) ); // make sure the plugin we're connecting is enabled. should always be the case
|
Q_ASSERT( m_enabledPlugins.contains( sip ) ); // make sure the plugin we're connecting is enabled. should always be the case
|
||||||
|
sip->setProxy( m_proxy );
|
||||||
sip->connectPlugin( startup );
|
sip->connectPlugin( startup );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -417,6 +419,17 @@ SipHandler::toggleConnect()
|
|||||||
connectAll();
|
connectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipHandler::setProxy( const QNetworkProxy& proxy )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
m_proxy = proxy;
|
||||||
|
|
||||||
|
foreach( SipPlugin* sip, m_allPlugins )
|
||||||
|
sip->setProxy( proxy );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SipHandler::onPeerOnline( const QString& jid )
|
SipHandler::onPeerOnline( const QString& jid )
|
||||||
@@ -471,39 +484,27 @@ SipHandler::onPeerOffline( const QString& jid )
|
|||||||
qDebug() << "SIP offline:" << jid;
|
qDebug() << "SIP offline:" << jid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SipHandler::onMessage( const QString& from, const QString& msg )
|
SipHandler::onSipInfo( const QString& peerId, const SipInfo& info )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO << "SIP Message:" << peerId << info;
|
||||||
qDebug() << "SIP Message:" << from << msg;
|
|
||||||
|
|
||||||
QJson::Parser parser;
|
|
||||||
bool ok;
|
|
||||||
QVariant v = parser.parse( msg.toAscii(), &ok );
|
|
||||||
if ( !ok || v.type() != QVariant::Map )
|
|
||||||
{
|
|
||||||
qDebug() << "Invalid JSON in XMPP msg";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap m = v.toMap();
|
|
||||||
/*
|
/*
|
||||||
If only one party is externally visible, connection is obvious
|
If only one party is externally visible, connection is obvious
|
||||||
If both are, peer with lowest IP address initiates the connection.
|
If both are, peer with lowest IP address initiates the connection.
|
||||||
This avoids dupe connections.
|
This avoids dupe connections.
|
||||||
*/
|
*/
|
||||||
if ( m.value( "visible" ).toBool() )
|
if ( info.isVisible() )
|
||||||
{
|
{
|
||||||
if( !Servent::instance()->visibleExternally() ||
|
if( !Servent::instance()->visibleExternally() ||
|
||||||
Servent::instance()->externalAddress() <= m.value( "ip" ).toString() )
|
Servent::instance()->externalAddress() <= info.host().hostName() )
|
||||||
{
|
{
|
||||||
qDebug() << "Initiate connection to" << from;
|
qDebug() << "Initiate connection to" << peerId;
|
||||||
Servent::instance()->connectToPeer( m.value( "ip" ).toString(),
|
Servent::instance()->connectToPeer( info.host().hostName(),
|
||||||
m.value( "port" ).toInt(),
|
info.port(),
|
||||||
m.value( "key" ).toString(),
|
info.key(),
|
||||||
from,
|
peerId,
|
||||||
m.value( "uniqname" ).toString() );
|
info.uniqname() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -515,7 +516,13 @@ SipHandler::onMessage( const QString& from, const QString& msg )
|
|||||||
qDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm";
|
qDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm";
|
||||||
}
|
}
|
||||||
|
|
||||||
m_peersSipInfos.insert( from, m );
|
m_peersSipInfos.insert( peerId, info );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipHandler::onMessage( const QString& from, const QString& msg )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -52,7 +52,7 @@ public:
|
|||||||
|
|
||||||
const QPixmap avatar( const QString& name ) const;
|
const QPixmap avatar( const QString& name ) const;
|
||||||
//TODO: implement a proper SipInfo class and maybe attach it to the source
|
//TODO: implement a proper SipInfo class and maybe attach it to the source
|
||||||
const QVariantMap sipInfo( const QString& peerId ) const;
|
const SipInfo sipInfo( const QString& peerId ) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void checkSettings();
|
void checkSettings();
|
||||||
@@ -67,6 +67,8 @@ public slots:
|
|||||||
|
|
||||||
void toggleConnect();
|
void toggleConnect();
|
||||||
|
|
||||||
|
void setProxy( const QNetworkProxy &proxy );
|
||||||
|
|
||||||
// create a new plugin of the given name. the name is the value returned in SipPluginFactory::pluginName
|
// create a new plugin of the given name. the name is the value returned in SipPluginFactory::pluginName
|
||||||
// be default sip plugins are NOt connected when created
|
// be default sip plugins are NOt connected when created
|
||||||
SipPlugin* createPlugin( const QString& factoryName );
|
SipPlugin* createPlugin( const QString& factoryName );
|
||||||
@@ -85,6 +87,7 @@ signals:
|
|||||||
void pluginRemoved( SipPlugin* p );
|
void pluginRemoved( SipPlugin* p );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onSipInfo( const QString& peerId, const SipInfo& info );
|
||||||
void onMessage( const QString&, const QString& );
|
void onMessage( const QString&, const QString& );
|
||||||
void onPeerOffline( const QString& );
|
void onPeerOffline( const QString& );
|
||||||
void onPeerOnline( const QString& );
|
void onPeerOnline( const QString& );
|
||||||
@@ -116,9 +119,10 @@ private:
|
|||||||
QList< SipPlugin* > m_enabledPlugins;
|
QList< SipPlugin* > m_enabledPlugins;
|
||||||
QList< SipPlugin* > m_connectedPlugins;
|
QList< SipPlugin* > m_connectedPlugins;
|
||||||
bool m_connected;
|
bool m_connected;
|
||||||
|
QNetworkProxy m_proxy;
|
||||||
|
|
||||||
//TODO: move this to source
|
//TODO: move this to source
|
||||||
QHash<QString, QVariantMap> m_peersSipInfos;
|
QHash<QString, SipInfo> m_peersSipInfos;
|
||||||
QHash<QString, QPixmap> m_usernameAvatars;
|
QHash<QString, QPixmap> m_usernameAvatars;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -20,6 +20,8 @@
|
|||||||
#ifndef SIPPLUGIN_H
|
#ifndef SIPPLUGIN_H
|
||||||
#define SIPPLUGIN_H
|
#define SIPPLUGIN_H
|
||||||
|
|
||||||
|
#include "sipinfo.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@@ -87,7 +89,7 @@ public slots:
|
|||||||
virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0;
|
virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0;
|
||||||
virtual void sendMsg( const QString& to, const QString& msg ) = 0;
|
virtual void sendMsg( const QString& to, const QString& msg ) = 0;
|
||||||
|
|
||||||
void setProxy( const QNetworkProxy &proxy );
|
virtual void setProxy( const QNetworkProxy &proxy );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void error( int, const QString& );
|
void error( int, const QString& );
|
||||||
@@ -96,6 +98,7 @@ signals:
|
|||||||
void peerOnline( const QString& );
|
void peerOnline( const QString& );
|
||||||
void peerOffline( const QString& );
|
void peerOffline( const QString& );
|
||||||
void msgReceived( const QString& from, const QString& msg );
|
void msgReceived( const QString& from, const QString& msg );
|
||||||
|
void sipInfoReceived( const QString& peerId, const SipInfo& info );
|
||||||
|
|
||||||
// new data for own source
|
// new data for own source
|
||||||
void avatarReceived ( const QPixmap& avatar );
|
void avatarReceived ( const QPixmap& avatar );
|
||||||
|
229
src/libtomahawk/sip/sipinfo.cpp
Normal file
229
src/libtomahawk/sip/sipinfo.cpp
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011, Dominik Schmidt <dev@dominik-schmidt.de>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sipinfo.h"
|
||||||
|
|
||||||
|
#include <qjson/parser.h>
|
||||||
|
#include <qjson/serializer.h>
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
class SipInfoPrivate : public QSharedData {
|
||||||
|
public:
|
||||||
|
SipInfoPrivate()
|
||||||
|
: port( -1 )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SipInfoPrivate( const SipInfoPrivate& other ) : QSharedData( other ),
|
||||||
|
visible(other.visible),
|
||||||
|
host(other.host),
|
||||||
|
port(other.port),
|
||||||
|
uniqname(other.uniqname),
|
||||||
|
key(other.key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~SipInfoPrivate() { }
|
||||||
|
|
||||||
|
QVariant visible;
|
||||||
|
QHostInfo host;
|
||||||
|
int port;
|
||||||
|
QString uniqname;
|
||||||
|
QString key;
|
||||||
|
};
|
||||||
|
|
||||||
|
SipInfo::SipInfo()
|
||||||
|
{
|
||||||
|
d = new SipInfoPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
SipInfo::SipInfo(const SipInfo& other): d ( other.d )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SipInfo::~SipInfo()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SipInfo&
|
||||||
|
SipInfo::operator=( const SipInfo& other )
|
||||||
|
{
|
||||||
|
d = other.d;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipInfo::clear()
|
||||||
|
{
|
||||||
|
d->visible.clear();
|
||||||
|
d->host = QHostInfo();
|
||||||
|
d->port = -1;
|
||||||
|
d->uniqname = QString();
|
||||||
|
d->key = QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
SipInfo::isValid() const
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << d->visible << d->host.hostName() << d->port << d->uniqname << d->key;
|
||||||
|
if( !d->visible.isNull() )
|
||||||
|
{
|
||||||
|
if(
|
||||||
|
// visible and all data available
|
||||||
|
( d->visible.toBool() && !d->host.hostName().isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() )
|
||||||
|
// invisible and no data available
|
||||||
|
|| ( !d->visible.toBool() && d->host.hostName().isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() )
|
||||||
|
)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipInfo::setVisible(bool visible)
|
||||||
|
{
|
||||||
|
d->visible.setValue(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
SipInfo::isVisible() const
|
||||||
|
{
|
||||||
|
Q_ASSERT( isValid() );
|
||||||
|
|
||||||
|
return d->visible.toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipInfo::setHost( const QHostInfo& host )
|
||||||
|
{
|
||||||
|
d->host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QHostInfo
|
||||||
|
SipInfo::host() const
|
||||||
|
{
|
||||||
|
Q_ASSERT( isValid() );
|
||||||
|
|
||||||
|
return d->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipInfo::setPort( int port )
|
||||||
|
{
|
||||||
|
d->port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
SipInfo::port() const
|
||||||
|
{
|
||||||
|
Q_ASSERT( isValid() );
|
||||||
|
|
||||||
|
return d->port;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipInfo::setUniqname( const QString& uniqname )
|
||||||
|
{
|
||||||
|
d->uniqname = uniqname;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString
|
||||||
|
SipInfo::uniqname() const
|
||||||
|
{
|
||||||
|
Q_ASSERT( isValid() );
|
||||||
|
|
||||||
|
return d->uniqname;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SipInfo::setKey( const QString& key )
|
||||||
|
{
|
||||||
|
d->key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString
|
||||||
|
SipInfo::key() const
|
||||||
|
{
|
||||||
|
Q_ASSERT( isValid() );
|
||||||
|
|
||||||
|
return d->key;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString
|
||||||
|
SipInfo::toJson() const
|
||||||
|
{
|
||||||
|
// build variant map
|
||||||
|
QVariantMap m;
|
||||||
|
m["visible"] = isVisible();
|
||||||
|
if( isVisible() )
|
||||||
|
{
|
||||||
|
m["ip"] = host().hostName();
|
||||||
|
m["port"] = port();
|
||||||
|
m["key"] = key();
|
||||||
|
m["uniqname"] = uniqname();
|
||||||
|
}
|
||||||
|
|
||||||
|
// serialize
|
||||||
|
QJson::Serializer serializer;
|
||||||
|
QByteArray ba = serializer.serialize( m );
|
||||||
|
|
||||||
|
return QString::fromAscii( ba );
|
||||||
|
}
|
||||||
|
|
||||||
|
const SipInfo
|
||||||
|
SipInfo::fromJson( QString json )
|
||||||
|
{
|
||||||
|
SipInfo info;
|
||||||
|
|
||||||
|
QJson::Parser parser;
|
||||||
|
bool ok;
|
||||||
|
QVariant v = parser.parse( json.toAscii(), &ok );
|
||||||
|
if ( !ok || v.type() != QVariant::Map )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "Invalid JSON: " << json;
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
QVariantMap m = v.toMap();
|
||||||
|
|
||||||
|
info.setVisible( m["visible"].toBool() );
|
||||||
|
if( m["visible"].toBool() )
|
||||||
|
{
|
||||||
|
QHostInfo hostInfo;
|
||||||
|
hostInfo.setHostName( m["host"].toString() );
|
||||||
|
info.setHost( hostInfo );
|
||||||
|
info.setPort( m["port"].toInt() );
|
||||||
|
info.setUniqname( m["uniqname"].toString() );
|
||||||
|
info.setKey( m["key"].toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDebug operator<< ( QDebug dbg, const SipInfo& info )
|
||||||
|
{
|
||||||
|
if( !info.isValid() )
|
||||||
|
dbg.nospace() << "info is invalid";
|
||||||
|
else
|
||||||
|
dbg.nospace() << info.toJson();
|
||||||
|
|
||||||
|
return dbg.maybeSpace();
|
||||||
|
}
|
70
src/libtomahawk/sip/sipinfo.h
Normal file
70
src/libtomahawk/sip/sipinfo.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011, Dominik Schmidt <dev@dominik-schmidt.de>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SIPINFO_H
|
||||||
|
#define SIPINFO_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QHostInfo>
|
||||||
|
|
||||||
|
class SipInfoPrivate;
|
||||||
|
|
||||||
|
#include "../dllmacro.h"
|
||||||
|
|
||||||
|
class DLLEXPORT SipInfo : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SipInfo();
|
||||||
|
SipInfo(const SipInfo& other);
|
||||||
|
virtual ~SipInfo();
|
||||||
|
SipInfo& operator=(const SipInfo& info);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
|
void setVisible( bool visible );
|
||||||
|
bool isVisible() const;
|
||||||
|
|
||||||
|
void setHost( const QHostInfo& host );
|
||||||
|
const QHostInfo host() const;
|
||||||
|
|
||||||
|
void setPort( int port );
|
||||||
|
int port() const;
|
||||||
|
|
||||||
|
void setUniqname( const QString& uniqname );
|
||||||
|
const QString uniqname() const;
|
||||||
|
|
||||||
|
void setKey( const QString& key );
|
||||||
|
const QString key() const;
|
||||||
|
|
||||||
|
|
||||||
|
const QString toJson() const;
|
||||||
|
static const SipInfo fromJson( QString json );
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedDataPointer<SipInfoPrivate> d;
|
||||||
|
};
|
||||||
|
|
||||||
|
DLLEXPORT QDebug operator<<( QDebug dbg, const SipInfo &info );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SIPINFO_H
|
@@ -41,6 +41,8 @@ GoogleWrapper::GoogleWrapper ( const QString& pluginID )
|
|||||||
m_ui->emailLabel->setText( tr( "Google Address" ) );
|
m_ui->emailLabel->setText( tr( "Google Address" ) );
|
||||||
m_ui->jabberBlurb->setText( tr( "Enter your Google login to connect with your friends using Tomahawk!" ) );
|
m_ui->jabberBlurb->setText( tr( "Enter your Google login to connect with your friends using Tomahawk!" ) );
|
||||||
m_ui->logoLabel->setPixmap( QPixmap( ":/gmail-logo.png" ) );
|
m_ui->logoLabel->setPixmap( QPixmap( ":/gmail-logo.png" ) );
|
||||||
|
m_ui->jabberServer->setText( "talk.google.com" );
|
||||||
|
m_ui->jabberPort->setValue( 5222 );
|
||||||
m_ui->groupBoxJabberAdvanced->hide();
|
m_ui->groupBoxJabberAdvanced->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -139,11 +139,13 @@ JabberPlugin::~JabberPlugin()
|
|||||||
void
|
void
|
||||||
JabberPlugin::setProxy( const QNetworkProxy &proxy )
|
JabberPlugin::setProxy( const QNetworkProxy &proxy )
|
||||||
{
|
{
|
||||||
if(m_currentServer.isEmpty() || !(m_currentPort > 0))
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
if( ( proxy.type() != QNetworkProxy::NoProxy ) && ( m_currentServer.isEmpty() || !(m_currentPort > 0) ) )
|
||||||
{
|
{
|
||||||
// patches are welcome in Jreen that implement jdns through proxy
|
// patches are welcome in Jreen that implement jdns through proxy
|
||||||
qDebug() << Q_FUNC_INFO << "Jreen proxy only works when you explicitly set host and port";
|
emit error( SipPlugin::ConnectionError,
|
||||||
Q_ASSERT(false);
|
tr( "You need to set hostname and port of your jabber server, if you want to use it through a proxy" ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,13 +556,12 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message)
|
|||||||
QString from = message.from().full();
|
QString from = message.from().full();
|
||||||
QString msg = message.body();
|
QString msg = message.body();
|
||||||
|
|
||||||
if ( msg.isEmpty() )
|
if(msg.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QJson::Parser parser;
|
SipInfo info = SipInfo::fromJson( msg );
|
||||||
bool ok;
|
|
||||||
QVariant v = parser.parse( msg.toAscii(), &ok );
|
if ( !info.isValid() )
|
||||||
if ( !ok || v.type() != QVariant::Map )
|
|
||||||
{
|
{
|
||||||
QString to = from;
|
QString to = from;
|
||||||
QString response = QString( tr("I'm sorry -- I'm just an automatic presence used by Tomahawk Player"
|
QString response = QString( tr("I'm sorry -- I'm just an automatic presence used by Tomahawk Player"
|
||||||
@@ -570,11 +571,12 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message)
|
|||||||
// this is not a sip message, so we send it directly through the client
|
// this is not a sip message, so we send it directly through the client
|
||||||
m_client->send( Jreen::Message ( Jreen::Message::Chat, Jreen::JID(to), response) );
|
m_client->send( Jreen::Message ( Jreen::Message::Chat, Jreen::JID(to), response) );
|
||||||
|
|
||||||
|
emit msgReceived( from, msg );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "From:" << message.from().full() << ":" << message.body();
|
qDebug() << Q_FUNC_INFO << "From:" << message.from().full() << ":" << message.body();
|
||||||
emit msgReceived( from, msg );
|
emit sipInfoReceived( from, info );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -768,35 +770,29 @@ void JabberPlugin::onNewIq(const Jreen::IQ& iq, int context)
|
|||||||
iq.accept();
|
iq.accept();
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Got SipMessage ...";
|
qDebug() << Q_FUNC_INFO << "Got SipMessage ...";
|
||||||
qDebug() << "ip" << sipMessage->ip();
|
qDebug() << Q_FUNC_INFO << "ip" << sipMessage->ip();
|
||||||
qDebug() << "port" << sipMessage->port();
|
qDebug() << Q_FUNC_INFO << "port" << sipMessage->port();
|
||||||
qDebug() << "uniqname" << sipMessage->uniqname();
|
qDebug() << Q_FUNC_INFO << "uniqname" << sipMessage->uniqname();
|
||||||
qDebug() << "key" << sipMessage->key();
|
qDebug() << Q_FUNC_INFO << "key" << sipMessage->key();
|
||||||
qDebug() << "visible" << sipMessage->visible();
|
qDebug() << Q_FUNC_INFO << "visible" << sipMessage->visible();
|
||||||
|
|
||||||
|
SipInfo info;
|
||||||
QVariantMap m;
|
info.setVisible( sipMessage->visible() );
|
||||||
if( sipMessage->visible() )
|
if( sipMessage->visible() )
|
||||||
{
|
{
|
||||||
m["visible"] = true;
|
|
||||||
m["ip"] = sipMessage->ip();
|
QHostInfo hi;
|
||||||
m["port"] = sipMessage->port();
|
hi.setHostName( sipMessage->ip() );
|
||||||
m["key"] = sipMessage->key();
|
info.setHost( hi );
|
||||||
m["uniqname"] = sipMessage->uniqname();
|
info.setPort( sipMessage->port() );
|
||||||
}
|
info.setUniqname( sipMessage->uniqname() );
|
||||||
else
|
info.setKey( sipMessage->key() );
|
||||||
{
|
|
||||||
m["visible"] = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_ASSERT( info.isValid() );
|
||||||
|
|
||||||
QJson::Serializer ser;
|
qDebug() << Q_FUNC_INFO << "From:" << iq.from().full() << ":" << info;
|
||||||
QByteArray ba = ser.serialize( m );
|
emit sipInfoReceived( iq.from().full(), info );
|
||||||
QString msg = QString::fromAscii( ba );
|
|
||||||
|
|
||||||
QString from = iq.from().full();
|
|
||||||
qDebug() << Q_FUNC_INFO << "From:" << from << ":" << msg;
|
|
||||||
emit msgReceived( from, msg );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -534,10 +534,8 @@ TomahawkApp::setupSIP()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
qDebug() << "Connecting SIP classes";
|
qDebug() << "Connecting SIP classes";
|
||||||
|
SipHandler::instance()->setProxy( *TomahawkUtils::proxy() );
|
||||||
SipHandler::instance()->loadFromConfig( true );
|
SipHandler::instance()->loadFromConfig( true );
|
||||||
|
|
||||||
// m_sipHandler->setProxy( *TomahawkUtils::proxy() );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user