1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

* Remote-control Tomahawk via the XMPPBot: e.g. 'play Beatles - Yesterday'

This commit is contained in:
Christian Muehlhaeuser
2010-10-28 14:42:17 +02:00
parent f6179b9245
commit 59d269d631
2 changed files with 33 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/infosystem.h"
#include "tomahawk/typedefs.h"
#include <tomahawksettings.h>
#include <audio/audioengine.h>
@@ -129,10 +130,30 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
if (msg.subtype() != Message::Chat || msg.from().full().empty() || msg.to().full().empty())
return;
QString body = QString::fromStdString(msg.body());
QString originatingJid = QString::fromStdString(msg.from().full());
QStringList tokens(body.split(QString(" and "), QString::SkipEmptyParts));
QString body = QString::fromStdString( msg.body() );
QString originatingJid = QString::fromStdString( msg.from().full() );
if ( body.toLower().startsWith( "play" ) )
{
QStringList tokens = body.right( body.length() - 5 ).split( QString( "-" ), QString::SkipEmptyParts );
qDebug() << tokens;
QVariantMap qv;
qv["artist"] = tokens.first().trimmed();
qv["track"] = tokens.last().trimmed();
Tomahawk::query_ptr q( new Tomahawk::Query( qv ) );
connect( q.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ),
SLOT( onResultsAdded( QList<Tomahawk::result_ptr> ) ) );
QList<Tomahawk::query_ptr> ql;
ql.append( q );
APP->pipeline()->add( ql );
return;
}
QStringList tokens( body.toLower().split( QString( " and " ), QString::SkipEmptyParts ) );
if ( tokens.isEmpty() )
return;
@@ -355,6 +376,12 @@ void XMPPBot::infoFinishedSlot(QString caller)
m_currReturnJid.clear();
}
void XMPPBot::onResultsAdded( const QList<Tomahawk::result_ptr>& result )
{
APP->audioEngine()->playItem( 0, result.first() );
}
///////////////////////////////////////////////////////////////////////////////////////
XMPPBotClient::XMPPBotClient(QObject *parent, JID &jid, std::string password, int port)

View File

@@ -63,6 +63,9 @@ protected:
// MessageHandler
virtual void handleMessage(const gloox::Message &msg, gloox::MessageSession *session = 0);
private slots:
void onResultsAdded( const QList<Tomahawk::result_ptr>& result );
private:
QWeakPointer<XMPPBotClient> m_client;
Tomahawk::result_ptr m_currTrack;