Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
Loading...
Searching...
No Matches
Jellyfin::Support::Loader< R, P > Class Template Reference

#include <loader.h>

Inheritance diagram for Jellyfin::Support::Loader< R, P >:
Jellyfin::Support::LoaderBase Jellyfin::Support::HttpLoaderBase< R, P > Jellyfin::Support::HttpLoader< R, P >

Public Types

using ResultType = std::optional<R>
 

Public Member Functions

 Loader (ApiClient *apiClient)
 
R result () const
 Retrieves the loaded resource. Only valid after the ready signal has been emitted.
 
bool hasResult () const
 
void setParameters (const P &parameters)
 Sets the parameters for this loader.
 
- Public Member Functions inherited from Jellyfin::Support::LoaderBase
virtual void load ()
 load Loads the given resource asynchronously.
 
virtual void cancel ()
 
bool isRunning () const
 
virtual bool isAvailable () const
 Heuristic to determine if this resource can be loaded via this loaded.
 
void setApiClient (ApiClient *newApiClient)
 
ApiClientapiClient () const
 

Protected Member Functions

ResultType createFailureResult ()
 
ResultType createSuccessResult (R &&result)
 
- Protected Member Functions inherited from Jellyfin::Support::LoaderBase
 LoaderBase (ApiClient *apiClient)
 
void stopWithError (QString message=QString())
 

Static Protected Member Functions

static R createDummyResponse ()
 

Protected Attributes

std::optional< P > m_parameters
 
ResultType m_result
 
- Protected Attributes inherited from Jellyfin::Support::LoaderBase
Jellyfin::ApiClientm_apiClient
 
bool m_isRunning = false
 

Additional Inherited Members

- Signals inherited from Jellyfin::Support::LoaderBase
void error (QString message=QString())
 Emitted when an error has occurred during loading and no result is available.
 
void ready ()
 Emitted when data was successfully loaded.
 

Detailed Description

template<typename R, typename P>
class Jellyfin::Support::Loader< R, P >

Interface describing a way to load items. Used to abstract away the difference between loading from a cache or loading over the network.

To implement this class, implement prepareLoad() and load(). These are always called in the same order, but prepareLoad() must always be called on the same thread as the m_apiClient, while load() may be called on another thread.

Note
: Loaders should NEVER call load() again while load() is running on another thread or change the apiClient while running. This will result in undefined behaviour. Please use a Mutex to enforce this.
Template Parameters
Rthe type of data that should be fetched, R for result.
Pthe type of paramaters given, to determine which resource should be loaded.

Member Typedef Documentation

◆ ResultType

template<typename R , typename P >
using Jellyfin::Support::Loader< R, P >::ResultType = std::optional<R>

Constructor & Destructor Documentation

◆ Loader()

template<typename R , typename P >
Jellyfin::Support::Loader< R, P >::Loader ( ApiClient * apiClient)
inlineexplicit

Member Function Documentation

◆ createDummyResponse()

template<typename R , typename P >
static R Jellyfin::Support::Loader< R, P >::createDummyResponse ( )
inlinestaticprotected

◆ createFailureResult()

template<typename R , typename P >
ResultType Jellyfin::Support::Loader< R, P >::createFailureResult ( )
inlineprotected

◆ createSuccessResult()

template<typename R , typename P >
ResultType Jellyfin::Support::Loader< R, P >::createSuccessResult ( R && result)
inlineprotected

◆ hasResult()

template<typename R , typename P >
bool Jellyfin::Support::Loader< R, P >::hasResult ( ) const
inline

◆ result()

template<typename R , typename P >
R Jellyfin::Support::Loader< R, P >::result ( ) const
inline

Retrieves the loaded resource. Only valid after the ready signal has been emitted.

Returns
The loaded resource.

◆ setParameters()

template<typename R , typename P >
void Jellyfin::Support::Loader< R, P >::setParameters ( const P & parameters)
inline

Sets the parameters for this loader.

Parameters
parametersThe parameters to set

This method will copy the parameters. The parameters must have a copy constructor.

Member Data Documentation

◆ m_parameters

template<typename R , typename P >
std::optional<P> Jellyfin::Support::Loader< R, P >::m_parameters
protected

◆ m_result

template<typename R , typename P >
ResultType Jellyfin::Support::Loader< R, P >::m_result
protected

The documentation for this class was generated from the following file: