Clementine-audio-player-Mac.../src/internet/podcasts/podcasturlloader.h

115 lines
3.3 KiB
C
Raw Permalink Normal View History

2012-03-05 19:15:45 +01:00
/* This file is part of Clementine.
Copyright 2012, David Sansome <me@davidsansome.com>
Copyright 2014, John Maguire <john.maguire@gmail.com>
2014-11-02 19:50:39 +01:00
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
2012-03-05 19:15:45 +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.
2012-03-05 19:15:45 +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.
2012-03-05 19:15:45 +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/>.
*/
2014-12-18 23:54:21 +01:00
#ifndef INTERNET_PODCASTS_PODCASTURLLOADER_H_
#define INTERNET_PODCASTS_PODCASTURLLOADER_H_
2012-03-05 19:15:45 +01:00
#include <QObject>
#include <QRegExp>
2012-03-07 16:11:56 +01:00
#include "opmlcontainer.h"
2012-03-05 19:15:45 +01:00
#include "podcast.h"
class PodcastParser;
class QNetworkAccessManager;
class QNetworkReply;
class PodcastUrlLoaderReply : public QObject {
Q_OBJECT
public:
2012-03-05 19:15:45 +01:00
PodcastUrlLoaderReply(const QUrl& url, QObject* parent);
enum ResultType { Type_Podcast, Type_Opml };
2012-03-07 16:11:56 +01:00
2012-03-05 19:15:45 +01:00
const QUrl& url() const { return url_; }
bool is_finished() const { return finished_; }
bool is_success() const { return error_text_.isEmpty(); }
const QString& error_text() const { return error_text_; }
2012-03-07 16:11:56 +01:00
ResultType result_type() const { return result_type_; }
const PodcastList& podcast_results() const { return podcast_results_; }
const OpmlContainer& opml_results() const { return opml_results_; }
2012-03-05 19:15:45 +01:00
void SetFinished(const QString& error_text);
void SetFinished(const PodcastList& results);
2012-03-07 16:11:56 +01:00
void SetFinished(const OpmlContainer& results);
2012-03-05 19:15:45 +01:00
2014-02-07 20:34:34 +01:00
signals:
2012-03-05 19:15:45 +01:00
void Finished(bool success);
private:
2012-03-05 19:15:45 +01:00
QUrl url_;
bool finished_;
QString error_text_;
2012-03-07 16:11:56 +01:00
ResultType result_type_;
PodcastList podcast_results_;
OpmlContainer opml_results_;
2012-03-05 19:15:45 +01:00
};
class PodcastUrlLoader : public QObject {
Q_OBJECT
public:
2014-02-10 14:20:20 +01:00
explicit PodcastUrlLoader(QObject* parent = nullptr);
2012-03-05 19:15:45 +01:00
~PodcastUrlLoader();
static const int kMaxRedirects;
PodcastUrlLoaderReply* Load(const QString& url_text);
2012-03-07 16:31:12 +01:00
PodcastUrlLoaderReply* Load(const QUrl& url);
2012-03-05 19:15:45 +01:00
// Both the FixPodcastUrl functions replace common podcatcher URL schemes
// like itpc:// or zune:// with their http:// equivalents. The QString
// overload also cleans up user-entered text a bit - stripping whitespace and
// applying shortcuts like sc:tag.
static QUrl FixPodcastUrl(const QString& url_text);
static QUrl FixPodcastUrl(const QUrl& url);
private:
2012-03-05 19:15:45 +01:00
struct RequestState {
int redirects_remaining_;
PodcastUrlLoaderReply* reply_;
};
typedef QPair<QString, QString> QuickPrefix;
typedef QList<QuickPrefix> QuickPrefixList;
private slots:
2012-03-05 19:15:45 +01:00
void RequestFinished(RequestState* state, QNetworkReply* reply);
private:
2012-03-05 19:15:45 +01:00
void SendErrorAndDelete(const QString& error_text, RequestState* state);
void NextRequest(const QUrl& url, RequestState* state);
private:
2012-03-05 19:15:45 +01:00
QNetworkAccessManager* network_;
PodcastParser* parser_;
QRegExp html_link_re_;
QRegExp whitespace_re_;
QRegExp html_link_rel_re_;
QRegExp html_link_type_re_;
QRegExp html_link_href_re_;
};
2014-12-18 23:54:21 +01:00
#endif // INTERNET_PODCASTS_PODCASTURLLOADER_H_