Line data Source code
1 : #ifndef FEEDFETCHER_H
2 : #define FEEDFETCHER_H
3 :
4 : #include <memory>
5 :
6 : #include <QObject>
7 : #include <QString>
8 : #include <QNetworkReply>
9 : #include <QFutureWatcher>
10 :
11 : #include "FeedSource.h"
12 : #include "FeedParseResult.h"
13 : #include "QWebDownload.h"
14 :
15 : /*!
16 : PaRSSes RSS/Atom feeds into RawFeed/RawNews objects.
17 : */
18 : class FeedFetcher : public FeedSource
19 : {
20 : Q_OBJECT
21 :
22 : public:
23 : explicit FeedFetcher(QObject *parent = nullptr);
24 : explicit FeedFetcher(QNetworkAccessManager* networkManager, QObject *parent = nullptr);
25 : virtual ~FeedFetcher();
26 :
27 : public slots:
28 : void parse(const QUrl& url,
29 : const QString& ifNoneMatch = QString(),
30 : const QString& ifModifiedSince = QString()) override;
31 :
32 : FeedFetchResult getResult() override;
33 0 : QNetworkReply::NetworkError getNetworkError() { return networkError; }
34 : std::shared_ptr<RawFeed> getFeed() override;
35 5 : QUrl getURL() override { return finalFeedURL; }
36 :
37 3 : QString responseEtag() override { return respEtag; }
38 3 : QString responseLastModified() override { return respLastModified; }
39 5 : bool wasPermanentRedirect() const { return permanentRedirect; }
40 :
41 : private slots:
42 : // When the download completes (success or error).
43 : void onDownloadResult(WebDownloadResult downloadResult);
44 :
45 : private:
46 : // When parsing completes on the thread pool.
47 : void workerDone(FeedParseResult parseResult);
48 :
49 : void initParse(const QUrl& url = QUrl("")); // called prior to parse.
50 :
51 : std::shared_ptr<RawFeed> feed;
52 : FeedFetchResult result;
53 : QNetworkReply::NetworkError networkError;
54 :
55 : QWebDownload* downloader;
56 : QUrl finalFeedURL;
57 :
58 : QString respEtag;
59 : QString respLastModified;
60 :
61 : bool permanentRedirect;
62 :
63 : QFutureWatcher<FeedParseResult> parseWatcher;
64 : };
65 :
66 : #endif // FEEDFETCHER_H
|