File indexing completed on 2025-01-19 04:28:12
0001 /** 0002 * SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org> 0003 * SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "models/entriesmodel.h" 0009 0010 #include <QString> 0011 0012 #include "datamanager.h" 0013 #include "entry.h" 0014 #include "feed.h" 0015 0016 EntriesModel::EntriesModel(Feed *feed) 0017 : AbstractEpisodeModel(feed) 0018 , m_feed(feed) 0019 { 0020 // When feed is updated, the entire model needs to be reset because we 0021 // cannot know where the new entries will be inserted into the list (or that 0022 // maybe even items have been removed. 0023 connect(&DataManager::instance(), &DataManager::feedEntriesUpdated, this, [this](const QString &url) { 0024 if (m_feed->url() == url) { 0025 beginResetModel(); 0026 endResetModel(); 0027 } 0028 }); 0029 } 0030 0031 QVariant EntriesModel::data(const QModelIndex &index, int role) const 0032 { 0033 Entry *entry = DataManager::instance().getEntry(m_feed, index.row()); 0034 switch (role) { 0035 case AbstractEpisodeModel::Roles::TitleRole: 0036 return QVariant::fromValue(entry->title()); 0037 case AbstractEpisodeModel::Roles::EntryRole: 0038 return QVariant::fromValue(entry); 0039 case AbstractEpisodeModel::Roles::IdRole: 0040 return QVariant::fromValue(DataManager::instance().getIdList(m_feed)[index.row()]); 0041 case AbstractEpisodeModel::Roles::ReadRole: 0042 return QVariant::fromValue(entry->read()); 0043 case AbstractEpisodeModel::Roles::NewRole: 0044 return QVariant::fromValue(entry->getNew()); 0045 case AbstractEpisodeModel::Roles::FavoriteRole: 0046 return QVariant::fromValue(entry->favorite()); 0047 case AbstractEpisodeModel::Roles::ContentRole: 0048 return QVariant::fromValue(entry->content()); 0049 case AbstractEpisodeModel::Roles::FeedNameRole: 0050 return QVariant::fromValue(m_feed->name()); 0051 case AbstractEpisodeModel::Roles::UpdatedRole: 0052 return QVariant::fromValue(entry->updated()); 0053 default: 0054 return QVariant(); 0055 } 0056 } 0057 0058 int EntriesModel::rowCount(const QModelIndex &parent) const 0059 { 0060 Q_UNUSED(parent) 0061 return DataManager::instance().entryCount(m_feed); 0062 } 0063 0064 Feed *EntriesModel::feed() const 0065 { 0066 return m_feed; 0067 } 0068 0069 void EntriesModel::updateInternalState() 0070 { 0071 // nothing to do; DataManager already has the updated data. 0072 }