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