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

Discover remote sessions

Adds a way of discovering remote sessions and in Jellyfin the UI.
This commit is contained in:
Chris Josten 2022-12-28 21:20:04 +01:00 committed by Chris Josten
parent b1bd15f2c1
commit b257fe60aa
20 changed files with 1051 additions and 80 deletions

View file

@ -96,6 +96,7 @@ public:
explicit ApiClient(QObject *parent = nullptr);
virtual ~ApiClient();
Q_PROPERTY(QString baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged)
Q_PROPERTY(QString appName READ appName WRITE setAppName NOTIFY appNameChanged)
Q_PROPERTY(bool authenticated READ authenticated WRITE setAuthenticated NOTIFY authenticatedChanged)
Q_PROPERTY(QString userId READ userId NOTIFY userIdChanged)
Q_PROPERTY(QJsonObject deviceProfile READ deviceProfileJson NOTIFY deviceProfileChanged)
@ -114,6 +115,7 @@ public:
bool authenticated() const;
void setBaseUrl(const QString &url);
void setAppName(const QString &appName);
QNetworkReply *get(const QString &path, const QUrlQuery &params = QUrlQuery());
QNetworkReply *post(const QString &path, const QJsonDocument &data, const QUrlQuery &params = QUrlQuery());
QNetworkReply *post(const QString &path, const QByteArray &data = QByteArray(), const QUrlQuery &params = QUrlQuery());
@ -127,6 +129,7 @@ public:
Q_ENUM(ApiError)
const QString &baseUrl() const;
const QString &appName() const;
const QString &userId() const;
const QString &deviceId() const;
/**
@ -185,6 +188,7 @@ signals:
void authenticatedChanged(bool authenticated);
void baseUrlChanged(const QString &baseUrl);
void appNameChanged(const QString &newAppName);
void settingsChanged();
/**

View file

@ -0,0 +1,171 @@
#ifndef JELLYFIN_MODEL_CONTROLLABLESESSION_H
#define JELLYFIN_MODEL_CONTROLLABLESESSION_H
#include <QObject>
#include <QScopedPointer>
#include <QSharedPointer>
#include "JellyfinQt/dto/sessioninfo.h"
namespace Jellyfin {
class ApiClient;
namespace DTO {
class ClientCapabilities;
} // NS DTO
namespace Model {
class PlaybackManager;
class DeviceTypeClass { Q_GADGET
public:
enum Value {
Unknown,
Tv,
Computer,
Phone
};
Q_ENUM(Value)
};
class MediaTypeClass {
Q_GADGET
public:
enum Value {
None = 0x0,
Audio = 0x1,
Video = 0x2,
Photo = 0x4
};
Q_DECLARE_FLAGS(MediaTypes, Value)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MediaTypeClass::MediaTypes)
using DeviceType = DeviceTypeClass::Value;
using MediaTypes = MediaTypeClass::MediaTypes;
/**
* @brief Abstract class for describing a playback session that can be controlled.
*
* Main purpose for this class is to hold information for displaying it in a UI for an user to select
* and to create an implementation of a PlaybackManager instance to control this session.
*/
class ControllableSession : public QObject {
Q_OBJECT
public:
explicit ControllableSession(QObject *parent = nullptr);
/**
* @brief An unique id for this session.
*/
virtual QString id() const = 0;
/**
* @brief An human-readable name for this session
*/
virtual QString name() const = 0;
/**
* @brief The app for this session
*/
virtual QString appName() const = 0;
virtual DeviceType deviceType() const = 0;
/**
* @brief user The username of who started this session
*/
virtual QString userName() const = 0;
/**
* @brief Creates a playbackManager for this device. This PlaybackManager has no
* QObject parent and must be cleaned up by the caller.
*/
virtual PlaybackManager *createPlaybackManager() const = 0;
};
/**
* @brief Dummy session representing this device.
*/
class LocalSession : public ControllableSession {
Q_OBJECT
public:
LocalSession(ApiClient &apiClient, QObject *parent = nullptr);
QString id() const override;
QString name() const override;
QString appName() const override;
DeviceType deviceType() const override;
QString userName() const override;
PlaybackManager *createPlaybackManager() const override;
private:
ApiClient &m_apiClient;
};
/**
* @brief A session on the Jellyfin server that can be controlled.
*/
class ControllableJellyfinSession : public ControllableSession {
Q_OBJECT
public:
ControllableJellyfinSession(QSharedPointer<DTO::SessionInfo> info, QObject *parent = nullptr);
QString id() const override;
QString name() const override;
QString appName() const override;
DeviceType deviceType() const override;
QString userName() const override;
PlaybackManager *createPlaybackManager() const override;
private:
QSharedPointer<DTO::SessionInfo> m_data;
};
/**
* Abstract class for finding remotely controllable sessions
*/
class RemoteSessionScanner : public QObject {
Q_OBJECT
public:
explicit RemoteSessionScanner(QObject *parent = nullptr);
/**
* The session scanner should start discovering sessions
*/
virtual void startScanning() = 0;
/**
* The session scanner should stop discovering sessions
*/
virtual void stopScanning() = 0;
signals:
/**
* This signal should be emitted when an session has been discovered.
* The session should be reparented to whoever is listening for this signal.
*/
void sessionFound(Jellyfin::Model::ControllableSession *session);
/**
* Should be emitted when an session is gone.
*/
void sessionLost(const QString &sessionId);
/**
* Should be emitted when the listener should delete all sessions by this discoverer.
*/
void resetSessions();
};
class RemoteJellyfinSessionScannerPrivate;
/**
* @brief Lists controllable Jellyfin sessions from the Jellyfin server
*/
class RemoteJellyfinSessionScanner : public RemoteSessionScanner {
Q_OBJECT
Q_DECLARE_PRIVATE(RemoteJellyfinSessionScanner);
public:
explicit RemoteJellyfinSessionScanner(ApiClient *client, QObject *parent);
virtual ~RemoteJellyfinSessionScanner();
void startScanning() override;
void stopScanning() override;
private:
QScopedPointer<RemoteJellyfinSessionScannerPrivate> d_ptr;
};
} // NS Model
} // NS Jellyfin
#endif // JELLYFIN_MODEL_CONTROLLABLESESSION_H

