mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-06 10:32: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
|
@ -36,7 +36,7 @@ void Item::setData(QSharedPointer<Model::Item> newData) {
|
|||
// ItemLoader
|
||||
|
||||
ItemLoader::ItemLoader(QObject *parent)
|
||||
: BaseClass(Jellyfin::Loader::HTTP::GetItem(), parent) {
|
||||
: BaseClass(Jellyfin::Loader::HTTP::GetItemLoader(), parent) {
|
||||
}
|
||||
|
||||
void ItemLoader::onApiClientChanged(ApiClient *newApiClient) {
|
||||
|
|
77
core/src/viewmodel/itemmodel.cpp
Normal file
77
core/src/viewmodel/itemmodel.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
#include "JellyfinQt/viewmodel/itemmodel.h"
|
||||
|
||||
#define JF_CASE(roleName) case roleName: \
|
||||
return QVariant(item.roleName());
|
||||
|
||||
namespace Jellyfin {
|
||||
|
||||
namespace ViewModel {
|
||||
|
||||
UserViewsLoader::UserViewsLoader(QObject *parent)
|
||||
: UserViewsLoaderBase(Loader::HTTP::GetUserViewsLoader(), parent) {}
|
||||
|
||||
void UserViewsLoader::apiClientChanged(ApiClient *newApiClient) {
|
||||
if (m_apiClient != nullptr) disconnect(m_apiClient, &ApiClient::userIdChanged, this, &UserViewsLoader::userIdChanged);
|
||||
if (newApiClient != nullptr) connect(newApiClient, &ApiClient::userIdChanged, this, &UserViewsLoader::userIdChanged);
|
||||
}
|
||||
|
||||
void UserViewsLoader::userIdChanged(const QString &newUserId) {
|
||||
m_parameters.setUserId(newUserId);
|
||||
autoReloadIfNeeded();
|
||||
}
|
||||
void UserItemsLoader::apiClientChanged(ApiClient *newApiClient) {
|
||||
if (m_apiClient != nullptr) disconnect(m_apiClient, &ApiClient::userIdChanged, this, &UserItemsLoader::userIdChanged);
|
||||
if (newApiClient != nullptr) connect(newApiClient, &ApiClient::userIdChanged, this, &UserItemsLoader::userIdChanged);
|
||||
}
|
||||
|
||||
void UserItemsLoader::userIdChanged(const QString &newUserId) {
|
||||
m_parameters.setUserId(newUserId);
|
||||
autoReloadIfNeeded();
|
||||
}
|
||||
|
||||
ItemModel::ItemModel(QObject *parent)
|
||||
: ApiModel<Model::Item>(parent) { }
|
||||
|
||||
QVariant ItemModel::data(const QModelIndex &index, int role) const {
|
||||
if (role <= Qt::UserRole || !index.isValid()) return QVariant();
|
||||
int row = index.row();
|
||||
if (row < 0 || row >= m_array.size()) return QVariant();
|
||||
Model::Item item = m_array[row];
|
||||
switch(role) {
|
||||
JF_CASE(jellyfinId)
|
||||
JF_CASE(name)
|
||||
JF_CASE(originalTitle)
|
||||
JF_CASE(serverId)
|
||||
JF_CASE(etag)
|
||||
JF_CASE(sourceType)
|
||||
JF_CASE(playlistItemId)
|
||||
JF_CASE(dateCreated)
|
||||
JF_CASE(dateLastMediaAdded)
|
||||
JF_CASE(extraType)
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // NS ViewModel
|
||||
|
||||
} // NS Jellyfin
|
Loading…
Add table
Add a link
Reference in a new issue