1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2025-09-04 01:42:44 +00:00

Add MPRIS support

Besides MPRIS support, this also adds support for hasPrevious() and
hasNext() in several parts to determine whether the
player/playlist/shuffler has a previous or next item.
This commit is contained in:
Chris Josten 2021-08-31 01:29:51 +02:00
parent 757327ceac
commit 54235f298e
23 changed files with 2574 additions and 2 deletions

View file

@ -22,6 +22,7 @@
#include <QtQml>
#include "model/item.h"
#include "dto/itemfields.h"
#include "dto/mediastream.h"
#include "dto/nameguidpair.h"
#include "dto/userdto.h"
@ -36,6 +37,7 @@
#include "viewmodel/loader.h"
#include "viewmodel/mediastream.h"
#include "viewmodel/modelstatus.h"
#include "viewmodel/platformmediacontrol.h"
#include "viewmodel/playbackmanager.h"
#include "viewmodel/playlist.h"
#include "viewmodel/userdata.h"

View file

@ -58,11 +58,15 @@ public:
*/
int currentItemIndexInList() const;
bool hasPrevious();
/**
* @brief Determine the previous item to be played.
*/
void previous();
bool hasNext();
/**
* @brief Determine the next item to be played.
*/

View file

@ -83,6 +83,9 @@ public:
*/
virtual int nextItem() const { return -1; }
virtual bool hasPrevious() const { return false; }
virtual bool hasNext() const { return false; }
/**
* @brief Sets whether the shuffler to loop over the list if all items are played.
*/
@ -108,6 +111,8 @@ public:
virtual void previous() override;
virtual void next() override;
virtual void setIndex(int i) override;
virtual bool hasPrevious() const override;
virtual bool hasNext() const override;
protected:
int nextIndex() const;
int previousIndex() const;
@ -148,6 +153,8 @@ public:
virtual int nextItem() const override;
virtual void previous() override;
virtual void next() override;
virtual bool hasPrevious() const override;
virtual bool hasNext() const override;
protected:
int m_previous, m_current, m_next = -1;
};

View file

@ -0,0 +1,118 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
* Command line was: qdbusxml2cpp org.mpris.MediaPlayer2.xml -a ../include/JellyfinQt/platform/freedesktop/mediaplayer2.h:../src/platform/freedesktop/mediaplayer2.cpp
*
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
* before re-generating it.
*/
//HAND-EDIT: include-guard
#ifndef JELLYFIN_PLATFORM_FREEDESKTOP_MEDIAPLAYER2_H
#define JELLYFIN_PLATFORM_FREEDESKTKOP_MEDIAPLAYER2_H
#include <QtCore/QObject>
#include <QtDBus/QtDBus>
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
QT_END_NAMESPACE
//HAND-EDIT: added namespaces
namespace Jellyfin {
namespace ViewModel {
class PlatformMediaControl;
}
namespace Platform {
namespace FreeDesktop {
/*
* Adaptor class for interface org.mpris.MediaPlayer2
*/
class MediaPlayer2Adaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2")
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"org.mpris.MediaPlayer2\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" <method name=\"Raise\">\n"
" </method>\n"
" <method name=\"Quit\">\n"
" </method>\n"
" <property access=\"read\" type=\"b\" name=\"CanQuit\">\n"
" </property>\n"
" <property access=\"readwrite\" type=\"b\" name=\"Fullscreen\">\n"
" <annotation value=\"true\" name=\"org.mpris.MediaPlayer2.property.optional\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanSetFullscreen\">\n"
" <annotation value=\"true\" name=\"org.mpris.MediaPlayer2.property.optional\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanRaise\">\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"HasTrackList\">\n"
" </property>\n"
" <property access=\"read\" type=\"s\" name=\"Identity\">\n"
" </property>\n"
" <property access=\"read\" type=\"s\" name=\"DesktopEntry\">\n"
" <annotation value=\"true\" name=\"org.mpris.MediaPlayer2.property.optional\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"as\" name=\"SupportedUriSchemes\">\n"
" </property>\n"
" <property access=\"read\" type=\"as\" name=\"SupportedMimeTypes\">\n"
" </property>\n"
" </interface>\n"
"")
public:
MediaPlayer2Adaptor(ViewModel::PlatformMediaControl *parent);
virtual ~MediaPlayer2Adaptor();
public: // PROPERTIES
Q_PROPERTY(bool CanQuit READ canQuit)
bool canQuit() const;
Q_PROPERTY(bool CanRaise READ canRaise)
bool canRaise() const;
Q_PROPERTY(bool CanSetFullscreen READ canSetFullscreen)
bool canSetFullscreen() const;
Q_PROPERTY(QString DesktopEntry READ desktopEntry)
QString desktopEntry() const;
Q_PROPERTY(bool Fullscreen READ fullscreen WRITE setFullscreen)
bool fullscreen() const;
void setFullscreen(bool value);
Q_PROPERTY(bool HasTrackList READ hasTrackList)
bool hasTrackList() const;
Q_PROPERTY(QString Identity READ identity)
QString identity() const;
Q_PROPERTY(QStringList SupportedMimeTypes READ supportedMimeTypes)
QStringList supportedMimeTypes() const;
Q_PROPERTY(QStringList SupportedUriSchemes READ supportedUriSchemes)
QStringList supportedUriSchemes() const;
public Q_SLOTS: // METHODS
void Quit();
void Raise();
Q_SIGNALS: // SIGNALS
private:
ViewModel::PlatformMediaControl *m_mediaControl;
};
} // NS FreeDesktop
} // NS Platform
} // NS Jellyfin
#endif

