20#ifndef JELLYFIN_API_CLIENT
21#define JELLYFIN_API_CLIENT
24#include <QJsonDocument>
26#include <QJsonParseError>
31#include <QQmlListProperty>
32#include <QQmlParserStatus>
33#include <QScopedPointer>
39#include <QNetworkReply>
90class ApiClient :
public QObject,
public QQmlParserStatus {
94 Q_INTERFACES(QQmlParserStatus)
97 explicit ApiClient(QObject *parent =
nullptr);
123 QNetworkReply *
get(const QString &path, const QUrlQuery ¶ms = QUrlQuery());
124 QNetworkReply *
post(const QString &path, const QJsonDocument &data, const QUrlQuery ¶ms = QUrlQuery());
125 QNetworkReply *
post(const QString &path, const QByteArray &data = QByteArray(), const QUrlQuery ¶ms = QUrlQuery());
135 const QString &
baseUrl()
const;
136 const QString &
appName()
const;
137 const QString &
userId()
const;
159 const QString &
token()
const;
175#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
178 connect(rep,
static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)
>(&QNetworkReply::error),
243 void authenticate(QString username, QString password,
bool storeCredentials =
false);
273 void addBaseRequestHeaders(QNetworkRequest &request,
const QString &path,
const QUrlQuery ¶ms = QUrlQuery())
const;
297 QScopedPointer<ApiClientPrivate> d_ptr;
298 QNetworkAccessManager m_naManager;
306 void setUserId(
const QString &
userId);
316 static inline int statusCode(QNetworkReply *rep) {
317 return rep->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
Definition apiclient.cpp:34
An Api client for Jellyfin. Handles requests and authentication.
Definition apiclient.h:90
QString appName
Definition apiclient.h:100
Jellyfin::ViewModel::Settings * settings
Definition apiclient.h:109
void authenticatedChanged(bool authenticated)
void setupConnection()
Definition apiclient.cpp:339
QString downloadUrl(const QString &itemId) const
Definition apiclient.cpp:469
void generateDeviceProfile()
Generates a profile, containing the name of the application, manufacturer and most importantly,...
Definition apiclient.cpp:474
void defaultNetworkErrorHandler(QNetworkReply::NetworkError error)
Definition apiclient.cpp:496
void addTokenHeader(QNetworkRequest &request) const
Adds the authorization to the header.
Definition apiclient.cpp:249
const QString & token() const
Retrieves the authentication token. Null QString if not authenticated.
Definition apiclient.cpp:169
ApiError
Definition apiclient.h:127
@ UNEXPECTED_REPLY
Definition apiclient.h:129
@ UNEXPECTED_STATUS
Definition apiclient.h:130
@ INVALID_PASSWORD
Definition apiclient.h:131
@ JSON_ERROR
Definition apiclient.h:128
void quickConnectRejected()
Emitted after submitQuickConnectCode failed.
void deviceProfileChanged()
void quickConnectAccepted()
Emitted after submitQuickConnectCode succeeded.
void credManagerTokenRetrieved(const QString &server, const QString &user, const QString &token)
Definition apiclient.cpp:330
void baseUrlChanged(const QString &baseUrl)
QVariantList supportedCommands
Definition apiclient.h:108
void setDefaultErrorHandler(QNetworkReply *rep)
Sets the error handler of a reply to this classes default error handler.
Definition apiclient.h:174
void componentComplete() override
Definition apiclient.cpp:225
virtual ~ApiClient()
Definition apiclient.cpp:86
void addBaseRequestHeaders(QNetworkRequest &request, const QString &path, const QUrlQuery ¶ms=QUrlQuery()) const
Adds default headers to each request, like authentication headers etc.
Definition apiclient.cpp:239
QString baseUrl
Definition apiclient.h:99
void userDataChanged(const QString &itemId, UserData *userData)
onUserDataChanged Emitted when the user data of an item is changed on the server.
void appNameChanged(const QString &newAppName)
const QString & deviceId() const
Definition apiclient.cpp:135
QNetworkReply * get(const QString &path, const QUrlQuery ¶ms=QUrlQuery())
Definition apiclient.cpp:262
void connectionFailed(ApiError error)
void restoreSavedSession()
Tries to access credentials and connect to a server. If nothing has been configured yet,...
Definition apiclient.cpp:298
QNetworkReply * post(const QString &path, const QJsonDocument &data, const QUrlQuery ¶ms=QUrlQuery())
Definition apiclient.cpp:268
friend class PlaybackManager
Definition apiclient.h:92
void networkError(QNetworkReply::NetworkError error)
ApiClient(QObject *parent=nullptr)
Definition apiclient.cpp:70
Jellyfin::WebSocket * websocket
Definition apiclient.h:107
void supportedCommandsChanged()
void postCapabilities()
Shares the capabilities of this device to the server.
Definition apiclient.cpp:463
void setSupportedCommands(QVariantList newSupportedCommands)
Definition apiclient.cpp:189
void authenticationError(ApiError error)
void authenticate(QString username, QString password, bool storeCredentials=false)
Definition apiclient.cpp:395
void userIdChanged(QString userId)
void getBrandingConfiguration()
getBrandingConfiguration Gets the login message and custom CSS (which we ignore)
Definition apiclient.cpp:370
QString userId
Definition apiclient.h:103
Jellyfin::Model::DeviceTypeClass::Value deviceType
Definition apiclient.h:101
void setDeviceType(Model::DeviceType deviceType)
Definition apiclient.cpp:145
void classBegin() override
Definition apiclient.cpp:220
Jellyfin::EventBus * eventbus
Definition apiclient.h:106
bool online
Definition apiclient.h:116
void setupRequired()
Set-up is required. You'll need to manually set up the baseUrl-property, call setupConnection afterwa...
QJsonObject deviceProfile
Definition apiclient.h:104
void setAppName(const QString &appName)
Definition apiclient.cpp:114
void authenticationRequired()
QString version
Definition apiclient.h:105
bool authenticated
Definition apiclient.h:102
void submitQuickConnectCode(const QString &code)
Definition apiclient.cpp:432
void credManagerServersListed(QStringList users)
Definition apiclient.cpp:303
void deleteSession()
Logs the user out and clears the session.
Definition apiclient.cpp:452
void connectionSuccess(QString loginMessage)
const QJsonObject clientCapabilities() const
Definition apiclient.cpp:214
void onUserDataChanged(const QString &itemId, UserData *newData)
Definition apiclient.cpp:509
void credManagerUsersListed(const QString &server, QStringList users)
Definition apiclient.cpp:318
void setBaseUrl(const QString &url)
Definition apiclient.cpp:100
const QJsonObject deviceProfileJson() const
Definition apiclient.cpp:210
Definition useritemdatadto.h:49
"EventBus" object through which "events" are sent.
Definition eventbus.h:35
Value
Definition controllablesession.h:24
Keeps a connection with the Jellyfin server to receive real time updates.
Definition websocket.h:52
Jellyfin::DTO::UserItemDataDto UserItemDataDto
Definition useritemdatadto.h:207