1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 00:54:20 +02:00

Make the gloox plugin aware of the tomahawk caps node

This commit is contained in:
Dominik Schmidt
2011-02-28 01:39:12 +01:00
parent a728c9643c
commit 116a1d8501
2 changed files with 20 additions and 28 deletions

View File

@@ -7,10 +7,12 @@
#include <QRegExp> #include <QRegExp>
#include <QThread> #include <QThread>
#include <utils/tomahawkutils.h> #include <utils/tomahawkutils.h>
#include <gloox/capabilities.h>
using namespace gloox; using namespace gloox;
using namespace std; using namespace std;
#define TOMAHAWK_CAP_NODE_NAME QLatin1String("http://tomahawk-player.org/")
Jabber_p::Jabber_p( const QString& jid, const QString& password, const QString& server, const int port ) Jabber_p::Jabber_p( const QString& jid, const QString& password, const QString& server, const int port )
: QObject() : QObject()
@@ -133,7 +135,6 @@ Jabber_p::go()
return; return;
} }
m_client->registerConnectionListener( this ); m_client->registerConnectionListener( this );
m_client->rosterManager()->registerRosterListener( this );
m_client->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this ); m_client->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this );
m_client->registerMessageHandler( this ); m_client->registerMessageHandler( this );
@@ -510,23 +511,25 @@ Jabber_p::handleRosterError( const IQ& /*iq*/ )
void void
Jabber_p::handleRosterPresence( const RosterItem& item, const std::string& resource, Jabber_p::handlePresence( const gloox::Presence& presence )
Presence::PresenceType presence, const std::string& /*msg*/ )
{ {
JID jid( item.jid() ); //JID jid( item.jid() );
jid.setResource( resource ); JID jid = presence.from();
//jid.setResource( resource );
QString fulljid( jid.full().c_str() ); QString fulljid( jid.full().c_str() );
qDebug() << "* handleRosterPresence" << fulljid << presence; qDebug() << "* handleRosterPresence" << fulljid << presence.subtype();
if( jid == m_jid ) if( jid == m_jid )
return; return;
// ignore anyone not running tomahawk: // ignore anyone not running tomahawk:
// convert to QString to get proper regex support // convert to QString to get proper regex support
QString res( jid.resource().c_str() ); const gloox::Capabilities *caps = presence.findExtension<gloox::Capabilities>(gloox::ExtCaps);
QRegExp regex( "tomahawk\\d+" ); QString node = QString::fromAscii( caps->node().c_str() );
if( res != "tomahawk-tomahawk" && !res.startsWith( "tomahawk" ) ) if( QString::fromAscii( jid.resource().c_str() ).startsWith(QLatin1String("tomahawk"))
|| node == TOMAHAWK_CAP_NODE_NAME
)
{ {
//qDebug() << "not considering resource of" << res; //qDebug() << "not considering resource of" << res;
// Disco them to check if they are tomahawk-capable // Disco them to check if they are tomahawk-capable
@@ -543,41 +546,33 @@ Jabber_p::handleRosterPresence( const RosterItem& item, const std::string& resou
// << " presencetype" << presence; // << " presencetype" << presence;
// "going offline" event // "going offline" event
if ( !presenceMeansOnline( presence ) && if ( !presenceMeansOnline( presence.subtype() ) &&
( !m_peers.contains( fulljid ) || ( !m_peers.contains( fulljid ) ||
presenceMeansOnline( m_peers.value( fulljid ) ) presenceMeansOnline( m_peers.value( fulljid ) )
) )
) )
{ {
m_peers[ fulljid ] = presence; m_peers[ fulljid ] = presence.subtype();
qDebug() << "* Peer goes offline:" << fulljid; qDebug() << "* Peer goes offline:" << fulljid;
emit peerOffline( fulljid ); emit peerOffline( fulljid );
return; return;
} }
// "coming online" event // "coming online" event
if( presenceMeansOnline( presence ) && if( presenceMeansOnline( presence.subtype() ) &&
( !m_peers.contains( fulljid ) || ( !m_peers.contains( fulljid ) ||
!presenceMeansOnline( m_peers.value( fulljid ) ) !presenceMeansOnline( m_peers.value( fulljid ) )
) )
) )
{ {
m_peers[ fulljid ] = presence; m_peers[ fulljid ] = presence.subtype();
qDebug() << "* Peer goes online:" << fulljid; qDebug() << "* Peer goes online:" << fulljid;
emit peerOnline( fulljid ); emit peerOnline( fulljid );
return; return;
} }
//qDebug() << "Updating presence data for" << fulljid; //qDebug() << "Updating presence data for" << fulljid;
m_peers[ fulljid ] = presence; m_peers[ fulljid ] = presence.subtype();
}
void
Jabber_p::handleSelfPresence( const RosterItem& item, const std::string& resource,
Presence::PresenceType presence, const std::string& msg )
{
handleRosterPresence( item, resource, presence, msg );
} }

View File

@@ -53,9 +53,9 @@
class SIPDLLEXPORT Jabber_p : class SIPDLLEXPORT Jabber_p :
public QObject, public QObject,
public gloox::ConnectionListener, public gloox::ConnectionListener,
public gloox::RosterListener,
public gloox::MessageHandler, public gloox::MessageHandler,
public gloox::VCardHandler, public gloox::VCardHandler,
public gloox::PresenceHandler,
gloox::LogHandler gloox::LogHandler
//public gloox::DiscoHandler, //public gloox::DiscoHandler,
{ {
@@ -89,10 +89,7 @@ public:
virtual void handleRoster( const gloox::Roster& roster ); virtual void handleRoster( const gloox::Roster& roster );
virtual void handleRosterError( const gloox::IQ& /*iq*/ ); virtual void handleRosterError( const gloox::IQ& /*iq*/ );
virtual void handleRosterPresence( const gloox::RosterItem& item, const std::string& resource, virtual void handlePresence( const gloox::Presence& presence );
gloox::Presence::PresenceType presence, const std::string& /*msg*/ );
virtual void handleSelfPresence( const gloox::RosterItem& item, const std::string& resource,
gloox::Presence::PresenceType presence, const std::string& msg );
virtual bool handleSubscription( const gloox::JID& jid, const std::string& /*msg*/ ); virtual bool handleSubscription( const gloox::JID& jid, const std::string& /*msg*/ );
virtual bool handleSubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ ); virtual bool handleSubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ );
virtual bool handleUnsubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ ); virtual bool handleUnsubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ );