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

@ -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