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 #include <QMainWindow>
32 
33 #include "Helper/Settings/SayonaraClass.h"
34 #include "Components/PlayManager/PlayManager.h"
35 
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(QMainWindow* 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  Q_PROPERTY(QString Identity READ Identity)
86  QString Identity();
87 
88  Q_PROPERTY(QString DesktopEntry READ DesktopEntry)
89  QString DesktopEntry();
90 
91  Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes)
92  QStringList SupportedUriSchemes();
93 
94 
95  Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes)
96  QStringList SupportedMimeTypes();
97 
98 
99  Q_PROPERTY(bool CanSetFullscreen READ CanSetFullscreen)
100  bool CanSetFullscreen();
101 
102  Q_PROPERTY(bool Fullscreen READ Fullscreen WRITE SetFullscreen)
103  bool Fullscreen();
104  void SetFullscreen(bool b);
105 
106  void Raise();
107  void Quit();
108 
109 
110  private:
111 
112  QMainWindow* _player=nullptr;
113  int _len_playlist;
114  int _cur_idx;
115 
116  bool _can_next;
117  bool _can_previous;
118  double _volume;
119  QString _playback_status;
120  MetaData _md;
121  qint64 _pos;
122 
123  bool _initialized;
124  void init();
125 
126 
127  public:
128  Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus)
129  QString PlaybackStatus();
130 
131 
132  Q_PROPERTY(QString LoopStatus READ LoopStatus WRITE SetLoopStatus)
133  QString LoopStatus();
134  void SetLoopStatus(QString status);
135 
136 
137 
138  Q_PROPERTY(double Rate READ Rate WRITE SetRate)
139  double Rate();
140  void SetRate(double rate);
141 
142 
143 
144  Q_PROPERTY(bool Shuffle READ Shuffle WRITE SetShuffle)
145  bool Shuffle();
146  void SetShuffle(bool shuffle);
147 
148 
149  Q_PROPERTY(QVariantMap Metadata READ Metadata)
150  QVariantMap Metadata();
151 
152 
153  Q_PROPERTY(double Volume READ Volume WRITE SetVolume)
154  double Volume();
155  void SetVolume(double volume);
156 
157 
158  Q_PROPERTY(qint64 Position READ Position)
159  qint64 Position();
160  void SetPosition(const QDBusObjectPath& track_id, qint64 position);
161 
162 
163 
164  Q_PROPERTY(double MinimumRate READ MinimumRate)
165  double MinimumRate();
166 
167 
168  Q_PROPERTY(double MaximumRate READ MaximumRate)
169  double MaximumRate();
170 
171 
172  Q_PROPERTY(bool CanGoNext READ CanGoNext)
173  bool CanGoNext();
174 
175 
176  Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious)
177  bool CanGoPrevious();
178 
179 
180  Q_PROPERTY(bool CanPlay READ CanPlay)
181  bool CanPlay();
182 
183 
184  Q_PROPERTY(bool CanPause READ CanPause)
185  bool CanPause();
186 
187 
188  Q_PROPERTY(bool CanSeek READ CanSeek)
189  bool CanSeek();
190 
191 
192  Q_PROPERTY(bool CanControl READ CanControl)
193  bool CanControl();
194 
195 
196  void Next();
197  void Previous();
198  void Pause();
199  void PlayPause();
200  void Stop();
201  void Play();
202  void Seek(qint64 offset);
203 
204  void OpenUri(const QString& uri);
205 
206 
207  public slots:
208 
209  void position_changed(quint64 pos_ms);
210  void volume_changed(int volume);
211  void track_idx_changed(int idx);
212  void playlist_len_changed(int len);
213  void track_changed(const MetaData& md);
214  void playstate_changed(PlayManager::PlayState);
215 
216  signals:
217  void Seeked(qint64 position);
218  void sig_raise();
219 
220 };
221 
222 } // end namespace DBusMPRIS
223 
224 #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:79
Definition: DBusMPRIS.h:61
Global handler for current playback state (Singleton)
Definition: PlayManager.h:67
Definition: DBusHandler.h:34