aboutsummaryrefslogtreecommitdiff
path: root/mpris-plugin/qmprisdbusinterface.hpp
blob: 071c5090e63c2342b9527fb33452ee132aaab31d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * DBus adaptor for the MPRIS Interface
 * Based on MPRIS D-Bus Interface Specification Version 2.2:
 * https://specifications.freedesktop.org/mpris-spec/2.2/index.html
 */
#ifndef QMPRISDBUSINTERFACE_HPP
#define QMPRISDBUSINTERFACE_HPP

#include <QDBusAbstractAdaptor>
#include <QDBusObjectPath>
#include <QVariant>

class QMPrisWrapper;

class QMPrisPlayer : public QDBusAbstractAdaptor
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player")

    Q_PROPERTY(QString PlaybackStatus READ getPlaybackStatus)
    Q_PROPERTY(QString LoopStatus READ getLoopStatus WRITE setLoopStatus)
    Q_PROPERTY(double Rate READ getRate WRITE setRate)
    Q_PROPERTY(bool Shuffle READ getShuffle WRITE setShuffle)
    Q_PROPERTY(QVariantMap Metadata READ getMetadata)
    Q_PROPERTY(double Volume READ getVolume WRITE setVolume)
    Q_PROPERTY(qlonglong Position READ getPosition)
    Q_PROPERTY(double MinimumRate READ getMinimumRate)
    Q_PROPERTY(double MaximumRate READ getMaximumRate)

    Q_PROPERTY(bool CanGoNext READ getCanGoNext)
    Q_PROPERTY(bool CanGoPrevious READ getCanGoPrevious)
    Q_PROPERTY(bool CanPlay READ getCanPlay)
    Q_PROPERTY(bool CanPause READ getCanPause)
    Q_PROPERTY(bool CanSeek READ getCanSeek)
    Q_PROPERTY(bool CanControl READ getCanControl)
public:
    enum PlaybackStatus
    {
        Playing,
        Paused,
        Stopped
    };
    Q_ENUM(PlaybackStatus)

    enum LoopStatus
    {
        None,
        Track,
        Playlist
    };
    Q_ENUM(LoopStatus)

    explicit QMPrisPlayer(QObject *parent=nullptr);

    virtual QString getPlaybackStatus();
    virtual QString getLoopStatus();
    virtual double getRate();
    virtual bool getShuffle();
    virtual QVariantMap getMetadata();
    virtual double getVolume();
    virtual qlonglong getPosition();
    virtual double getMinimumRate();
    virtual double getMaximumRate();
    virtual bool getCanGoNext();
    virtual bool getCanGoPrevious();
    virtual bool getCanPlay();
    virtual bool getCanPause();
    virtual bool getCanSeek();
    virtual bool getCanControl();

    virtual void setLoopStatus(QString loopStatus);
    virtual void setRate(double playbackRate);
    virtual bool setShuffle(bool shuffle);
    virtual void setVolume(double volume);

public slots:
    virtual void Next();
    virtual void Previous();
    virtual void Pause();
    virtual void PlayPause();
    virtual void Stop();
    virtual void Play();
    virtual void Seek(qlonglong t);
    virtual void SetPosition(QDBusObjectPath o, qlonglong t);
    virtual void OpenUri(QString s);

signals:
    void Seeked(qlonglong t);
};

class QMPrisTrackList : public QDBusAbstractAdaptor
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.TrackList")
    Q_PROPERTY(QList<QDBusObjectPath> Tracks READ getTracks)
    Q_PROPERTY(bool CanEditTracks READ getCanEditTracks)
public slots:
    virtual QList<QVariantMap> GetTracksMetaData(QList<QDBusObjectPath> trackIds);
    virtual void AddTrack(QString uri, QDBusObjectPath after, bool setCurrent);
    virtual void RemoveTrack(QDBusObjectPath trackId);
    virtual void GoTo(QDBusObjectPath trackId);
signals:
    void TrackListReplaced(QList<QDBusObjectPath> tracks, QDBusObjectPath currentTrack);
    void TrackAdded(QVariantMap metadata, QDBusObjectPath after);
    void TrackRemoved(QDBusObjectPath track);
    void TrackMetadataChanged(QDBusObjectPath track, QVariantMap metadata);
public:
    explicit QMPrisTrackList(QObject *parent=nullptr);
    virtual QList<QDBusObjectPath> getTracks();
    virtual bool getCanEditTracks();
};

class QMPrisMediaPlayer2 : public QDBusAbstractAdaptor
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2")

    Q_PROPERTY(bool CanQuit READ getCanQuit)
    Q_PROPERTY(bool CanRaise READ getCanRaise)
    Q_PROPERTY(bool Fullscreen READ getFullscreen WRITE setFullscreen)
    Q_PROPERTY(bool CanSetFullscreen READ getCanSetFullscreen)
    Q_PROPERTY(bool HasTrackList READ getHasTrackList)
    Q_PROPERTY(QString Identity READ getIdentity)
    Q_PROPERTY(QString DesktopEntry READ getDesktopEntry)
    Q_PROPERTY(QStringList SupportedUriSchemes READ getSupportedUriSchemes)
    Q_PROPERTY(QStringList SupportedMimeTypes READ getSupportedMimeTypes)

public slots:
    virtual void Raise();
    virtual void Quit();

public:
    explicit QMPrisMediaPlayer2(QObject *parent=nullptr);

    virtual bool getCanQuit();
    virtual bool getCanRaise();
    virtual bool getFullscreen();
    virtual bool getCanSetFullscreen();
    virtual bool getHasTrackList();
    virtual QString getIdentity();
    virtual QString getDesktopEntry();
    virtual QStringList getSupportedUriSchemes();
    virtual QStringList getSupportedMimeTypes();

    virtual void setFullscreen(bool fullscreen);
};

#endif // QMPRISDBUSINTERFACE_HPP