예제 #1
0
void PodcastBackend::Unsubscribe(const Podcast& podcast) {
  // If this podcast is not already in the database, do nothing
  if (!podcast.is_valid()) {
    return;
  }

  QMutexLocker l(db_->Mutex());
  QSqlDatabase db(db_->Connect());
  ScopedTransaction t(&db);

  // Remove the podcast.
  QSqlQuery q("DELETE FROM podcasts WHERE ROWID = :id", db);
  q.bindValue(":id", podcast.database_id());
  q.exec();
  if (db_->CheckErrors(q)) return;

  // Remove all episodes in the podcast
  q = QSqlQuery("DELETE FROM podcast_episodes WHERE podcast_id = :id", db);
  q.bindValue(":id", podcast.database_id());
  q.exec();
  if (db_->CheckErrors(q)) return;

  t.Commit();

  emit SubscriptionRemoved(podcast);
}
예제 #2
0
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();
}