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