diff --git a/src/accounts/xmpp/CMakeLists.txt b/src/accounts/xmpp/CMakeLists.txt index aaa6ce0ce..03313b8df 100644 --- a/src/accounts/xmpp/CMakeLists.txt +++ b/src/accounts/xmpp/CMakeLists.txt @@ -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 diff --git a/src/accounts/xmpp/XmppInfoPlugin.cpp b/src/accounts/xmpp/XmppInfoPlugin.cpp new file mode 100644 index 000000000..6cfd7cc0f --- /dev/null +++ b/src/accounts/xmpp/XmppInfoPlugin.cpp @@ -0,0 +1,137 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Dominik Schmidt + * + * 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 . + */ + + +#include "XmppInfoPlugin.h" + +#include "globalactionmanager.h" +#include "sip/xmppsip.h" +#include "utils/logger.h" + +#include +#include +#include + +#include + +// 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() << 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() << 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 ); +} diff --git a/src/accounts/xmpp/XmppInfoPlugin.h b/src/accounts/xmpp/XmppInfoPlugin.h new file mode 100644 index 000000000..f7d298de4 --- /dev/null +++ b/src/accounts/xmpp/XmppInfoPlugin.h @@ -0,0 +1,68 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Dominik Schmidt + * + * 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 . + */ + +#ifndef XMPPINFOPLUGIN_H +#define XMPPINFOPLUGIN_H + +#include "infosystem/infosystem.h" + +#include + +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 diff --git a/src/accounts/xmpp/googlewrapper/CMakeLists.txt b/src/accounts/xmpp/googlewrapper/CMakeLists.txt index b7631e19b..a6c1a7ce3 100644 --- a/src/accounts/xmpp/googlewrapper/CMakeLists.txt +++ b/src/accounts/xmpp/googlewrapper/CMakeLists.txt @@ -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 ) diff --git a/src/accounts/xmpp/sip/xmppsip.cpp b/src/accounts/xmpp/sip/xmppsip.cpp index 1e877c40e..6ff55b7c7 100644 --- a/src/accounts/xmpp/sip/xmppsip.cpp +++ b/src/accounts/xmpp/sip/xmppsip.cpp @@ -56,6 +56,7 @@ #include #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 diff --git a/src/accounts/xmpp/sip/xmppsip.h b/src/accounts/xmpp/sip/xmppsip.h index 722d04f53..33b7b61dd 100644 --- a/src/accounts/xmpp/sip/xmppsip.h +++ b/src/accounts/xmpp/sip/xmppsip.h @@ -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; diff --git a/src/accounts/xmpp/xmppaccount.cpp b/src/accounts/xmpp/xmppaccount.cpp index bb3cbcf2c..3ea09aeab 100644 --- a/src/accounts/xmpp/xmppaccount.cpp +++ b/src/accounts/xmpp/xmppaccount.cpp @@ -22,6 +22,7 @@ #include "xmppconfigwidget.h" #include "sip/SipPlugin.h" #include "ui_xmppconfigwidget.h" +#include "XmppInfoPlugin.h" #include @@ -90,6 +91,16 @@ XmppAccount::saveConfig() } +InfoSystem::InfoPlugin* +XmppAccount::infoPlugin() +{ + if( !m_xmppSipPlugin.isNull() ) + m_xmppSipPlugin.data()->infoPlugin(); + + return 0; +} + + SipPlugin* XmppAccount::sipPlugin() { diff --git a/src/accounts/xmpp/xmppaccount.h b/src/accounts/xmpp/xmppaccount.h index ad45d3414..8529d9e11 100644 --- a/src/accounts/xmpp/xmppaccount.h +++ b/src/accounts/xmpp/xmppaccount.h @@ -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; }; }; diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index 97ef2902b..6ea43c6e8 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -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,