1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 16:29:43 +01:00

Implement PropertiesChanged for AudioState in MPRIS.

This commit is contained in:
Alejandro Wainzinger 2011-08-12 07:25:33 -07:00
parent 5f59b30a8c
commit ce396ab060
2 changed files with 48 additions and 9 deletions

View File

@ -39,6 +39,8 @@ MprisPlugin::MprisPlugin()
{
qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Stopped";
m_supportedPushTypes << InfoNowPlaying << InfoNowPaused << InfoNowResumed << InfoNowStopped;
new MprisPluginRootAdaptor( this );
@ -225,13 +227,7 @@ MprisPlugin::minimumRate() const
QString
MprisPlugin::playbackStatus() const
{
if( AudioEngine::instance()->state() == AudioEngine::Playing )
return "Playing";
else if( AudioEngine::instance()->state() == AudioEngine::Paused )
return "Paused";
else if( AudioEngine::instance()->state() == AudioEngine::Stopped )
return "Stopped";
return QString("");
return m_playbackStatus;
}
qlonglong
@ -365,26 +361,40 @@ void
MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input )
{
qDebug() << Q_FUNC_INFO;
bool isPlayingInfo = false;
switch ( type )
{
case InfoNowPlaying:
isPlayingInfo = true;
audioStarted( input );
break;
case InfoNowPaused:
isPlayingInfo = true;
audioPaused();
return;
break;
case InfoNowResumed:
isPlayingInfo = true;
audioResumed( input );
break;
case InfoNowStopped:
isPlayingInfo = true;
audioStopped();
break;
default:
return;
break;
}
if( isPlayingInfo )
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "PlaybackStatus");
}
void
MprisPlugin::stateChanged( AudioState newState, AudioState oldState )
{
}
/** Audio state slots */
@ -393,6 +403,8 @@ MprisPlugin::audioStarted( const QVariant &input )
{
qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Playing";
if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
return;
@ -416,12 +428,14 @@ void
MprisPlugin::audioStopped()
{
qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Stopped";
}
void
MprisPlugin::audioPaused()
{
qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Paused";
}
void
@ -430,3 +444,20 @@ MprisPlugin::audioResumed( const QVariant &input )
qDebug() << Q_FUNC_INFO;
audioStarted( input );
}
void
MprisPlugin::notifyPropertyChanged( const QString& interface,
const QString& propertyName )
{
QDBusMessage signal = QDBusMessage::createSignal(
"/org/mpris/MediaPlayer2",
"org.freedesktop.DBus.Properties",
"PropertiesChanged");
signal << interface;
QVariantMap changedProps;
changedProps.insert(propertyName, property(propertyName.toAscii()));
signal << changedProps;
signal << QStringList();
QDBusConnection::sessionBus().send(signal);
}

View File

@ -19,6 +19,7 @@
#ifndef MPRISPLUGIN_H
#define MPRISPLUGIN_H
#include "audio/audioengine.h"
#include "infosystem/infosystem.h"
#include <QObject>
@ -143,6 +144,9 @@ protected slots:
void getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
private slots:
void stateChanged( AudioState newState, AudioState oldState );
private:
// Get Info
@ -153,6 +157,10 @@ private:
void audioPaused();
void audioResumed( const QVariant &input );
// DBus
void notifyPropertyChanged( const QString& interface, const QString& propertyName );
QString m_playbackStatus;
};
};