~neon/juk/master

« back to all changes in this revision

Viewing changes to mpris2/mediaplayer2player.h

  • Committer: Michael Pyne
  • Date: 2012-04-16 01:53:04 UTC
  • Revision ID: git-v1:54c6db81c2fe09999b9953249dce839f5c7a0a66
Initial MPRIS2 support.

Eike Hein has kindly donated a working Mpris2 adaptor with instructions
on how to integrate into JuK, so I've done so.

This is just at the "compiles and links" stage and the track ID will
give a lot of weirdness due to the strictness of the D-Bus Object Path
name spec.

The reason we don't just use an identifier for a track is that the
"primary key" JuK uses is the canonical file name. JuK has no internal
RDBMS or anything similar where primary keys would be assigned. Because
of this we encode track IDs using z-Base-32 so they will not violate the
D-Bus spec.

Thanks to Eike for the large code contribution and integration support!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************************************
 
2
 * Copyright 2012  Eike Hein <hein@kde.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; either version 2 of
 
7
 * the License or (at your option) version 3 or any later version
 
8
 * accepted by the membership of KDE e.V. (or its successor approved
 
9
 * by the membership of KDE e.V.), which shall act as a proxy
 
10
 * defined in Section 14 of version 3 of the license.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 ***********************************************************************/
 
20
 
 
21
#ifndef JUK_MEDIAPLAYRER2PLAYER_H
 
22
#define JUK_MEDIAPLAYRER2PLAYER_H
 
23
 
 
24
#include <QDBusAbstractAdaptor>
 
25
#include <QDBusObjectPath>
 
26
#include <QPointer>
 
27
 
 
28
#include <Phonon/MediaSource>
 
29
 
 
30
#include "playermanager.h"
 
31
 
 
32
class MediaPlayer2Player : public QDBusAbstractAdaptor
 
33
{
 
34
    Q_OBJECT
 
35
    Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player") // Docs: http://www.mpris.org/2.1/spec/Player_Node.html
 
36
 
 
37
    Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus)
 
38
    Q_PROPERTY(QString LoopStatus READ LoopStatus WRITE setLoopStatus)
 
39
    Q_PROPERTY(double Rate READ Rate WRITE setRate)
 
40
    Q_PROPERTY(bool Shuffle READ Shuffle WRITE setShuffle)
 
41
    Q_PROPERTY(QVariantMap Metadata READ Metadata)
 
42
    Q_PROPERTY(double Volume READ Volume WRITE setVolume)
 
43
    Q_PROPERTY(qlonglong Position READ Position)
 
44
    Q_PROPERTY(double MinimumRate READ MinimumRate)
 
45
    Q_PROPERTY(double MaximumRate READ MaximumRate)
 
46
    Q_PROPERTY(bool CanGoNext READ CanGoNext)
 
47
    Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious)
 
48
    Q_PROPERTY(bool CanPlay READ CanPlay)
 
49
    Q_PROPERTY(bool CanPause READ CanPause)
 
50
    Q_PROPERTY(bool CanSeek READ CanSeek)
 
51
    Q_PROPERTY(bool CanControl READ CanControl)
 
52
 
 
53
    public:
 
54
        explicit MediaPlayer2Player(QObject* parent);
 
55
        ~MediaPlayer2Player();
 
56
 
 
57
        QString PlaybackStatus() const;
 
58
        QString LoopStatus() const;
 
59
        void setLoopStatus(const QString& loopStatus) const;
 
60
        double Rate() const;
 
61
        void setRate(double rate) const;
 
62
        bool Shuffle() const;
 
63
        void setShuffle(bool shuffle) const;
 
64
        QVariantMap Metadata() const;
 
65
        double Volume() const;
 
66
        void setVolume(double volume) const;
 
67
        qlonglong Position() const;
 
68
        double MinimumRate() const;
 
69
        double MaximumRate() const;
 
70
        bool CanGoNext() const;
 
71
        bool CanGoPrevious() const;
 
72
        bool CanPlay() const;
 
73
        bool CanPause() const;
 
74
        bool CanSeek() const;
 
75
        bool CanControl() const;
 
76
 
 
77
    signals:
 
78
        void Seeked(qlonglong Position) const;
 
79
 
 
80
    public slots:
 
81
        void Next() const;
 
82
        void Previous() const;
 
83
        void Pause() const;
 
84
        void PlayPause() const;
 
85
        void Stop() const;
 
86
        void Play() const;
 
87
        void Seek(qlonglong Offset) const;
 
88
        void SetPosition(const QDBusObjectPath& TrackId, qlonglong Position) const;
 
89
        void OpenUri(QString Uri) const;
 
90
 
 
91
    private slots:
 
92
        void tick(qint64 newPos);
 
93
        void currentSourceChanged() const;
 
94
        void stateUpdated() const;
 
95
        void totalTimeChanged() const;
 
96
        void seekableChanged(bool seekable) const;
 
97
        void volumeChanged(qreal newVol) const;
 
98
 
 
99
    private:
 
100
        void signalPropertiesChange(const QVariantMap& properties) const;
 
101
 
 
102
        qint64 oldPos;
 
103
        QPointer<PlayerManager> m_player;
 
104
};
 
105
 
 
106
#endif