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