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:
parent
b1bd15f2c1
commit
b257fe60aa
20 changed files with 1051 additions and 80 deletions
|
@ -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);
|
||||
|
|
118
core/include/JellyfinQt/viewmodel/remotedevice.h
Normal file
118
core/include/JellyfinQt/viewmodel/remotedevice.h
Normal 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
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue