| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef FEEDREADER_H |
| 4 | #define FEEDREADER_H |
| 5 | |
| 6 | #include "core/feeddownloader.h" |
| 7 | #include "core/messagefilter.h" |
| 8 | #include "services/abstract/cacheforserviceroot.h" |
| 9 | #include "services/abstract/feed.h" |
| 10 | |
| 11 | #include <QObject> |
| 12 | |
| 13 | class FeedsModel; |
| 14 | class MessagesModel; |
| 15 | class MessagesProxyModel; |
| 16 | class FeedsProxyModel; |
| 17 | class ServiceEntryPoint; |
| 18 | class QTimer; |
| 19 | class QThread; |
| 20 | |
| 21 | class RSSGUARD_DLLSPEC FeedReader : public QObject { |
| 22 | Q_OBJECT |
| 23 | |
| 24 | public: |
| 25 | explicit FeedReader(QObject* parent = nullptr); |
| 26 | virtual ~FeedReader(); |
| 27 | |
| 28 | // List of all installed "feed service plugins". |
| 29 | QList<ServiceEntryPoint*> feedServices(); |
| 30 | |
| 31 | // Access to DB cleaner. |
| 32 | FeedDownloader* feedDownloader() const; |
| 33 | FeedsModel* feedsModel() const; |
| 34 | MessagesModel* messagesModel() const; |
| 35 | FeedsProxyModel* feedsProxyModel() const; |
| 36 | MessagesProxyModel* messagesProxyModel() const; |
| 37 | |
| 38 | // Update feeds in extra thread. |
| 39 | void updateFeeds(const QList<Feed*>& feeds, bool update_switched_off_too = false); |
| 40 | |
| 41 | // Push back cached message states back to servers in extra thread. |
| 42 | void synchronizeMessageData(const QList<CacheForServiceRoot*>& caches); |
| 43 | |
| 44 | void showMessageFiltersManager(); |
| 45 | |
| 46 | // True if feed update is running right now. |
| 47 | bool isFeedUpdateRunning() const; |
| 48 | |
| 49 | // Resets global auto-download intervals according to settings |
| 50 | // and starts/stop the timer as needed. |
| 51 | void updateAutoUpdateStatus(); |
| 52 | |
| 53 | bool autoUpdateEnabled() const; |
| 54 | int autoUpdateInterval() const; |
| 55 | QDateTime lastAutoUpdate() const; |
| 56 | |
| 57 | void loadSavedMessageFilters(); |
| 58 | QList<MessageFilter*> messageFilters() const; |
| 59 | MessageFilter* addMessageFilter(const QString& title, const QString& script); |
| 60 | void removeMessageFilter(MessageFilter* filter); |
| 61 | void updateMessageFilter(MessageFilter* filter); |
| 62 | void assignMessageFilterToFeed(Feed* feed, MessageFilter* filter); |
| 63 | void removeMessageFilterToFeedAssignment(Feed* feed, MessageFilter* filter); |
| 64 | |
| 65 | public slots: |
| 66 | void updateAllFeeds(); |
| 67 | void updateManuallyIntervaledFeeds(); |
| 68 | void stopRunningFeedUpdate(); |
| 69 | void pauseUnpaseFeedFetching(bool pause); |
| 70 | void quit(); |
| 71 | |
| 72 | private slots: |
| 73 | void executeNextAutoUpdate(); |
| 74 | void onFeedUpdatesFinished(FeedDownloadResults updated_feeds); |
| 75 | |
| 76 | signals: |
| 77 | void feedUpdatesStarted(); |
| 78 | void feedUpdatesFinished(FeedDownloadResults updated_feeds); |
| 79 | void feedUpdatesProgress(const Feed* feed, int current, int total); |
| 80 | |
| 81 | private: |
| 82 | void initializeFeedDownloader(); |
| 83 | |
| 84 | private: |
| 85 | QList<ServiceEntryPoint*> m_feedServices; |
| 86 | QList<MessageFilter*> m_messageFilters; |
| 87 | FeedsModel* m_feedsModel; |
| 88 | FeedsProxyModel* m_feedsProxyModel; |
| 89 | MessagesModel* m_messagesModel; |
| 90 | MessagesProxyModel* m_messagesProxyModel; |
| 91 | |
| 92 | // Auto-update stuff. |
| 93 | QTimer* m_autoUpdateTimer; |
| 94 | bool m_globalAutoUpdateEnabled{}; |
| 95 | bool m_globalAutoUpdateFast{}; |
| 96 | bool m_globalAutoUpdateOnlyUnfocused{}; |
| 97 | int m_globalAutoUpdateInterval{}; // In seconds. |
| 98 | QDateTime m_lastAutoUpdate; |
| 99 | QThread* m_feedDownloaderThread; |
| 100 | FeedDownloader* m_feedDownloader; |
| 101 | bool m_feedFetchingPaused; |
| 102 | }; |
| 103 | |
| 104 | #endif // FEEDREADER_H |