mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-06 10:32: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
87
core/src/viewmodel/platformmediacontrol_freedesktop.cpp
Normal file
87
core/src/viewmodel/platformmediacontrol_freedesktop.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "JellyfinQt/viewmodel/platformmediacontrol.h"
|
||||
#include "JellyfinQt/platform/freedesktop/mediaplayer2.h"
|
||||
#include "JellyfinQt/platform/freedesktop/mediaplayer2player.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace ViewModel {
|
||||
|
||||
using Platform::FreeDesktop::MediaPlayer2Adaptor;
|
||||
using Platform::FreeDesktop::PlayerAdaptor;
|
||||
|
||||
class PlatformMediaControlPrivate {
|
||||
public:
|
||||
PlatformMediaControlPrivate(PlatformMediaControl *parent);
|
||||
void setupConnection();
|
||||
private:
|
||||
PlatformMediaControl *q_ptr;
|
||||
Q_DECLARE_PUBLIC(PlatformMediaControl)
|
||||
|
||||
MediaPlayer2Adaptor *m_mainAdaptor;
|
||||
PlayerAdaptor *m_playerAdaptor;
|
||||
QDBusConnection m_connection;
|
||||
public slots:
|
||||
// MPRIS Player methods
|
||||
void Quit();
|
||||
|
||||
};
|
||||
|
||||
PlatformMediaControl::PlatformMediaControl(QObject *parent)
|
||||
: QObject(parent) {
|
||||
d_ptr = new PlatformMediaControlPrivate(this);
|
||||
}
|
||||
|
||||
void PlatformMediaControl::setup() {
|
||||
Q_D(PlatformMediaControl);
|
||||
d->setupConnection();
|
||||
}
|
||||
|
||||
PlatformMediaControlPrivate::PlatformMediaControlPrivate(PlatformMediaControl *parent)
|
||||
: q_ptr(parent),
|
||||
m_mainAdaptor(new MediaPlayer2Adaptor(parent)),
|
||||
m_playerAdaptor(new PlayerAdaptor(parent)),
|
||||
m_connection(QDBusConnection::sessionBus()) {
|
||||
|
||||
}
|
||||
|
||||
void PlatformMediaControlPrivate::setupConnection() {
|
||||
Q_Q(PlatformMediaControl);
|
||||
if(!m_connection.registerObject(QStringLiteral("/org/mpris/MediaPlayer2"), q)) {
|
||||
qWarning() << "MediaPlayer2 dbus object not registered: " << m_connection.lastError();
|
||||
}
|
||||
if (!m_connection.registerService(QStringLiteral("org.mpris.MediaPlayer2.sailfin.instance").append(QString::number(QCoreApplication::applicationPid())))) {
|
||||
qWarning() << "Could not aqcuire DBus name: " << m_connection.lastError();
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformMediaControlPrivate::Quit() {
|
||||
Q_Q(PlatformMediaControl);
|
||||
q->requestQuit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
29
core/src/viewmodel/platformmediacontrol_stub.cpp
Normal file
29
core/src/viewmodel/platformmediacontrol_stub.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "JellyfinQt/viewmodel/platformmediacontrol.h"
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace ViewModel {
|
||||
|
||||
PlatformMediaControl::PlatformMediaControl(QObject *parent)
|
||||
: QObject(parent) {}
|
||||
|
||||
}
|
||||
}
|
|
@ -84,6 +84,9 @@ void PlaybackManager::setItem(QSharedPointer<Model::Item> newItem) {
|
|||
}
|
||||
emit itemChanged(m_displayItem);
|
||||
|
||||
emit hasNextChanged(m_queue->hasNext());
|
||||
emit hasPreviousChanged(m_queue->hasPrevious());
|
||||
|
||||
if (m_apiClient == nullptr) {
|
||||
qWarning() << "apiClient is not set on this MediaSource instance! Aborting.";
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue