strawberry-audio-player-win.../src/core/mpris2.h

248 lines
7.3 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef MPRIS2_H
#define MPRIS2_H
#include "config.h"
#include <QtGlobal>
2018-02-27 18:06:05 +01:00
#include <QObject>
#include <QList>
#include <QMap>
#include <QSet>
#include <QMetaType>
#include <QVariant>
#include <QString>
#include <QStringList>
2018-02-27 18:06:05 +01:00
#include <QtDBus>
#include <QDBusArgument>
#include <qdbusextratypes.h>
#include <QJsonObject>
#include "engine/engine_fwd.h"
#include "covermanager/albumcoverloaderresult.h"
2018-02-27 18:06:05 +01:00
class Application;
class Song;
2018-02-27 18:06:05 +01:00
class Playlist;
typedef QList<QVariantMap> TrackMetadata;
2020-04-23 21:08:28 +02:00
typedef QList<QDBusObjectPath> Track_Ids;
2019-09-15 20:27:32 +02:00
Q_DECLARE_METATYPE(TrackMetadata)
2018-02-27 18:06:05 +01:00
struct MprisPlaylist {
QDBusObjectPath id;
QString name;
QString icon; // Uri
};
typedef QList<MprisPlaylist> MprisPlaylistList;
2019-09-15 20:27:32 +02:00
Q_DECLARE_METATYPE(MprisPlaylist)
Q_DECLARE_METATYPE(MprisPlaylistList)
2018-02-27 18:06:05 +01:00
struct MaybePlaylist {
bool valid;
MprisPlaylist playlist;
};
2019-09-15 20:27:32 +02:00
Q_DECLARE_METATYPE(MaybePlaylist)
2018-02-27 18:06:05 +01:00
QDBusArgument &operator<<(QDBusArgument &arg, const MprisPlaylist &playlist);
const QDBusArgument &operator>> (const QDBusArgument &arg, MprisPlaylist &playlist);
QDBusArgument &operator<<(QDBusArgument &arg, const MaybePlaylist &playlist);
const QDBusArgument &operator>> (const QDBusArgument &arg, MaybePlaylist &playlist);
namespace mpris {
class Mpris2 : public QObject {
Q_OBJECT
public:
2020-04-07 16:49:15 +02:00
explicit Mpris2(Application *app, QObject *parent = nullptr);
2018-02-27 18:06:05 +01:00
// org.mpris.MediaPlayer2 MPRIS 2.0 Root interface
Q_PROPERTY(bool CanQuit READ CanQuit)
Q_PROPERTY(bool CanRaise READ CanRaise)
Q_PROPERTY(bool HasTrackList READ HasTrackList)
Q_PROPERTY(QString Identity READ Identity)
Q_PROPERTY(QString DesktopEntry READ DesktopEntry)
Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes)
Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes)
// org.mpris.MediaPlayer2 MPRIS 2.2 Root interface
Q_PROPERTY(bool CanSetFullscreen READ CanSetFullscreen)
Q_PROPERTY(bool Fullscreen READ Fullscreen WRITE SetFullscreen)
// org.mpris.MediaPlayer2.Player MPRIS 2.0 Player interface
Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus)
Q_PROPERTY(QString LoopStatus READ LoopStatus WRITE SetLoopStatus)
Q_PROPERTY(double Rate READ Rate WRITE SetRate)
Q_PROPERTY(bool Shuffle READ Shuffle WRITE SetShuffle)
Q_PROPERTY(QVariantMap Metadata READ Metadata)
Q_PROPERTY(double Volume READ Volume WRITE SetVolume)
2021-03-21 18:53:02 +01:00
Q_PROPERTY(qint64 Position READ Position)
2018-02-27 18:06:05 +01:00
Q_PROPERTY(double MinimumRate READ MinimumRate)
Q_PROPERTY(double MaximumRate READ MaximumRate)
Q_PROPERTY(bool CanGoNext READ CanGoNext)
Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious)
Q_PROPERTY(bool CanPlay READ CanPlay)
Q_PROPERTY(bool CanPause READ CanPause)
Q_PROPERTY(bool CanSeek READ CanSeek)
Q_PROPERTY(bool CanControl READ CanControl)
// org.mpris.MediaPlayer2.TrackList MPRIS 2.0 Player interface
2020-04-23 21:08:28 +02:00
Q_PROPERTY(Track_Ids Tracks READ Tracks)
2018-02-27 18:06:05 +01:00
Q_PROPERTY(bool CanEditTracks READ CanEditTracks)
// org.mpris.MediaPlayer2.Playlists MPRIS 2.1 Playlists interface
Q_PROPERTY(quint32 PlaylistCount READ PlaylistCount)
Q_PROPERTY(QStringList Orderings READ Orderings)
Q_PROPERTY(MaybePlaylist ActivePlaylist READ ActivePlaylist)
// Root Properties
bool CanQuit() const;
bool CanRaise() const;
bool HasTrackList() const;
QString Identity() const;
QString DesktopEntry() const;
QStringList SupportedUriSchemes() const;
QStringList SupportedMimeTypes() const;
// Root Properties added in MPRIS 2.2
bool CanSetFullscreen() const { return false; }
bool Fullscreen() const { return false; }
void SetFullscreen(bool) {}
// Methods
void Raise();
void Quit();
// Player Properties
QString PlaybackStatus() const;
QString LoopStatus() const;
void SetLoopStatus(const QString &value);
double Rate() const;
2020-06-14 18:58:24 +02:00
void SetRate(double rate);
2018-02-27 18:06:05 +01:00
bool Shuffle() const;
2020-06-14 18:58:24 +02:00
void SetShuffle(bool enable);
2018-02-27 18:06:05 +01:00
QVariantMap Metadata() const;
double Volume() const;
void SetVolume(double value);
2021-03-21 18:53:02 +01:00
qint64 Position() const;
2018-02-27 18:06:05 +01:00
double MaximumRate() const;
double MinimumRate() const;
bool CanGoNext() const;
bool CanGoPrevious() const;
bool CanPlay() const;
bool CanPause() const;
bool CanSeek() const;
bool CanControl() const;
// Methods
void Next();
void Previous();
void Pause();
void PlayPause();
void Stop();
void Play();
2021-03-21 18:53:02 +01:00
void Seek(qint64 offset);
void SetPosition(const QDBusObjectPath &trackId, qint64 offset);
2018-02-27 18:06:05 +01:00
void OpenUri(const QString &uri);
// TrackList Properties
2020-04-23 21:08:28 +02:00
Track_Ids Tracks() const;
2018-02-27 18:06:05 +01:00
bool CanEditTracks() const;
// Methods
2020-04-23 21:08:28 +02:00
TrackMetadata GetTracksMetadata(const Track_Ids &tracks) const;
2018-02-27 18:06:05 +01:00
void AddTrack(const QString &uri, const QDBusObjectPath &afterTrack, bool setAsCurrent);
void RemoveTrack(const QDBusObjectPath &trackId);
void GoTo(const QDBusObjectPath &trackId);
// Playlist Properties
quint32 PlaylistCount() const;
QStringList Orderings() const;
MaybePlaylist ActivePlaylist() const;
// Methods
void ActivatePlaylist(const QDBusObjectPath &playlist_id);
MprisPlaylistList GetPlaylists(quint32 index, quint32 max_count, const QString &order, bool reverse_order);
2018-02-27 18:06:05 +01:00
2021-01-26 16:48:04 +01:00
signals:
2018-02-27 18:06:05 +01:00
// Player
2021-03-21 18:53:02 +01:00
void Seeked(qint64 position);
2018-02-27 18:06:05 +01:00
// TrackList
2021-02-10 18:32:10 +01:00
void TrackListReplaced(Track_Ids Tracks, QDBusObjectPath CurrentTrack);
void TrackAdded(TrackMetadata Metadata, QDBusObjectPath AfterTrack);
void TrackRemoved(QDBusObjectPath trackId);
void TrackMetadataChanged(QDBusObjectPath trackId, TrackMetadata metadata);
2018-02-27 18:06:05 +01:00
void RaiseMainWindow();
// Playlist
2021-02-10 18:32:10 +01:00
void PlaylistChanged(MprisPlaylist playlist);
2018-02-27 18:06:05 +01:00
private slots:
void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result = AlbumCoverLoaderResult());
2018-02-27 18:06:05 +01:00
void EngineStateChanged(Engine::State newState);
void VolumeChanged();
void PlaylistManagerInitialized();
void CurrentSongChanged(const Song &song);
void ShuffleModeChanged();
void RepeatModeChanged();
2021-01-26 16:48:04 +01:00
void PlaylistChangedSlot(Playlist *playlist);
2018-02-27 18:06:05 +01:00
void PlaylistCollectionChanged(Playlist *playlist);
private:
void EmitNotification(const QString &name);
void EmitNotification(const QString &name, const QVariant &val);
void EmitNotification(const QString &name, const QVariant &val, const QString &mprisEntity);
QString PlaybackStatus(Engine::State state) const;
QString current_track_id() const;
bool CanSeek(Engine::State state) const;
QString DesktopEntryAbsolutePath() const;
private:
static const char *kMprisObjectPath;
static const char *kServiceName;
static const char *kFreedesktopPath;
Application *app_;
QString app_name_;
QStringList data_dirs_;
QStringList desktop_files_;
QString desktop_file_;
QVariantMap last_metadata_;
2018-02-27 18:06:05 +01:00
};
} // namespace mpris
2021-02-02 21:08:58 +01:00
#endif // MPRIS2_H