View file

@ -0,0 +1,205 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
* Command line was: qdbusxml2cpp org.mpris.MediaPlayer2.Player.xml -a ../include/JellyfinQt/platform/freedesktop/mediaplayer2player.h:../src/platform/freedesktop/mediaplayer2player.cpp
*
* qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd.
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
* before re-generating it.
*/
//HAND-EDIT: include-guard
#ifndef JELLYFIN_PLATFORM_FREEDESKTOP_MEDIAPLAYER2PLAYER_H
#define JELLYFIN_PLATFORM_FREEDESKTOP_MEDIAPLAYER2PLAYER_H
#include <QtCore/QObject>
#include <QtDBus/QtDBus>
#include <QMediaPlayer>
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
QT_END_NAMESPACE
//HAND-EDIT: added namespaces
namespace Jellyfin {
namespace ViewModel {
class Item;
class PlatformMediaControl;
class PlaybackManager;
}
namespace Platform {
namespace FreeDesktop {
/*
* Adaptor class for interface org.mpris.MediaPlayer2.Player
*/
class PlayerAdaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player")
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"org.mpris.MediaPlayer2.Player\">\n"
" <method name=\"Next\">\n"
" </method>\n"
" <method name=\"Previous\">\n"
" </method>\n"
" <method name=\"Pause\">\n"
" </method>\n"
" <method name=\"PlayPause\">\n"
" </method>\n"
" <method name=\"Stop\">\n"
" </method>\n"
" <method name=\"Play\">\n"
" </method>\n"
" <method name=\"Seek\">\n"
" <arg direction=\"in\" type=\"x\" name=\"Offset\"/>\n"
" </method>\n"
" <method name=\"SetPosition\">\n"
" <arg direction=\"in\" type=\"o\" name=\"TrackId\"/>\n"
" <arg direction=\"in\" type=\"x\" name=\"Position\"/>\n"
" </method>\n"
" <method name=\"OpenUri\">\n"
" <arg direction=\"in\" type=\"s\" name=\"Uri\"/>\n"
" </method>\n"
" <property access=\"read\" type=\"s\" name=\"PlaybackStatus\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"readwrite\" type=\"s\" name=\"LoopStatus\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" <annotation value=\"true\" name=\"org.mpris.MediaPlayer2.property.optional\"/>\n"
" </property>\n"
" <property access=\"readwrite\" type=\"d\" name=\"Rate\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"readwrite\" type=\"b\" name=\"Shuffle\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" <annotation value=\"true\" name=\"org.mpris.MediaPlayer2.property.optional\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"a{sv}\" name=\"Metadata\">\n"
" <annotation value=\"QVariantMap\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"readwrite\" type=\"d\" name=\"Volume\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"x\" name=\"Position\">\n"
" <annotation value=\"false\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"d\" name=\"MinimumRate\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"d\" name=\"MaximumRate\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanGoNext\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanGoPrevious\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanPlay\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanPause\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanSeek\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <property access=\"read\" type=\"b\" name=\"CanControl\">\n"
" <annotation value=\"false\" name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\"/>\n"
" </property>\n"
" <signal name=\"Seeked\">\n"
" <arg type=\"x\" name=\"Position\"/>\n"
" </signal>\n"
" </interface>\n"
"")
public:
PlayerAdaptor(ViewModel::PlatformMediaControl *parent);
virtual ~PlayerAdaptor();
public: // PROPERTIES
Q_PROPERTY(bool CanControl READ canControl)
bool canControl() const;
Q_PROPERTY(bool CanGoNext READ canGoNext)
bool canGoNext() const;
Q_PROPERTY(bool CanGoPrevious READ canGoPrevious)
bool canGoPrevious() const;
Q_PROPERTY(bool CanPause READ canPause)
bool canPause() const;
Q_PROPERTY(bool CanPlay READ canPlay)
bool canPlay() const;
Q_PROPERTY(bool CanSeek READ canSeek)
bool canSeek() const;
Q_PROPERTY(QString LoopStatus READ loopStatus WRITE setLoopStatus)
QString loopStatus() const;
void setLoopStatus(const QString &value);
Q_PROPERTY(double MaximumRate READ maximumRate)
double maximumRate() const;
Q_PROPERTY(QVariantMap Metadata READ metadata)
QVariantMap metadata() const;
Q_PROPERTY(double MinimumRate READ minimumRate)
double minimumRate() const;
Q_PROPERTY(QString PlaybackStatus READ playbackStatus)
QString playbackStatus() const;
Q_PROPERTY(qlonglong Position READ position)
qlonglong position() const;
Q_PROPERTY(double Rate READ rate WRITE setRate)
double rate() const;
void setRate(double value);
Q_PROPERTY(bool Shuffle READ shuffle WRITE setShuffle)
bool shuffle() const;
void setShuffle(bool value);
Q_PROPERTY(double Volume READ volume WRITE setVolume)
double volume() const;
void setVolume(double value);
public Q_SLOTS: // METHODS
void Next();
void OpenUri(const QString &Uri);
void Pause();
void Play();
void PlayPause();
void Previous();
void Seek(qlonglong Offset);
void SetPosition(const QDBusObjectPath &TrackId, qlonglong Position);
void Stop();
Q_SIGNALS: // SIGNALS
void Seeked(qlonglong Position);
private:
ViewModel::PlatformMediaControl *m_mediaControl;
void notifyPropertiesChanged(QStringList properties);
private slots:
void onCurrentItemChanged(ViewModel::Item *newItem);
void onPlaybackStateChanged(QMediaPlayer::State state);
void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
void onPositionChanged(qint64 position);
void onSeekableChanged(bool seekable);
void onPlaybackManagerChanged(ViewModel::PlaybackManager *newPlaybackManager);
};
} // NS FreeDesktop
} // NS Platform
} // NS Jellyfin
#endif

