TTKMusicPlayer  4.3.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 - 2026 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
39 public:
43  MusicMPRISPlayer(QObject *parent = nullptr);
48 
52  void execute();
53 
54 private:
57 
58 };
59 
60 
64 class TTK_MODULE_EXPORT MusicMPRISPlayerRoot : public QDBusAbstractAdaptor
65 {
66  Q_OBJECT
67  Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2")
68  Q_PROPERTY(bool CanQuit READ canQuit)
69  Q_PROPERTY(bool CanRaise READ canRaise)
70  Q_PROPERTY(QString DesktopEntry READ desktopEntry)
71  Q_PROPERTY(bool HasTrackList READ hasTrackList)
72  Q_PROPERTY(QString Identity READ identity)
73  Q_PROPERTY(QStringList SupportedMimeTypes READ supportedMimeTypes)
74  Q_PROPERTY(QStringList SupportedUriSchemes READ supportedUriSchemes)
75 
76 public:
80  MusicMPRISPlayerRoot(QObject *parent = nullptr);
81 
82  bool canQuit() const;
83  bool canRaise() const;
84  QString desktopEntry() const;
85  bool hasTrackList() const;
86  QString identity() const;
87  QStringList supportedMimeTypes() const;
88  QStringList supportedUriSchemes() const;
89 
90 public Q_SLOTS:
91  void Quit();
92  void Raise();
93 
94 };
95 
96 
100 class TTK_MODULE_EXPORT MusicMPRISPlayerCore : public QDBusAbstractAdaptor
101 {
102  Q_OBJECT
103  Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player")
104  Q_PROPERTY(bool CanControl READ canControl)
105  Q_PROPERTY(bool CanGoNext READ canGoNext)
106  Q_PROPERTY(bool CanGoPrevious READ canGoPrevious)
107  Q_PROPERTY(bool CanPause READ canPause)
108  Q_PROPERTY(bool CanPlay READ canPlay)
109  Q_PROPERTY(bool CanSeek READ canSeek)
110  Q_PROPERTY(QString LoopStatus READ loopStatus WRITE setLoopStatus)
111  Q_PROPERTY(double MaximumRate READ maximumRate)
112  Q_PROPERTY(QVariantMap Metadata READ metadata)
113  Q_PROPERTY(double MinimumRate READ minimumRate)
114  Q_PROPERTY(QString PlaybackStatus READ playbackStatus)
115  Q_PROPERTY(qlonglong Position READ position)
116  Q_PROPERTY(double Rate READ rate WRITE setRate)
117  Q_PROPERTY(bool Shuffle READ shuffle WRITE setShuffle)
118  Q_PROPERTY(double Volume READ volume WRITE setVolume)
119 
120 public:
124  MusicMPRISPlayerCore(QObject *parent = nullptr);
125 
126  bool canControl() const noexcept;
127  bool canGoNext() const noexcept;
128  bool canGoPrevious() const noexcept;
129  bool canPause() const noexcept;
130  bool canPlay() const noexcept;
131  bool canSeek() const noexcept;
132  QString loopStatus() const noexcept;
133  void setLoopStatus(const QString &value) noexcept;
134  double maximumRate() const noexcept;
135  QVariantMap metadata() const;
136  double minimumRate() const noexcept;
137  QString playbackStatus() const noexcept;
138  qlonglong position() const;
139  double rate() const noexcept;
140  void setRate(double value) noexcept;
141  bool shuffle() const noexcept;
142  void setShuffle(bool value) noexcept;
143  double volume() const;
144  void setVolume(double value);
145 
146 public Q_SLOTS:
147  void Next();
148  void Previous();
149  void OpenUri(const QString &uri);
150  void Pause();
151  void Play();
152  void PlayPause();
153  void Stop();
154  void Seek(qlonglong offset);
155  void SetPosition(const QDBusObjectPath &trackId, qlonglong position);
156 
157 Q_SIGNALS:
158  void Seeked(qlonglong position);
159 
160 private Q_SLOTS:
164  void trackInfoChanged();
168  void stateChanged();
172  void volumeChanged();
176  void elapsedChanged(qint64 elapsed);
180  void playbackModeChanged();
181 
182 private:
183  void updateTrackID();
184  void syncProperties();
185  void sendProperties();
186 
187  int m_prevTrack;
188  qint64 m_prevPos;
189  SoundCore *m_core;
190  MusicApplication *m_application;
191  QDBusObjectPath m_trackID;
192  TTKVariantMap m_properties;
193 
194 };
195 
196 #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.
TTK_MODULE_EXPORT bool execute(const QString &path)
voidpf uLong offset
Definition: ioapi.h:142
QMap< QString, QVariant > TTKVariantMap
Definition: ttkqtglobal.h:203
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.