Пример #1
0
PodcastService::PodcastService(Application* app, InternetModel* parent)
    : InternetService(kServiceName, app, parent, parent),
      use_pretty_covers_(true),
      icon_loader_(new StandardItemIconLoader(app->album_cover_loader(), this)),
      backend_(app->podcast_backend()),
      model_(new PodcastServiceModel(this)),
      proxy_(new PodcastSortProxyModel(this)),
      context_menu_(nullptr),
      root_(nullptr),
      organise_dialog_(new OrganiseDialog(app_->task_manager())) {
  icon_loader_->SetModel(model_);
  proxy_->setSourceModel(model_);
  proxy_->setDynamicSortFilter(true);
  proxy_->sort(0);

  connect(backend_, SIGNAL(SubscriptionAdded(Podcast)),
          SLOT(SubscriptionAdded(Podcast)));
  connect(backend_, SIGNAL(SubscriptionRemoved(Podcast)),
          SLOT(SubscriptionRemoved(Podcast)));
  connect(backend_, SIGNAL(EpisodesAdded(PodcastEpisodeList)),
          SLOT(EpisodesAdded(PodcastEpisodeList)));
  connect(backend_, SIGNAL(EpisodesUpdated(PodcastEpisodeList)),
          SLOT(EpisodesUpdated(PodcastEpisodeList)));

  connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)),
          SLOT(CurrentSongChanged(Song)));
}
Пример #2
0
PodcastUpdater::PodcastUpdater(Application* app, QObject* parent)
  : QObject(parent),
    app_(app),
    update_interval_secs_(0),
    update_timer_(new QTimer(this)),
    loader_(new PodcastUrlLoader(this)),
    pending_replies_(0)
{
  connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
  connect(update_timer_, SIGNAL(timeout()), SLOT(UpdateAllPodcastsNow()));
  connect(app_->podcast_backend(), SIGNAL(SubscriptionAdded(Podcast)),
          SLOT(SubscriptionAdded(Podcast)));

  update_timer_->setSingleShot(true);

  ReloadSettings();
}
Пример #3
0
void PodcastBackend::Subscribe(Podcast* podcast) {
  // If this podcast is already in the database, do nothing
  if (podcast->is_valid()) {
    return;
  }

  // If there's an entry in the database with the same URL, take its data.
  Podcast existing_podcast = GetSubscriptionByUrl(podcast->url());
  if (existing_podcast.is_valid()) {
    *podcast = existing_podcast;
    return;
  }

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

  // Insert the podcast.
  QSqlQuery q("INSERT INTO podcasts (" + Podcast::kColumnSpec +
                  ")"
                  " VALUES (" +
                  Podcast::kBindSpec + ")",
              db);
  podcast->BindToQuery(&q);

  q.exec();
  if (db_->CheckErrors(q)) return;

  // Update the database ID.
  const int database_id = q.lastInsertId().toInt();
  podcast->set_database_id(database_id);

  // Update the IDs of any episodes.
  PodcastEpisodeList* episodes = podcast->mutable_episodes();
  for (auto it = episodes->begin(); it != episodes->end(); ++it) {
    it->set_podcast_database_id(database_id);
  }

  // Add those episodes to the database.
  AddEpisodes(episodes, &db);

  t.Commit();

  emit SubscriptionAdded(*podcast);
}