1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2025-09-05 10:12:46 +00:00

Resolved remaining issues with ApiModel

This commit is contained in:
Chris Josten 2021-03-29 17:10:25 +02:00
parent 89fef6d7f4
commit 9abee12658
8 changed files with 79 additions and 66 deletions

View file

@ -46,6 +46,7 @@ void BaseModelLoader::componentComplete() {
void BaseModelLoader::autoReloadIfNeeded() {
if (m_autoReload && canReload()) {
qDebug() << "reloading due to 'autoReloadIfNeeded()'";
emit reloadWanted();
}
}
@ -74,28 +75,39 @@ void BaseModelLoader::setAutoReload(bool newAutoReload) {
}
bool BaseModelLoader::canReload() const {
return m_apiClient != nullptr && (!m_needsAuthentication || m_apiClient->authenticated());
return m_apiClient != nullptr
// If the loader for this model needs authentication (almost every one does)
// block if the ApiClient is not authenticated yet.
&& (!m_needsAuthentication || m_apiClient->authenticated())
// Only allow for a reload if this model is ready or uninitialised.
&& (m_status == ViewModel::ModelStatus::Ready
|| m_status == ViewModel::ModelStatus::Uninitialised);
}
void BaseApiModel::reload() {
qWarning() << " BaseApiModel slot called instead of overloaded method";
}
void setStartIndex(Loader::GetUserViewsParams &params, int startIndex) {
template <>
bool setRequestStartIndex(Loader::GetUserViewsParams &params, int startIndex) {
// Not supported
Q_UNUSED(params)
Q_UNUSED(startIndex)
return false;
}
void setLimit(Loader::GetUserViewsParams &params, int limit) {
template <>
void setRequestLimit(Loader::GetUserViewsParams &params, int limit) {
Q_UNUSED(params)
Q_UNUSED(limit)
}
template <>
QList<DTO::BaseItemDto> extractRecords(const DTO::BaseItemDtoQueryResult &result) {
return result.items();
}
template <>
int extractTotalRecordCount(const DTO::BaseItemDtoQueryResult &result) {
return result.totalRecordCount();
}

View file

@ -29,7 +29,6 @@ void registerTypes(const char *uri) {
qmlRegisterUncreatableType<ViewModel::LoaderBase>(uri, 1, 0, "LoaderBase", "Use on eof its subclasses");
qmlRegisterUncreatableType<ViewModel::Item>(uri, 1, 0, "Item", "Acquire one via ItemLoader or exposed properties");
qmlRegisterType<ViewModel::ModelStatusTest>(uri, 1, 0, "ModelStatusTest");
qmlRegisterType<ViewModel::ItemLoader>(uri, 1, 0, "ItemLoader");
qmlRegisterType<ViewModel::ItemModel>(uri, 1, 0, "ItemModel");
qmlRegisterType<ViewModel::UserViewsLoader>(uri, 1, 0, "UsersViewLoader");

View file

@ -19,7 +19,11 @@
#include "JellyfinQt/viewmodel/itemmodel.h"
#define JF_CASE(roleName) case roleName: \
return QVariant(item.roleName());
try { \
return QVariant(item.roleName()); \
} catch(std::bad_optional_access e) { \
return QVariant(); \
}
namespace Jellyfin {