mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 20:00:13 +02:00
* Clean up XMPPBot and make it work with Google Talk: You need to set a presence state before connecting.
This commit is contained in:
@@ -47,7 +47,7 @@ Jabber_p::Jabber_p( const QString& jid, const QString& password, const QString&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_client = QSharedPointer<gloox::Client>( new gloox::Client( m_jid, password.toStdString(), port) );
|
m_client = QSharedPointer<gloox::Client>( new gloox::Client( m_jid, password.toStdString(), port ) );
|
||||||
if( !server.isEmpty() )
|
if( !server.isEmpty() )
|
||||||
m_client->setServer( server.toStdString() );
|
m_client->setServer( server.toStdString() );
|
||||||
}
|
}
|
||||||
|
@@ -177,7 +177,6 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
|
|||||||
QNetworkProxy::setApplicationProxy( *m_proxy );
|
QNetworkProxy::setApplicationProxy( *m_proxy );
|
||||||
|
|
||||||
m_infoSystem = new Tomahawk::InfoSystem::InfoSystem( this );
|
m_infoSystem = new Tomahawk::InfoSystem::InfoSystem( this );
|
||||||
m_xmppBot = new XMPPBot( this );
|
|
||||||
|
|
||||||
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
|
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
|
||||||
boost::bind( &TomahawkApp::httpIODeviceFactory, this, _1 );
|
boost::bind( &TomahawkApp::httpIODeviceFactory, this, _1 );
|
||||||
@@ -192,6 +191,7 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
|
|||||||
startHTTP();
|
startHTTP();
|
||||||
|
|
||||||
if( !arguments().contains("--nojabber") ) setupJabber();
|
if( !arguments().contains("--nojabber") ) setupJabber();
|
||||||
|
m_xmppBot = new XMPPBot( this );
|
||||||
|
|
||||||
if ( !arguments().contains( "--nozeroconf" ) )
|
if ( !arguments().contains( "--nozeroconf" ) )
|
||||||
{
|
{
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
#include <gloox/client.h>
|
#include <gloox/client.h>
|
||||||
#include <gloox/rostermanager.h>
|
#include <gloox/rostermanager.h>
|
||||||
#include <gloox/message.h>
|
#include <gloox/message.h>
|
||||||
|
#include <gloox/connectiontcpclient.h>
|
||||||
|
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
using namespace gloox;
|
using namespace gloox;
|
||||||
@@ -29,15 +31,17 @@ XMPPBot::XMPPBot(QObject *parent)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
JID jid(jidstring.toStdString());
|
JID jid(jidstring.toStdString());
|
||||||
|
jid.setResource( QString( "tomahawkbot%1" ).arg( qrand() ).toStdString() );
|
||||||
|
|
||||||
m_client = new XMPPBotClient(this, jid, password.toStdString(), port);
|
m_client = new XMPPBotClient(this, jid, password.toStdString(), port);
|
||||||
if (!server.isEmpty())
|
if (!server.isEmpty())
|
||||||
m_client.data()->setServer(server.toStdString());
|
m_client.data()->setServer(server.toStdString());
|
||||||
|
|
||||||
m_client.data()->registerConnectionListener(this);
|
m_client.data()->registerConnectionListener(this);
|
||||||
m_client.data()->registerSubscriptionHandler(this);
|
m_client.data()->registerSubscriptionHandler(this);
|
||||||
m_client.data()->registerMessageHandler(this);
|
m_client.data()->registerMessageHandler(this);
|
||||||
|
m_client.data()->setPresence(Presence::Available, 1, "Tomahawkbot available");
|
||||||
|
|
||||||
connect(TomahawkApp::instance()->audioEngine(), SIGNAL(started(const Tomahawk::result_ptr &)),
|
connect(TomahawkApp::instance()->audioEngine(), SIGNAL(started(const Tomahawk::result_ptr &)),
|
||||||
SLOT(newTrackSlot(const Tomahawk::result_ptr &)));
|
SLOT(newTrackSlot(const Tomahawk::result_ptr &)));
|
||||||
|
|
||||||
@@ -46,7 +50,7 @@ XMPPBot::XMPPBot(QObject *parent)
|
|||||||
SLOT(infoReturnedSlot(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash)));
|
SLOT(infoReturnedSlot(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash)));
|
||||||
|
|
||||||
connect(TomahawkApp::instance()->infoSystem(), SIGNAL(finished(QString)), SLOT(infoFinishedSlot(QString)));
|
connect(TomahawkApp::instance()->infoSystem(), SIGNAL(finished(QString)), SLOT(infoFinishedSlot(QString)));
|
||||||
|
|
||||||
bool success = m_client.data()->gloox::Client::connect(false);
|
bool success = m_client.data()->gloox::Client::connect(false);
|
||||||
if (success)
|
if (success)
|
||||||
m_client.data()->run();
|
m_client.data()->run();
|
||||||
@@ -70,7 +74,8 @@ void XMPPBot::newTrackSlot(const Tomahawk::result_ptr &track)
|
|||||||
.arg(track->artist())
|
.arg(track->artist())
|
||||||
.arg(track->track())
|
.arg(track->track())
|
||||||
.arg(track->album());
|
.arg(track->album());
|
||||||
m_client.data()->setPresence(Presence::Chat, 1, status.toStdString());
|
|
||||||
|
m_client.data()->setPresence(Presence::Available, 1, status.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMPPBot::onConnect()
|
void XMPPBot::onConnect()
|
||||||
@@ -83,8 +88,7 @@ void XMPPBot::onDisconnect(ConnectionError e)
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
qDebug() << "XMPPBot Disconnected";
|
qDebug() << "XMPPBot Disconnected";
|
||||||
if (e != gloox::ConnNoError && e != gloox::ConnUserDisconnected)
|
qDebug() << "Connection error msg:" << e;
|
||||||
qDebug() << "ERROR: in XMPPBot, disconnected";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XMPPBot::onTLSConnect(const gloox::CertInfo& info)
|
bool XMPPBot::onTLSConnect(const gloox::CertInfo& info)
|
||||||
@@ -125,13 +129,15 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
|
|||||||
if (msg.subtype() != Message::Chat || msg.from().full().empty() || msg.to().full().empty())
|
if (msg.subtype() != Message::Chat || msg.from().full().empty() || msg.to().full().empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug() << "jid from: " << QString::fromStdString(msg.from().full()) << ", jid to: " << QString::fromStdString(msg.to().full());
|
|
||||||
|
|
||||||
QString body = QString::fromStdString(msg.body());
|
QString body = QString::fromStdString(msg.body());
|
||||||
QString originatingJid = QString::fromStdString(msg.from().full());
|
QString originatingJid = QString::fromStdString(msg.from().full());
|
||||||
QStringList tokens(body.split(QString(" and "), QString::SkipEmptyParts));
|
QStringList tokens(body.split(QString(" and "), QString::SkipEmptyParts));
|
||||||
|
|
||||||
qDebug() << "Operating on tokens: " << tokens;
|
if ( tokens.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
qDebug() << "jid from:" << QString::fromStdString(msg.from().full()) << ", jid to:" << QString::fromStdString(msg.to().full());
|
||||||
|
qDebug() << "Operating on tokens:" << tokens;
|
||||||
|
|
||||||
if (m_currTrack.isNull() || m_currTrack->artist().isEmpty() || m_currTrack->track().isEmpty())
|
if (m_currTrack.isNull() || m_currTrack->artist().isEmpty() || m_currTrack->track().isEmpty())
|
||||||
{
|
{
|
||||||
@@ -357,20 +363,6 @@ XMPPBotClient::XMPPBotClient(QObject *parent, JID &jid, std::string password, in
|
|||||||
, m_timer(this)
|
, m_timer(this)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
setResource(QString( "tomahawkbot%1" ).arg( qrand() ).toStdString() );
|
|
||||||
|
|
||||||
// the google hack, because they filter disco features they don't know.
|
|
||||||
if( server().find( "googlemail." ) != std::string::npos
|
|
||||||
|| server().find( "gmail." ) != std::string::npos
|
|
||||||
|| server().find( "gtalk." ) != std::string::npos )
|
|
||||||
{
|
|
||||||
if( resource().find( "tomahawkbot" ) == std::string::npos )
|
|
||||||
{
|
|
||||||
qDebug() << "Forcing your /resource to contain 'tomahawk' (the google workaround)";
|
|
||||||
setResource( "tomahawkbot-tomahawkbot" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XMPPBotClient::~XMPPBotClient()
|
XMPPBotClient::~XMPPBotClient()
|
||||||
@@ -381,7 +373,6 @@ XMPPBotClient::~XMPPBotClient()
|
|||||||
void XMPPBotClient::run()
|
void XMPPBotClient::run()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
setPresence(Presence::Chat, 1, "Hi!");
|
|
||||||
QObject::connect(&m_timer, SIGNAL(timeout()), SLOT(recvSlot()));
|
QObject::connect(&m_timer, SIGNAL(timeout()), SLOT(recvSlot()));
|
||||||
m_timer.start(200);
|
m_timer.start(200);
|
||||||
qDebug() << "XMPPBot running";
|
qDebug() << "XMPPBot running";
|
||||||
@@ -391,6 +382,5 @@ void XMPPBotClient::recvSlot()
|
|||||||
{
|
{
|
||||||
gloox::ConnectionError error = recv(100);
|
gloox::ConnectionError error = recv(100);
|
||||||
if (error != gloox::ConnNoError)
|
if (error != gloox::ConnNoError)
|
||||||
qDebug() << "ERROR: in XMPPBotClient::recvSlot";
|
qDebug() << "ERROR: in XMPPBotClient::recvSlot" << error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,7 +62,7 @@ protected:
|
|||||||
|
|
||||||
// MessageHandler
|
// MessageHandler
|
||||||
virtual void handleMessage(const gloox::Message &msg, gloox::MessageSession *session = 0);
|
virtual void handleMessage(const gloox::Message &msg, gloox::MessageSession *session = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWeakPointer<XMPPBotClient> m_client;
|
QWeakPointer<XMPPBotClient> m_client;
|
||||||
Tomahawk::result_ptr m_currTrack;
|
Tomahawk::result_ptr m_currTrack;
|
||||||
|
Reference in New Issue
Block a user