1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 20:00:13 +02: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; qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Stopped";
m_supportedPushTypes << InfoNowPlaying << InfoNowPaused << InfoNowResumed << InfoNowStopped; m_supportedPushTypes << InfoNowPlaying << InfoNowPaused << InfoNowResumed << InfoNowStopped;
new MprisPluginRootAdaptor( this ); new MprisPluginRootAdaptor( this );
@@ -225,13 +227,7 @@ MprisPlugin::minimumRate() const
QString QString
MprisPlugin::playbackStatus() const MprisPlugin::playbackStatus() const
{ {
if( AudioEngine::instance()->state() == AudioEngine::Playing ) return m_playbackStatus;
return "Playing";
else if( AudioEngine::instance()->state() == AudioEngine::Paused )
return "Paused";
else if( AudioEngine::instance()->state() == AudioEngine::Stopped )
return "Stopped";
return QString("");
} }
qlonglong qlonglong
@@ -365,26 +361,40 @@ void
MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ) MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
bool isPlayingInfo = false;
switch ( type ) switch ( type )
{ {
case InfoNowPlaying: case InfoNowPlaying:
isPlayingInfo = true;
audioStarted( input ); audioStarted( input );
break; break;
case InfoNowPaused: case InfoNowPaused:
isPlayingInfo = true;
audioPaused(); audioPaused();
return; break;
case InfoNowResumed: case InfoNowResumed:
isPlayingInfo = true;
audioResumed( input ); audioResumed( input );
break; break;
case InfoNowStopped: case InfoNowStopped:
isPlayingInfo = true;
audioStopped(); audioStopped();
break; break;
default: default:
return; break;
} }
if( isPlayingInfo )
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "PlaybackStatus");
}
void
MprisPlugin::stateChanged( AudioState newState, AudioState oldState )
{
} }
/** Audio state slots */ /** Audio state slots */
@@ -393,6 +403,8 @@ MprisPlugin::audioStarted( const QVariant &input )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Playing";
if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() ) if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
return; return;
@@ -416,12 +428,14 @@ void
MprisPlugin::audioStopped() MprisPlugin::audioStopped()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Stopped";
} }
void void
MprisPlugin::audioPaused() MprisPlugin::audioPaused()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Paused";
} }
void void
@@ -430,3 +444,20 @@ MprisPlugin::audioResumed( const QVariant &input )
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
audioStarted( input ); 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 #ifndef MPRISPLUGIN_H
#define MPRISPLUGIN_H #define MPRISPLUGIN_H
#include "audio/audioengine.h"
#include "infosystem/infosystem.h" #include "infosystem/infosystem.h"
#include <QObject> #include <QObject>
@@ -143,6 +144,9 @@ protected slots:
void getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); void getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ); void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
private slots:
void stateChanged( AudioState newState, AudioState oldState );
private: private:
// Get Info // Get Info
@@ -153,6 +157,10 @@ private:
void audioPaused(); void audioPaused();
void audioResumed( const QVariant &input ); void audioResumed( const QVariant &input );
// DBus
void notifyPropertyChanged( const QString& interface, const QString& propertyName );
QString m_playbackStatus;
}; };
}; };