mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-04 01:42:44 +00:00
WIP: Reimplementation of ListModels.
This commit is contained in:
parent
76a49868b9
commit
e421adf733
356 changed files with 1830 additions and 1833 deletions
|
@ -46,7 +46,6 @@
|
|||
#include "loader.h"
|
||||
|
||||
namespace Jellyfin {
|
||||
|
||||
namespace ViewModel {
|
||||
|
||||
class Item : public QObject {
|
||||
|
|
152
core/include/JellyfinQt/viewmodel/itemmodel.h
Normal file
152
core/include/JellyfinQt/viewmodel/itemmodel.h
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Sailfin: a Jellyfin client written using Qt
|
||||
* Copyright (C) 2021 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_ITEMMODEL_H
|
||||
#define JELLYFIN_VIEWMODEL_ITEMMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QObject>
|
||||
|
||||
#include "propertyhelper.h"
|
||||
#include "../dto/baseitemdto.h"
|
||||
#include "../dto/baseitemdtoqueryresult.h"
|
||||
#include "../loader/http/getuserviews.h"
|
||||
#include "../loader/requesttypes.h"
|
||||
#include "../model/item.h"
|
||||
#include "../apimodel.h"
|
||||
|
||||
// Jellyfin Forward Read/Write Property
|
||||
#define FWDPROP(type, propName, propSetName) JF_FWD_RW_PROP(type, propName, propSetName, this->m_parameters)
|
||||
|
||||
namespace Jellyfin {
|
||||
|
||||
namespace ViewModel {
|
||||
|
||||
// JellyFinRoleName
|
||||
#define JFRN(name) {RoleNames::name, #name}
|
||||
|
||||
// This file contains all models that expose a Model::Item
|
||||
|
||||
using UserViewsLoaderBase = LoaderModelLoader<Model::Item, DTO::BaseItemDto, DTO::BaseItemDtoQueryResult, Jellyfin::Loader::GetUserViewsParams>;
|
||||
class UserViewsLoader : public UserViewsLoaderBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UserViewsLoader(QObject *parent = nullptr);
|
||||
|
||||
FWDPROP(bool, includeExternalContent, IncludeExternalContent)
|
||||
FWDPROP(bool, includeHidden, IncludeHidden)
|
||||
FWDPROP(QStringList, presetViews, PresetViews)
|
||||
private slots:
|
||||
void apiClientChanged(ApiClient *newApiClient);
|
||||
void userIdChanged(const QString &newUserId);
|
||||
};
|
||||
|
||||
using UserItemsLoaderBase = LoaderModelLoader<Model::Item, DTO::BaseItemDto, DTO::BaseItemDtoQueryResult, Jellyfin::Loader::GetItemsByUserIdParams>;
|
||||
class UserItemsLoader : public UserItemsLoaderBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UserItemsLoader(QObject *parent = nullptr);
|
||||
|
||||
FWDPROP(QString, adjacentTo, AdjacentTo)
|
||||
FWDPROP(QStringList, albumArtistIds, AlbumArtistIds)
|
||||
FWDPROP(QStringList, albumIds, AlbumIds)
|
||||
FWDPROP(QStringList, albums, Albums)
|
||||
FWDPROP(QStringList, artistIds, ArtistIds)
|
||||
FWDPROP(QStringList, artists, Artists)
|
||||
FWDPROP(bool, recursive, Recursive)
|
||||
//FWDPROP(bool, collapseBoxSetItems)
|
||||
private slots:
|
||||
void apiClientChanged(ApiClient *newApiClient);
|
||||
void userIdChanged(const QString &newUserId);
|
||||
};
|
||||
/**
|
||||
* @brief Base class for each model that works with items.
|
||||
*/
|
||||
|
||||
class ItemModel : public ApiModel<Model::Item> {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum RoleNames {
|
||||
jellyfinId = Qt::UserRole + 1,
|
||||
name,
|
||||
originalTitle,
|
||||
serverId,
|
||||
etag,
|
||||
sourceType,
|
||||
playlistItemId,
|
||||
dateCreated,
|
||||
dateLastMediaAdded,
|
||||
extraType
|
||||
};
|
||||
|
||||
explicit ItemModel (QObject *parent = nullptr);
|
||||
|
||||
QHash<int, QByteArray> roleNames() const override {
|
||||
return {
|
||||
JFRN(jellyfinId),
|
||||
JFRN(name),
|
||||
JFRN(originalTitle),
|
||||
JFRN(serverId),
|
||||
JFRN(etag),
|
||||
JFRN(sourceType),
|
||||
JFRN(playlistItemId),
|
||||
JFRN(dateCreated),
|
||||
JFRN(dateLastMediaAdded),
|
||||
JFRN(extraType)
|
||||
};
|
||||
}
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
};
|
||||
|
||||
/*class UserItemModel : public ItemModel {
|
||||
public:
|
||||
explicit UserItemModel (QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
class UserItemResumeModel : public ItemModel {
|
||||
public:
|
||||
explicit UserItemResumeModel (QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
class UserItemLatestModel : public ItemModel {
|
||||
public:
|
||||
explicit UserItemLatestModel (QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
class ShowNextUpModel : public ItemModel {
|
||||
public:
|
||||
explicit ShowNextUpModel (QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
class ShowSeasonsModel : public ItemModel {
|
||||
public:
|
||||
explicit ShowSeasonsModel (QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
class ShowEpisodesModel : public ItemModel {
|
||||
public:
|
||||
explicit ShowEpisodesModel (QObject *parent = nullptr);
|
||||
};*/
|
||||
#undef JFRN
|
||||
|
||||
} // NS Jellyfin
|
||||
} // NS ViewModel
|
||||
|
||||
#undef FWDPROP
|
||||
|
||||
#endif // JELLYFIN_VIEWMODEL_ITEMMODEL_H
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "../support/loader.h"
|
||||
|
@ -178,9 +180,12 @@ private:
|
|||
* @return empty optional if an error occured, otherwise the result.
|
||||
*/
|
||||
std::optional<R> invokeLoader(P parameters) {
|
||||
QMutexLocker(&this->m_mutex);
|
||||
this->m_loader.setApiClient(m_apiClient);
|
||||
try {
|
||||
return this->m_loader.load(parameters);
|
||||
} catch (Support::LoadException e) {
|
||||
} catch (Support::LoadException &e) {
|
||||
qWarning() << "Exception while loading an item: " << e.what();
|
||||
this->setErrorString(QString(e.what()));
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -206,6 +211,7 @@ private:
|
|||
setStatus(Error);
|
||||
}
|
||||
}
|
||||
QMutex m_mutex;
|
||||
};
|
||||
|
||||
void registerRemoteTypes(const char *uri);
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "../viewmodel/item.h"
|
||||
|
||||
#include "../apiclient.h"
|
||||
#include "itemmodel.h"
|
||||
|
||||
|
||||
namespace Jellyfin {
|
||||
|
|
41
core/include/JellyfinQt/viewmodel/propertyhelper.h
Normal file
41
core/include/JellyfinQt/viewmodel/propertyhelper.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Sailfin: a Jellyfin client written using Qt
|
||||
* Copyright (C) 2021 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_PROPERTYHELPER
|
||||
#define JELLYFIN_VIEWMODEL_PROPERTYHELPER
|
||||
|
||||
// Jellyfin Forward Read/Write Property
|
||||
#define JF_FWD_RW_PROP(type, propName, propSetName, obj) \
|
||||
public: \
|
||||
Q_PROPERTY(type propName READ propName WRITE set##propSetName NOTIFY propName##Changed) \
|
||||
type propName() const { return obj.propName(); } \
|
||||
void set##propSetName(type newValue) { \
|
||||
obj.set##propSetName( newValue ); \
|
||||
emit propName##Changed(); \
|
||||
} \
|
||||
Q_SIGNALS: \
|
||||
void propName##Changed();
|
||||
|
||||
// Jellyfin Forward Read Property
|
||||
#define JF_FWD_R_PROP(type, propName, propSetName, obj) \
|
||||
public: \
|
||||
Q_PROPERTY(type propName READ propName NOTIFY propName##Changed) \
|
||||
type propName() const { return obj.propName(); } \
|
||||
signals: \
|
||||
void propName##Changed(type newValue);
|
||||
#endif // JELLYFIN_VIEWMODEL_PROPERTYHELPER
|
Loading…
Add table
Add a link
Reference in a new issue