View file

@ -0,0 +1,127 @@
/*
* Sailfin: a Jellyfin client written using Qt
* Copyright (C) 2021 Chris Josten and the Sailfin Contributors.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef JELLYFIN_VIEWMODEL_PLATFORMMEDIACONTROL_H
#define JELLYFIN_VIEWMODEL_PLATFORMMEDIACONTROL_H
#include <QObject>
#include <QQmlParserStatus>
#include <QScopedPointer>
namespace Jellyfin {
namespace ViewModel {
class PlatformMediaControlPrivate;
class PlaybackManager;
/**
* @brief Exposes media control and information to the OS. Uses MPRIS on FreeDesktop-enabled systems.
*/
class PlatformMediaControl : public QObject, public QQmlParserStatus {
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
public:
explicit PlatformMediaControl(QObject *parent = nullptr);
Q_PROPERTY(Jellyfin::ViewModel::PlaybackManager *playbackManager READ playbackManager WRITE setPlaybackManager NOTIFY playbackManagerChanged)
/**
* Whether the operating system can request the media player to quit. If set,
* the quitRequested signal may be emitted and the application should quit.
*/
Q_PROPERTY(bool canQuit READ canQuit WRITE setCanQuit NOTIFY canQuitChanged)
Q_PROPERTY(bool canRaise READ canRaise WRITE setCanRaise NOTIFY canRaiseChanged)
Q_PROPERTY(QString playerName READ playerName WRITE setPlayerName NOTIFY playerNameChanged)
Q_PROPERTY(QString desktopFile READ playerName WRITE setPlayerName NOTIFY playerNameChanged)
PlaybackManager *playbackManager() const { return m_playbackManager; };
void setPlaybackManager(PlaybackManager *newPlaybackManager) {
m_playbackManager = newPlaybackManager;
emit playbackManagerChanged(newPlaybackManager);
};
bool canQuit() const { return m_canQuit; };
void setCanQuit(bool newCanQuit) {
m_canQuit = newCanQuit;
emit canQuitChanged(newCanQuit);
}
void requestQuit() {
emit quitRequested();
}
bool canRaise() const { return m_canRaise; };
void setCanRaise(bool newCanRaise) {
m_canRaise = newCanRaise;
emit canRaiseChanged(newCanRaise);
}
void requestRaise() {
emit raiseRequested();
};;
QString playerName() const { return m_playerName; }
void setPlayerName(QString newPlayerName) {
m_playerName = newPlayerName;
emit playerNameChanged(newPlayerName);
}
QString desktopFile() const { return m_desktopFile; }
void setDesktopFile(QString newDesktopFile) {
m_desktopFile = newDesktopFile;
emit desktopFileChanged(newDesktopFile);
}
void classBegin() override {
m_isParsing = true;
}
void componentComplete() override {
m_isParsing = false;
setup();
}
signals:
void playbackManagerChanged(PlaybackManager *newPlaybackManager);
void canQuitChanged(bool newCanQuit);
void canRaiseChanged(bool newCanRaise);
void playerNameChanged(QString newPlayerName);
void desktopFileChanged(QString newDesktopFile);
void quitRequested();
void raiseRequested();
private:
Q_DECLARE_PRIVATE(PlatformMediaControl)
PlatformMediaControlPrivate* d_ptr;
void setup();
bool m_isParsing = false;
PlaybackManager *m_playbackManager = nullptr;
bool m_canQuit = false;
bool m_canRaise = false;
QString m_playerName = QStringLiteral("JellyfinQt");
QString m_desktopFile = QStringLiteral("sailfin");
};
} // NS ViewModel
} // NS Jellyfin
#endif // PLATFORMMEDIACONTROL_H

