File indexing completed on 2024-05-19 04:49:36

0001 /***********************************************************************
0002  * Copyright 2012  Eike Hein <hein@kde.org>
0003  *
0004  * This program is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU General Public License as
0006  * published by the Free Software Foundation; either version 2 of
0007  * the License or (at your option) version 3 or any later version
0008  * accepted by the membership of KDE e.V. (or its successor approved
0009  * by the membership of KDE e.V.), which shall act as a proxy
0010  * defined in Section 14 of version 3 of the license.
0011  *
0012  * This program is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015  * GNU General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU General Public License
0018  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019  ***********************************************************************/
0020 
0021 #ifndef AMAROK_MEDIAPLAYER2PLAYER_H
0022 #define AMAROK_MEDIAPLAYER2PLAYER_H
0023 
0024 #include "DBusAbstractAdaptor.h"
0025 
0026 #include "core/meta/forward_declarations.h"
0027 
0028 #include <QDBusObjectPath>
0029 #include <QModelIndex>
0030 #include <QVariantMap>
0031 
0032 namespace Amarok
0033 {
0034     class MediaPlayer2Player : public DBusAbstractAdaptor
0035     {
0036         Q_OBJECT
0037         Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player") // Docs: http://www.mpris.org/2.1/spec/Player_Node.html
0038 
0039         Q_PROPERTY( QString PlaybackStatus READ PlaybackStatus )
0040         Q_PROPERTY( QString LoopStatus READ LoopStatus WRITE setLoopStatus )
0041         Q_PROPERTY( double Rate READ Rate WRITE setRate )
0042         Q_PROPERTY( bool Shuffle READ Shuffle WRITE setShuffle )
0043         Q_PROPERTY( QVariantMap Metadata READ Metadata )
0044         Q_PROPERTY( double Volume READ Volume WRITE setVolume )
0045         Q_PROPERTY( qlonglong Position READ Position )
0046         Q_PROPERTY( double MinimumRate READ MinimumRate )
0047         Q_PROPERTY( double MaximumRate READ MaximumRate )
0048         Q_PROPERTY( bool CanGoNext READ CanGoNext )
0049         Q_PROPERTY( bool CanGoPrevious READ CanGoPrevious )
0050         Q_PROPERTY( bool CanPlay READ CanPlay )
0051         Q_PROPERTY( bool CanPause READ CanPause )
0052         Q_PROPERTY( bool CanSeek READ CanSeek )
0053         Q_PROPERTY( bool CanControl READ CanControl )
0054 
0055         public:
0056             explicit MediaPlayer2Player( QObject* parent );
0057             ~MediaPlayer2Player() override;
0058 
0059             QString PlaybackStatus() const;
0060             QString LoopStatus() const;
0061             void setLoopStatus( const QString& loopStatus ) const;
0062             double Rate() const;
0063             void setRate( double rate ) const;
0064             bool Shuffle() const;
0065             void setShuffle( bool shuffle ) const;
0066             QVariantMap Metadata() const;
0067             double Volume() const;
0068             void setVolume( double volume ) const;
0069             qlonglong Position() const;
0070             double MinimumRate() const;
0071             double MaximumRate() const;
0072             bool CanGoNext() const;
0073             bool CanGoPrevious() const;
0074             bool CanPlay() const;
0075             bool CanPause() const;
0076             bool CanSeek() const;
0077             bool CanControl() const;
0078 
0079         Q_SIGNALS:
0080             void Seeked( qlonglong Position ) const;
0081 
0082         public Q_SLOTS:
0083             void Next() const;
0084             void Previous() const;
0085             void Pause() const;
0086             void PlayPause() const;
0087             void Stop() const;
0088             void Play() const;
0089             void Seek( qlonglong Offset ) const;
0090             void SetPosition( const QDBusObjectPath& TrackId, qlonglong Position ) const;
0091             void OpenUri( const QString &Uri ) const;
0092 
0093         private Q_SLOTS:
0094             void trackPositionChanged( qint64 position, bool userSeek );
0095             void trackChanged( const Meta::TrackPtr &track );
0096             void trackMetadataChanged( const Meta::TrackPtr &track );
0097             void albumMetadataChanged( const Meta::AlbumPtr &album );
0098             void seekableChanged( bool seekable );
0099             void volumeChanged( int newVolPercent );
0100             void trackLengthChanged( qint64 milliseconds );
0101             void playbackStateChanged();
0102             void playlistNavigatorChanged();
0103             void playlistRowsInserted(const QModelIndex &, int, int );
0104             void playlistRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int );
0105             void playlistRowsRemoved(const QModelIndex &, int, int );
0106             void playlistReplaced();
0107             void playlistActiveTrackChanged( quint64 );
0108 
0109         private:
0110             QVariantMap metadataForTrack( const Meta::TrackPtr &track ) const;
0111 
0112             qint64 m_lastPosition;
0113     };
0114 }
0115 
0116 #endif // AMAROK_MEDIAPLAYER2PLAYER_H