View file

@ -62,10 +62,25 @@ class PlaybackManager : public QObject {
Q_PROPERTY(bool resumePlayback READ resumePlayback WRITE setResumePlayback NOTIFY resumePlaybackChanged)
Q_PROPERTY(int audioIndex READ audioIndex WRITE setAudioIndex NOTIFY audioIndexChanged)
Q_PROPERTY(int subtitleIndex READ subtitleIndex WRITE setSubtitleIndex NOTIFY subtitleIndexChanged)
/**
* @brief The position in ticks in the currently playing item
*/
Q_PROPERTY(qint64 position READ position NOTIFY positionChanged)
/**
* @brief The duration in ticks of the currently playing item
*/
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
/**
* @brief Whether the playbackmanager is currently able to seek
*/
Q_PROPERTY(bool seekable READ seekable NOTIFY seekableChanged)
/**
* @brief Whether the currently playing item has audio
*/
Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged)
/**
* @brief Whether the currently playing item has video
*/
Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
Q_PROPERTY(Jellyfin::Model::PlayerStateClass::Value playbackState READ playbackState NOTIFY playbackStateChanged)
Q_PROPERTY(Jellyfin::Model::MediaStatusClass::Value mediaStatus READ mediaStatus NOTIFY mediaStatusChanged)
@ -104,7 +119,15 @@ public:
virtual bool hasAudio() const = 0;
virtual bool hasVideo() const = 0;
/**
* @brief Start playing the given item
*/
virtual void playItem(QSharedPointer<Model::Item> item) = 0;
/**
* @brief Set the playlist to the given playlist and start playing the item at the given index
* @param items The list of items to play
* @param index Index of the item to play
*/
virtual void playItemInList(const QList<QSharedPointer<Model::Item>> &items, int index) = 0;
signals:

View file

