Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
|
An Api client for Jellyfin. Handles requests and authentication. More...
#include <apiclient.h>
Public Types | |
enum | ApiError { JSON_ERROR , UNEXPECTED_REPLY , UNEXPECTED_STATUS , INVALID_PASSWORD } |
Public Slots | |
void | restoreSavedSession () |
Tries to access credentials and connect to a server. If nothing has been configured yet, emits setupRequired();. | |
void | setupConnection () |
void | authenticate (QString username, QString password, bool storeCredentials=false) |
void | submitQuickConnectCode (const QString &code) |
void | deleteSession () |
Logs the user out and clears the session. | |
void | postCapabilities () |
Shares the capabilities of this device to the server. | |
QString | downloadUrl (const QString &itemId) const |
Signals | |
void | authenticationRequired () |
void | authenticationError (ApiError error) |
void | connectionFailed (ApiError error) |
void | connectionSuccess (QString loginMessage) |
void | networkError (QNetworkReply::NetworkError error) |
void | authenticatedChanged (bool authenticated) |
void | baseUrlChanged (const QString &baseUrl) |
void | appNameChanged (const QString &newAppName) |
void | settingsChanged () |
void | setupRequired () |
Set-up is required. You'll need to manually set up the baseUrl-property, call setupConnection afterwards and finally call authenticate. | |
void | userIdChanged (QString userId) |
void | deviceProfileChanged () |
void | deviceTypeChanged () |
void | supportedCommandsChanged () |
void | onlineChanged () |
void | quickConnectAccepted () |
Emitted after submitQuickConnectCode succeeded. | |
void | quickConnectRejected () |
Emitted after submitQuickConnectCode failed. | |
void | userDataChanged (const QString &itemId, UserData *userData) |
onUserDataChanged Emitted when the user data of an item is changed on the server. | |
Public Member Functions | |
ApiClient (QObject *parent=nullptr) | |
virtual | ~ApiClient () |
bool | authenticated () const |
void | setBaseUrl (const QString &url) |
void | setAppName (const QString &appName) |
void | setDeviceType (Model::DeviceType deviceType) |
QNetworkReply * | get (const QString &path, const QUrlQuery ¶ms=QUrlQuery()) |
QNetworkReply * | post (const QString &path, const QJsonDocument &data, const QUrlQuery ¶ms=QUrlQuery()) |
QNetworkReply * | post (const QString &path, const QByteArray &data=QByteArray(), const QUrlQuery ¶ms=QUrlQuery()) |
const QString & | baseUrl () const |
const QString & | appName () const |
const QString & | userId () const |
const QString & | deviceId () const |
Model::DeviceType | deviceType () const |
QVariantList | supportedCommands () const |
QML applications can set this type to indicate which commands they support. | |
void | setSupportedCommands (QVariantList newSupportedCommands) |
const QJsonObject | deviceProfileJson () const |
QSharedPointer< DTO::DeviceProfile > | deviceProfile () const |
const QJsonObject | clientCapabilities () const |
const QString & | token () const |
Retrieves the authentication token. Null QString if not authenticated. | |
QString | version () const |
bool | online () const |
EventBus * | eventbus () const |
WebSocket * | websocket () const |
ViewModel::Settings * | settings () const |
void | setDefaultErrorHandler (QNetworkReply *rep) |
Sets the error handler of a reply to this classes default error handler. | |
Protected Slots | |
void | defaultNetworkErrorHandler (QNetworkReply::NetworkError error) |
void | onUserDataChanged (const QString &itemId, UserData *newData) |
void | credManagerServersListed (QStringList users) |
void | credManagerUsersListed (const QString &server, QStringList users) |
void | credManagerTokenRetrieved (const QString &server, const QString &user, const QString &token) |
void | classBegin () override |
void | componentComplete () override |
Protected Member Functions | |
void | addBaseRequestHeaders (QNetworkRequest &request, const QString &path, const QUrlQuery ¶ms=QUrlQuery()) const |
Adds default headers to each request, like authentication headers etc. | |
void | addTokenHeader (QNetworkRequest &request) const |
Adds the authorization to the header. | |
void | getBrandingConfiguration () |
getBrandingConfiguration Gets the login message and custom CSS (which we ignore) | |
void | generateDeviceProfile () |
Generates a profile, containing the name of the application, manufacturer and most importantly, which media types this device supports. | |
Properties | |
QString | baseUrl |
QString | appName |
Jellyfin::Model::DeviceTypeClass::Value | deviceType |
bool | authenticated |
QString | userId |
QJsonObject | deviceProfile |
QString | version |
Jellyfin::EventBus * | eventbus |
Jellyfin::WebSocket * | websocket |
QVariantList | supportedCommands |
Jellyfin::ViewModel::Settings * | settings |
bool | online |
Friends | |
class | WebSocket |
class | PlaybackManager |
An Api client for Jellyfin. Handles requests and authentication.
This class should also be given to certain models and other sources, so they are able to make requests to the correct server.
General usage is as follows:
These steps might change. I'm considering decoupling CredentialsManager from this class to clean some code up.
|
explicit |
|
virtual |
|
protected |
Adds default headers to each request, like authentication headers etc.
request | The request to add headers to |
path | The path to which the request is being made |
|
protected |
Adds the authorization to the header.
The | request to add the header to |
const QString & Jellyfin::ApiClient::appName | ( | ) | const |
|
signal |
|
slot |
bool Jellyfin::ApiClient::authenticated | ( | ) | const |
|
signal |
|
signal |
|
signal |
const QString & Jellyfin::ApiClient::baseUrl | ( | ) | const |
|
signal |
|
overrideprotectedslot |
const QJsonObject Jellyfin::ApiClient::clientCapabilities | ( | ) | const |
|
overrideprotectedslot |
|
signal |
|
signal |
|
protectedslot |
|
protectedslot |
|
protectedslot |
|
protectedslot |
|
slot |
Logs the user out and clears the session.
const QString & Jellyfin::ApiClient::deviceId | ( | ) | const |
QSharedPointer< DTO::DeviceProfile > Jellyfin::ApiClient::deviceProfile | ( | ) | const |
|
signal |
const QJsonObject Jellyfin::ApiClient::deviceProfileJson | ( | ) | const |
Model::DeviceType Jellyfin::ApiClient::deviceType | ( | ) | const |
|
signal |
|
slot |
EventBus * Jellyfin::ApiClient::eventbus | ( | ) | const |
|
protected |
Generates a profile, containing the name of the application, manufacturer and most importantly, which media types this device supports.
The actual detection of supported media types is done within jellyfindeviceprofile.cpp, since the code is a big mess and should be safely contained in it's own file.
QNetworkReply * Jellyfin::ApiClient::get | ( | const QString & | path, |
const QUrlQuery & | params = QUrlQuery() ) |
|
protected |
getBrandingConfiguration Gets the login message and custom CSS (which we ignore)
|
signal |
bool Jellyfin::ApiClient::online | ( | ) | const |
|
signal |
|
protectedslot |
QNetworkReply * Jellyfin::ApiClient::post | ( | const QString & | path, |
const QByteArray & | data = QByteArray(), | ||
const QUrlQuery & | params = QUrlQuery() ) |
QNetworkReply * Jellyfin::ApiClient::post | ( | const QString & | path, |
const QJsonDocument & | data, | ||
const QUrlQuery & | params = QUrlQuery() ) |
|
slot |
Shares the capabilities of this device to the server.
|
signal |
Emitted after submitQuickConnectCode succeeded.
|
signal |
Emitted after submitQuickConnectCode failed.
|
slot |
Tries to access credentials and connect to a server. If nothing has been configured yet, emits setupRequired();.
void Jellyfin::ApiClient::setAppName | ( | const QString & | appName | ) |
void Jellyfin::ApiClient::setBaseUrl | ( | const QString & | url | ) |
|
inline |
Sets the error handler of a reply to this classes default error handler.
rep | The reply to set the error handler on. |
Motivation for this helper is because I forget the correct signature each time, with all the funky casts.
void Jellyfin::ApiClient::setDeviceType | ( | Model::DeviceType | deviceType | ) |
void Jellyfin::ApiClient::setSupportedCommands | ( | QVariantList | newSupportedCommands | ) |
ViewModel::Settings * Jellyfin::ApiClient::settings | ( | ) | const |
|
signal |
|
slot |
|
signal |
Set-up is required. You'll need to manually set up the baseUrl-property, call setupConnection afterwards and finally call authenticate.
|
slot |
QVariantList Jellyfin::ApiClient::supportedCommands | ( | ) | const |
QML applications can set this type to indicate which commands they support.
These commands can be sent by other Jellyfin clients to instruct this Jellyfin client to play a certain item, control playback and so on.
This property must be set before restoreSavedSession() is called and not be changed afterwards. The list support commands will be sent to the Jellyfin server. QML applications should listen to the events emitted by the eventBus and act accordingly.
|
signal |
const QString & Jellyfin::ApiClient::token | ( | ) | const |
Retrieves the authentication token. Null QString if not authenticated.
|
signal |
onUserDataChanged Emitted when the user data of an item is changed on the server.
itemId | The id of the item being changed |
userData | The new user data |
Note: only Jellyfin::UserData should connect to this signal, they will update themselves! Note: the userData is only valid during this callback, afterwards it is deleted!
const QString & Jellyfin::ApiClient::userId | ( | ) | const |
|
signal |
QString Jellyfin::ApiClient::version | ( | ) | const |
WebSocket * Jellyfin::ApiClient::websocket | ( | ) | const |
|
friend |
|
friend |
|
readwrite |
|
readwrite |
|
readwrite |
|
read |
|
readwrite |
|
read |
|
read |
Wether this ApiClient operates in "online mode".
When operating in offline mode, this client will not make network requests and only use a local cache, making certain features unavailable.
|
read |
|
readwrite |
|
read |
|
read |
|
read |