Sayonara Player
DBusMPRIS.h
1 /* DBusMPRIS.h */
2 
3 /* Copyright (C) 2011-2017 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 #include <QMainWindow>
28 
29 #include "Helper/MetaData/MetaData.h"
30 #include "Helper/Settings/SayonaraClass.h"
31 #include "Components/PlayManager/PlayState.h"
32 
33 class PlayManager;
34 class DBusAdaptor :
35  public QObject
36 {
37  Q_OBJECT
38 
39 protected:
40 
41  PlayManager* _play_manager=nullptr;
42 
43  QString _object_path;
44  QString _service_name;
45  QString _dbus_service;
46  QString _dbus_interface;
47 
48  explicit DBusAdaptor(QObject *parent=nullptr);
49  virtual ~DBusAdaptor();
50 
51  void create_message(QString name, QVariant val);
52 };
53 
54 
55 namespace DBusMPRIS
56 {
57 
58 class MediaPlayer2 :
59  public DBusAdaptor,
60  protected SayonaraClass
61 {
62  Q_OBJECT
63 
64  private:
65  QStringList _supported_uri_schemes;
66  QStringList _supported_mime_types;
67 
68 
69  public:
70 
71  explicit MediaPlayer2(QMainWindow* player, QObject *parent=nullptr);
72  ~MediaPlayer2();
73 
74  Q_PROPERTY(bool CanQuit READ CanQuit)
75  bool CanQuit();
76 
77  Q_PROPERTY(bool CanRaise READ CanRaise)
78  bool CanRaise();
79 
80  Q_PROPERTY(bool HasTrackList READ HasTrackList)
81  bool HasTrackList();
82 
83 
84  Q_PROPERTY(QString Identity READ Identity)
85  QString Identity();
86 
87  Q_PROPERTY(QString DesktopEntry READ DesktopEntry)
88  QString DesktopEntry();
89 
90  Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes)
91  QStringList SupportedUriSchemes();
92 
93 
94  Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes)
95  QStringList SupportedMimeTypes();
96 
97 
98  Q_PROPERTY(bool CanSetFullscreen READ CanSetFullscreen)
99  bool CanSetFullscreen();
100 
101  Q_PROPERTY(bool Fullscreen READ Fullscreen WRITE SetFullscreen)
102  bool Fullscreen();
103  void SetFullscreen(bool b);
104 
105  void Raise();
106  void Quit();
107 
108 
109  private:
110 
111  QMainWindow* _player=nullptr;
112  int _len_playlist;
113  int _cur_idx;
114 
115  bool _can_next;
116  bool _can_previous;
117  double _volume;
118  QString _playback_status;
119  MetaData _md;
120  qint64 _pos;
121 
122  bool _initialized;
123  void init();
124 
125 
126  public:
127  Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus)
128  QString PlaybackStatus();
129 
130 
131  Q_PROPERTY(QString LoopStatus READ LoopStatus WRITE SetLoopStatus)
132  QString LoopStatus();
133  void SetLoopStatus(QString status);
134 
135 
136  Q_PROPERTY(double Rate READ Rate WRITE SetRate)
137  double Rate();
138  void SetRate(double rate);
139 
140 
141  Q_PROPERTY(bool Shuffle READ Shuffle WRITE SetShuffle)
142  bool Shuffle();
143  void SetShuffle(bool shuffle);
144 
145 
146  Q_PROPERTY(QVariantMap Metadata READ Metadata)
147  QVariantMap Metadata();
148 
149 
150  Q_PROPERTY(double Volume READ Volume WRITE SetVolume)
151  double Volume();
152  void SetVolume(double volume);
153 
154 
155  Q_PROPERTY(qint64 Position READ Position)
156  qint64 Position();
157  void SetPosition(const QDBusObjectPath& track_id, qint64 position);
158 
159 
160  Q_PROPERTY(double MinimumRate READ MinimumRate)
161  double MinimumRate();
162 
163 
164  Q_PROPERTY(double MaximumRate READ MaximumRate)
165  double MaximumRate();
166 
167 
168  Q_PROPERTY(bool CanGoNext READ CanGoNext)
169  bool CanGoNext();
170 
171 
172  Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious)
173  bool CanGoPrevious();
174 
175 
176  Q_PROPERTY(bool CanPlay READ CanPlay)
177  bool CanPlay();
178 
179 
180  Q_PROPERTY(bool CanPause READ CanPause)
181  bool CanPause();
182 
183 
184  Q_PROPERTY(bool CanSeek READ CanSeek)
185  bool CanSeek();
186 
187 
188  Q_PROPERTY(bool CanControl READ CanControl)
189  bool CanControl();
190 
191 
192  void Next();
193  void Previous();
194  void Pause();
195  void PlayPause();
196  void Stop();
197  void Play();
198  void Seek(qint64 offset);
199 
200  void OpenUri(const QString& uri);
201 
202 
203  public slots:
204 
205  void position_changed(quint64 pos_ms);
206  void volume_changed(int volume);
207  void track_idx_changed(int idx);
208  void playlist_len_changed(int len);
209  void track_changed(const MetaData& md);
210  void playstate_changed(PlayState state);
211 
212  signals:
213  void Seeked(qint64 position);
214  void sig_raise();
215 };
216 } // end namespace DBusMPRIS
217 
218 #endif // DBUS_MPRIS_H
Definition: DBusMPRIS.h:34
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:29
The MetaData class.
Definition: MetaData.h:55
Definition: DBusMPRIS.h:58
Global handler for current playback state (Singleton)
Definition: PlayManager.h:37
Definition: DBusHandler.h:33
PlayState
The PlayState enum.
Definition: PlayState.h:30