2012-03-06 22:25:16 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
2014-11-02 19:50:39 +01:00
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2014-11-01 19:38:39 +01:00
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-06 22:25:16 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-06 22:25:16 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-06 22:25:16 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gpoddersearchpage.h"
|
2014-12-13 02:24:20 +01:00
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2012-03-06 22:25:16 +01:00
|
|
|
#include "core/closure.h"
|
|
|
|
#include "core/network.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "podcast.h"
|
|
|
|
#include "podcastdiscoverymodel.h"
|
2015-10-14 03:01:08 +02:00
|
|
|
#include "ui/iconloader.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "ui_gpoddersearchpage.h"
|
2012-03-06 22:25:16 +01:00
|
|
|
|
|
|
|
GPodderSearchPage::GPodderSearchPage(Application* app, QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: AddPodcastPage(app, parent),
|
|
|
|
ui_(new Ui_GPodderSearchPage),
|
|
|
|
network_(new NetworkAccessManager(this)),
|
|
|
|
api_(new mygpo::ApiRequest(network_)) {
|
2012-03-06 22:25:16 +01:00
|
|
|
ui_->setupUi(this);
|
|
|
|
connect(ui_->search, SIGNAL(clicked()), SLOT(SearchClicked()));
|
2015-10-14 03:01:08 +02:00
|
|
|
setWindowIcon(IconLoader::Load("mygpo", IconLoader::Provider));
|
2012-03-06 22:25:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GPodderSearchPage::~GPodderSearchPage() {
|
|
|
|
delete ui_;
|
|
|
|
delete api_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPodderSearchPage::SearchClicked() {
|
|
|
|
emit Busy(true);
|
|
|
|
|
2012-03-19 20:35:59 +01:00
|
|
|
mygpo::PodcastListPtr list(api_->search(ui_->query->text()));
|
2014-02-07 16:34:20 +01:00
|
|
|
NewClosure(list, SIGNAL(finished()), this,
|
|
|
|
SLOT(SearchFinished(mygpo::PodcastListPtr)), list);
|
|
|
|
NewClosure(list, SIGNAL(parseError()), this,
|
|
|
|
SLOT(SearchFailed(mygpo::PodcastListPtr)), list);
|
|
|
|
NewClosure(list, SIGNAL(requestError(QNetworkReply::NetworkError)), this,
|
|
|
|
SLOT(SearchFailed(mygpo::PodcastListPtr)), list);
|
2012-03-06 22:25:16 +01:00
|
|
|
}
|
|
|
|
|
2012-03-19 22:16:37 +01:00
|
|
|
void GPodderSearchPage::SearchFinished(mygpo::PodcastListPtr list) {
|
2012-03-06 22:25:16 +01:00
|
|
|
emit Busy(false);
|
|
|
|
|
|
|
|
model()->clear();
|
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (mygpo::PodcastPtr gpo_podcast : list->list()) {
|
2012-03-06 22:25:16 +01:00
|
|
|
Podcast podcast;
|
|
|
|
podcast.InitFromGpo(gpo_podcast.data());
|
|
|
|
|
|
|
|
model()->appendRow(model()->CreatePodcastItem(podcast));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 22:16:37 +01:00
|
|
|
void GPodderSearchPage::SearchFailed(mygpo::PodcastListPtr list) {
|
2012-03-06 22:25:16 +01:00
|
|
|
emit Busy(false);
|
|
|
|
|
|
|
|
model()->clear();
|
|
|
|
|
|
|
|
if (QMessageBox::warning(
|
2014-02-07 16:34:20 +01:00
|
|
|
nullptr, tr("Failed to fetch podcasts"),
|
|
|
|
tr("There was a problem communicating with gpodder.net"),
|
|
|
|
QMessageBox::Retry | QMessageBox::Close,
|
|
|
|
QMessageBox::Retry) != QMessageBox::Retry) {
|
2012-03-06 22:25:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try doing the search again.
|
|
|
|
SearchClicked();
|
|
|
|
}
|
2012-03-09 20:12:45 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void GPodderSearchPage::Show() { ui_->query->setFocus(); }
|