@ -0,0 +1,74 @@
/*
* Sailfin: a Jellyfin client written using Qt
* Copyright (C) 2023 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_MODEL_REMOTEJELLYFINPLAYBACK_H
#define JELLYFIN_MODEL_REMOTEJELLYFINPLAYBACK_H
#include <JellyfinQt/dto/generalcommandtype.h>
#include <JellyfinQt/model/playbackmanager.h>
#include <QJsonObject>
#include <QSharedPointer>
namespace Jellyfin {
class ApiClient;
namespace Model {
class RemoteJellyfinPlayback : public PlaybackManager {
public:
RemoteJellyfinPlayback(ApiClient &apiClient, QObject *parent = nullptr);
// PlaybackManager
void swap(PlaybackManager &other) override;
PlayerState playbackState() const override;
MediaStatus mediaStatus() const override;
bool hasNext() const override;
bool hasPrevious() const override;
PlaybackManagerError error() const override;
const QString &errorString() const override;
qint64 position() const override;
qint64 duration() const override;
bool seekable() const override;
bool hasAudio() const override;
bool hasVideo() const override;
void playItem(QSharedPointer<Item> item) override;
void playItemInList(const QList<QSharedPointer<Item> > &items, int index) override;
public slots:
void pause() override;
void play() override;
void playItemId(const QString &id) override;
void previous() override;
void next() override;
void goTo(int index) override;
void stop() override;
void seek(qint64 pos) override;
private:
void sendGeneralCommand(DTO::GeneralCommandType command, QJsonObject arguments = QJsonObject());
ApiClient &m_apiClient;
};
} // NS Model
} // NS Jellyfin
#endif // JELLYFIN_MODEL_REMOTEJELLYFINPLAYBACK_H

View file

@ -20,11 +20,12 @@
#define JELLYFIN_VIEWMODEL_PLAYBACKMANAGER_H
#include <QAbstractItemModel>
#include <QFuture>
#include <QJsonArray>
#include <QJsonObject>
#include <QLoggingCategory>
#include <QFuture>
#include <QObject>
#include <QSharedPointer>
#include <QtGlobal>
#include <QUrlQuery>
#include <QVariant>
@ -34,17 +35,18 @@
#include <functional>
#include "../dto/baseitemdto.h"
#include "../dto/playbackinfodto.h"
#include "../dto/playbackinforesponse.h"
#include "../dto/playmethod.h"
#include "../loader/requesttypes.h"
#include "../model/player.h"
#include "../model/playlist.h"
#include "../support/jsonconv.h"
#include "../viewmodel/item.h"
#include "../viewmodel/playlist.h"
#include "../apiclient.h"
#include <JellyfinQt/dto/baseitemdto.h>
#include <JellyfinQt/dto/playbackinfodto.h>
#include <JellyfinQt/dto/playbackinforesponse.h>
#include <JellyfinQt/dto/playmethod.h>
#include <JellyfinQt/loader/requesttypes.h>
#include <JellyfinQt/model/controllablesession.h>
#include <JellyfinQt/model/player.h>
#include <JellyfinQt/model/playlist.h>
#include <JellyfinQt/support/jsonconv.h>
#include <JellyfinQt/viewmodel/item.h>
#include <JellyfinQt/viewmodel/playlist.h>
#include <JellyfinQt/apiclient.h>
#include "itemmodel.h"
@ -81,6 +83,13 @@ public:
virtual ~PlaybackManager();
Q_PROPERTY(ApiClient *apiClient READ apiClient WRITE setApiClient)
Q_PROPERTY(QString controllingSessionId READ controllingSessionId NOTIFY controllingSessionIdChanged)
Q_PROPERTY(QString controllingSessionName READ controllingSessionName NOTIFY controllingSessionNameChanged)
/**
* Whether the playback is done by this client
*/
Q_PROPERTY(bool controllingSessionLocal READ controllingSessionLocal NOTIFY controllingSessionLocalChanged)
Q_PROPERTY(int audioIndex READ audioIndex WRITE setAudioIndex NOTIFY audioIndexChanged)
Q_PROPERTY(int subtitleIndex READ subtitleIndex WRITE setSubtitleIndex NOTIFY subtitleIndexChanged)
Q_PROPERTY(QString streamUrl READ streamUrl NOTIFY streamUrlChanged)
@ -91,7 +100,7 @@ public:
Q_PROPERTY(bool resumePlayback READ resumePlayback WRITE setResumePlayback NOTIFY resumePlaybackChanged)
Q_PROPERTY(Jellyfin::DTO::PlayMethodClass::Value playMethod READ playMethod NOTIFY playMethodChanged)
// Current Item and queue informatoion
// Current Item and queue information
Q_PROPERTY(QObject *item READ item NOTIFY itemChanged)
Q_PROPERTY(int queueIndex READ queueIndex NOTIFY queueIndexChanged)
Q_PROPERTY(Jellyfin::ViewModel::Playlist *queue READ queue NOTIFY queueChanged)
@ -124,6 +133,11 @@ public:
ViewModel::Item *item() const;
QSharedPointer<Model::Item> dataItem() const;
QSharedPointer<Model::ControllableSession> controllingSession() const;
void setControllingSession(QSharedPointer<Model::ControllableSession> session);
QString controllingSessionId() const;
QString controllingSessionName() const;
bool controllingSessionLocal() const;
QString streamUrl() const;
PlayMethod playMethod() const;
qint64 position() const;
@ -146,6 +160,10 @@ public:
void setHandlePlaystateCommands(bool newHandlePlaystateCommands);
signals:
void itemChanged();
void controllingSessionChanged();
void controllingSessionIdChanged();
void controllingSessionNameChanged();
void controllingSessionLocalChanged();
void streamUrlChanged(const QString &newStreamUrl);
void autoOpenChanged(bool autoOpen);
void audioIndexChanged(int audioIndex);

