/* * Copyright (C) 2019 Kevin Whitaker * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef MPRISINTERFACE_H #define MPRISINTERFACE_H #include "minimediaplayer.h" #include #include #include #include /** * Simple DBus interface which registers and provides simple controls over media playing. */ class MPRISInterface : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface","org.mpris.MediaPlayer2") Q_PROPERTY(bool CanQuit READ CanQuit) Q_PROPERTY(bool CanRaise READ CanRaise) Q_PROPERTY(bool HasTrackList READ HasTrackList) Q_PROPERTY(QString Identity READ Identity) Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes) Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes) public: MPRISInterface(QObject *parent = 0); bool CanQuit(); bool CanRaise(); bool HasTrackList(); QString Identity(); QStringList SupportedUriSchemes(); QStringList SupportedMimeTypes(); public slots: Q_NOREPLY void Raise() {}; Q_NOREPLY void Quit() {}; }; class MPRISPlayerInterface : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface","org.mpris.MediaPlayer2.Player") Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus NOTIFY playbackStatusChanged) Q_PROPERTY(double Rate READ Rate WRITE setRate) Q_PROPERTY(QVariantMap Metadata READ Metadata NOTIFY metadataChanged) Q_PROPERTY(double Volume READ Volume WRITE setVolume NOTIFY volumeChanged) Q_PROPERTY(qlonglong Position READ Position NOTIFY positionChanged) Q_PROPERTY(double MinimumRate READ MinimumRate) Q_PROPERTY(double MaximumRate READ MaximumRate) Q_PROPERTY(bool CanGoNext READ CanGoNext) Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious) Q_PROPERTY(bool CanPlay READ CanPlay) Q_PROPERTY(bool CanPause READ CanPause) Q_PROPERTY(bool CanSeek READ CanSeek) Q_PROPERTY(bool CanControl READ CanControl) public: MPRISPlayerInterface(MiniMediaPlayer *player,QObject *parent = 0); QString PlaybackStatus(); double Rate(); void setRate(double rate) {}; QVariantMap Metadata(); double Volume(); void setVolume(double volume); qlonglong Position(); double MinimumRate(); double MaximumRate(); bool CanGoNext(); bool CanGoPrevious(); bool CanPlay(); bool CanPause(); bool CanSeek(); bool CanControl(); public slots: Q_NOREPLY void Next(); Q_NOREPLY void Previous() {}; Q_NOREPLY void Pause(); Q_NOREPLY void PlayPause(); Q_NOREPLY void Stop(); Q_NOREPLY void Play(); Q_NOREPLY void Seek(qlonglong offset) {}; Q_NOREPLY void SetPosition(QDBusObjectPath trackId,qlonglong position) {}; Q_NOREPLY void OpenUri(QString uri); signals: void Seeked(qlonglong position); //Not used void playbackStatusChanged(QString status); void metadataChanged(QVariantMap metadata); void volumeChanged(double volume); void positionChanged(qlonglong position); private slots: void mediaStateChanged(bool isPlaying); void mediaPositionChanged(qint64 position); void mediaVolumeChanged(int volume); void mediaPlaylistChanged(QStringList playlist); private: MiniMediaPlayer *player; void dbusUpdate(QVariantMap changed); double volumeFromMediaPlayer(int volume); }; #endif // MPRISINTERFACE_H