Line data Source code
1 : #ifndef RAWFEEDIMAGESIZEREWRITER_H
2 : #define RAWFEEDIMAGESIZEREWRITER_H
3 :
4 : #include <QObject>
5 : #include <QFutureWatcher>
6 : #include <QList>
7 : #include <QSet>
8 : #include <QUrl>
9 :
10 : #include "../parser/RawNews.h"
11 : #include "../FangObject.h"
12 : #include "HTMLSanitizer.h"
13 : #include "ImageGrabber.h"
14 :
15 : /*!
16 : \brief Takes a "raw" HTML feed and processes it in the following ways:
17 : - Tidy'd into XHTML fragments
18 : - Image sizes are baked in
19 : - Javascript is stripped
20 : - Common social media buttons removed
21 : - Tracking pixels? Nope.
22 :
23 : This class orchestrates the processing by delegating to:
24 : - HTMLSanitizer for HTML cleanup and XHTML conversion
25 : - ImageGrabber for fetching image dimensions
26 : */
27 : class RawFeedRewriter : public FangObject
28 : {
29 : Q_OBJECT
30 : public:
31 : explicit RawFeedRewriter(QObject *parent = nullptr,
32 : QNetworkAccessManager* networkManager = nullptr);
33 :
34 :
35 : signals:
36 : /*!
37 : \brief We're done! The feed you passed in as been modified.
38 : */
39 : void finished();
40 :
41 : public slots:
42 :
43 : void rewrite(QList<RawNews*>* newsList);
44 :
45 : /*!
46 : \return The news list being processed.
47 : */
48 0 : inline QList<RawNews*>* getNewsList() { return newsList; }
49 :
50 : private slots:
51 : void onImageGrabberFinished();
52 : void onSanitizeFinished();
53 :
54 : private:
55 : void finalizeAll();
56 :
57 : QList<RawNews*>* newsList;
58 : HTMLSanitizer sanitizer;
59 : ImageGrabber imageGrabber;
60 : QFutureWatcher<QSet<QUrl>> sanitizeWatcher;
61 : QFutureWatcher<void> finalizeWatcher;
62 : };
63 :
64 : #endif // RAWFEEDIMAGESIZEREWRITER_H
|