mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 09:19:41 +01:00
Add XmppInfoPlugin for updating the user tune
This commit is contained in:
parent
5593c134cd
commit
8e0f44a374
@ -14,6 +14,7 @@ set( xmppAccountSources
|
||||
sip/tomahawkxmppmessagefactory.cpp
|
||||
sip/avatarmanager.cpp
|
||||
sip/xmlconsole.cpp
|
||||
XmppInfoPlugin.cpp
|
||||
)
|
||||
|
||||
set( xmppAccountHeaders
|
||||
@ -22,6 +23,7 @@ set( xmppAccountHeaders
|
||||
sip/xmppsip.h
|
||||
sip/avatarmanager.h
|
||||
sip/xmlconsole.h
|
||||
XmppInfoPlugin.h
|
||||
)
|
||||
|
||||
set( xmppAccountUI
|
||||
|
137
src/accounts/xmpp/XmppInfoPlugin.cpp
Normal file
137
src/accounts/xmpp/XmppInfoPlugin.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2012, Dominik Schmidt <domme@tomahawk-player.org>
|
||||
*
|
||||
* 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 "XmppInfoPlugin.h"
|
||||
|
||||
#include "globalactionmanager.h"
|
||||
#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;
|
||||
|
||||
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 >();
|
||||
|
||||
m_pauseTimer.setSingleShot( true );
|
||||
connect( &m_pauseTimer, SIGNAL( timeout() ),
|
||||
this, SLOT( audioStopped() ) );
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::~XmppInfoPlugin()
|
||||
{
|
||||
delete m_pubSubManager;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::pushInfo(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input)
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case InfoNowPlaying:
|
||||
case InfoNowResumed:
|
||||
m_pauseTimer.stop();
|
||||
if ( input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||
audioStarted( input.value< Tomahawk::InfoSystem::InfoStringHash >() );
|
||||
break;
|
||||
case InfoNowPaused:
|
||||
m_pauseTimer.start( PAUSE_TIMEOUT * 1000 );
|
||||
audioPaused();
|
||||
break;
|
||||
case InfoNowStopped:
|
||||
m_pauseTimer.stop();
|
||||
audioStopped();
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted(const Tomahawk::InfoSystem::InfoStringHash& info)
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin->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") );
|
||||
tune->setUri( GlobalActionManager::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) ) );
|
||||
|
||||
//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() );
|
||||
}
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::audioPaused()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full();
|
||||
}
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::audioStopped()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full();
|
||||
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::getInfo(Tomahawk::InfoSystem::InfoRequestData requestData)
|
||||
{
|
||||
Q_UNUSED( requestData );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::XmppInfoPlugin::notInCacheSlot(const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData)
|
||||
{
|
||||
Q_UNUSED( criteria );
|
||||
Q_UNUSED( requestData );
|
||||
}
|
68
src/accounts/xmpp/XmppInfoPlugin.h
Normal file
68
src/accounts/xmpp/XmppInfoPlugin.h
Normal file
@ -0,0 +1,68 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2012, Dominik Schmidt <domme@tomahawk-player.org>
|
||||
*
|
||||
* 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 XMPPINFOPLUGIN_H
|
||||
#define XMPPINFOPLUGIN_H
|
||||
|
||||
#include "infosystem/infosystem.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace Jreen {
|
||||
namespace PubSub {
|
||||
class Manager;
|
||||
}
|
||||
}
|
||||
|
||||
class XmppSipPlugin;
|
||||
|
||||
namespace Tomahawk {
|
||||
|
||||
namespace InfoSystem {
|
||||
|
||||
class XmppInfoPlugin : public InfoPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
XmppInfoPlugin(XmppSipPlugin* parent);
|
||||
virtual ~XmppInfoPlugin();
|
||||
|
||||
public slots:
|
||||
void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||
|
||||
protected slots:
|
||||
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||
|
||||
private slots:
|
||||
void audioStarted( const Tomahawk::InfoSystem::InfoStringHash& info );
|
||||
void audioStopped();
|
||||
void audioPaused();
|
||||
|
||||
private:
|
||||
XmppSipPlugin* m_sipPlugin;
|
||||
Jreen::PubSub::Manager* m_pubSubManager;
|
||||
QTimer m_pauseTimer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // XMPPINFOPLUGIN_H
|
@ -7,6 +7,7 @@ set( googleHeaders
|
||||
../sip/xmppsip.h
|
||||
../sip/avatarmanager.h
|
||||
../sip/xmlconsole.h
|
||||
../XmppInfoPlugin.h
|
||||
googlewrapper.h )
|
||||
|
||||
set( googleSources
|
||||
@ -17,6 +18,7 @@ set( googleSources
|
||||
../sip/tomahawkxmppmessagefactory.cpp
|
||||
../sip/avatarmanager.cpp
|
||||
../sip/xmlconsole.cpp
|
||||
../XmppInfoPlugin.cpp
|
||||
|
||||
googlewrapper.cpp )
|
||||
|
||||
|
@ -56,6 +56,7 @@
|
||||
|
||||
#include <utils/tomahawkutilsgui.h>
|
||||
#include "utils/logger.h"
|
||||
#include "XmppInfoPlugin.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
using namespace Accounts;
|
||||
@ -85,6 +86,7 @@ JreenMessageHandler(QtMsgType type, const char *msg)
|
||||
|
||||
XmppSipPlugin::XmppSipPlugin( Account *account )
|
||||
: SipPlugin( account )
|
||||
, m_infoPlugin( 0 )
|
||||
, m_state( Account::Disconnected )
|
||||
#ifndef ENABLE_HEADLESS
|
||||
, m_menu( 0 )
|
||||
@ -163,6 +165,7 @@ XmppSipPlugin::XmppSipPlugin( Account *account )
|
||||
|
||||
XmppSipPlugin::~XmppSipPlugin()
|
||||
{
|
||||
delete m_infoPlugin;
|
||||
delete m_avatarManager;
|
||||
delete m_roster;
|
||||
#ifndef ENABLE_HEADLESS
|
||||
@ -172,6 +175,13 @@ XmppSipPlugin::~XmppSipPlugin()
|
||||
}
|
||||
|
||||
|
||||
InfoSystem::InfoPlugin*
|
||||
XmppSipPlugin::infoPlugin()
|
||||
{
|
||||
return m_infoPlugin;
|
||||
}
|
||||
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
QMenu*
|
||||
XmppSipPlugin::menu()
|
||||
@ -255,6 +265,13 @@ XmppSipPlugin::onConnect()
|
||||
// load roster
|
||||
m_roster->load();
|
||||
|
||||
// load XmppInfoPlugin
|
||||
if( !m_infoPlugin )
|
||||
{
|
||||
m_infoPlugin = new Tomahawk::InfoSystem::XmppInfoPlugin( this );
|
||||
InfoSystem::InfoSystem::instance()->addInfoPlugin( m_infoPlugin );
|
||||
}
|
||||
|
||||
//FIXME: this implementation is totally broken atm, so it's disabled to avoid harm :P
|
||||
// join MUC with bare jid as nickname
|
||||
//TODO: make the room a list of rooms and make that configurable
|
||||
|
@ -52,10 +52,14 @@
|
||||
|
||||
#include "accounts/accountdllmacro.h"
|
||||
|
||||
#include "XmppInfoPlugin.h"
|
||||
|
||||
class ACCOUNTDLLEXPORT XmppSipPlugin : public SipPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class Tomahawk::InfoSystem::XmppInfoPlugin;
|
||||
|
||||
public:
|
||||
XmppSipPlugin( Tomahawk::Accounts::Account* account );
|
||||
virtual ~XmppSipPlugin();
|
||||
@ -63,6 +67,8 @@ public:
|
||||
//FIXME: Make this more correct
|
||||
virtual bool isValid() const { return true; }
|
||||
|
||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin();
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
virtual QMenu* menu();
|
||||
#endif
|
||||
@ -123,10 +129,11 @@ private:
|
||||
QString m_currentPassword;
|
||||
QString m_currentServer;
|
||||
int m_currentPort;
|
||||
Tomahawk::Accounts::Account::ConnectionState m_state;
|
||||
|
||||
QString m_currentResource;
|
||||
|
||||
Tomahawk::InfoSystem::InfoPlugin* m_infoPlugin;
|
||||
Tomahawk::Accounts::Account::ConnectionState m_state;
|
||||
|
||||
// sort out
|
||||
Jreen::Client *m_client;
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "xmppconfigwidget.h"
|
||||
#include "sip/SipPlugin.h"
|
||||
#include "ui_xmppconfigwidget.h"
|
||||
#include "XmppInfoPlugin.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
@ -90,6 +91,16 @@ XmppAccount::saveConfig()
|
||||
}
|
||||
|
||||
|
||||
InfoSystem::InfoPlugin*
|
||||
XmppAccount::infoPlugin()
|
||||
{
|
||||
if( !m_xmppSipPlugin.isNull() )
|
||||
m_xmppSipPlugin.data()->infoPlugin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
SipPlugin*
|
||||
XmppAccount::sipPlugin()
|
||||
{
|
||||
|
@ -69,7 +69,8 @@ public:
|
||||
void deauthenticate();
|
||||
bool isAuthenticated() const;
|
||||
|
||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
|
||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin();
|
||||
|
||||
SipPlugin* sipPlugin();
|
||||
|
||||
QWidget* configurationWidget() { return m_configWidget.data(); }
|
||||
@ -81,6 +82,7 @@ public:
|
||||
protected:
|
||||
QWeakPointer< QWidget > m_configWidget; // so the google wrapper can change the config dialog a bit
|
||||
QWeakPointer< XmppSipPlugin > m_xmppSipPlugin;
|
||||
QWeakPointer< Tomahawk::InfoSystem::XmppInfoPlugin > m_xmppInfoPlugin;
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -78,7 +78,7 @@ AudioEngine::AudioEngine()
|
||||
connect( m_audioOutput, SIGNAL( volumeChanged( qreal ) ), SLOT( onVolumeChanged( qreal ) ) );
|
||||
|
||||
connect( this, SIGNAL( sendWaitingNotification() ), SLOT( sendWaitingNotificationSlot() ), Qt::QueuedConnection );
|
||||
|
||||
|
||||
onVolumeChanged( m_audioOutput->volume() );
|
||||
|
||||
#ifndef Q_WS_X11
|
||||
@ -134,14 +134,22 @@ AudioEngine::play()
|
||||
{
|
||||
m_mediaObject->play();
|
||||
emit resumed();
|
||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
||||
|
||||
trackInfo["title"] = m_currentTrack->track();
|
||||
trackInfo["artist"] = m_currentTrack->artist()->name();
|
||||
trackInfo["album"] = m_currentTrack->album()->name();
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
|
||||
s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowResumed,
|
||||
QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ) );
|
||||
if ( TomahawkSettings::instance()->privateListeningMode() != TomahawkSettings::FullyPrivate )
|
||||
{
|
||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
||||
|
||||
trackInfo["title"] = m_currentTrack->track();
|
||||
trackInfo["artist"] = m_currentTrack->artist()->name();
|
||||
trackInfo["album"] = m_currentTrack->album()->name();
|
||||
trackInfo["albumpos"] = QString::number( m_currentTrack->albumpos() );
|
||||
trackInfo["duration"] = QString::number( m_currentTrack->duration() );
|
||||
|
||||
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
|
||||
s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowResumed,
|
||||
QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
next();
|
||||
@ -319,7 +327,7 @@ AudioEngine::sendWaitingNotificationSlot() const
|
||||
//since it's async, after this is triggered our result could come in, so don't show the popup in that case
|
||||
if ( !m_playlist.isNull() && m_playlist->hasNextItem() )
|
||||
return;
|
||||
|
||||
|
||||
QVariantMap retryInfo;
|
||||
retryInfo["message"] = QString( "The current track could not be resolved. Tomahawk will pick back up with the next resolvable track from this source." );
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
|
||||
@ -460,6 +468,8 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
|
||||
trackInfo["title"] = m_currentTrack->track();
|
||||
trackInfo["artist"] = m_currentTrack->artist()->name();
|
||||
trackInfo["album"] = m_currentTrack->album()->name();
|
||||
trackInfo["duration"] = QString::number( m_currentTrack->duration() );
|
||||
trackInfo["albumpos"] = QString::number( m_currentTrack->albumpos() );
|
||||
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
|
||||
s_aeInfoIdentifier,
|
||||
|
Loading…
x
Reference in New Issue
Block a user