aboutsummaryrefslogtreecommitdiff
path: root/mpris-plugin/qmpriswrapper.hpp
blob: 54186d2b9971a1c5614c48e046bceff4756212db (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
#ifndef QMPRISWRAPPER_HPP
#define QMPRISWRAPPER_HPP

#include <QObject>

class QMPrisMediaPlayer2;
class QMPrisPlayer;
class QMPrisTrackList;
class qmpPluginAPI;

class QMPrisWrapper : public QObject
{
    Q_OBJECT
public:
    ~QMPrisWrapper();

    template <class TP, class TM, class TT>
    static QMPrisWrapper *create(QString serviceSuffix, qmpPluginAPI *api, QObject *parent = nullptr)
    {
        static_assert(std::is_base_of<QMPrisPlayer, TP>(), "TP must be a subclass of QMPrisPlayer");
        static_assert(std::is_base_of<QMPrisMediaPlayer2, TM>(), "TM must be a subclass of QMPrisMediaPlayer2");
        static_assert(std::is_base_of<QMPrisTrackList, TT>(), "TT must be a subclass of QMPrisTrackList");

        auto w = new QMPrisWrapper(serviceSuffix, api, parent);
        auto p = new TP(api, w);
        auto t = new TT(api, w);
        auto mp = new TM(api, w);
        w->player = p;
        w->tracklist = t;
        w->mediaplayer = mp;
        w->post_creation();

        return w;
    }

    static void notifyPropertyChange(QString intf, QString prop, QVariant val);

private:
    explicit QMPrisWrapper(QString serviceSuffix, qmpPluginAPI *_api, QObject *parent = nullptr);
    void post_creation();
    QMPrisPlayer *player = nullptr;
    QMPrisMediaPlayer2 *mediaplayer = nullptr;
    QMPrisTrackList *tracklist = nullptr;
    QString svcsuffix;
    qmpPluginAPI *api;

    const QString PLAYER_INTERFACE = "org.mpris.MediaPlayer2.Player";

    friend class QMPrisPlayer;
    friend class QMPrisMediaPlayer2;
};

#endif // QMPRISWRAPPER_HPP