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