1 /* This file is part of Clementine.
2 Copyright 2012, David Sansome <me@davidsansome.com>
3 Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
4 Copyright 2014, John Maguire <john.maguire@gmail.com>
5
6 Clementine is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Clementine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "fixedopmlpage.h"
21
22 #include <QMessageBox>
23
24 #include "podcastdiscoverymodel.h"
25 #include "podcasturlloader.h"
26 #include "core/closure.h"
27
FixedOpmlPage(const QUrl & opml_url,const QString & title,const QIcon & icon,Application * app,QWidget * parent)28 FixedOpmlPage::FixedOpmlPage(const QUrl& opml_url, const QString& title,
29 const QIcon& icon, Application* app,
30 QWidget* parent)
31 : AddPodcastPage(app, parent),
32 loader_(new PodcastUrlLoader(this)),
33 opml_url_(opml_url),
34 done_initial_load_(false) {
35 setWindowTitle(title);
36 setWindowIcon(icon);
37 }
38
Show()39 void FixedOpmlPage::Show() {
40 if (!done_initial_load_) {
41 emit Busy(true);
42 done_initial_load_ = true;
43
44 PodcastUrlLoaderReply* reply = loader_->Load(opml_url_);
45 NewClosure(reply, SIGNAL(Finished(bool)), this,
46 SLOT(LoadFinished(PodcastUrlLoaderReply*)), reply);
47 }
48 }
49
LoadFinished(PodcastUrlLoaderReply * reply)50 void FixedOpmlPage::LoadFinished(PodcastUrlLoaderReply* reply) {
51 reply->deleteLater();
52 emit Busy(false);
53
54 if (!reply->is_success()) {
55 QMessageBox::warning(this, tr("Failed to load podcast"),
56 reply->error_text(), QMessageBox::Close);
57 return;
58 }
59
60 switch (reply->result_type()) {
61 case PodcastUrlLoaderReply::Type_Podcast:
62 for (const Podcast& podcast : reply->podcast_results()) {
63 model()->appendRow(model()->CreatePodcastItem(podcast));
64 }
65 break;
66
67 case PodcastUrlLoaderReply::Type_Opml:
68 model()->CreateOpmlContainerItems(reply->opml_results(),
69 model()->invisibleRootItem());
70 break;
71 }
72 }
73