void EpisodeModel::setEpisode(int episode) { if (_episode == episode) return; _episode = episode; load(); emit episodeChanged(); }
void SubtitleListModel::setEpisode(int episode) { if (_episode == episode) return; _episode = episode; load(); emit episodeChanged(); }
void PodcastEpisodesModel::addEpisodes(QList<PodcastEpisode *> episodes) { if (episodes.isEmpty()) { return; } QDateTime modelsLatestEpisode; if (m_episodes.isEmpty()) { modelsLatestEpisode = QDateTime(); } else { modelsLatestEpisode = m_episodes.at(0)->pubTime(); } QDateTime dbsLatestEpisode = m_sqlmanager->latestEpisodeTimestampInDB(m_channelId); PodcastEpisode *episode; QList<PodcastEpisode *> newEpisodesToAdd; // Add the episode to the UI model if its timestamp is > modelsLatestEpisode. By default the modelsLatestEpisode // is the result of the most recent model population - with or without episodes added to the DB. // If the episode also has a timestmap > dbsLatestEpisode, then also add it to the DB. // Last query the latest timestamp of all channel's episodes after the operation. for(int i=episodes.size()-1; i>=0; i--) { episode = episodes.at(i); // Take the last episode in the new model. if (episode->pubTime() > modelsLatestEpisode) { // If this episodes has a more recent timestamp, add to model. qDebug() << "Adding to UI..."; beginInsertRows(QModelIndex(), 0, 0); m_episodes.prepend(episode); // Since we took that last item from the new episodes model, we add this item first to the view. endInsertRows(); // When we do this for new episodes not yet in the model, all new episodes (episode->pubTime() > modelsLatestEpisode) // ends up on top of the list. Note that the QModelIndex is also updated accordingly. episode->setChannelId(m_channelId); connect(episode, SIGNAL(episodeChanged()), this, SLOT(onEpisodeChanged())); if (episode->pubTime() > dbsLatestEpisode) { newEpisodesToAdd << episode; } } } if (!newEpisodesToAdd.isEmpty()) { qDebug() << "Adding new episodes to DB: " << newEpisodesToAdd.size(); m_sqlmanager->podcastEpisodesToDB(newEpisodesToAdd, m_channelId); m_latestEpisodeTimestamp = m_sqlmanager->latestEpisodeTimestampInDB(m_channelId); } else { qDebug() << "No new episodes to be added to the DB."; } }