void PodcastUpdater::PodcastLoaded(PodcastUrlLoaderReply* reply, const Podcast& podcast, bool one_of_many) { reply->deleteLater(); if (one_of_many) { if (--pending_replies_ == 0) { // This was the last reply we were waiting for. Save this time as being // the last sucessful update and restart the timer. last_full_update_ = QDateTime::currentDateTime(); SaveSettings(); RestartTimer(); } } if (!reply->is_success()) { qLog(Warning) << "Error fetching podcast at" << podcast.url() << ":" << reply->error_text(); return; } if (reply->result_type() != PodcastUrlLoaderReply::Type_Podcast) { qLog(Warning) << "The URL" << podcast.url() << "no longer contains a podcast"; return; } // Get the episode URLs we had for this podcast already. QSet<QUrl> existing_urls; foreach (const PodcastEpisode& episode, app_->podcast_backend()->GetEpisodes(podcast.database_id())) { existing_urls.insert(episode.url()); } // Add any new episodes PodcastEpisodeList new_episodes; foreach (const Podcast& reply_podcast, reply->podcast_results()) { foreach (const PodcastEpisode& episode, reply_podcast.episodes()) { if (!existing_urls.contains(episode.url())) { PodcastEpisode episode_copy(episode); episode_copy.set_podcast_database_id(podcast.database_id()); new_episodes.append(episode_copy); } } } app_->podcast_backend()->AddEpisodes(&new_episodes); qLog(Info) << "Added" << new_episodes.count() << "new episodes for" << podcast.url(); }
void PodcastUpdater::UpdatePodcastNow(const Podcast& podcast) { PodcastUrlLoaderReply* reply = loader_->Load(podcast.url()); NewClosure(reply, SIGNAL(Finished(bool)), this, SLOT(PodcastLoaded(PodcastUrlLoaderReply*,Podcast,bool)), reply, podcast, false); }