View file

@ -0,0 +1,118 @@
/*
* Sailfin: a Jellyfin client written using Qt
* Copyright (C) 2022 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_REMOTEDEVICE_H
#define JELLYFIN_VIEWMODEL_REMOTEDEVICE_H
#include <JellyfinQt/model/controllablesession.h>
#include <QAbstractItemModel>
#include <QList>
#include <QObject>
#include <QQmlParserStatus>
#include <QSharedPointer>
#include <utility>
namespace Jellyfin {
class ApiClient;
namespace ViewModel {
class PlaybackManager;
/**
* @brief AbstractListModel of remotely controllable devices by JellyfinQt.
*
* This class controls a set of \link ViewModel::RemoteSessionScanner RemoteSessionScanners\endlink and
* puts their found devices in this list.
*/
class RemoteDeviceList : public QAbstractListModel, public QQmlParserStatus {
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
/**
* The ApiClient for interacting with the Jellyfin API.
*/
Q_PROPERTY(Jellyfin::ApiClient* apiClient READ apiClient WRITE setApiClient NOTIFY apiClientChanged)
/**
* Gets/sets whether the model is scanning for other devices.
*/
Q_PROPERTY(bool scanning READ scanning WRITE setScanning NOTIFY scanningChanged);
public:
enum RoleNames {
jellyfinId = Qt::UserRole + 1,
name,
deviceName,
deviceType,
userName,
session
};
explicit RemoteDeviceList(QObject *parent = nullptr);
ApiClient *apiClient() const { return m_apiClient; }
void setApiClient(ApiClient *apiClient);
bool scanning() const { return m_scanning; }
void setScanning(bool scanning);
// QAbstractListModel
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override {
return {
{ RoleNames::jellyfinId, "jellyfinId"},
{ RoleNames::name, "name" },
{ RoleNames::deviceName, "deviceName" },
{ RoleNames::deviceType, "deviceType" },
{ RoleNames::userName, "userName" },
{ RoleNames::session, "session" }
};
}
/**
* @brief Sets the PlaybackManager to control the session at the given index in this model
* @param manager The PlaybackManager
* @param index The index of the session that should be controlled
*/
Q_INVOKABLE void activateSession(Jellyfin::ViewModel::PlaybackManager *manager, int index);
// QQmlParserStatus
void classBegin() override;
void componentComplete() override;
signals:
void apiClientChanged();
void scanningChanged();
private slots:
void onSessionFound(Jellyfin::Model::ControllableSession * session);
void onSessionLost(QString sessionId);
void onSessionsReset();
private:
ApiClient *m_apiClient = nullptr;
bool m_scanning = false;
bool m_componentComplete = false;
QList<std::pair<Model::RemoteSessionScanner *, QSharedPointer<Model::ControllableSession>>> m_sessions;
QList<Model::RemoteSessionScanner *> m_scanners;
};
} // NS ViewModel
} // NS Jellyfin
#endif // JELLYFIN_VIEWMODEL_REMOTEDEVICE_H

View file

@ -43,17 +43,17 @@ public:
userId = Qt::UserRole + 1,
name,
hasPassword,
primaryImageTag,
primaryImageTag
};
explicit UserModel (QObject *parent = nullptr);
virtual QHash<int, QByteArray> roleNames() const override {
return {
{ RoleNames::userId, "userId" },
{ RoleNames::name, "name" },
{ RoleNames::hasPassword, "hasPassword" },
{ RoleNames::primaryImageTag, "primaryImageTag" },
{ RoleNames::userId, "userId" },
{ RoleNames::name, "name" },
{ RoleNames::hasPassword, "hasPassword" },
{ RoleNames::primaryImageTag, "primaryImageTag" }
};
}
QVariant data(const QModelIndex &index, int role) const override;