TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicmprisplayer.h
Go to the documentation of this file.
1 #ifndef MUSICMPRISPLAYER_H
2 #define MUSICMPRISPLAYER_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Music Player project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include "musicglobaldefine.h"
23 
24 #include <QDBusConnection>
25 #include <QDBusObjectPath>
26 #include <QDBusAbstractAdaptor>
27 
28 class SoundCore;
29 class MusicApplication;
32 
36 class TTK_MODULE_EXPORT MusicMPRISPlayer : public QObject
37 {
38  Q_OBJECT
40 public:
44  MusicMPRISPlayer(QObject *parent = nullptr);
49 
53  void run();
54 
55 private:
58 
59 };
60 
61 
65 class TTK_MODULE_EXPORT MusicMPRISPlayerRoot : public QDBusAbstractAdaptor
66 {
67  Q_OBJECT
68  Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2")
69  Q_PROPERTY(bool CanQuit READ canQuit)
70  Q_PROPERTY(bool CanRaise READ canRaise)
71  Q_PROPERTY(QString DesktopEntry READ desktopEntry)
72  Q_PROPERTY(bool HasTrackList READ hasTrackList)
73  Q_PROPERTY(QString Identity READ identity)
74  Q_PROPERTY(QStringList SupportedMimeTypes READ supportedMimeTypes)
75  Q_PROPERTY(QStringList SupportedUriSchemes READ supportedUriSchemes)
76 
77 public:
81  MusicMPRISPlayerRoot(QObject *parent = nullptr);
82 
83  bool canQuit() const;
84  bool canRaise() const;
85  QString desktopEntry() const;
86  bool hasTrackList() const;
87  QString identity() const;
88  QStringList supportedMimeTypes() const;
89  QStringList supportedUriSchemes() const;
90 
91 public Q_SLOTS:
92  void Quit();
93  void Raise();
94 
95 };
96 
97 
101 class TTK_MODULE_EXPORT MusicMPRISPlayerCore : public QDBusAbstractAdaptor
102 {
103  Q_OBJECT
104  Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player")
105  Q_PROPERTY(bool CanControl READ canControl)
106  Q_PROPERTY(bool CanGoNext READ canGoNext)
107  Q_PROPERTY(bool CanGoPrevious READ canGoPrevious)
108  Q_PROPERTY(bool CanPause READ canPause)
109  Q_PROPERTY(bool CanPlay READ canPlay)
110  Q_PROPERTY(bool CanSeek READ canSeek)
111  Q_PROPERTY(QString LoopStatus READ loopStatus WRITE setLoopStatus)
112  Q_PROPERTY(double MaximumRate READ maximumRate)
113  Q_PROPERTY(QVariantMap Metadata READ metadata)
114  Q_PROPERTY(double MinimumRate READ minimumRate)
115  Q_PROPERTY(QString PlaybackStatus READ playbackStatus)
116  Q_PROPERTY(qlonglong Position READ position)
117  Q_PROPERTY(double Rate READ rate WRITE setRate)
118  Q_PROPERTY(bool Shuffle READ shuffle WRITE setShuffle)
119  Q_PROPERTY(double Volume READ volume WRITE setVolume)
120 
121 public:
125  MusicMPRISPlayerCore(QObject *parent = nullptr);
126 
127  bool canControl() const;
128  bool canGoNext() const;
129  bool canGoPrevious() const;
130  bool canPause() const;
131  bool canPlay() const;
132  bool canSeek() const;
133  QString loopStatus() const;
134  void setLoopStatus(const QString &value);
135  double maximumRate() const;
136  QVariantMap metadata() const;
137  double minimumRate() const;
138  QString playbackStatus() const;
139  qlonglong position() const;
140  double rate() const;
141  void setRate(double value);
142  bool shuffle() const;
143  void setShuffle(bool value);
144  double volume() const;
145  void setVolume(double value);
146 
147 public Q_SLOTS:
148  void Next();
149  void Previous();
150  void OpenUri(const QString &uri);
151  void Pause();
152  void Play();
153  void PlayPause();
154  void Stop();
155  void Seek(qlonglong offset);
156  void SetPosition(const QDBusObjectPath &trackId, qlonglong position);
157 
158 Q_SIGNALS:
159  void Seeked(qlonglong position);
160 
161 private Q_SLOTS:
165  void trackInfoChanged();
169  void stateChanged();
173  void volumeChanged();
177  void elapsedChanged(qint64 elapsed);
181  void playbackModeChanged();
182 
183 private:
184  void updateTrackID();
185  void syncProperties();
186  void sendProperties();
187 
188  int m_prevTrack;
189  qint64 m_prevPos;
190  SoundCore *m_core;
191  MusicApplication *m_application;
192  QDBusObjectPath m_trackID;
193  TTKVariantMap m_properties;
194 
195 };
196 
197 #endif // MUSICMPRISPLAYER_H
The class of the app mpris player object.
#define TTK_MODULE_EXPORT
MusicMPRISPlayerCore * m_player
The Volume class provides asbtract volume interface.
Definition: volume.h:51
The class of the app main widget.
voidpf uLong offset
Definition: ioapi.h:142
QMap< QString, QVariant > TTKVariantMap
Definition: ttkqtglobal.h:191
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:152
MusicMPRISPlayerRoot * m_root
#define const
Definition: zconf.h:233
The SoundCore class provides a simple interface for audio playback.
Definition: soundcore.h:40
The class of the app mpris main widget.
The class of the app mpris root object.