internet/podcasts: Fix crash when updating podcasts.
When a podcast is updated and the number of visible items is set in the podcast settings, child items that disappear from the view, and are deleted, are still referenced by the database id map. Move the removal code from SubscriptionRemoved to a common method and use that for this case.
This commit is contained in:
parent
ac3a0d33f7
commit
ef93e8211d
|
@ -395,6 +395,20 @@ QStandardItem* PodcastService::CreatePodcastItem(const Podcast& podcast) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PodcastService::RemovePodcastItem(QStandardItem* item) {
|
||||||
|
// Remove any episode ID -> item mappings for the episodes in this podcast.
|
||||||
|
for (int i = 0; i < item->rowCount(); ++i) {
|
||||||
|
QStandardItem* episode_item = item->child(i);
|
||||||
|
const int episode_id =
|
||||||
|
episode_item->data(Role_Episode).value<PodcastEpisode>().database_id();
|
||||||
|
|
||||||
|
episodes_by_database_id_.remove(episode_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove this podcast's row
|
||||||
|
model_->removeRow(item->row());
|
||||||
|
}
|
||||||
|
|
||||||
QStandardItem* PodcastService::CreatePodcastEpisodeItem(
|
QStandardItem* PodcastService::CreatePodcastEpisodeItem(
|
||||||
const PodcastEpisode& episode) {
|
const PodcastEpisode& episode) {
|
||||||
QStandardItem* item = new QStandardItem;
|
QStandardItem* item = new QStandardItem;
|
||||||
|
@ -621,18 +635,7 @@ void PodcastService::SubscriptionAdded(const Podcast& podcast) {
|
||||||
void PodcastService::SubscriptionRemoved(const Podcast& podcast) {
|
void PodcastService::SubscriptionRemoved(const Podcast& podcast) {
|
||||||
QStandardItem* item = podcasts_by_database_id_.take(podcast.database_id());
|
QStandardItem* item = podcasts_by_database_id_.take(podcast.database_id());
|
||||||
if (item) {
|
if (item) {
|
||||||
// Remove any episode ID -> item mappings for the episodes in this podcast.
|
RemovePodcastItem(item);
|
||||||
for (int i = 0; i < item->rowCount(); ++i) {
|
|
||||||
QStandardItem* episode_item = item->child(i);
|
|
||||||
const int episode_id = episode_item->data(Role_Episode)
|
|
||||||
.value<PodcastEpisode>()
|
|
||||||
.database_id();
|
|
||||||
|
|
||||||
episodes_by_database_id_.remove(episode_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove this episode's row
|
|
||||||
model_->removeRow(item->row());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,6 +862,6 @@ void PodcastService::ReloadPodcast(const Podcast& podcast) {
|
||||||
}
|
}
|
||||||
QStandardItem* item = podcasts_by_database_id_[podcast.database_id()];
|
QStandardItem* item = podcasts_by_database_id_[podcast.database_id()];
|
||||||
|
|
||||||
model_->invisibleRootItem()->removeRow(item->row());
|
RemovePodcastItem(item);
|
||||||
model_->invisibleRootItem()->appendRow(CreatePodcastItem(podcast));
|
model_->invisibleRootItem()->appendRow(CreatePodcastItem(podcast));
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,7 @@ class PodcastService : public InternetService {
|
||||||
|
|
||||||
QStandardItem* CreatePodcastItem(const Podcast& podcast);
|
QStandardItem* CreatePodcastItem(const Podcast& podcast);
|
||||||
QStandardItem* CreatePodcastEpisodeItem(const PodcastEpisode& episode);
|
QStandardItem* CreatePodcastEpisodeItem(const PodcastEpisode& episode);
|
||||||
|
void RemovePodcastItem(QStandardItem* item);
|
||||||
|
|
||||||
QModelIndex MapToMergedModel(const QModelIndex& index) const;
|
QModelIndex MapToMergedModel(const QModelIndex& index) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue