Sayonara Player
DBusMPRIS.h
1 /* DBusMPRIS.h */
2 
3 /* Copyright (C) 2011-2019 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
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 DBUS_MPRIS_H
22 #define DBUS_MPRIS_H
23 
24 #include <QObject>
25 #include <QVariant>
26 #include <QDBusObjectPath>
27 
28 #include "Components/PlayManager/PlayState.h"
29 
30 #include "Utils/MetaData/MetaData.h"
31 #include "Utils/Pimpl.h"
32 
33 using QStrRef=const QString&;
34 
35 class QMainWindow;
36 class DBusAdaptor :
37  public QObject
38 {
39  Q_OBJECT
40  PIMPL(DBusAdaptor)
41 
42 protected:
43  explicit DBusAdaptor(QStrRef object_path, QStrRef service_name, QStrRef dbus_service, QStrRef dbus_interface, QObject *parent=nullptr);
44  virtual ~DBusAdaptor();
45 
46  void create_message(QString name, QVariant val);
47 
48  QString object_path() const;
49  QString service_name() const;
50  QString dbus_service() const;
51  QString dbus_interface() const;
52 };
53 
54 
55 namespace DBusMPRIS
56 {
57 
58 class MediaPlayer2 :
59  public DBusAdaptor
60 {
61  Q_OBJECT
62  PIMPL(MediaPlayer2)
63 
64  public:
65  explicit MediaPlayer2(QMainWindow* player, QObject *parent=nullptr);
66  ~MediaPlayer2();
67 
68  Q_PROPERTY(bool CanQuit READ CanQuit CONSTANT)
69  bool CanQuit() const;
70 
71  Q_PROPERTY(bool CanRaise READ CanRaise CONSTANT)
72  bool CanRaise();
73 
74  Q_PROPERTY(bool HasTrackList READ HasTrackList)
75  bool HasTrackList();
76 
77 
78  Q_PROPERTY(QString Identity READ Identity CONSTANT)
79  QString Identity();
80 
81  Q_PROPERTY(QString DesktopEntry READ DesktopEntry CONSTANT)
82  QString DesktopEntry();
83 
84  Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes CONSTANT)
85  QStringList SupportedUriSchemes();
86 
87 
88  Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes CONSTANT)
89  QStringList SupportedMimeTypes();
90 
91 
92  Q_PROPERTY(bool CanSetFullscreen READ CanSetFullscreen)
93  bool CanSetFullscreen();
94 
95  Q_PROPERTY(bool Fullscreen READ Fullscreen WRITE SetFullscreen)
96  bool Fullscreen();
97  void SetFullscreen(bool b);
98 
99  void Raise();
100  void Quit();
101 
102 
103  private:
104  void init();
105 
106 
107  public:
108  Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus)
109  QString PlaybackStatus();
110 
111 
112  Q_PROPERTY(QString LoopStatus READ LoopStatus WRITE SetLoopStatus)
113  QString LoopStatus();
114  void SetLoopStatus(QString status);
115 
116 
117  Q_PROPERTY(double Rate READ Rate WRITE SetRate)
118  double Rate();
119  void SetRate(double rate);
120 
121 
122  Q_PROPERTY(bool Shuffle READ Shuffle WRITE SetShuffle)
123  bool Shuffle();
124  void SetShuffle(bool shuffle);
125 
126 
127  Q_PROPERTY(QVariantMap Metadata READ Metadata)
128  QVariantMap Metadata();
129 
130 
131  Q_PROPERTY(double Volume READ Volume WRITE SetVolume)
132  double Volume();
133  void SetVolume(double volume);
134 
135 
136  Q_PROPERTY(qlonglong Position READ Position)
137  qlonglong Position();
138  void SetPosition(const QDBusObjectPath& track_id, qlonglong position);
139 
140 
141  Q_PROPERTY(double MinimumRate READ MinimumRate)
142  double MinimumRate();
143 
144 
145  Q_PROPERTY(double MaximumRate READ MaximumRate)
146  double MaximumRate();
147 
148 
149  Q_PROPERTY(bool CanGoNext READ CanGoNext)
150  bool CanGoNext();
151 
152 
153  Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious)
154  bool CanGoPrevious();
155 
156 
157  Q_PROPERTY(bool CanPlay READ CanPlay)
158  bool CanPlay();
159 
160 
161  Q_PROPERTY(bool CanPause READ CanPause)
162  bool CanPause();
163 
164 
165  Q_PROPERTY(bool CanSeek READ CanSeek)
166  bool CanSeek();
167 
168 
169  Q_PROPERTY(bool CanControl READ CanControl)
170  bool CanControl();
171 
172 
173  void Next();
174  void Previous();
175  void Pause();
176  void PlayPause();
177  void Stop();
178  void Play();
179  void Seek(qlonglong offset);
180 
181  void OpenUri(const QString& uri);
182 
183 
184  public slots:
185 
186  void position_changed(MilliSeconds pos_ms);
187  void volume_changed(int volume);
188  void track_idx_changed(int idx);
189  void track_changed(const MetaData& md);
190  void playstate_changed(PlayState state);
191 
192  signals:
193  void Seeked(qlonglong position);
194  void sig_raise();
195 };
196 } // end namespace DBusMPRIS
197 
198 #endif // DBUS_MPRIS_H
Definition: DBusMPRIS.h:36
PlayState
The PlayState enum.
Definition: PlayState.h:28
The MetaData class.
Definition: MetaData.h:44
Definition: DBusMPRIS.h:58
Definition: DBusHandler.h:28