mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
Move Jreen bits in xmpp info plugin to the SIP side, allowing the plugin to run in the correct thread.
This commit is contained in:
parent
2b09915a0d
commit
7284a53d0f
@ -24,31 +24,18 @@
|
||||
#include "sip/xmppsip.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
#include <jreen/tune.h>
|
||||
#include <jreen/pubsubmanager.h>
|
||||
#include <jreen/jid.h>
|
||||
|
||||
#include <jreen/client.h>
|
||||
|
||||
// remove now playing status after PAUSE_TIMEOUT seconds
|
||||
static const int PAUSE_TIMEOUT = 60;
|
||||
static const int PAUSE_TIMEOUT = 10;
|
||||
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::XmppInfoPlugin( XmppSipPlugin* sipPlugin )
|
||||
: m_sipPlugin( sipPlugin )
|
||||
, m_pubSubManager( 0 )
|
||||
, m_pauseTimer( this )
|
||||
{
|
||||
Q_ASSERT( sipPlugin->m_client );
|
||||
|
||||
m_supportedPushTypes << InfoNowPlaying << InfoNowPaused << InfoNowResumed << InfoNowStopped;
|
||||
|
||||
m_pubSubManager = new Jreen::PubSub::Manager( sipPlugin->m_client );
|
||||
m_pubSubManager->addEntityType< Jreen::Tune >();
|
||||
|
||||
// Clear status
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
|
||||
|
||||
m_pauseTimer.setSingleShot( true );
|
||||
connect( &m_pauseTimer, SIGNAL( timeout() ),
|
||||
this, SLOT( audioStopped() ) );
|
||||
@ -57,24 +44,28 @@ Tomahawk::InfoSystem::XmppInfoPlugin::XmppInfoPlugin( XmppSipPlugin* sipPlugin )
|
||||
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::~XmppInfoPlugin()
|
||||
{
|
||||
//Note: the next two lines don't currently work, because the deletion wipes out internally posted events, need to talk to euro about a fix
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
|
||||
m_pubSubManager->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::init()
|
||||
{
|
||||
if ( QThread::currentThread() != Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() )
|
||||
{
|
||||
QMetaObject::invokeMethod( this, "init", Qt::QueuedConnection );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_sipPlugin.isNull() )
|
||||
return;
|
||||
|
||||
connect( this, SIGNAL( publishTune( QUrl, Tomahawk::InfoSystem::InfoStringHash ) ), m_sipPlugin.data(), SLOT( publishTune( QUrl, Tomahawk::InfoSystem::InfoStringHash ) ), Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin.data()->m_client->jid().full();
|
||||
|
||||
if( m_sipPlugin.data()->m_account->configuration().value("publishtracks").toBool() == false )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin.data()->m_client->jid().full() << "Not publishing now playing info (disabled in account config)";
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( pushData.type )
|
||||
{
|
||||
case InfoNowPlaying:
|
||||
@ -109,8 +100,7 @@ Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted( const Tomahawk::InfoSystem::
|
||||
QVariantMap map = pushInfoPair.second.toMap();
|
||||
if ( map.contains( "private" ) && map[ "private" ] == TomahawkSettings::FullyPrivate )
|
||||
{
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems( QList<Jreen::Payload::Ptr>() << tune, Jreen::JID() );
|
||||
emit publishTune( QUrl(), Tomahawk::InfoSystem::InfoStringHash() );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -121,42 +111,25 @@ Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted( const Tomahawk::InfoSystem::
|
||||
}
|
||||
|
||||
Tomahawk::InfoSystem::InfoStringHash info = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >();
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin.data()->m_client->jid().full() << info;
|
||||
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
|
||||
tune->setTitle( info.value( "title" ) );
|
||||
tune->setArtist( info.value( "artist" ) );
|
||||
tune->setLength( info.value("duration").toInt() );
|
||||
tune->setTrack( info.value("albumpos") );
|
||||
QUrl url;
|
||||
if ( pushInfoPair.first.contains( "shorturl" ) )
|
||||
tune->setUri( pushInfoPair.first[ "shorturl" ].toUrl() );
|
||||
url = pushInfoPair.first[ "shorturl" ].toUrl();
|
||||
else
|
||||
tune->setUri( GlobalActionManager::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) ) );
|
||||
url = GlobalActionManager::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) );
|
||||
|
||||
tDebug() << Q_FUNC_INFO << "Setting URI of " << tune->uri().toString();
|
||||
//TODO: provide a rating once available in Tomahawk
|
||||
tune->setRating( 10 );
|
||||
|
||||
//TODO: it would be nice to set Spotify, Dilandau etc here, but not the jabber ids of friends
|
||||
tune->setSource( "Tomahawk" );
|
||||
|
||||
m_pubSubManager->publishItems( QList<Jreen::Payload::Ptr>() << tune, Jreen::JID() );
|
||||
emit publishTune( url, info );
|
||||
}
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::audioPaused()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin.data()->m_client->jid().full();
|
||||
}
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::audioStopped()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin.data()->m_client->jid().full();
|
||||
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
|
||||
emit publishTune( QUrl(), Tomahawk::InfoSystem::InfoStringHash() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,12 +24,6 @@
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace Jreen {
|
||||
namespace PubSub {
|
||||
class Manager;
|
||||
}
|
||||
}
|
||||
|
||||
class XmppSipPlugin;
|
||||
|
||||
namespace Tomahawk {
|
||||
@ -44,7 +38,11 @@ namespace Tomahawk {
|
||||
XmppInfoPlugin(XmppSipPlugin* parent);
|
||||
virtual ~XmppInfoPlugin();
|
||||
|
||||
signals:
|
||||
void publishTune( QUrl url, Tomahawk::InfoSystem::InfoStringHash trackInfo );
|
||||
|
||||
public slots:
|
||||
void init();
|
||||
void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||
|
||||
protected slots:
|
||||
@ -58,7 +56,6 @@ namespace Tomahawk {
|
||||
|
||||
private:
|
||||
QWeakPointer< XmppSipPlugin > m_sipPlugin;
|
||||
Jreen::PubSub::Manager* m_pubSubManager;
|
||||
QTimer m_pauseTimer;
|
||||
};
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <jreen/softwareversion.h>
|
||||
#include <jreen/iqreply.h>
|
||||
#include <jreen/logger.h>
|
||||
#include <jreen/tune.h>
|
||||
|
||||
#include <qjson/parser.h>
|
||||
#include <qjson/serializer.h>
|
||||
@ -90,6 +91,7 @@ XmppSipPlugin::XmppSipPlugin( Account *account )
|
||||
#ifndef ENABLE_HEADLESS
|
||||
, m_menu( 0 )
|
||||
, m_xmlConsole( 0 )
|
||||
, m_pubSubManager( 0 )
|
||||
#endif
|
||||
{
|
||||
Jreen::Logger::addHandler( JreenMessageHandler );
|
||||
@ -160,10 +162,22 @@ XmppSipPlugin::XmppSipPlugin( Account *account )
|
||||
#ifndef ENABLE_HEADLESS
|
||||
connect(m_avatarManager, SIGNAL(newAvatar(QString)), SLOT(onNewAvatar(QString)));
|
||||
#endif
|
||||
|
||||
m_pubSubManager = new Jreen::PubSub::Manager( m_client );
|
||||
m_pubSubManager->addEntityType< Jreen::Tune >();
|
||||
|
||||
// Clear status
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
|
||||
|
||||
}
|
||||
|
||||
XmppSipPlugin::~XmppSipPlugin()
|
||||
{
|
||||
//Note: the next two lines don't currently work, because the deletion wipes out internally posted events, need to talk to euro about a fix
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
|
||||
delete m_pubSubManager;
|
||||
delete m_avatarManager;
|
||||
delete m_roster;
|
||||
#ifndef ENABLE_HEADLESS
|
||||
@ -242,6 +256,8 @@ XmppSipPlugin::disconnectPlugin()
|
||||
|
||||
m_peers.clear();
|
||||
|
||||
publishTune( QUrl(), Tomahawk::InfoSystem::InfoStringHash() );
|
||||
|
||||
m_client->disconnectFromServer( true );
|
||||
m_state = Account::Disconnecting;
|
||||
emit stateChanged( m_state );
|
||||
@ -273,8 +289,12 @@ XmppSipPlugin::onConnect()
|
||||
m_roster->load();
|
||||
|
||||
// load XmppInfoPlugin
|
||||
if( infoPlugin() )
|
||||
InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
|
||||
if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() )
|
||||
{
|
||||
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
|
||||
QMetaObject::invokeMethod( infoPlugin().data(), "init", Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
//FIXME: this implementation is totally broken atm, so it's disabled to avoid harm :P
|
||||
// join MUC with bare jid as nickname
|
||||
@ -510,6 +530,41 @@ XmppSipPlugin::showAddFriendDialog()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmppSipPlugin::publishTune( const QUrl& url, const InfoSystem::InfoStringHash& trackInfo )
|
||||
{
|
||||
if( m_account->configuration().value("publishtracks").toBool() == false )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_client->jid().full() << "Not publishing now playing info (disabled in account config)";
|
||||
return;
|
||||
}
|
||||
|
||||
if ( trackInfo.isEmpty() )
|
||||
{
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
|
||||
}
|
||||
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
|
||||
tune->setTitle( trackInfo.value( "title" ) );
|
||||
tune->setArtist( trackInfo.value( "artist" ) );
|
||||
tune->setLength( trackInfo.value("duration").toInt() );
|
||||
tune->setTrack( trackInfo.value("albumpos") );
|
||||
|
||||
//TODO: provide a rating once available in Tomahawk
|
||||
tune->setRating( 10 );
|
||||
|
||||
//TODO: it would be nice to set Spotify, Dilandau etc here, but not the jabber ids of friends
|
||||
tune->setSource( "Tomahawk" );
|
||||
|
||||
tune->setUri( url );
|
||||
tDebug() << Q_FUNC_INFO << "Setting URI of " << tune->uri().toString();
|
||||
|
||||
m_pubSubManager->publishItems( QList<Jreen::Payload::Ptr>() << tune, Jreen::JID() );
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
XmppSipPlugin::defaultSuffix() const
|
||||
{
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <jreen/abstractroster.h>
|
||||
#include <jreen/connection.h>
|
||||
#include <jreen/mucroom.h>
|
||||
#include <jreen/pubsubmanager.h>
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
#include <QtGui/QMessageBox>
|
||||
@ -92,6 +93,7 @@ public slots:
|
||||
void broadcastMsg( const QString &msg );
|
||||
virtual void addContact( const QString &jid, const QString& msg = QString() );
|
||||
void showAddFriendDialog();
|
||||
void publishTune( const QUrl &url, const Tomahawk::InfoSystem::InfoStringHash &trackInfo );
|
||||
|
||||
protected:
|
||||
virtual QString defaultSuffix() const;
|
||||
@ -147,6 +149,7 @@ private:
|
||||
#endif
|
||||
enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
|
||||
AvatarManager *m_avatarManager;
|
||||
Jreen::PubSub::Manager* m_pubSubManager;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user