1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-05-08 23:22:42 +00:00
harbour-sailfin/core/src/viewmodel/itemmodel.cpp

82 lines
2.6 KiB
C++
Raw Normal View History

2021-03-26 20:27:35 +00:00
/*
* 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"
2021-03-29 21:48:16 +00:00
#include "JellyfinQt/loader/http/getlatestmedia.h"
#include "JellyfinQt/loader/http/getitemsbyuserid.h"
2021-03-26 20:27:35 +00:00
#define JF_CASE(roleName) case roleName: \
try { \
return QVariant(item.roleName()); \
} catch(std::bad_optional_access &e) { \
return QVariant(); \
}
2021-03-26 20:27:35 +00:00
namespace Jellyfin {
namespace ViewModel {
UserViewsLoader::UserViewsLoader(QObject *parent)
2021-03-29 21:48:16 +00:00
: UserViewsLoaderBase(new Jellyfin::Loader::HTTP::GetUserViewsLoader(), parent) { }
2021-03-26 20:27:35 +00:00
2021-03-29 21:48:16 +00:00
LatestMediaLoader::LatestMediaLoader(QObject *parent)
: LatestMediaBase(new Jellyfin::Loader::HTTP::GetLatestMediaLoader(), parent){ }
2021-03-26 20:27:35 +00:00
2021-03-29 21:48:16 +00:00
UserItemsLoader::UserItemsLoader(QObject *parent)
: UserItemsLoaderBase(new Jellyfin::Loader::HTTP::GetItemsByUserIdLoader(), parent) {}
2021-03-26 20:27:35 +00:00
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)
2021-03-29 21:48:16 +00:00
// Handpicked, important ones
JF_CASE(imageTags)
JF_CASE(imageBlurHashes)
JF_CASE(mediaType)
JF_CASE(type)
JF_CASE(collectionType)
2021-03-26 20:27:35 +00:00
default:
return QVariant();
}
}
QSharedPointer<Model::Item> ItemModel::itemAt(int index) {
return QSharedPointer<Model::Item>::create(m_array[index]);
}
2021-03-26 20:27:35 +00:00
} // NS ViewModel
} // NS Jellyfin