diff --git a/data/data.qrc b/data/data.qrc index 764267795..b44a0e37c 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -342,5 +342,6 @@ providers/podcast32.png providers/mygpo32.png providers/itunes.png + providers/bbc.png diff --git a/data/providers/bbc.png b/data/providers/bbc.png new file mode 100644 index 000000000..d00a8dc28 Binary files /dev/null and b/data/providers/bbc.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a2770279d..5aa51425f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -231,6 +231,7 @@ set(SOURCES podcasts/addpodcastbyurl.cpp podcasts/addpodcastdialog.cpp podcasts/addpodcastpage.cpp + podcasts/fixedopmlpage.cpp podcasts/gpoddersearchpage.cpp podcasts/gpoddertoptagsmodel.cpp podcasts/gpoddertoptagspage.cpp @@ -483,6 +484,7 @@ set(HEADERS podcasts/addpodcastbyurl.h podcasts/addpodcastdialog.h podcasts/addpodcastpage.h + podcasts/fixedopmlpage.h podcasts/gpoddersearchpage.h podcasts/gpoddertoptagsmodel.h podcasts/gpoddertoptagspage.h diff --git a/src/podcasts/addpodcastdialog.cpp b/src/podcasts/addpodcastdialog.cpp index f0774eec7..17fb7fd16 100644 --- a/src/podcasts/addpodcastdialog.cpp +++ b/src/podcasts/addpodcastdialog.cpp @@ -17,6 +17,7 @@ #include "addpodcastdialog.h" #include "addpodcastbyurl.h" +#include "fixedopmlpage.h" #include "gpoddersearchpage.h" #include "gpoddertoptagspage.h" #include "itunessearchpage.h" @@ -29,6 +30,8 @@ #include +const char* AddPodcastDialog::kBbcOpmlUrl = "http://www.bbc.co.uk/podcasts.opml"; + AddPodcastDialog::AddPodcastDialog(Application* app, QWidget* parent) : QDialog(parent), app_(app), @@ -57,6 +60,8 @@ AddPodcastDialog::AddPodcastDialog(Application* app, QWidget* parent) // Add providers AddPage(new AddPodcastByUrl(app, this)); + AddPage(new FixedOpmlPage(QUrl(kBbcOpmlUrl), tr("BBC Podcasts"), + QIcon(":providers/bbc.png"), app, this)); AddPage(new GPodderTopTagsPage(app, this)); AddPage(new GPodderSearchPage(app, this)); AddPage(new ITunesSearchPage(app, this)); diff --git a/src/podcasts/addpodcastdialog.h b/src/podcasts/addpodcastdialog.h index 75022d8c4..534fc089d 100644 --- a/src/podcasts/addpodcastdialog.h +++ b/src/podcasts/addpodcastdialog.h @@ -36,6 +36,8 @@ public: AddPodcastDialog(Application* app, QWidget* parent = 0); ~AddPodcastDialog(); + static const char* kBbcOpmlUrl; + private slots: void AddPodcast(); void RemovePodcast(); diff --git a/src/podcasts/fixedopmlpage.cpp b/src/podcasts/fixedopmlpage.cpp new file mode 100644 index 000000000..6ec42b041 --- /dev/null +++ b/src/podcasts/fixedopmlpage.cpp @@ -0,0 +1,70 @@ +/* This file is part of Clementine. + Copyright 2012, David Sansome + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "fixedopmlpage.h" +#include "podcastdiscoverymodel.h" +#include "podcasturlloader.h" +#include "core/closure.h" + +#include + +FixedOpmlPage::FixedOpmlPage(const QUrl& opml_url, const QString& title, + const QIcon& icon, Application* app, + QWidget* parent) + : AddPodcastPage(app, parent), + loader_(new PodcastUrlLoader(this)), + opml_url_(opml_url), + done_initial_load_(false) +{ + setWindowTitle(title); + setWindowIcon(icon); +} + +void FixedOpmlPage::Show() { + if (!done_initial_load_) { + emit Busy(true); + done_initial_load_ = true; + + PodcastUrlLoaderReply* reply = loader_->Load(opml_url_); + NewClosure(reply, SIGNAL(Finished(bool)), + this, SLOT(LoadFinished(PodcastUrlLoaderReply*)), + reply); + } +} + +void FixedOpmlPage::LoadFinished(PodcastUrlLoaderReply* reply) { + reply->deleteLater(); + emit Busy(false); + + if (!reply->is_success()) { + QMessageBox::warning(this, tr("Failed to load podcast"), + reply->error_text(), QMessageBox::Close); + return; + } + + switch (reply->result_type()) { + case PodcastUrlLoaderReply::Type_Podcast: + foreach (const Podcast& podcast, reply->podcast_results()) { + model()->appendRow(model()->CreatePodcastItem(podcast)); + } + break; + + case PodcastUrlLoaderReply::Type_Opml: + model()->CreateOpmlContainerItems(reply->opml_results(), model()->invisibleRootItem()); + break; + } +} diff --git a/src/podcasts/fixedopmlpage.h b/src/podcasts/fixedopmlpage.h new file mode 100644 index 000000000..af0315079 --- /dev/null +++ b/src/podcasts/fixedopmlpage.h @@ -0,0 +1,48 @@ +/* This file is part of Clementine. + Copyright 2012, David Sansome + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef FIXEDOPMLPAGE_H +#define FIXEDOPMLPAGE_H + +#include "addpodcastpage.h" + +#include + +class PodcastUrlLoader; +class PodcastUrlLoaderReply; + +class FixedOpmlPage : public AddPodcastPage { + Q_OBJECT + +public: + FixedOpmlPage(const QUrl& opml_url, const QString& title, const QIcon& icon, + Application* app, QWidget* parent = 0); + + bool has_visible_widget() const { return false; } + void Show(); + +private slots: + void LoadFinished(PodcastUrlLoaderReply* reply); + +private: + PodcastUrlLoader* loader_; + QUrl opml_url_; + + bool done_initial_load_; +}; + +#endif // FIXEDOPMLPAGE_H diff --git a/src/podcasts/podcasturlloader.cpp b/src/podcasts/podcasturlloader.cpp index cfb2e1ff4..55a9b47f7 100644 --- a/src/podcasts/podcasturlloader.cpp +++ b/src/podcasts/podcasturlloader.cpp @@ -79,8 +79,10 @@ QUrl PodcastUrlLoader::FixPodcastUrl(const QString& url_text) const { } PodcastUrlLoaderReply* PodcastUrlLoader::Load(const QString& url_text) { - QUrl url(FixPodcastUrl(url_text)); + return Load(FixPodcastUrl(url_text)); +} +PodcastUrlLoaderReply* PodcastUrlLoader::Load(const QUrl& url) { // Create a reply PodcastUrlLoaderReply* reply = new PodcastUrlLoaderReply(url, this); diff --git a/src/podcasts/podcasturlloader.h b/src/podcasts/podcasturlloader.h index 32b7fb196..8522bd89a 100644 --- a/src/podcasts/podcasturlloader.h +++ b/src/podcasts/podcasturlloader.h @@ -77,6 +77,7 @@ public: static const int kMaxRedirects; PodcastUrlLoaderReply* Load(const QString& url_text); + PodcastUrlLoaderReply* Load(const QUrl& url); private: struct RequestState {