diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index 49a55ca14..5b49cc4e2 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -224,7 +224,7 @@ AudioEngine::next() void -AudioEngine::seek( int ms ) +AudioEngine::seek( qint64 ms ) { if ( !m_playlist.isNull() && m_playlist.data()->seekRestrictions() == PlaylistInterface::NoSeek ) return; @@ -236,6 +236,11 @@ AudioEngine::seek( int ms ) } } +void +AudioEngine::seek( int ms ) +{ + seek( (qint64) ms ); +} void AudioEngine::setVolume( int percentage ) diff --git a/src/libtomahawk/audio/audioengine.h b/src/libtomahawk/audio/audioengine.h index be6a7ac44..410eec5d8 100644 --- a/src/libtomahawk/audio/audioengine.h +++ b/src/libtomahawk/audio/audioengine.h @@ -69,6 +69,9 @@ public: Tomahawk::result_ptr currentTrack() const { return m_currentTrack; } + qint64 currentTime() const { return m_mediaObject->currentTime(); } + qint64 currentTrackTotalTime() const { return m_mediaObject->totalTime(); } + public slots: void playPause(); void play(); @@ -78,7 +81,8 @@ public slots: void previous(); 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 lowerVolume() { setVolume( volume() - AUDIO_VOLUME_STEP ); } void raiseVolume() { setVolume( volume() + AUDIO_VOLUME_STEP ); } diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp index 3a0039b15..f8e1c1da4 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.cpp @@ -16,8 +16,10 @@ * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>. */ +#include <QApplication> #include <QtDBus/QtDBus> +#include "audio/audioengine.h" #include "infosystem/infosystemworker.h" #include "artist.h" #include "result.h" @@ -58,7 +60,7 @@ bool MprisPlugin::canQuit() const { qDebug() << Q_FUNC_INFO; - return false; + return true; } bool @@ -109,6 +111,7 @@ MprisPlugin::Raise() void MprisPlugin::Quit() { + QApplication::quit(); } // org.mpris.MediaPlayer2.Player @@ -116,54 +119,83 @@ MprisPlugin::Quit() bool MprisPlugin::canControl() const { - return false; + return true; } bool MprisPlugin::canGoNext() const { - return false; + return true; } bool MprisPlugin::canGoPrevious() const { - return false; + return true; } bool MprisPlugin::canPause() const { - return false; + return true; } bool MprisPlugin::canPlay() const { - return false; + return true; } bool MprisPlugin::canSeek() const { - return false; + return true; } QString 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 -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 MprisPlugin::maximumRate() const { - return 0.0; + return 1.0; } QVariantMap @@ -175,92 +207,131 @@ MprisPlugin::metadata() const double MprisPlugin::minimumRate() const { - return 0.0; + return 1.0; } 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(""); } qlonglong MprisPlugin::position() const { - return 0; + // Convert Tomahawk's milliseconds to microseconds + return (qlonglong) ( AudioEngine::instance()->currentTime() * 1000 ); } double MprisPlugin::rate() const { - return 0.0; + return 1.0; } void MprisPlugin::setRate( double value ) { + Q_UNUSED( value ); } bool MprisPlugin::shuffle() const { - return false; + PlaylistInterface *p = AudioEngine::instance()->playlist(); + if (!p) + return false; + return p->shuffled(); } void MprisPlugin::setShuffle( bool value ) { + PlaylistInterface *p = AudioEngine::instance()->playlist(); + if (!p) + return; + return p->setShuffled( value ); } double MprisPlugin::volume() const { - return 0.0; + return AudioEngine::instance()->volume(); +} + +void +MprisPlugin::setVolume( double value ) +{ + AudioEngine::instance()->setVolume( value ); } void MprisPlugin::Next() { + AudioEngine::instance()->next(); } void MprisPlugin::OpenUri(const QString &Uri) { + // TODO } void MprisPlugin::Pause() { + AudioEngine::instance()->pause(); } void MprisPlugin::Play() { + AudioEngine::instance()->play(); } void MprisPlugin::PlayPause() { + AudioEngine::instance()->playPause(); } void MprisPlugin::Previous() { + AudioEngine::instance()->previous(); } void 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 MprisPlugin::SetPosition( const QDBusObjectPath &TrackId, qlonglong Position ) { + // TODO } void MprisPlugin::Stop() { + AudioEngine::instance()->stop(); } // InfoPlugin Methods diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h index 3168856d2..a1eca49a2 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h @@ -109,8 +109,9 @@ public: bool shuffle() const; void setShuffle(bool value); - Q_PROPERTY(double Volume READ volume) + Q_PROPERTY(double Volume READ volume WRITE setVolume) double volume() const; + void setVolume(double value); public slots: void namChangedSlot( QNetworkAccessManager* /*nam*/ ) {} // unused diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.cpp b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.cpp index 46f22cf2f..47e8c8c9f 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.cpp +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.cpp @@ -141,6 +141,12 @@ double MprisPluginPlayerAdaptor::volume() const 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() { // handle method call org.mpris.MediaPlayer2.Player.Next diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.h b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.h index 9445af3b6..d94cfc90e 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.h +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.h @@ -9,8 +9,8 @@ * before re-generating it. */ -#ifndef MPRISPLUGINPLAYERADAPTOR_H_1312900500 -#define MPRISPLUGINPLAYERADAPTOR_H_1312900500 +#ifndef MPRISPLUGINPLAYERADAPTOR_H_1313089554 +#define MPRISPLUGINPLAYERADAPTOR_H_1313089554 #include <QtCore/QObject> #include <QtDBus/QtDBus> @@ -37,17 +37,17 @@ class MprisPluginPlayerAdaptor: public QDBusAbstractAdaptor " <method name=\"Stop\"/>\n" " <method name=\"Play\"/>\n" " <method name=\"Seek\">\n" -" <arg type=\"x\" name=\"Offset\"/>\n" +" <arg direction=\"in\" type=\"x\" name=\"Offset\"/>\n" " </method>\n" " <method name=\"SetPosition\">\n" -" <arg type=\"o\" name=\"TrackId\"/>\n" -" <arg type=\"x\" name=\"Position\"/>\n" +" <arg direction=\"in\" type=\"o\" name=\"TrackId\"/>\n" +" <arg direction=\"in\" type=\"x\" name=\"Position\"/>\n" " </method>\n" " <method name=\"OpenUri\">\n" -" <arg type=\"s\" name=\"Uri\"/>\n" +" <arg direction=\"in\" type=\"s\" name=\"Uri\"/>\n" " </method>\n" " <signal name=\"Seeked\">\n" -" <arg type=\"x\" name=\"Position\"/>\n" +" <arg direction=\"out\" type=\"x\" name=\"Position\"/>\n" " </signal>\n" " <property access=\"read\" type=\"s\" name=\"PlaybackStatus\"/>\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" " <annotation value=\"QVariantMap\" name=\"com.trolltech.QtDBus.QtTypeName\"/>\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=\"d\" name=\"MinimumRate\"/>\n" " <property access=\"read\" type=\"d\" name=\"MaximumRate\"/>\n" @@ -118,8 +118,9 @@ public: // PROPERTIES bool shuffle() const; void setShuffle(bool value); - Q_PROPERTY(double Volume READ volume) + Q_PROPERTY(double Volume READ volume WRITE setVolume) double volume() const; + void setVolume(double value); public Q_SLOTS: // METHODS void Next(); diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.xml b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.xml index 8d060ae8c..4a7fc214b 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.xml +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprispluginplayeradaptor.xml @@ -8,17 +8,17 @@ <method name="Stop"/> <method name="Play"/> <method name="Seek"> - <arg name="Offset" type="x"/> + <arg type="x" name="Offset" direction="in" /> </method> <method name="SetPosition"> - <arg name="TrackId" type="o"/> - <arg name="Position" type="x"/> + <arg type="o" name="TrackId" direction="in" /> + <arg type="x" name="Position" direction="in" /> </method> <method name="OpenUri"> - <arg name="Uri" type="s"/> + <arg type="s" name="Uri" direction="in" /> </method> <signal name="Seeked"> - <arg name="Position" type="x"/> + <arg type="x" name="Position" direction="out" /> </signal> <property name="PlaybackStatus" type="s" access="read"/> <property name="LoopStatus" type="s" access="readwrite"/> @@ -27,7 +27,7 @@ <property name="Metadata" type="a{sv}" access="read"> <annotation name="com.trolltech.QtDBus.QtTypeName" value="QVariantMap"/> </property> - <property name="Volume" type="d" access="read"/> + <property name="Volume" type="d" access="readwrite"/> <property name="Position" type="x" access="read"/> <property name="MinimumRate" type="d" access="read"/> <property name="MaximumRate" type="d" access="read"/> diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 9f46a3b11..f4c6650a1 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -36,12 +36,16 @@ class DLLEXPORT PlaylistInterface public: enum RepeatMode { NoRepeat, RepeatOne, RepeatAll }; + Q_ENUMS( RepeatMode ) enum ViewMode { Unknown, Tree, Flat, Album }; enum SeekRestrictions { NoSeekRestrictions, NoSeek }; enum SkipRestrictions { NoSkipRestrictions, NoSkipForwards, NoSkipBackwards, NoSkip }; 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 QList< Tomahawk::query_ptr > tracks() = 0;