mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Implement most MPRIS methods, minus metadata and related methods.
This commit is contained in:
@@ -224,7 +224,7 @@ AudioEngine::next()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AudioEngine::seek( int ms )
|
AudioEngine::seek( qint64 ms )
|
||||||
{
|
{
|
||||||
if ( !m_playlist.isNull() && m_playlist.data()->seekRestrictions() == PlaylistInterface::NoSeek )
|
if ( !m_playlist.isNull() && m_playlist.data()->seekRestrictions() == PlaylistInterface::NoSeek )
|
||||||
return;
|
return;
|
||||||
@@ -236,6 +236,11 @@ AudioEngine::seek( int ms )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AudioEngine::seek( int ms )
|
||||||
|
{
|
||||||
|
seek( (qint64) ms );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AudioEngine::setVolume( int percentage )
|
AudioEngine::setVolume( int percentage )
|
||||||
|
@@ -69,6 +69,9 @@ public:
|
|||||||
|
|
||||||
Tomahawk::result_ptr currentTrack() const { return m_currentTrack; }
|
Tomahawk::result_ptr currentTrack() const { return m_currentTrack; }
|
||||||
|
|
||||||
|
qint64 currentTime() const { return m_mediaObject->currentTime(); }
|
||||||
|
qint64 currentTrackTotalTime() const { return m_mediaObject->totalTime(); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void playPause();
|
void playPause();
|
||||||
void play();
|
void play();
|
||||||
@@ -78,7 +81,8 @@ public slots:
|
|||||||
void previous();
|
void previous();
|
||||||
void next();
|
void next();
|
||||||
|
|
||||||
void seek( int ms );
|
void seek( qint64 ms );
|
||||||
|
void seek( int ms ); // for compatibility with seekbar in audiocontrols
|
||||||
void setVolume( int percentage );
|
void setVolume( int percentage );
|
||||||
void lowerVolume() { setVolume( volume() - AUDIO_VOLUME_STEP ); }
|
void lowerVolume() { setVolume( volume() - AUDIO_VOLUME_STEP ); }
|
||||||
void raiseVolume() { setVolume( volume() + AUDIO_VOLUME_STEP ); }
|
void raiseVolume() { setVolume( volume() + AUDIO_VOLUME_STEP ); }
|
||||||
|
@@ -16,8 +16,10 @@
|
|||||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QtDBus/QtDBus>
|
#include <QtDBus/QtDBus>
|
||||||
|
|
||||||
|
#include "audio/audioengine.h"
|
||||||
#include "infosystem/infosystemworker.h"
|
#include "infosystem/infosystemworker.h"
|
||||||
#include "artist.h"
|
#include "artist.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
@@ -58,7 +60,7 @@ bool
|
|||||||
MprisPlugin::canQuit() const
|
MprisPlugin::canQuit() const
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -109,6 +111,7 @@ MprisPlugin::Raise()
|
|||||||
void
|
void
|
||||||
MprisPlugin::Quit()
|
MprisPlugin::Quit()
|
||||||
{
|
{
|
||||||
|
QApplication::quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// org.mpris.MediaPlayer2.Player
|
// org.mpris.MediaPlayer2.Player
|
||||||
@@ -116,54 +119,83 @@ MprisPlugin::Quit()
|
|||||||
bool
|
bool
|
||||||
MprisPlugin::canControl() const
|
MprisPlugin::canControl() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canGoNext() const
|
MprisPlugin::canGoNext() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canGoPrevious() const
|
MprisPlugin::canGoPrevious() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canPause() const
|
MprisPlugin::canPause() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canPlay() const
|
MprisPlugin::canPlay() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::canSeek() const
|
MprisPlugin::canSeek() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
MprisPlugin::loopStatus() const
|
MprisPlugin::loopStatus() const
|
||||||
{
|
{
|
||||||
return QString("");
|
PlaylistInterface *p = AudioEngine::instance()->playlist();
|
||||||
|
if (!p)
|
||||||
|
return "None";
|
||||||
|
PlaylistInterface::RepeatMode mode = p->repeatMode();
|
||||||
|
switch( mode )
|
||||||
|
{
|
||||||
|
case PlaylistInterface::RepeatOne:
|
||||||
|
return "Track";
|
||||||
|
break;
|
||||||
|
case PlaylistInterface::RepeatAll:
|
||||||
|
return "Playlist";
|
||||||
|
break;
|
||||||
|
case PlaylistInterface::NoRepeat:
|
||||||
|
return "None";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return QString("None");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::setLoopStatus(const QString &value)
|
MprisPlugin::setLoopStatus( const QString &value )
|
||||||
{
|
{
|
||||||
|
PlaylistInterface *p = AudioEngine::instance()->playlist();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
|
if( value == "Track")
|
||||||
|
p->setRepeatMode( PlaylistInterface::RepeatOne );
|
||||||
|
else if( value == "Playlist" )
|
||||||
|
p->setRepeatMode( PlaylistInterface::RepeatAll );
|
||||||
|
else if( value == "None" )
|
||||||
|
p->setRepeatMode( PlaylistInterface::NoRepeat );
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
MprisPlugin::maximumRate() const
|
MprisPlugin::maximumRate() const
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap
|
QVariantMap
|
||||||
@@ -175,92 +207,131 @@ MprisPlugin::metadata() const
|
|||||||
double
|
double
|
||||||
MprisPlugin::minimumRate() const
|
MprisPlugin::minimumRate() const
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
MprisPlugin::playbackStatus() const
|
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 QString("");
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong
|
qlonglong
|
||||||
MprisPlugin::position() const
|
MprisPlugin::position() const
|
||||||
{
|
{
|
||||||
return 0;
|
// Convert Tomahawk's milliseconds to microseconds
|
||||||
|
return (qlonglong) ( AudioEngine::instance()->currentTime() * 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
MprisPlugin::rate() const
|
MprisPlugin::rate() const
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::setRate( double value )
|
MprisPlugin::setRate( double value )
|
||||||
{
|
{
|
||||||
|
Q_UNUSED( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MprisPlugin::shuffle() const
|
MprisPlugin::shuffle() const
|
||||||
{
|
{
|
||||||
|
PlaylistInterface *p = AudioEngine::instance()->playlist();
|
||||||
|
if (!p)
|
||||||
return false;
|
return false;
|
||||||
|
return p->shuffled();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::setShuffle( bool value )
|
MprisPlugin::setShuffle( bool value )
|
||||||
{
|
{
|
||||||
|
PlaylistInterface *p = AudioEngine::instance()->playlist();
|
||||||
|
if (!p)
|
||||||
|
return;
|
||||||
|
return p->setShuffled( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
MprisPlugin::volume() const
|
MprisPlugin::volume() const
|
||||||
{
|
{
|
||||||
return 0.0;
|
return AudioEngine::instance()->volume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MprisPlugin::setVolume( double value )
|
||||||
|
{
|
||||||
|
AudioEngine::instance()->setVolume( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Next()
|
MprisPlugin::Next()
|
||||||
{
|
{
|
||||||
|
AudioEngine::instance()->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::OpenUri(const QString &Uri)
|
MprisPlugin::OpenUri(const QString &Uri)
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Pause()
|
MprisPlugin::Pause()
|
||||||
{
|
{
|
||||||
|
AudioEngine::instance()->pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Play()
|
MprisPlugin::Play()
|
||||||
{
|
{
|
||||||
|
AudioEngine::instance()->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::PlayPause()
|
MprisPlugin::PlayPause()
|
||||||
{
|
{
|
||||||
|
AudioEngine::instance()->playPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Previous()
|
MprisPlugin::Previous()
|
||||||
{
|
{
|
||||||
|
AudioEngine::instance()->previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Seek( qlonglong Offset )
|
MprisPlugin::Seek( qlonglong Offset )
|
||||||
{
|
{
|
||||||
|
qlonglong seekTime = position() + Offset;
|
||||||
|
if( seekTime < 0 )
|
||||||
|
AudioEngine::instance()->seek( 0 );
|
||||||
|
else if( seekTime > AudioEngine::instance()->currentTrackTotalTime() )
|
||||||
|
Next();
|
||||||
|
// seekTime is in microseconds, but we work internally in milliseconds
|
||||||
|
else
|
||||||
|
AudioEngine::instance()->seek( (qint64) ( seekTime / 1000 ) );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::SetPosition( const QDBusObjectPath &TrackId, qlonglong Position )
|
MprisPlugin::SetPosition( const QDBusObjectPath &TrackId, qlonglong Position )
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::Stop()
|
MprisPlugin::Stop()
|
||||||
{
|
{
|
||||||
|
AudioEngine::instance()->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// InfoPlugin Methods
|
// InfoPlugin Methods
|
||||||
|
@@ -109,8 +109,9 @@ public:
|
|||||||
bool shuffle() const;
|
bool shuffle() const;
|
||||||
void setShuffle(bool value);
|
void setShuffle(bool value);
|
||||||
|
|
||||||
Q_PROPERTY(double Volume READ volume)
|
Q_PROPERTY(double Volume READ volume WRITE setVolume)
|
||||||
double volume() const;
|
double volume() const;
|
||||||
|
void setVolume(double value);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void namChangedSlot( QNetworkAccessManager* /*nam*/ ) {} // unused
|
void namChangedSlot( QNetworkAccessManager* /*nam*/ ) {} // unused
|
||||||
|
@@ -141,6 +141,12 @@ double MprisPluginPlayerAdaptor::volume() const
|
|||||||
return qvariant_cast< double >(parent()->property("Volume"));
|
return qvariant_cast< double >(parent()->property("Volume"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MprisPluginPlayerAdaptor::setVolume(double value)
|
||||||
|
{
|
||||||
|
// set the value of property Volume
|
||||||
|
parent()->setProperty("Volume", qVariantFromValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
void MprisPluginPlayerAdaptor::Next()
|
void MprisPluginPlayerAdaptor::Next()
|
||||||
{
|
{
|
||||||
// handle method call org.mpris.MediaPlayer2.Player.Next
|
// handle method call org.mpris.MediaPlayer2.Player.Next
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
* before re-generating it.
|
* before re-generating it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPRISPLUGINPLAYERADAPTOR_H_1312900500
|
#ifndef MPRISPLUGINPLAYERADAPTOR_H_1313089554
|
||||||
#define MPRISPLUGINPLAYERADAPTOR_H_1312900500
|
#define MPRISPLUGINPLAYERADAPTOR_H_1313089554
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtDBus/QtDBus>
|
#include <QtDBus/QtDBus>
|
||||||
@@ -37,17 +37,17 @@ class MprisPluginPlayerAdaptor: public QDBusAbstractAdaptor
|
|||||||
" <method name=\"Stop\"/>\n"
|
" <method name=\"Stop\"/>\n"
|
||||||
" <method name=\"Play\"/>\n"
|
" <method name=\"Play\"/>\n"
|
||||||
" <method name=\"Seek\">\n"
|
" <method name=\"Seek\">\n"
|
||||||
" <arg type=\"x\" name=\"Offset\"/>\n"
|
" <arg direction=\"in\" type=\"x\" name=\"Offset\"/>\n"
|
||||||
" </method>\n"
|
" </method>\n"
|
||||||
" <method name=\"SetPosition\">\n"
|
" <method name=\"SetPosition\">\n"
|
||||||
" <arg type=\"o\" name=\"TrackId\"/>\n"
|
" <arg direction=\"in\" type=\"o\" name=\"TrackId\"/>\n"
|
||||||
" <arg type=\"x\" name=\"Position\"/>\n"
|
" <arg direction=\"in\" type=\"x\" name=\"Position\"/>\n"
|
||||||
" </method>\n"
|
" </method>\n"
|
||||||
" <method name=\"OpenUri\">\n"
|
" <method name=\"OpenUri\">\n"
|
||||||
" <arg type=\"s\" name=\"Uri\"/>\n"
|
" <arg direction=\"in\" type=\"s\" name=\"Uri\"/>\n"
|
||||||
" </method>\n"
|
" </method>\n"
|
||||||
" <signal name=\"Seeked\">\n"
|
" <signal name=\"Seeked\">\n"
|
||||||
" <arg type=\"x\" name=\"Position\"/>\n"
|
" <arg direction=\"out\" type=\"x\" name=\"Position\"/>\n"
|
||||||
" </signal>\n"
|
" </signal>\n"
|
||||||
" <property access=\"read\" type=\"s\" name=\"PlaybackStatus\"/>\n"
|
" <property access=\"read\" type=\"s\" name=\"PlaybackStatus\"/>\n"
|
||||||
" <property access=\"readwrite\" type=\"s\" name=\"LoopStatus\"/>\n"
|
" <property access=\"readwrite\" type=\"s\" name=\"LoopStatus\"/>\n"
|
||||||
@@ -56,7 +56,7 @@ class MprisPluginPlayerAdaptor: public QDBusAbstractAdaptor
|
|||||||
" <property access=\"read\" type=\"a{sv}\" name=\"Metadata\">\n"
|
" <property access=\"read\" type=\"a{sv}\" name=\"Metadata\">\n"
|
||||||
" <annotation value=\"QVariantMap\" name=\"com.trolltech.QtDBus.QtTypeName\"/>\n"
|
" <annotation value=\"QVariantMap\" name=\"com.trolltech.QtDBus.QtTypeName\"/>\n"
|
||||||
" </property>\n"
|
" </property>\n"
|
||||||
" <property access=\"read\" type=\"d\" name=\"Volume\"/>\n"
|
" <property access=\"readwrite\" type=\"d\" name=\"Volume\"/>\n"
|
||||||
" <property access=\"read\" type=\"x\" name=\"Position\"/>\n"
|
" <property access=\"read\" type=\"x\" name=\"Position\"/>\n"
|
||||||
" <property access=\"read\" type=\"d\" name=\"MinimumRate\"/>\n"
|
" <property access=\"read\" type=\"d\" name=\"MinimumRate\"/>\n"
|
||||||
" <property access=\"read\" type=\"d\" name=\"MaximumRate\"/>\n"
|
" <property access=\"read\" type=\"d\" name=\"MaximumRate\"/>\n"
|
||||||
@@ -118,8 +118,9 @@ public: // PROPERTIES
|
|||||||
bool shuffle() const;
|
bool shuffle() const;
|
||||||
void setShuffle(bool value);
|
void setShuffle(bool value);
|
||||||
|
|
||||||
Q_PROPERTY(double Volume READ volume)
|
Q_PROPERTY(double Volume READ volume WRITE setVolume)
|
||||||
double volume() const;
|
double volume() const;
|
||||||
|
void setVolume(double value);
|
||||||
|
|
||||||
public Q_SLOTS: // METHODS
|
public Q_SLOTS: // METHODS
|
||||||
void Next();
|
void Next();
|
||||||
|
@@ -8,17 +8,17 @@
|
|||||||
<method name="Stop"/>
|
<method name="Stop"/>
|
||||||
<method name="Play"/>
|
<method name="Play"/>
|
||||||
<method name="Seek">
|
<method name="Seek">
|
||||||
<arg name="Offset" type="x"/>
|
<arg type="x" name="Offset" direction="in" />
|
||||||
</method>
|
</method>
|
||||||
<method name="SetPosition">
|
<method name="SetPosition">
|
||||||
<arg name="TrackId" type="o"/>
|
<arg type="o" name="TrackId" direction="in" />
|
||||||
<arg name="Position" type="x"/>
|
<arg type="x" name="Position" direction="in" />
|
||||||
</method>
|
</method>
|
||||||
<method name="OpenUri">
|
<method name="OpenUri">
|
||||||
<arg name="Uri" type="s"/>
|
<arg type="s" name="Uri" direction="in" />
|
||||||
</method>
|
</method>
|
||||||
<signal name="Seeked">
|
<signal name="Seeked">
|
||||||
<arg name="Position" type="x"/>
|
<arg type="x" name="Position" direction="out" />
|
||||||
</signal>
|
</signal>
|
||||||
<property name="PlaybackStatus" type="s" access="read"/>
|
<property name="PlaybackStatus" type="s" access="read"/>
|
||||||
<property name="LoopStatus" type="s" access="readwrite"/>
|
<property name="LoopStatus" type="s" access="readwrite"/>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<property name="Metadata" type="a{sv}" access="read">
|
<property name="Metadata" type="a{sv}" access="read">
|
||||||
<annotation name="com.trolltech.QtDBus.QtTypeName" value="QVariantMap"/>
|
<annotation name="com.trolltech.QtDBus.QtTypeName" value="QVariantMap"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="Volume" type="d" access="read"/>
|
<property name="Volume" type="d" access="readwrite"/>
|
||||||
<property name="Position" type="x" access="read"/>
|
<property name="Position" type="x" access="read"/>
|
||||||
<property name="MinimumRate" type="d" access="read"/>
|
<property name="MinimumRate" type="d" access="read"/>
|
||||||
<property name="MaximumRate" type="d" access="read"/>
|
<property name="MaximumRate" type="d" access="read"/>
|
||||||
|
@@ -36,12 +36,16 @@ class DLLEXPORT PlaylistInterface
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
enum RepeatMode { NoRepeat, RepeatOne, RepeatAll };
|
enum RepeatMode { NoRepeat, RepeatOne, RepeatAll };
|
||||||
|
Q_ENUMS( RepeatMode )
|
||||||
enum ViewMode { Unknown, Tree, Flat, Album };
|
enum ViewMode { Unknown, Tree, Flat, Album };
|
||||||
enum SeekRestrictions { NoSeekRestrictions, NoSeek };
|
enum SeekRestrictions { NoSeekRestrictions, NoSeek };
|
||||||
enum SkipRestrictions { NoSkipRestrictions, NoSkipForwards, NoSkipBackwards, NoSkip };
|
enum SkipRestrictions { NoSkipRestrictions, NoSkipForwards, NoSkipBackwards, NoSkip };
|
||||||
enum RetryMode { NoRetry, Retry };
|
enum RetryMode { NoRetry, Retry };
|
||||||
|
|
||||||
PlaylistInterface( QObject* parent = 0 ) : m_object( parent ) {}
|
PlaylistInterface( QObject* parent = 0 ) : m_object( parent )
|
||||||
|
{
|
||||||
|
qRegisterMetaType<Tomahawk::PlaylistInterface::RepeatMode>( "Tomahawk::PlaylistInterface::RepeatMode" );
|
||||||
|
}
|
||||||
virtual ~PlaylistInterface() {}
|
virtual ~PlaylistInterface() {}
|
||||||
|
|
||||||
virtual QList< Tomahawk::query_ptr > tracks() = 0;
|
virtual QList< Tomahawk::query_ptr > tracks() = 0;
|
||||||
|
Reference in New Issue
Block a user