View file

@ -97,8 +97,12 @@ public:
Q_PROPERTY(QMediaPlayer::MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged)
Q_PROPERTY(QMediaPlayer::State playbackState READ playbackState NOTIFY playbackStateChanged)
Q_PROPERTY(qint64 position READ position NOTIFY positionChanged)
Q_PROPERTY(bool hasNext READ hasNext NOTIFY hasNextChanged)
Q_PROPERTY(bool hasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
ViewModel::Item *item() const { return m_displayItem; }
QSharedPointer<Model::Item> dataItem() const { return m_item; }
ApiClient *apiClient() const { return m_apiClient; }
void setApiClient(ApiClient *apiClient);
QString streamUrl() const { return m_streamUrl; }
@ -108,6 +112,8 @@ public:
qint64 duration() const { return m_mediaPlayer->duration(); }
ViewModel::Playlist *queue() const { return m_displayQueue; }
int queueIndex() const { return m_queueIndex; }
bool hasNext() const { return m_queue->hasNext(); }
bool hasPrevious() const { return m_queue->hasPrevious(); }
// Current media player related property getters
QMediaPlayer::State playbackState() const { return m_mediaPlayer->state()/*m_playbackState*/; }
@ -138,6 +144,8 @@ signals:
void seekableChanged(bool newSeekable);
void errorChanged(QMediaPlayer::Error newError);
void errorStringChanged(const QString &newErrorString);
void hasNextChanged(bool newHasNext);
void hasPreviousChanged(bool newHasPrevious);
public slots:
/**
* @brief playItem Replaces the current queue and plays the item with the given id.