Line data Source code
1 : #ifndef BATCHFEEDFETCHER_H
2 : #define BATCHFEEDFETCHER_H
3 :
4 : #include <memory>
5 :
6 : #include <QHash>
7 : #include <QMap>
8 : #include <QUrl>
9 :
10 : #include "FeedSource.h"
11 : #include "RawFeed.h"
12 :
13 : /*!
14 : * \brief The BatchFeedFetcher is a wrapper for FeedFetcher that handles multiple feeds.
15 : */
16 : class BatchFeedFetcher : public QObject
17 : {
18 : Q_OBJECT
19 : public:
20 : explicit BatchFeedFetcher(QObject *parent = nullptr);
21 :
22 : // Parses a list of feed URLs and emits ready() when all are complete.
23 : virtual void parse(const QList<QUrl> &urls);
24 :
25 : // Map of parse results
26 10 : virtual QMap<QUrl, FeedFetchResult> getResults() { return results; }
27 :
28 : // Get parsed feed for a specific URL (nullptr if parse failed)
29 : virtual std::shared_ptr<RawFeed> getFeed(const QUrl& url);
30 :
31 : signals:
32 : void ready();
33 :
34 : protected:
35 : // Virtual method for creating parsers; can be overridden for unit tests.
36 : virtual std::shared_ptr<FeedSource> createParser();
37 :
38 : // Called whenever a parser is done.
39 : void onParserDone();
40 :
41 : // Parsers that are in flight.
42 : QMap<QUrl, std::shared_ptr<FeedSource>> parsers;
43 :
44 : // Reverse index: parser pointer -> original request URL.
45 : QHash<FeedSource*, QUrl> parserUrls;
46 :
47 : // Results of parsing per-URL.
48 : QMap<QUrl, FeedFetchResult> results;
49 :
50 : // Parsed feeds per-URL.
51 : QMap<QUrl, std::shared_ptr<RawFeed>> feeds;
52 : };
53 :
54 : #endif // BATCHFEEDFETCHER_H
|