2021-03-24 19:04:03 +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/model/item.h>
|
2021-03-20 15:29:31 +00:00
|
|
|
|
|
|
|
namespace Jellyfin {
|
|
|
|
namespace Model {
|
|
|
|
|
2021-03-29 21:48:16 +00:00
|
|
|
|
2021-08-11 21:35:33 +00:00
|
|
|
Item::Item(QObject *parent)
|
|
|
|
: Item(DTO::BaseItemDto(), nullptr, parent) { }
|
|
|
|
|
|
|
|
Item::Item(const DTO::BaseItemDto &data, ApiClient *apiClient, QObject *parent)
|
|
|
|
: DTO::BaseItemDto(data),
|
|
|
|
QObject(parent),
|
|
|
|
m_apiClient(nullptr) {
|
|
|
|
setApiClient(apiClient);
|
2021-03-24 19:04:03 +00:00
|
|
|
}
|
|
|
|
|
2021-03-25 16:32:00 +00:00
|
|
|
bool Item::sameAs(const DTO::BaseItemDto &other) {
|
2021-03-24 19:04:03 +00:00
|
|
|
return jellyfinId() == other.jellyfinId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::setApiClient(ApiClient *apiClient) {
|
|
|
|
if (m_apiClient != nullptr) {
|
2021-08-11 21:35:33 +00:00
|
|
|
disconnect(m_apiClient->eventbus(), &EventBus::itemUserDataUpdated,
|
|
|
|
this, &Item::updateUserData);
|
2021-03-24 19:04:03 +00:00
|
|
|
}
|
|
|
|
this->m_apiClient = apiClient;
|
|
|
|
if (apiClient != nullptr) {
|
2021-08-11 21:35:33 +00:00
|
|
|
QObject::connect(m_apiClient->eventbus(), &EventBus::itemUserDataUpdated,
|
|
|
|
this, &Item::updateUserData);
|
2021-03-24 19:04:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-11 21:35:33 +00:00
|
|
|
void Item::updateUserData(const QString &itemId, const DTO::UserItemDataDto &userData) {
|
|
|
|
if (itemId == this->jellyfinId()) {
|
2021-09-10 03:17:28 +00:00
|
|
|
this->m_userData = QSharedPointer<DTO::UserItemDataDto>::create(userData);
|
2021-08-11 21:35:33 +00:00
|
|
|
emit userDataChanged(userData);
|
|
|
|
}
|
2021-03-24 19:04:03 +00:00
|
|
|
}
|
2021-03-20 15:29:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|