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:
parent
757327ceac
commit
54235f298e
23 changed files with 2574 additions and 2 deletions
127
core/include/JellyfinQt/viewmodel/platformmediacontrol.h
Normal file
127
core/include/JellyfinQt/viewmodel/platformmediacontrol.h
Normal 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
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue